Skip to content

Instantly share code, notes, and snippets.

@4tochka
Last active July 9, 2018 11:54
Show Gist options
  • Save 4tochka/86798ed341cae1a90eeed484a0e11300 to your computer and use it in GitHub Desktop.
Save 4tochka/86798ed341cae1a90eeed484a0e11300 to your computer and use it in GitHub Desktop.
Sign P2SH with nested multisig 1 of 2
>>> from pybtc import *
>>>
>>> # first step create multisig script
>>> a1 = Address("cPBuqn4ZsddXunx6EEev6khbfUzFnh3xxdEUPCrm5uy9qGcmbBEt",
address_type="P2PKH", testnet=True)
>>> a2 = Address("cVgShyj2q4YKFX8VzCffuQcrJVYhp522NFozNi7ih2KgNVbnysKX",
address_type="P2PKH", testnet=True)
>>> script = b"".join([OP_1,
op_push_data(a1.public_key.key),
op_push_data(a2.public_key.key),
OP_2,
OP_CHECKMULTISIG])
>>> a = ScriptAddress(script, testnet=True, witness_version=None)
>>> a.address
'2MwYC4w4xucVYqTRk89u7V2FaBSdrpjmk15'
>>> # add same btc to this address
>>> # tx ad244cfa748b8635195abeca81e38b5db261ea2e7d7a39933135a2bc3aff7a85
>>> tx = Transaction(testnet=1)
>>> tx.add_input("ad244cfa748b8635195abeca81e38b5db261ea2e7d7a39933135a2bc3aff7a85", 0)
>>> tx.add_output(129000000, address="mwJMtn5hW54pJC748EExvhRm6FRVmUZXQt")
>>> tx.sign_input(0, private_key="cPBuqn4ZsddXunx6EEev6khbfUzFnh3xxdEUPCrm5uy9qGcmbBEt",
redeem_script=script, witness_version=None)
>>> tx.serialize()
"""
0100000001857aff3abca2353193397a7d2eea61b25d8be381cabe5a1935868b74fa4c24ad000000009100473
044022051c7546ff919248badd1012317066cc0edd3e5f49050ac54ef52b66a8e80e17b02201dd65963551e0d
c7d8ce5721fbd3125fa9272a98bad1ed5df91488a462eac1230147512103b4603330291721c0a8e9cae65124a
7099ecf0df3b46921d0e30c4220597702cb2102b2ec7de7e811c05aaf8443e3810483d5dbcf671512d9999f9c
9772b0ce9da47a52aeffffffff014062b007000000001976a914ad204de226b3d11a70dc53b4998f4603e138f
f3f88ac00000000
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment