elif args.command == "spend-from-claim": #TODO: Maybe make wallets recognize this as theirs? prev_tx = sidechain.getrawtransaction(args.sidechainClaimTx, 1) prev_out = prev_tx["vout"][0] assert (prev_out["scriptPubKey"]["type"] == "withdrawout") prev_script = prev_out["scriptPubKey"]["asm"].split(" ") assert (prev_script[10] == "OP_NOP3") if "confirmations" not in prev_tx or prev_tx["confirmations"] < int( prev_script[9]): print( "You must wait for at least %s confirmations to claim this output (have %d)" % (prev_script[9], prev_tx["confirmations"])) exit(1) p2sh_res = sidechain.createmultisig(1, [args.sidechainAddress]) cht = os.popen( '%s %s -create in=%s:%d:%s:%d outaddr=%s:"%s"' % (sidechain_tx_path, "-testnet" if is_testnet == 1 else "", args.sidechainClaimTx, 0, str( prev_out["value"]), 0x100000000 - int(prev_script[9]) - 1, str(prev_out["value"]), sidechain.getnewaddress())) tx_hex = cht.read().split("\n")[0] assert (cht.close() == None) tx_hex = sidechain.signrawtransaction( tx_hex, [{ "txid": args.sidechainClaimTx, "vout": 0, "scriptPubKey": prev_out["scriptPubKey"]["hex"],
# Educational Purposes only # Python 2.7.6 and relies on bitcoind & bitcoinrpc & wobine's github connection file # We had to change the bitcoinrpc 'connection.py' file to add multisig support # https://github.com/wobine/blackboard101/blob/master/wbn_multisigs_pt1_create-address.py # Modify: # ask private key from user. so we could use the code in real situation from bitcoinrpc.authproxy import AuthServiceProxy bitcoin = AuthServiceProxy( "http://*****:*****@127.0.0.1:8332" ) #creates an object called 'bitcoin' that allows for bitcoind calls pubkey = dict() print "Please input your pubKey, which is the oubput of command [validate address]" pubkey[0] = str(raw_input("Please input the pubkey owned by Partner 1£º")) pubkey[1] = str(raw_input("Please input the pubkey owned by Partner 2£º")) pubkey[2] = str(raw_input("Please input the pubkey owned by Partner 3£º")) n = int(raw_input("Please input the number which can sign the address£º")) threeaddy = [pubkey[0], pubkey[1], pubkey[2]] print "The multi-sig address is £º" multisigaddy = bitcoin.addmultisigaddress(n, threeaddy) multiaddyandredeem = (bitcoin.createmultisig(n, threeaddy)) print len(multisigaddy), "chars - ", multisigaddy print print "redeemScript -", len(multiaddyandredeem["redeemScript"] ), "chars -", multiaddyandredeem["redeemScript"] print print "Now you can copy all this ouput text and save it so you'll be ready for spend it"
# Python 2.7.6 and relies on bitcoind & bitcoinrpc & wobine's github connection file # We had to change the bitcoinrpc 'connection.py' file to add multisig support # https://github.com/wobine/blackboard101/blob/master/wbn_multisigs_pt1_create-address.py from bitcoinrpc.authproxy import AuthServiceProxy bitcoin = AuthServiceProxy("http://*****:*****@127.0.0.1:8332") #creates an object called 'bitcoin' that allows for bitcoind calls pubkey = dict() print "请输入公钥,公钥可以由命令[validate address]的输出pubKey字段得到" pubkey[0] = str(raw_input("请输入管理者1的公钥:")) pubkey[1] = str(raw_input("请输入管理者2的公钥:")) pubkey[2] = str(raw_input("请输入管理者3的公钥:")) n = int(raw_input("请输入几个私钥可以解锁:")) threeaddy = [pubkey[0],pubkey[1],pubkey[2]] print "多重签名地址是:" multisigaddy = bitcoin.addmultisigaddress(n,threeaddy) multiaddyandredeem = (bitcoin.createmultisig(n,threeaddy)) print len(multisigaddy),"chars - ", multisigaddy print print "redeemScript -", len(multiaddyandredeem["redeemScript"]), "chars -",multiaddyandredeem["redeemScript"] print print "现在可以把上面的输出都存起来,方便以后花费时构建输出单"
addresses = bitcoin.getaddressesbyaccount("") print addresses for add in addresses: if not add[0] == '2': print bitcoin.dumpprivkey(add), add ## Create a multi-sig print "" print "Multi sig address" adds = [pubkeymine, pubkeymike] print "Addresses used", adds multi = bitcoin.addmultisigaddress(2, adds) multi = bitcoin.createmultisig(2, adds) print multi """ print "" print "Unspent transactions" unspent = bitcoin.listunspent() for x in unspent: print x print "---" if x['address'] == multiaddress: print "Unspent Multi: " print x print ""
txid = sidechain.sendrawtransaction(res_tx) print("Success!") print("Resulting txid: " + str(txid)) elif args.command == "spend-from-claim": #TODO: Maybe make wallets recognize this as theirs? prev_tx = sidechain.getrawtransaction(args.sidechainClaimTx, 1) prev_out = prev_tx["vout"][0] assert(prev_out["scriptPubKey"]["type"] == "withdrawout") prev_script = prev_out["scriptPubKey"]["asm"].split(" ") assert(prev_script[10] == "OP_NOP3") if "confirmations" not in prev_tx or prev_tx["confirmations"] < int(prev_script[9]): print("You must wait for at least %s confirmations to claim this output (have %d)" % (prev_script[9], prev_tx["confirmations"])) exit(1) p2sh_res = sidechain.createmultisig(1, [args.sidechainAddress]) cht = os.popen('%s %s -create in=%s:%d:%s:%d outaddr=%s:"%s"' % (sidechain_tx_path, "-testnet" if is_testnet == 1 else "", args.sidechainClaimTx, 0, str(prev_out["value"]), 0x100000000 - int(prev_script[9]) - 1, str(prev_out["value"]), sidechain.getnewaddress())) tx_hex = cht.read().split("\n")[0] assert(cht.close() == None) tx_hex = sidechain.signrawtransaction(tx_hex, [{"txid": args.sidechainClaimTx, "vout": 0, "scriptPubKey": prev_out["scriptPubKey"]["hex"], "redeemScript": p2sh_res["redeemScript"], "nValue": prev_out["serValue"]}], [sidechain.dumpprivkey(args.sidechainAddress)]) if tx_hex["complete"] != True: print("Got incomplete transaction (signing failed to create spendable transaction):") print(tx_hex["hex"]) else: print("Submitting tx to mempool...") sidechain.sendrawtransaction(tx_hex["hex"]) print("Success!") elif args.command == "send-to-mainchain":
if len(sys.argv) != 4: help() prev_tx = sidechain.getrawtransaction(sys.argv[2], 1) prev_out = prev_tx["vout"][0] assert (prev_out["scriptPubKey"]["type"] == "withdrawout") prev_script = prev_out["scriptPubKey"]["asm"].split(" ") assert (prev_script[10] == "OP_NOP3") if "confirmations" not in prev_tx or prev_tx["confirmations"] < int( prev_script[9]): print( "You must wait for at least %s confirmations to claim this output (have %d)" % (prev_script[9], prev_tx["confirmations"])) exit(1) p2sh_res = sidechain.createmultisig(1, [sys.argv[3]]) cht = os.popen( '%s %s -create in=%s:%d:%s:%d outaddr=%s:"%s"' % (sidechain_tx_path, "-testnet" if is_testnet == 1 else "", sys.argv[2], 0, str( prev_out["value"]), 0x100000000 - int(prev_script[9]) - 1, str(prev_out["value"]), sidechain.getnewaddress())) tx_hex = cht.read().split("\n")[0] assert (cht.close() == None) tx_hex = sidechain.signrawtransaction( tx_hex, [{ "txid": sys.argv[2], "vout": 0, "scriptPubKey": prev_out["scriptPubKey"]["hex"],