简体   繁体   中英

How to set an arbitrary scriptPubKey during generation of escrow bitcoin transaction?

According to Example 2: Escrow and dispute mediation there is a possibility to create escrow transactions. Also there is BIP 16 , which introduces a pay-to-script-hash mechanism.

According to these documents, as i understand, i must follow these steps to process an escrow transaction between three participants:

  1. Each of those three participants creates a new address by executing rpc "getnewaddress".

  2. Then everybody must validate their addresses by executing "validateaddress" and get a pubkey.

  3. Then we must create a multisig adress by executing the rpc method "createmultisig" with three pubkeys as parameters, like this:

    bitcoind createmultisig 2 '["pubkey1","pubkey2","pubkey3"]'

  4. Then we create a transaction to put some coins to this multisig address:

    bitcoind createrawtransaction '[{"txid":"my some txid","vout":0}]' '{"created multisig address":0.001}'

  5. After that we must decode our created transaction by executing "decoderawtransaction" to get a txid, that will be needed to create a next transaction:

.

bitcoind decoderawtransaction <blah-blah>
{
    **"txid" : "txid,that we need",**
    "version" : 1,
    "locktime" : 0,
 <...>
and so on
<...>
}`
  1. One of the final steps: we must create our own scriptPubKey. Ok, that is not a problem: we can use the Pybitcointools, Python library for Bitcoin signatures and transactions to do that by executing pybtctool mk_multisig_script pub_key1 pub_key2 pub_key3 2 3 , as a result, we get a scriptPubKey , that we must use later in another createrawtransaction.

  2. Final step. The magic begins. We execute bitcoind to create a raw transaction with a custom script:

    bitcoind createrawtransaction '[{"txid":"txid","vout":0,"scriptPubKey":"**scriptPubKey**","redeemScript":"redeemScript from createmultisig transaction above"}]' '{"bitcoin address to output":0.001}' and this returns a transaction.

Magic : Everything above works fine. Final createrawtransaction creates a transaction. But when we decode the received transaction by executing bitcoind decoderawtransaction <transaction, received on the last step> in vout section there will be smth like that:

.

"vout" : [
    {
        "value" : 0.00100000,
        "n" : 0,
        "scriptPubKey" : {
            "asm" : "OP_DUP OP_HASH160 blah blah OP_EQUALVERIFY OP_CHECKSIG",
            "hex" : "blah blah",

`

As you see, in scriptPubKey there is "OP_CHECKSIG" but our script must have "OP_CHECKMULTISIGVERIFY"

So, the question is: how to set an arbitrary script to the output of transaction?

I am struggling with the same problem as you, but maybe I am a bit further along? Next I would: transaction=pybitcointools.deserialize(hex)
transaction["outs"][n]["script"]=**script pub key**
hex=pybitcointools.serialize(transaction)
transaction=pybitcointools.deserialize(hex)
transaction["outs"][n]["script"]=**script pub key**
hex=pybitcointools.serialize(transaction)

I don't think you use the redeem script until you want to spend the bitcoin you are sending with this transaction?

UPDATE https://bitcoin.stackexchange.com/questions/4486/transaction-with-slightly-changed-script-is-never-relayed It looks like our client will refuse to broadcast these transactions, we need to hand them off to a particular pool of miners.

If you want to collaborate more: zack[dott]bitcoin@gmail.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM