richardkiss / pycoin

Python-based Bitcoin and alt-coin utility library.
MIT License
1.4k stars 499 forks source link

TypeError: info() got an unexpected keyword argument 'netcode' after upgrade to 0.76 #225

Closed F483 closed 7 years ago

F483 commented 7 years ago

I upgraded from 0.70 to 0.76 and while I managed to fix most of my code that broke I have to work around this bug in a rather ugly manner.

The bug seems to stem from an inconsistent script type interface.

Code:

(env)f483@f483-laptop ~/dev/upstream/pycoin $ cat example_b.py 
from pycoin.tx import Tx
from pycoin.serialize import b2h_rev

UTXO_TXID = "86cc2a88f74383ed076d3645611a7dd955783d314aae3a1d42134e7d62d20580"
UTXO_RAWTX = (
    "0100000001cab352216252a0e2b64d5a7e1d1476c614d87f77e151a9d154d350fc45384be"
    "7020000006b483045022100fb5f078545ad31fdac4830062049ea5a68759dc235533c0559"
    "e17575d2f9896302206c25381b01a3e344fcd08603ee2941a640e130dcaeb6e9a8bc78fb2"
    "0a302fc1d01210282b886c087eb37dc8182f14ba6cc3e9485ed618b95804d44aecc17c300"
    "b585b0ffffffff0340420f00000000001976a914d232442539b752b2a02b0fecf9f662240"
    "7a2cfc688ac00000000000000001e6a1c8a5dda15fb6f05628a061e67576e926dc71a7fa2"
    "f0cceb9745240f728e9c7e0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b373"
    "9c6303788ac00000000"
)
RAWTXS = {UTXO_TXID: UTXO_RAWTX}

RAWTX = (
    "01000000018005d2627d4e13421d3aae4a313d7855d97d1a6145366d07ed8343f7882acc8"
    "6000000006a473044022038097160418985ebd53646bf1885ba6c8f3a9cf4b37337ffe823"
    "1e60931e77b5022006f7cd16016e87e1e02f589863edef31439ac5d40a9ce324455df3e7d"
    "93dba5a012102957cdd4b8595ede10c90179721589dab6dc1fd5ab2404b03fae866cda36e"
    "b1bcffffffff031ed200000000000017a9146124ead52d95f4883a7f385056ffe2ae09c97"
    "be28700000000000000001e6a1c8a5dda15fb6f05628a061e67576e926dc71a7fa2f0cceb"
    "9745240f724e3f0e00000000001976a914d232442539b752b2a02b0fecf9f6622407a2cfc"
    "688ac00000000"
)

tx = Tx.from_hex(RAWTX)
for txin in tx.txs_in:
    prev_index = txin.previous_index
    prev_txid = b2h_rev(txin.previous_hash)
    utxo_rawtx = RAWTXS[prev_txid]
    utxo_tx = Tx.from_hex(utxo_rawtx)
    tx.unspents.append(utxo_tx.txs_out[prev_index])

for tx_out in tx.txs_out:
    address = tx_out.bitcoin_address(netcode="XTN")
    print("{0} -> {1}".format(tx_out.coin_value, address))

Error:

(env)f483@f483-laptop ~/dev/upstream/pycoin $ python example_b.py 
53790 -> 2N26skx9EnYwUS2SF5Aa5YREk7CENVJDENU
Traceback (most recent call last):
  File "example_b.py", line 39, in <module>
    address = tx_out.bitcoin_address(netcode="XTN")
  File "/home/f483/dev/upstream/pycoin/pycoin/tx/TxOut.py", line 66, in address
    return script_obj_from_script(self.script).address(netcode=netcode)
  File "/home/f483/dev/upstream/pycoin/pycoin/tx/pay_to/ScriptType.py", line 90, in address
    return self.info(netcode=netcode)["address_f"](netcode)
TypeError: info() got an unexpected keyword argument 'netcode'

Setup:

(env)f483@f483-laptop ~/dev/upstream/pycoin $ pip freeze
pycoin==0.76
wheel==0.29.0
richardkiss commented 7 years ago

Great catch. Long term, I hope to remove these classes and create a generalized intelligent script parser. For now, this problem needs to be fixed. Are you okay with me incorporating this transaction into a test case? (Or, are you willing to do so?)

F483 commented 7 years ago

Sure, feel free to add this to your test cases.

richardkiss commented 7 years ago

Test case added in e939216b752ede45b0febc8f9e8a5cc8ef809c82