Advertisement
Guest User

Untitled

a guest
Mar 1st, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. from helper import decode_base58, little_endian_to_int, hash256, SIGHASH_ALL, hash160, h160_to_p2sh_address
  2. from script import p2pkh_script, p2sh_script, Script
  3. from tx import TxIn, TxOut, Tx
  4. from ecc import PrivateKey
  5.  
  6. # make a tx from a p2sh address
  7.  
  8. secret1 = little_endian_to_int(hash256(b'dat_test_private_key_p2sh1'))
  9.  
  10. secret2 = little_endian_to_int(hash256(b'dat_test_private_key2_p2sh2'))
  11.  
  12. private_key1 = PrivateKey(secret1)
  13. private_key2 = PrivateKey(secret2)
  14.  
  15. public_key1 = decode_base58('mvEg6eZ3sUApodedYQrkpEPMMALsr1K1k1')
  16. public_key2 = decode_base58('mwjg9Y1jeFdNu7DQBAW7DUbJqj6jMmhd74')
  17.  
  18. #redeem script as op code
  19.  
  20. dat_redeem_script_op = Script([0x52, public_key1, public_key2, 0x52, 0xae])
  21.  
  22. # we serialize it in binary
  23.  
  24. dat_redeem_script_serialized = dat_redeem_script_op.serialize()
  25.  
  26. prev_tx = bytes.fromhex('74aa4bb3ab5bd9966b8a06c442c37eb9177339dfdb1b1594a8d174e1dc201ff5')
  27. prev_index = 0
  28.  
  29. target_h160 = decode_base58('mvEg6eZ3sUApodedYQrkpEPMMALsr1K1k1')
  30. target_script = p2pkh_script(target_h160)
  31.  
  32. target_amount = int(0.00008 * 100000000)
  33. target_output = TxOut(amount=target_amount, script_pubkey=target_script)
  34.  
  35. tx_in = TxIn(prev_tx, prev_index)
  36.  
  37. tx_obj = Tx(1, [tx_in], [target_output], 0, True)
  38.  
  39. z = tx_obj.sig_hash(0)
  40. private_key1 = PrivateKey(secret1)
  41. private_key2 = PrivateKey(secret2)
  42. der1 = private_key1.sign(z).der()
  43. der2 = private_key2.sign(z).der()
  44. sig1 = der1 + SIGHASH_ALL.to_bytes(1, 'big')
  45. sig2 = der2 + SIGHASH_ALL.to_bytes(1, 'big')
  46. script_sig = Script([0x00, sig1, sig2, dat_redeem_script_serialized])
  47. print('script_sig=:{}'.format(script_sig))
  48. tx_obj.tx_ins[0].script_sig = script_sig
  49. print(tx_obj.serialize().hex())
  50.  
  51. # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement