不要将比特币发送给示例中的地址,否则您将失去他!
Alice花费0.005BTC购买Bob的货物,为了交易完全,两者找第三方Martin作为中间人。
Alice、Bob、Martin分别公开自己的公钥信息,并根据公钥生成一个2-3多重签名地址
例如,公钥信息如下:
Alice: 03e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f2161
Bob: 020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd97
Martin: 039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd
使用命令
getnewaddress
validateaddress “address”
可以查看地址对应的公钥信息。
使用命令
addmultisigaddress nrequired [“key”,…] ( “account” “address_type” )
生成2-3多重签名地址,例如,上述3个公钥生成的地址为:
addmultisigaddress 2 "[\"03e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f2161\",\"020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd97\",\"039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd\"]"
2N6UDb9eBjLKKN8f52PWZgj6Xn8VzdJcWzt
Alice将货款发送给上述多签名地址,并将交易ID发送给Bob
例如,交易ID为:
423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899
Bob收到交易ID后,校验交易信息
使用命令
getrawtransaction “txid” ( verbose “blockhash” )
decoderawtransaction “hexstring” ( iswitness )
查看交易信息,例如上述交易ID的交易信息为:
getrawtransaction 423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899
0200000000010176345c521e457a604000b1543aaa6bcdfef274bb614662f363c3b63ba0d6f1f300000000171600148e0d7aae920edda41e3fd0ae89fe0f8460c3132ffdffffff0220a107000000000017a914910eb5b15177193bad6bf65216a969289aca0ba1877aa007000000000017a914f1e97dd31778893c6f31a94f83ea7cb9b5340498870247304402202aa82440092153d4a316c31048f5e794a7ba96b2b217d77610127fca2661981e0220515d4d189918a889cb4c90aac71603a7c3f108f806ab2e41c23a5ca65c9c0ee7012103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f2161247d1500
decoderawtransaction 0200000000010176345c521e457a604000b1543aaa6bcdfef274bb614662f363c3b63ba0d6f1f300000000171600148e0d7aae920edda41e3fd0ae89fe0f8460c3132ffdffffff0220a107000000000017a914910eb5b15177193bad6bf65216a969289aca0ba1877aa007000000000017a914f1e97dd31778893c6f31a94f83ea7cb9b5340498870247304402202aa82440092153d4a316c31048f5e794a7ba96b2b217d77610127fca2661981e0220515d4d189918a889cb4c90aac71603a7c3f108f806ab2e41c23a5ca65c9c0ee7012103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f2161247d1500
{
"txid": "423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899",
"hash": "a41805f43b9f02c1d8ccee1a24d8b50e3e1d58c4e9c2415823dea15b42f0f13a",
"version": 2,
"size": 247,
"vsize": 166,
"locktime": 1408292,
"vin": [
{
"txid": "f3f1d6a03bb6c363f3624661bb74f2fecd6baa3a54b10040607a451e525c3476",
"vout": 0,
"scriptSig": {
"asm": "00148e0d7aae920edda41e3fd0ae89fe0f8460c3132f",
"hex": "1600148e0d7aae920edda41e3fd0ae89fe0f8460c3132f"
},
"txinwitness": [
"304402202aa82440092153d4a316c31048f5e794a7ba96b2b217d77610127fca2661981e0220515d4d189918a889cb4c90aac71603a7c3f108f806ab2e41c23a5ca65c9c0ee701",
"03e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f2161"
],
"sequence": 4294967293
}
],
"vout": [
{
"value": 0.00500000,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 910eb5b15177193bad6bf65216a969289aca0ba1 OP_EQUAL",
"hex": "a914910eb5b15177193bad6bf65216a969289aca0ba187",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2N6UDb9eBjLKKN8f52PWZgj6Xn8VzdJcWzt"
]
}
},
{
"value": 0.00499834,
"n": 1,
"scriptPubKey": {
"asm": "OP_HASH160 f1e97dd31778893c6f31a94f83ea7cb9b5340498 OP_EQUAL",
"hex": "a914f1e97dd31778893c6f31a94f83ea7cb9b534049887",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2NFJLYnihHtE6j3cvYVNSsdSnRikt6SFn4X"
]
}
}
]
}
Bob确认付款信息无误,发送货物给Alice
Bob提取货款时,先创建一个从交易ID到自己比特币地址的交易
使用命令
createrawtransaction [{“txid”:”id”,”vout”:n},…] {“address”:amount,”data”:”hex”,…} ( locktime ) ( replaceable )
来创建一个交易,例如:
createrawtransaction "[{\"txid\":\"423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899\",\"vout\":0}]" "{\"2N4bC6uNobbZUf3ybhg3ci4N7ZNQFohcsXG\":0.004998}"
0200000001991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f420000000000ffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a98700000000
提取的值要小于交易ID的值,差值作为矿工的奖励。
Bob对该交易进行签名
使用命令
signrawtransaction “hexstring” ( [{“txid”:”id”,”vout”:n,”scriptPubKey”:”hex”,”redeemScript”:”hex”},…] [“privatekey1”,…] sighashtype )
来对交易进行签名。
例如,Bob对上面的交易进行签名:
signrawtransaction 0200000001991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f420000000000ffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a98700000000
{
"hex": "02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a987030047304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000",
"complete": false,
"errors": [
{
"txid": "423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899",
"vout": 0,
"witness": [
"",
"304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a520101",
"522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae"
],
"scriptSig": "2200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18d",
"sequence": 4294967295,
"error": "Unable to sign input, invalid stack size (possibly missing key)"
}
]
}
Bob将自己签名后的交易发送给Alice,Alice对收到的货物和交易进行验证
使用命令decoderawtransaction查看Bob签名的交易信息,例如
decoderawtransaction 02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a987030047304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000
{
"txid": "67fcaf25ee12ee132ce6bbe179d064777a2e81e749fb51e103fd19e438337080",
"hash": "19db44e9cf965b365724a9eb8a54760d1a2e6fb42f3b7ab657066debe876e782",
"version": 2,
"size": 300,
"vsize": 164,
"locktime": 0,
"vin": [
{
"txid": "423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899",
"vout": 0,
"scriptSig": {
"asm": "00206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18d",
"hex": "2200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18d"
},
"txinwitness": [
"",
"304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a520101",
"522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae"
],
"sequence": 4294967295
}
],
"vout": [
{
"value": 0.00499800,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 7c7020ed135a05c86bcec1c491426eec48efb2a9 OP_EQUAL",
"hex": "a9147c7020ed135a05c86bcec1c491426eec48efb2a987",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2N4bC6uNobbZUf3ybhg3ci4N7ZNQFohcsXG"
]
}
}
]
}
Alice确认货物和交易无误后,对Bob创建的交易进行签名
例如:
signrawtransaction 02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a987030047304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000
{
"hex": "02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a9870400483045022100cf5d662011e226a82d8cb860290565acfe42cd332a16d2c4c81a60fa01b3c37802201983bd20263889acc18c06a47ee36cf77c6594fd1b0ddf8f9d20b954071bda170147304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000",
"complete": true
}
Alice将签名成功的交易发送到网络
使用命令
sendrawtransaction “hexstring” ( allowhighfees )
发送交易,例如:
sendrawtransaction 02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a9870400483045022100cf5d662011e226a82d8cb860290565acfe42cd332a16d2c4c81a60fa01b3c37802201983bd20263889acc18c06a47ee36cf77c6594fd1b0ddf8f9d20b954071bda170147304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000
返回的交易ID如下:
67fcaf25ee12ee132ce6bbe179d064777a2e81e749fb51e103fd19e438337080
待交易被网络确认后,Bob即可收到货款,及交易正常完成
上述交易信息如下:
getrawtransaction 67fcaf25ee12ee132ce6bbe179d064777a2e81e749fb51e103fd19e438337080
02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a9870400483045022100cf5d662011e226a82d8cb860290565acfe42cd332a16d2c4c81a60fa01b3c37802201983bd20263889acc18c06a47ee36cf77c6594fd1b0ddf8f9d20b954071bda170147304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000
decoderawtransaction 02000000000101991816e3bd6bb9faf77b836560f01d433d4819dbb3499120a3704c69b4d73f4200000000232200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18dffffffff0158a007000000000017a9147c7020ed135a05c86bcec1c491426eec48efb2a9870400483045022100cf5d662011e226a82d8cb860290565acfe42cd332a16d2c4c81a60fa01b3c37802201983bd20263889acc18c06a47ee36cf77c6594fd1b0ddf8f9d20b954071bda170147304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a52010169522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae00000000
{
"txid": "67fcaf25ee12ee132ce6bbe179d064777a2e81e749fb51e103fd19e438337080",
"hash": "6a611f56db7c64d7edc1c6497305bcc473634cedae690cd5424fe8296a29d7cf",
"version": 2,
"size": 373,
"vsize": 182,
"locktime": 0,
"vin": [
{
"txid": "423fd7b4694c70a3209149b3db19483d431df06065837bf7fab96bbde3161899",
"vout": 0,
"scriptSig": {
"asm": "00206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18d",
"hex": "2200206f0f2d495c106ccb69b10a8f57ca115674d0f302fa918b29df65e464b132c18d"
},
"txinwitness": [
"",
"3045022100cf5d662011e226a82d8cb860290565acfe42cd332a16d2c4c81a60fa01b3c37802201983bd20263889acc18c06a47ee36cf77c6594fd1b0ddf8f9d20b954071bda1701",
"304402205637494e4efbe71052d084f133c81f6af7d134170f12b546c3ca926ff80bbff9022037bffc1e9cba1c485032d5fc6cf92f73d8fe76295c467ff48b0b9cdcfe2a520101",
"522103e3bd2f408e4415aa57c747f6550937823a8605706c358facdc6325b4a99f216121020e80933a750e84b4c35c10bc797ca34d1c885e4e65531a7499170a1c78ffdd9721039155f9024807d126be4df4d09273c5fece4767e89b4527c68b48414a2877eddd53ae"
],
"sequence": 4294967295
}
],
"vout": [
{
"value": 0.00499800,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 7c7020ed135a05c86bcec1c491426eec48efb2a9 OP_EQUAL",
"hex": "a9147c7020ed135a05c86bcec1c491426eec48efb2a987",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2N4bC6uNobbZUf3ybhg3ci4N7ZNQFohcsXG"
]
}
}
]
}
同理,如果交易出现问题,如Alice拒绝付款或Bob的货物有问题,Alice要求退款,而对方拒绝,就可以找仲裁Martin来签署交易,从而保护自己的财产,当然Martin也可以将一部分钱发送给自己,作为调解费用。
交易流程图示例:
参考文章:https://bitcoinmagazine.com/articles/multisig-future-bitcoin-1394686504/