def witness_script(version, pubkey): if (version == 0): pubkeyhash = bytes_to_hex_str(ripemd160(sha256(hex_str_to_bytes(pubkey)))) pkscript = "0014" + pubkeyhash elif (version == 1): # 1-of-1 multisig scripthash = bytes_to_hex_str(sha256(hex_str_to_bytes("5121" + pubkey + "51ae"))) pkscript = "0020" + scripthash else: assert("Wrong version" == "0 or 1") return pkscript
def create_witnessprogram(version, node, utxo, pubkey, encode_p2sh, amount): pkscript = witness_script(version, pubkey) if (encode_p2sh): p2sh_hash = bytes_to_hex_str(ripemd160(sha256(hex_str_to_bytes(pkscript)))) pkscript = "a914"+p2sh_hash+"87" inputs = [] outputs = {} inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]} ) DUMMY_P2SH = convert_btc_address_to_btn("2MySexEGVzZpRgNQ1JdjdP5bRETznm3roQ2") # P2SH of "OP_1 OP_DROP" outputs[DUMMY_P2SH] = amount tx_to_witness = node.createrawtransaction(inputs,outputs) tx_to_witness = tx_to_witness[0:110] + addlength(pkscript) + tx_to_witness[-8:] return tx_to_witness
def create_witnessprogram(version, node, utxo, pubkey, encode_p2sh, amount): pkscript = witness_script(version, pubkey); if (encode_p2sh): p2sh_hash = bytes_to_hex_str(ripemd160(sha256(hex_str_to_bytes(pkscript)))) pkscript = "a914"+p2sh_hash+"87" inputs = [] outputs = {} inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]} ) DUMMY_P2SH = "2MySexEGVzZpRgNQ1JdjdP5bRETznm3roQ2" # P2SH of "OP_1 OP_DROP" outputs[DUMMY_P2SH] = amount tx_to_witness = node.createrawtransaction(inputs,outputs) #replace dummy output with our own tx_to_witness = tx_to_witness[0:110] + addlength(pkscript) + tx_to_witness[-8:] return tx_to_witness
def create_witnessprogram(version, node, utxo, pubkey, encode_p2sh, amount): pkscript = witness_script(version, pubkey); if (encode_p2sh): p2sh_hash = bytes_to_hex_str(ripemd160(sha256(hex_str_to_bytes(pkscript)))) pkscript = "a914"+p2sh_hash+"87" inputs = [] outputs = {} inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]} ) coinbase = CTransaction() DUMMY_P2SH = "8poAwF24PZJebPTtKJVyvAdFw1u7hX6uVX" # P2SH of "OP_1 OP_DROP" outputs[DUMMY_P2SH] = amount tx_to_witness = node.createrawtransaction(inputs,outputs) #replace dummy output with our own tx_to_witness = tx_to_witness[0:110] + addlength(pkscript) + tx_to_witness[-8:] return tx_to_witness
def create_witnessprogram(version, node, utxo, pubkey, encode_p2sh, amount): pkscript = witness_script(version, pubkey) if (encode_p2sh): p2sh_hash = bytes_to_hex_str( ripemd160(sha256(hex_str_to_bytes(pkscript)))) pkscript = "a914" + p2sh_hash + "87" inputs = [] outputs = {} inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) DUMMY_P2SH = "rCS26CDBTDXbAJ5bVb63VoTCf8vzA8Z7US" # P2SH of "OP_1 OP_DROP" outputs[DUMMY_P2SH] = amount tx_to_witness = node.createrawtransaction(inputs, outputs) #replace dummy output with our own tx_to_witness = tx_to_witness[0:110] + addlength( pkscript) + tx_to_witness[-8:] return tx_to_witness
def create_witnessprogram(version, node, utxo, pubkey, encode_p2sh, amount): pkscript = witness_script(version, pubkey) if (encode_p2sh): p2sh_hash = bytes_to_hex_str( ripemd160(sha256(hex_str_to_bytes(pkscript)))) pkscript = "a914" + p2sh_hash + "87" inputs = [] outputs = {} inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) DUMMY_P2SH = "P4tGp8vqTE2Jf65iNZMxr3LBH8Yzpw1jD3L5" # P2SH of "OP_4" outputs[DUMMY_P2SH] = amount tx_to_witness = node.createrawtransaction(inputs, outputs) #replace dummy output with our own tx_to_witness = tx_to_witness[0:110] + addlength( pkscript) + tx_to_witness[-8:] return tx_to_witness