[英]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.根据示例 2:托管和争议调解,有可能创建托管交易。 Also there is BIP 16 , which introduces a pay-to-script-hash mechanism.
还有BIP 16 ,它引入了支付脚本哈希机制。
According to these documents, as i understand, i must follow these steps to process an escrow transaction between three participants:根据这些文件,据我所知,我必须按照以下步骤处理三个参与者之间的托管交易:
Each of those three participants creates a new address by executing rpc "getnewaddress".这三个参与者中的每一个都通过执行 rpc "getnewaddress" 创建一个新地址。
Then everybody must validate their addresses by executing "validateaddress" and get a pubkey.然后每个人都必须通过执行“validateaddress”来验证他们的地址并获得一个公钥。
Then we must create a multisig adress by executing the rpc method "createmultisig" with three pubkeys as parameters, like this:然后我们必须通过使用三个公钥作为参数执行 rpc 方法“createmultisig”来创建一个 multisig 地址,如下所示:
bitcoind createmultisig 2 '["pubkey1","pubkey2","pubkey3"]'
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}'
After that we must decode our created transaction by executing "decoderawtransaction" to get a txid, that will be needed to create a next transaction:之后,我们必须通过执行“decoderawtransaction”来解码我们创建的交易,以获得创建下一个交易所需的 txid:
. .
bitcoind decoderawtransaction <blah-blah>
{
**"txid" : "txid,that we need",**
"version" : 1,
"locktime" : 0,
<...>
and so on
<...>
}`
One of the final steps: we must create our own scriptPubKey.最后的步骤之一:我们必须创建我们自己的 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.好的,这不是问题:我们可以使用 Pybitcointools,用于比特币签名和交易的 Python 库通过执行
pybtctool mk_multisig_script pub_key1 pub_key2 pub_key3 2 3
来做到这一点,结果,我们得到了一个scriptPubKey ,我们稍后必须在另一个中使用它创建原始交易。
Final step.最后一步。 The magic begins.
魔法开始。 We execute bitcoind to create a raw transaction with a custom script:
我们执行 bitcoind 以使用自定义脚本创建原始交易:
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. bitcoind createrawtransaction '[{"txid":"txid","vout":0,"scriptPubKey":"**scriptPubKey**","redeemScript":"redeemScript from createmultisig transaction above"}]' '{"bitcoin address to output":0.001}'
,这将返回一个交易。
Magic : Everything above works fine.魔术:以上一切正常。 Final createrawtransaction creates a transaction.
最后 createrawtransaction 创建一个事务。 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:但是当我们通过执行
bitcoind decoderawtransaction <transaction, received on the last step>
在bitcoind decoderawtransaction <transaction, received on the last step>
解码收到的交易时,将会有这样的情况:
. .
"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"如您所见,在 scriptPubKey 中有“OP_CHECKSIG”但我们的脚本必须有“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)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.更新https://bitcoin.stackexchange.com/questions/4486/transaction-with-slightly-changed-script-is-never-relayed看起来我们的客户将拒绝广播这些交易,我们需要将它们交给一个特定的矿工池。
If you want to collaborate more: zack[dott]bitcoin@gmail.com如果您想进行更多合作:zack[dott]bitcoin@gmail.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.