pycoin icon indicating copy to clipboard operation
pycoin copied to clipboard

Tx.txs_in[x].bitcoin_address() returns '(unknown)' for P2SH

Open ulrichard opened this issue 8 years ago • 3 comments

I tried to get the address manually, but that leads to a wrong result: ` txhex = '010000000112f5d425f34045c53d7371c10379fc7a56267ee5663244ce4bb052fa7a73125300000000fdfe0000483045022100f128cb729c2fbf8b05408d1b96c3325a47c35e2b0ce8dd8f0c90883f585a730a022044a2df347bf3e4debcfed919ae2631733c5cb5ff2c7321401090f75f591f684501483045022100af4182f1f78f13a0c41f74e5c261ed8485b9df47411cac57f78eaad57be1099902207933cb57d02f915b6e049f3985843681adf923c161a4f27db6853e581a239adb014c695221030fdc2ebc297df4047442f6079f1ce3b7d1938a41f88bd11497545cc94fcfd3152102b243af0f2dadafcebf00d8aa3506c4178d8fe00e359dd97f63ab8f9ec798b02f2102e182cad9635ff99d13555e28141aadd061b7c6b7f3f4bb1186eb12218e52c0a553aeffffffff02c0320a03000000001976a9141d7ec16c05ee7d18be6dfab0b682495bc4fe101788ac40420f00000000001976a91498a71b69e8ca462056707a313d1b3c522ae0acc288ac00000000'

tx = pycoin.tx.Tx.from_hex(txhex) for inp in tx.txs_in: addr = inp.bitcoin_address() if addr == '(unknown)': addr = pycoin.tx.pay_to.address_for_pay_to_script(inp.script) print(addr) `

ulrichard avatar Dec 16 '16 19:12 ulrichard

Yeah, pycoin doesn't currently get the bitcoin address for TxIn scripts except pay-to-address. Patches are welcome!

richardkiss avatar Dec 17 '16 07:12 richardkiss

If you fetch the unspents for the transaction, you can get the address from the TxOut. For example,

$ export PYCOIN_BTC_PROVIDERS=blockchain.info
$ tx -a efac648ac2c6fb8d00856a283e25850362fbcf4ab4f6f50abd57146aec60e6ff 
warning: transaction fees recommendations casually calculated and estimates may be incorrect
warning: transaction fee of 0.2 exceeds expected value of 0.1 mBTC
Version:  1  tx hash efac648ac2c6fb8d00856a283e25850362fbcf4ab4f6f50abd57146aec60e6ff  375 bytes
TxIn count: 1; TxOut count: 2
Lock time: 0 (valid anytime)
Input:
   0: 3HFwTTCdUAeYH1dyeguPddt6iY1gbFoFus from 5312737afa52b04bce443266e57e26567afc7903c171733dc54540f325d4f512:0       520.20000 mBTC  sig ok
Outputs:
   0: 13gxShDdyZizjde6fKbTXS1hKfysbYMH1k receives    510.00000 mBTC
   1: 1Ev9txoFwW7EeCxy1k3fq4i51cW682XAnZ receives     10.00000 mBTC
Total input     520.20000 mBTC
Total output    520.00000 mBTC
Total fees        0.20000 mBTC
010000000112f5d425f34045c53d7371c10379fc7a56267ee5663244ce4bb052fa7a73125300000000fdfe0000483045022100f128cb729c2fbf8b05408d1b96c3325a47c35e2b0ce8dd8f0c90883f585a730a022044a2df347bf3e4debcfed919ae2631733c5cb5ff2c7321401090f75f591f684501483045022100af4182f1f78f13a0c41f74e5c261ed8485b9df47411cac57f78eaad57be1099902207933cb57d02f915b6e049f3985843681adf923c161a4f27db6853e581a239adb014c695221030fdc2ebc297df4047442f6079f1ce3b7d1938a41f88bd11497545cc94fcfd3152102b243af0f2dadafcebf00d8aa3506c4178d8fe00e359dd97f63ab8f9ec798b02f2102e182cad9635ff99d13555e28141aadd061b7c6b7f3f4bb1186eb12218e52c0a553aeffffffff02c0320a03000000001976a9141d7ec16c05ee7d18be6dfab0b682495bc4fe101788ac40420f00000000001976a91498a71b69e8ca462056707a313d1b3c522ae0acc288ac00000000
all incoming transaction values validated

richardkiss avatar Oct 22 '17 00:10 richardkiss

I'm reopening this issue as a note to self, but it's a difficult problem in general, and can guess wrong if the TxOut script is non-standard.

richardkiss avatar Oct 22 '17 00:10 richardkiss