当前位置:   article > 正文

Omni研究系列【USDT raw transaction】_php btc rawtransaction

php btc rawtransaction

https://blog.csdn.net/ffzhihua/article/details/80733124

Omnicore-cli命令一览

Omni的资料相对比较少,把一些常用命令执行结果也列出来,便于快速的了解。
omni_getallbalancesforid
取指定omni代币
Chaim:bin Chaim$ ./omnicore-cli "omni_getallbalancesforid" 1
[
{
"address": "1DUJAPA5i7biVYyZNCnckqEBEjY1Act2ct",
"balance": "100.00000000",
"reserved": "0.00000000"
},
...
为什么是一堆地址?
It returns all balances for the entire state, not just for addresses in the wallet.
omni_getallbalancesforaddress
单独取某个地址的omni代币

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_getallbalancesforaddress" "1LziTa1SYJx4bB7X8imUufQHVJVG6VUuRJ"
  2. [
  3. {
  4. "propertyid": 1,
  5. "balance": "0.00050000",
  6. "reserved": "0.00000000"
  7. },
  8. {
  9. "propertyid": 2,
  10. "balance": "0.10000036",
  11. "reserved": "0.00000000"
  12. }
  13. ]

omni_gettransaction
取交易数据

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_gettransaction" "1fc6ef3e006fce0f18d409e2a49f86472a47532913e954e4397e100a49ff0390"
  2. {
  3. "txid": "1fc6ef3e006fce0f18d409e2a49f86472a47532913e954e4397e100a49ff0390",
  4. "fee": "0.00002612",
  5. "sendingaddress": "1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA",
  6. "referenceaddress": "1CYUf3Uq3cqLswFApccRup84szbgYLq1H3",
  7. "ismine": false,
  8. "version": 0,
  9. "type_int": 0,
  10. "type": "Simple Send",
  11. "propertyid": 31,
  12. "divisible": true,
  13. "amount": "12.70000000",
  14. "valid": true,
  15. "blockhash": "0000000000000000001647535108c3d997eeff8503e17369f3bd074fd3bd8ceb",
  16. "blocktime": 1522303393,
  17. "positioninblock": 503,
  18. "block": 515635,
  19. "confirmations": 7547
  20. }

propertyid为31,在这就是USDT了。
再取下以前测试过的地址,为什么这个地址USDT这么多?

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_getallbalancesforaddress" "1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA"
  2. [
  3. {
  4. "propertyid": 31,
  5. "balance": "689041561.18427944",
  6. "reserved": "0.00000000"
  7. }
  8. ]


omni_listproperties
列出propertyid的代币,可以看到propertyid=31是啥了

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_listproperties"
  2. [
  3. {
  4. "propertyid": 1,
  5. "name": "Omni",
  6. "category": "N/A",
  7. "subcategory": "N/A",
  8. "data": "Omni serve as the binding between Bitcoin, smart properties and contracts created on the Omni Layer.",
  9. "url": "http://www.omnilayer.org",
  10. "divisible": true
  11. },
  12. {
  13. "propertyid": 2,
  14. "name": "Test Omni",
  15. "category": "N/A",
  16. "subcategory": "N/A",
  17. "data": "Test Omni serve as the binding between Bitcoin, smart properties and contracts created on the Omni Layer.",
  18. "url": "http://www.omnilayer.org",
  19. "divisible": true
  20. },
  21. ...
  22. {
  23. "propertyid": 31,
  24. "name": "TetherUS",
  25. "category": "Financial and insurance activities",
  26. "subcategory": "Activities auxiliary to financial service and insurance activities",
  27. "data": "The next paradigm of money.",
  28. "url": "https://tether.to",
  29. "divisible": true
  30. },
  31. ...


详细查看propertyid=31的数据:

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_getproperty" 31
  2. {
  3. "propertyid": 31,
  4. "name": "TetherUS",
  5. "category": "Financial and insurance activities",
  6. "subcategory": "Activities auxiliary to financial service and insurance activities",
  7. "data": "The next paradigm of money.",
  8. "url": "https://tether.to",
  9. "divisible": true,
  10. "issuer": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL",
  11. "creationtxid": "5ed3694e8a4fa8d3ec5c75eb6789492c69e65511522b220e94ab51da2b6dd53f",
  12. "fixedissuance": false,
  13. "managedissuance": true,
  14. "freezingenabled": true,
  15. "totaltokens": "2520000000.00000000"
  16. }


raw transaction
到这说下我研究USDT的目的,我需要进行USDT转帐交易,同时希望是在冷钱包中签名,所以需要使用原始交易数据,生成交易数据后再拿到冷钱包中进行签名,再把签名后数据拿到热钱包中发送。

 

以下交易步骤按网上流程尝试,可能是已经使用过的数据,借此也可以看看相关api的结果,看看我的想法可不可行。

 

 

1.读取指定地址的UTXO(listunspent)

这个命令是比特币的命令,可以在这了解这些命令

 

  1. Chaim:bin Chaim$ ./omnicore-cli "listunspent" 0 999999 '["1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA"]'
  2. [
  3. ]

基于比特币UTXO的方式,并不是能在一个节点上列出任意地址的余额,也无法列出任意地址的UTXO,得先把地址导入钱包。
节点钱包操作

 

importaddress 1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA

2.构造发送代币类型和代币数量数据(payload)
指定omni代币和数量

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_createpayload_simplesend" 31 "1.0"
  2. 000000000000001f0000000005f5e100


3.构造交易基本数据(transaction base)
指定从哪个源地址(UTXO中txid和vout)转移比特币

 

  1. Chaim:bin Chaim$ ./omnicore-cli "createrawtransaction" '[{"txid":"9fd770cf78e48f562378e210c162be725d76c12e7dfcb682a210d91d6f23ffff","vout":1},{"txid":"7bdb7918de91036223e461fed4291f691267087a40e55d3e7b3fbcfef741ffff","vout":1}]' '{}'
  2. 0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff0000000000

点击地址可以来检验正确性 http://chainquery.com/bitcoin-api/createrawtransaction


4.在交易数据中加上omni代币数据
这一步把omni代币数据也组合到交易数据上

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_opreturn" "0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff0000000000" "000000000000001f0000000005f5e100"
  2. 0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff010000000000000000166a146f6d6e69000000000000001f0000000005f5e10000000000


5.在交易数据上加上接收地址

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_reference" "0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff010000000000000000166a146f6d6e69000000000000001f0000000005f5e10000000000" "1Njbpr7EkLA1R8ag8bjRN7oks7nv5wUn3o"
  2. 0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000


6.在交易数据上指定矿工费用
指定矿工费用和UTXO数据(txid、vout、scriptPubkey、value),也可以改变找零地址

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_change" "0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000" '[{"txid":"9fd770cf78e48f562378e210c162be725d76c12e7dfcb682a210d91d6f23ffff","vout":1,"scriptPubKey":"76a914a25dec4d0011064ef106a983c39c7a540699f22088ac","value":0.00000546},{"txid":"7bdb7918de91036223e461fed4291f691267087a40e55d3e7b3fbcfef741ffff","vout":1,"scriptPubKey":"76a914a25dec4d0011064ef106a983c39c7a540699f22088ac","value":0.00000546}]' "1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA" 0.0006
  2. 0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000


7.交易签名
这步是比特币的签名命令

 

  1. Chaim:bin Chaim$ ./omnicore-cli "signrawtransaction" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000"
  2. {
  3. "hex": "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000",
  4. "complete": false,
  5. "errors": [
  6. {
  7. "txid": "c23495f6e7ba24705d43583edd69ff25a354c18e69fd8514c07ec6f47cb995de",
  8. "vout": 0,
  9. "scriptSig": "",
  10. "sequence": 4294967295,
  11. "error": "Input not found or already spent"
  12. },
  13. {
  14. "txid": "ee1673b09b0edaf7aaf8eb0bfd53a5a2757eb3e342e731bfc960b869aa0ab6b3",
  15. "vout": 2,
  16. "scriptSig": "",
  17. "sequence": 4294967295,
  18. "error": "Input not found or already spent"
  19. }
  20. ]
  21. }


在这发现一个问题,交易签名时对input进行了判断,而不是我以为的只是用对应的私钥进行签名而已。
重新走一遍这个生成原始交易的流程,保证input存在且unspent,但没有私钥进行签名看看是什么结果?
USDT钱包基本没有可用的,也就Omnicore这边可以用,要再搭私链又太麻烦费事,只能从交易所提点USDT出来测试了。
继续走一遍生成原始交易数据的流程:

 

  1. Chaim:bin Chaim$ ./omnicore-cli "listunspent" 0 999999 '["15aiNs86ntF8pMpYW7SaTYDZSgpZDte5Jz"]'
  2. [
  3. {
  4. "txid": "16825d26fac2e433d7b3aff8b900e384f6d58784606f6813bee96105754cfd47",
  5. "vout": 1,
  6. "address": "15aiNs86ntF8pMpYW7SaTYDZSgpZDte5Jz",
  7. "account": "",
  8. "scriptPubKey": "76a9143240c506599c53dbc0bc86ab8f609139a1423de488ac",
  9. "amount": 0.00000546,
  10. "confirmations": 14,
  11. "spendable": true,
  12. "solvable": true
  13. }
  14. ]

 

  1. Chaim:bin Chaim$ ./omnicore-cli "omni_createpayload_simplesend" 31 "1.0"
  2. 000000000000001f0000000005f5e100
  3. Chaim:bin Chaim$ ./omnicore-cli "createrawtransaction" '[{"txid":"16825d26fac2e433d7b3aff8b900e384f6d58784606f6813bee96105754cfd47","vout":1}]' '{}'
  4. 010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff0000000000
  5. Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_opreturn" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff0000000000" "000000000000001f0000000005f5e100"
  6. 010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff010000000000000000166a146f6d6e69000000000000001f0000000005f5e10000000000
  7. Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_reference" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff010000000000000000166a146f6d6e69000000000000001f0000000005f5e10000000000" "128HHbgLdQ3tGKjUzLfWDCR6iCcHQVKfZu"
  8. 010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000
  9. Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_change" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000" '[{"txid":"16825d26fac2e433d7b3aff8b900e384f6d58784606f6813bee96105754cfd47","vout":1,"scriptPubKey":"76a9143240c506599c53dbc0bc86ab8f609139a1423de488ac","value":0.00000546}]' "15aiNs86ntF8pMpYW7SaTYDZSgpZDte5Jz" 0.00006
  10. 010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000
  11. Chaim:bin Chaim$ ./omnicore-cli "signrawtransaction" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000"
  12. {
  13. "hex": "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d8216010000006a4730440220088124ba6c64985b0cb1029ba5c626257a6d40aeede249b55c810284b62b2dfb02201e124e81bcf0738fe8c80778117e9598c0d4399dbe31d84bf1bdd08bae8d83e90121035ef84c0f6d725a4609902f69b90b6e233521c2514d0731139db8f786d1cb7cdaffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000",
  14. "complete": true
  15. }
  16. Chaim:bin Chaim$ ./omnicore-cli "sendrawtransaction" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d8216010000006a4730440220088124ba6c64985b0cb1029ba5c626257a6d40aeede249b55c810284b62b2dfb02201e124e81bcf0738fe8c80778117e9598c0d4399dbe31d84bf1bdd08bae8d83e90121035ef84c0f6d725a4609902f69b90b6e233521c2514d0731139db8f786d1cb7cdaffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000"
  17. error code: -26
  18. error message:
  19. 66: insufficient priority


这次执行到发送交易了,只是发送交易出错,据说是费用太低,其实我是特意做测试的,因为这个地址上除了转USDT带来的0.00000546BTC之外,根本就没有比特币,指定费用再大也没用!重新测试了一下指定更大的交易费错误也是一样,看来这个错误就是说BTC不够了!
还得转点BTC到这个地址,这样所有的流程又得重来,因为UTXO变了,哭...

 

  1. Chaim:bin Chaim$ ./omnicore-cli "sendrawtransaction" "010000000172623fe547c2230097b47d534860045945b7022681fe2c49c7fbdc054b06a105000000006a47304402205f550c82215ccb0d9f6600b5e0ea2c1b95ecfb201188fbd8b6b257cb0392487302206f9dc845ee8d40ad9dc02eaa5ad907777a4b882653a1be43ae955be3a9a2d06c0121035ef84c0f6d725a4609902f69b90b6e233521c2514d0731139db8f786d1cb7cdaffffffff03ae820000000000001976a9143240c506599c53dbc0bc86ab8f609139a1423de488ac0000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000"
  2. bebe30bd08d615aa5f54bdea6e662f3286e1270a97647a94f60b3b64f4d27191

检验其正确性 http://chainquery.com/bitcoin-api/sendrawtransaction
不过这次交易应该是成功了,等待确认吧!
在btc.com能查到这笔交易了,不过它上面有个交易加速,这个加速是怎么实现的呢?我给它钱,它怎么给矿工钱?
交易费设得太低了,不知道能不能成交了!
不过以上流程基本验证USDT转帐也可以使用热钱包建立原始交易,冷钱包签名的模式了!

 

原理上是和比特币是一样的,只是验证还是必需自己做一下!

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/831892
推荐阅读
相关标签
  

闽ICP备14008679号