def doit(raw_txn): # verify our understanding of a TXN (and esp its outputs) matches # the same values as what bitcoind generates try: return bitcoind.decoderawtransaction(B2A(raw_txn)) except ConnectionResetError: # bitcoind sleeps on us sometimes, give it another chance. return bitcoind.decoderawtransaction(B2A(raw_txn))
def doit(hex_txn, fee, num_warn=0, change_outs=None, dests=[]): # verify our understanding of a TXN (and esp its outputs) matches # the same values as what bitcoind generates try: decode = bitcoind.decoderawtransaction(hex_txn) except ConnectionResetError: # bitcoind sleeps on us sometimes, give it another chance. decode = bitcoind.decoderawtransaction(hex_txn) #print("Bitcoin code says:", end=''); pprint(decode) if dests: # check we got right destination address(es) for outn, expect_addr in dests: assert decode['vout'][outn]['scriptPubKey']['addresses'][ 0] == expect_addr # leverage bitcoind's transaction decoding ex = dict( lock_time=decode['locktime'], had_witness=False, # input txn doesn't have them, typical? num_inputs=len(decode['vin']), num_outputs=len(decode['vout']), miner_fee=U2SAT(fee), warnings_expected=num_warn, total_value_out=sum(U2SAT(i['value']) for i in decode['vout']), destinations=[(U2SAT(i['value']), i['scriptPubKey']['addresses'][0]) for i in decode['vout']], ) if change_outs is not None: ex['change_outs'] = set(change_outs) # need this for reliability time.sleep(0.01) # check we understood it right rv = sim_exec('import main; main.EXPECT = %r; ' % ex) if rv: pytest.fail(rv) rv = sim_execfile('devtest/check_decode.py') if rv: pytest.fail(rv) print(" [checks out against bitcoind] ") return decode