richardkiss / pycoin

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

ValueError: p2sh_lookup not set #76

Closed shayanb closed 9 years ago

shayanb commented 9 years ago

I'm trying to write a python code to spend from the generated P2SH address and I've been getting this error: ValueError: p2sh_lookup not set

I then tried running it with the following command (tx script) and got the same error.

tx -a -i 33byJBaS5N45RHFcatTSt9ZjiGb6nK4iV3 -F 0 -f ./wifs.txt -u 1shaYanre36PBhspFL9zG7nt6tfDhxQ4u

signing...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/tx", line 9, in <module>
    load_entry_point('pycoin==0.53', 'console_scripts', 'tx')()
  File "../pycoin-master/pycoin/scripts/tx.py", line 408, in main
    sign_tx(tx, wif_iter(key_iters))
  File "../pycoin-master/pycoin/tx/tx_utils.py", line 170, in sign_tx
    tx.sign(LazySecretExponentDB(wifs, secret_exponent_db))
  File "../pycoin-master/pycoin/tx/Tx.py", line 355, in sign
    self.sign_tx_in(hash160_lookup, idx, self.unspents[idx].script, hash_type=hash_type, **kwargs)
  File "../pycoin-master/pycoin/tx/Tx.py", line 232, in sign_tx_in
    existing_script=self.txs_in[tx_in_idx].script, **kwargs)
  File "../pycoin-master/pycoin/tx/pay_to/ScriptPayToScript.py", line 36, in solve
    raise ValueError("p2sh_lookup not set")
ValueError: p2sh_lookup not set
richardkiss commented 9 years ago

To sign a pay-to-script, you need to set p2sh_lookup to a dictionary that has hashes as keys and the corresponding script as values. Take a look at https://github.com/richardkiss/pycoin/blob/master/tests/pay_to_test.py#L151 as an example.

The tx tool should allow a list of scripts as an input, either from a file or directly on a command line (but it currently doesn't).

richardkiss commented 9 years ago

I took a first crack at solving this... I added a -p and -P option to the tx tool which might even work. If you'd like to try it, use the https://github.com/richardkiss/pycoin/tree/add_p2sh trunk, and pass the pay-to-script script as a hex string after -p (or put it into a file and pass the path to the file with -P).