赢金宝区块链落地:区块链担保交易购物

in cn •  7 years ago  (edited)

用赢金宝的赢金币作为区块链,进行购物担保交易:
先说原理:
第一步:查询赢金币钱包是否有未被花费的赢金币【这一步必须运行赢金币钱包】
listunspent:
[
{
"txid" : "b29daeaffea0d40356d13d20e6c3c860aa3925fc711a084bc17a9e73ab13f809",
"vout" : 1,
"address" : "YksRtgkqRiS7LNG6PasbbtMSh6mfnL3DiY",
"scriptPubKey" : "76a914ebe924e3306db60c333510cb6d087fb6268a051088ac",
"amount" : 0.50000000,
"confirmations" : 3,
"spendable" : true
},
{
"txid" : "bd0b1a067a63fb510903f9960f4da46fb5c8f8ec0e7b5f2d91f0278002ffe448",
"vout" : 0,
"address" : "YR7GEJi9cn9KRCVbBB5fgXitYGECFqzEuS",
"scriptPubKey" : "76a914132462fd5b3d77f6ce2f64390a87736ec31f1c8188ac",
"amount" : 0.07561905,
"confirmations" : 8,
"spendable" : true
}
]
第二步 创建一笔交易:
createrawtransaction
createrawtransaction '[{"txid":"b29daeaffea0d40356d13d20e6c3c860aa3925fc711a084bc17a9e73ab13f809","vout":1}]' '{"YYjfKkQh4GrBZktWon69qy2KTcGTkVrHuo":0.3,"YksRtgkqRiS7LNG6PasbbtMSh6mfnL3DiY":0.1}'

16:25:15

createrawtransaction '[{"txid":"b29daeaffea0d40356d13d20e6c3c860aa3925fc711a084bc17a9e73ab13f809","vout":1}]' '{"YYjfKkQh4GrBZktWon69qy2KTcGTkVrHuo":0.3,"YksRtgkqRiS7LNG6PasbbtMSh6mfnL3DiY":0.1}'

010000000109f813ab739e7ac14b081a71fc2539aa60c8c3e6203dd15603d4a0feafae9db20100000000ffffffff0280c3c901000000001976a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac80969800000000001976a914ebe924e3306db60c333510cb6d087fb6268a051088ac00000000

修改上述交易存证"hello world!"
replace

data = "hello world!"
newScriptPubKey = "6a" + hexlify(chr(len(data)).encode()).decode() + hexlify(data.encode()).decode()
newScriptPubKey1 = hexlify(chr(len(unhexlify(newScriptPubKey))).encode()).decode() + newScriptPubKey

0e6a0c68656c6c6f20776f726c6421

第3步 对这笔在区块链里写了“hello world!”的交易进行签名:
signrawtransaction
16:30:30

signrawtransaction "010000000109f813ab739e7ac14b081a71fc2539aa60c8c3e6203dd15603d4a0feafae9db20100000000ffffffff0280c3c901000000001976a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac80969800000000000e6a0c68656c6c6f20776f726c642100000000" '[{"txid":"b29daeaffea0d40356d13d20e6c3c860aa3925fc711a084bc17a9e73ab13f809","vout":1,"scriptPubKey":"76a914ebe924e3306db60c333510cb6d087fb6268a051088ac"}]'

16:30:30

{
"hex" : "010000000109f813ab739e7ac14b081a71fc2539aa60c8c3e6203dd15603d4a0feafae9db2010000006a47304402201f99c2c93dc1c0bd3c2f8cc700a5b45272eab4d9bf4d0c6e9dc3f1594feaac56022050c531f62ac413df45bbf533039cfff086beb42ced84d906e991305bdc4bd7f801210260be8769fd27add8d1f3fb2492593ce58fc8628b62a055ec28ad18c421ffb4f3ffffffff0280c3c901000000001976a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac80969800000000000e6a0c68656c6c6f20776f726c642100000000",
"complete" : true
}
第4步 发送这笔交易【广播】
sendrawtransaction

sendrawtransaction 010000000109f813ab739e7ac14b081a71fc2539aa60c8c3e6203dd15603d4a0feafae9db2010000006a47304402201f99c2c93dc1c0bd3c2f8cc700a5b45272eab4d9bf4d0c6e9dc3f1594feaac56022050c531f62ac413df45bbf533039cfff086beb42ced84d906e991305bdc4bd7f801210260be8769fd27add8d1f3fb2492593ce58fc8628b62a055ec28ad18c421ffb4f3ffffffff0280c3c901000000001976a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac80969800000000000e6a0c68656c6c6f20776f726c642100000000

232898795efae3062e2560dddf7e89f9889af16b39d630d8abf39086fb0ad87c

查询接受这笔交易的地址"YYjfKkQh4GrBZktWon69qy2KTcGTkVrHuo",结果如下:
gettransaction 232898795efae3062e2560dddf7e89f9889af16b39d630d8abf39086fb0ad87c

{
"amount": -0.4,
"blockhash": "4211c17235f9ecc43564cbbe3529289afdffa7b50601fc00fbbf860c2e937cb6",
"blockindex": 1,
"blocktime": 1524645250,
"confirmations": 16,
"details": [
{
"account": "",
"address": "YYjfKkQh4GrBZktWon69qy2KTcGTkVrHuo",
"amount": -0.3,
"category": "send",
"fee": -0.1,
"vout": 0
},
{
"account": "",
"amount": -0.1,
"category": "send",
"fee": -0.1,
"vout": 1
}
],
"fee": -0.1,
"hex": "010000000109f813ab739e7ac14b081a71fc2539aa60c8c3e6203dd15603d4a0feafae9db2010000006a47304402201f99c2c93dc1c0bd3c2f8cc700a5b45272eab4d9bf4d0c6e9dc3f1594feaac56022050c531f62ac413df45bbf533039cfff086beb42ced84d906e991305bdc4bd7f801210260be8769fd27add8d1f3fb2492593ce58fc8628b62a055ec28ad18c421ffb4f3ffffffff0280c3c901000000001976a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac80969800000000000e6a0c68656c6c6f20776f726c642100000000",
"time": 1524645058,
"timereceived": 1524645058,
"txid": "232898795efae3062e2560dddf7e89f9889af16b39d630d8abf39086fb0ad87c",
"walletconflicts": []
}

decoderawtransaction 010000000109f813ab739e7ac14b081a71fc2539aa60c8c3e6203dd15603d4a0feafae9db2010000006a47304402201f99c2c93dc1c0bd3c2f8cc700a5b45272eab4d9bf4d0c6e9dc3f1594feaac56022050c531f62ac413df45bbf533039cfff086beb42ced84d906e991305bdc4bd7f801210260be8769fd27add8d1f3fb2492593ce58fc8628b62a055ec28ad18c421ffb4f3ffffffff0280c3c901000000001976a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac80969800000000000e6a0c68656c6c6f20776f726c642100000000

{
"locktime": 0,
"txid": "232898795efae3062e2560dddf7e89f9889af16b39d630d8abf39086fb0ad87c",
"version": 1,
"vin": [
{
"scriptSig": {
"asm": "304402201f99c2c93dc1c0bd3c2f8cc700a5b45272eab4d9bf4d0c6e9dc3f1594feaac56022050c531f62ac413df45bbf533039cfff086beb42ced84d906e991305bdc4bd7f801 0260be8769fd27add8d1f3fb2492593ce58fc8628b62a055ec28ad18c421ffb4f3",
"hex": "47304402201f99c2c93dc1c0bd3c2f8cc700a5b45272eab4d9bf4d0c6e9dc3f1594feaac56022050c531f62ac413df45bbf533039cfff086beb42ced84d906e991305bdc4bd7f801210260be8769fd27add8d1f3fb2492593ce58fc8628b62a055ec28ad18c421ffb4f3"
},
"sequence": 4294967295,
"txid": "b29daeaffea0d40356d13d20e6c3c860aa3925fc711a084bc17a9e73ab13f809",
"vout": 1
}
],
"vout": [
{
"n": 0,
"scriptPubKey": {
"addresses": [
"YYjfKkQh4GrBZktWon69qy2KTcGTkVrHuo"
],
"asm": "OP_DUP OP_HASH160 66cf8501f8ffe3c1e15a62e74de979f5604e41ee OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a91466cf8501f8ffe3c1e15a62e74de979f5604e41ee88ac",
"reqSigs": 1,
"type": "pubkeyhash"
},
"value": 0.3
},
{
"n": 1,
"scriptPubKey": {
"asm": "OP_RETURN 68656c6c6f20776f726c6421",
"hex": "6a0c68656c6c6f20776f726c6421",
"type": "nulldata"
},
"value": 0.1
}
]
}

unhexlify('68656c6c6f20776f726c6421').decode()
'hello world!'

里面有"hello worl!"已经在区块里了,这个是无法修改的!

再说担保交易:
把hello world!改成“发了1500元!”创建一笔交易发送给卖方,1500元在平台卖方账上被冻结;卖方收到这笔交易通知发货,同时发送一笔交易并注明“货已发”;买方收到货并回复“收到货”的一笔交易,平台解冻1500元,交易完成。

区块链更多的应用场景如电子签名,电子合同,视频音频存证,等等,好多!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @szgwm! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!