def get_tx_info(conn, token_system, txid, pars=None): if token_system: import rpc_erachain return rpc_erachain.get_tx_info(token_system, txid) elif not conn: return None res = None try: res = conn.gettransaction(txid) except Exception as e: res = {'error': e} pass return res
def sender_addr(conn, token_system, tr): if token_system: import rpc_erachain return rpc_erachain.get_tx_info(token_system, tr)['creator'] elif not conn: return None tr_info = conn.getrawtransaction(tr, 1) vins = tr_info and 'vin' in tr_info and tr_info['vin'] if not vins: #res.append({ 'tr_info.vins': 'None'}) # тут может быть приход с добвтого блока - тогда тоже будет пусто! print 'ERROR: sender_addr - tr_in_info:', tr_in_info print 'RUN "crypto WALLET.exe" -reindex -txindex' return vin = vins[0] txid = vin['txid'] vout = vin['vout'] tr_in_info = conn.getrawtransaction(txid, 1) if 'error' in tr_in_info: print 'ERROR: sender_addr - tr_in_info:', tr_in_info print 'RUN "crypto WALLET.exe" -reindex -txindex' return vin = vins[0] txid = vin['txid'] vout = vin['vout'] tr_in_info = conn.getrawtransaction(txid, 1) if 'error' in tr_in_info: print 'ERROR: sender_addr - tr_in_info:', tr_in_info print 'RUN "crypto WALLET.exe" -reindex -txindex' return sender = tr_in_info[u'vout'][vout][u'scriptPubKey'][u'addresses'] return sender[0]
def get_incomed(db, token_system, from_block_in=None): erachain_addr = token_system.account erachain_rpc = token_system.connect_url tab = [] curr_block = rpc_erachain.get_info(erachain_rpc) print curr_block if type(curr_block) != type(1): # кошелек еще не запустился print 'not started else' return tab, from_block_in # если переиндексация то возможно что и меньше from_block = from_block_in or token_system.from_block if from_block: if not curr_block > from_block: print 'not curr_block > from_block', curr_block, from_block return tab, from_block # если переиндексация то возможно что и меньше print from_block, '-->', curr_block, erachain_addr tab, curr_block = rpc_erachain.get_transactions(token_system, erachain_rpc, erachain_addr, from_block, token_system.conf) if curr_block == None: return [], None else: # если нет еще номера обработанного блока # то и делать нечего - мол служба только запущена # на нее нет еще переводоов, хотя можно наоборот взять все входы token_system.from_block = from_block = 1 # все входы со всеми подтверждениями берем token_system.update_record() tab, curr_block = rpc_erachain.get_transactions(token_system, erachain_rpc, erachain_addr, conf = token_system.conf) if curr_block == None: return [], None print tab, curr_block transactions = [] for rec in tab: acc = parse_mess(db, rec.get('title'), rec.get('creator')) if not acc: acc = parse_mess(db, rec.get('message'), rec.get('creator')) if not acc: continue # make record INCOME from Erachain TRANSACTION make_rec(erachain_addr, acc, rec, transactions) lines = rec.get('message') if lines: lines = lines.strip().split('\n') if lines and len(lines) > 1: for line in lines: #try: if True: command = line.split(':') if len(command) > 1: if command[0].strip().lower() == 'add': ## ADD transactions without payments details to that payment ## need for txid in command[1].strip().split(' '): # see this TX in DB and set DETAILS pay_in = db(db.pay_ins.txid == txid).select().first() if pay_in: # already assigned continue recAdded = rpc_erachain.get_tx_info(token_system, txid.strip()) if not recAdded or 'creator' not in recAdded or recAdded['creator'] != rec['creator']: # set payment details only for this creator records continue # make record INCOME from Erachain TRANSACTION make_rec(erachain_addr, acc, recAdded, transactions) #except Exception as e: else: mess = 'COMMAND: %s - %s' % (line, e) log(db, mess) return transactions, curr_block