part1
unknown
python
2 years ago
1.8 kB
4
Indexable
from asyncio import run_coroutine_threadsafe from bitcoinutils.setup import setup from bitcoinutils.keys import P2shAddress, PublicKey, Address from bitcoinutils.script import Script import hashlib, base58, binascii # Setup the network setup('testnet') # This script ask the user 3 Public Keys in order to create a P2SH address with a 2-of-3 multisig # Collect the 3 public keys pkey1 = "027822baac734226f2bdecf7b483531e83c3400fcdbad6726b91a5cb9788260b7e" pkey2 = "03c86fef055997c3b6f1b151bb2d6e3ad18c49d70b6c44c7704c952baf021ba746" pkey3 = "03d0d743102243a76d4efc12b808c1cc78aa1ebefe108ea3398d001808fb5dd251" print("You succesfully entered your public keys.") # Convert string to Public Key objects publickey1 = PublicKey(pkey1) publickey2 = PublicKey(pkey2) publickey3 = PublicKey(pkey3) # Convert public keys to hex (IS THIS NEEDED?) key1 = publickey1.to_hex() key2 = publickey1.to_hex() key3 = publickey1.to_hex() def main(): # CREATE THE REDEEM SCRIPT redeem_script = Script(['OP2', key1, key2, key3, 'OP3', 'OP_CHECKMULTISIG']) print(redeem_script) # HASH OF THE REDEEM SCRIPT hash = Script(['OP_HASH160', redeem_script]) print(hash) # Possible alternative? hash = redeem_script._script_to_hash160() # hash_hex = hash.to_hex() # Why is this not working? # print(hash_hex) # CREATE THE LOCKING SCRIPT locking_script = Script(['OP_HASH160', hash, 'OP_EQUAL']) print(locking_script) # Possible alternative? locking_script = redeem_script.to_p2sh_script_pub_key() # GENERATE THE P2SH ADDRESS address = Address() address = address.from_script(hash) print('The 2-of-3 multisig address is: ' + address) # Possible alternative? use hashlib -> too much code :/ main()
Editor is loading...