Created
November 10, 2015 15:39
-
-
Save shayanb/9dd8dc5c6d79b9ff6a09 to your computer and use it in GitHub Desktop.
Get multisig RedeemScript and address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pycoin.tx.pay_to import address_for_pay_to_script, build_hash160_lookup, build_p2sh_lookup, ScriptMultisig | |
from pycoin.key import Key | |
def generate_multisig_address(priv_keys, N=3, M=2, netcode = COIN_NETWORK): | |
''' | |
Generate a multisig address from a list of pycoin keys (addresses public or private) | |
multisig N out of M | |
''' | |
#keys = sorted(keys, key=lambda k: k.sec_as_hex()) #sort keys to have the same multisig address from any similar list of keys | |
keys = [] | |
for priv in priv_keys: | |
print Key.from_text(priv) | |
keys.append(Key.from_text(priv)) | |
underlying_script = ScriptMultisig(n=M, sec_keys=[key.sec() for key in keys[:N]]).script() | |
address = address_for_pay_to_script(underlying_script, netcode="BTC") | |
print "Multisig address: %s" %address | |
print "Redeam Script: %s" % b2h(underlying_script) | |
return address, underlying_script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment