Omni研究系列【USDT raw transaction】

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代币

 

Chaim:bin Chaim$ ./omnicore-cli "omni_getallbalancesforaddress" "1LziTa1SYJx4bB7X8imUufQHVJVG6VUuRJ"
[
  {
    "propertyid": 1,
    "balance": "0.00050000",
    "reserved": "0.00000000"
  }, 
  {
    "propertyid": 2,
    "balance": "0.10000036",
    "reserved": "0.00000000"
  }
]

omni_gettransaction
取交易数据

 

Chaim:bin Chaim$ ./omnicore-cli "omni_gettransaction" "1fc6ef3e006fce0f18d409e2a49f86472a47532913e954e4397e100a49ff0390"
{
  "txid": "1fc6ef3e006fce0f18d409e2a49f86472a47532913e954e4397e100a49ff0390",
  "fee": "0.00002612",
  "sendingaddress": "1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA",
  "referenceaddress": "1CYUf3Uq3cqLswFApccRup84szbgYLq1H3",
  "ismine": false,
  "version": 0,
  "type_int": 0,
  "type": "Simple Send",
  "propertyid": 31,
  "divisible": true,
  "amount": "12.70000000",
  "valid": true,
  "blockhash": "0000000000000000001647535108c3d997eeff8503e17369f3bd074fd3bd8ceb",
  "blocktime": 1522303393,
  "positioninblock": 503,
  "block": 515635,
  "confirmations": 7547
}

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

 

Chaim:bin Chaim$ ./omnicore-cli "omni_getallbalancesforaddress" "1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA"
[
  {
    "propertyid": 31,
    "balance": "689041561.18427944",
    "reserved": "0.00000000"
  }
]


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

 

Chaim:bin Chaim$ ./omnicore-cli "omni_listproperties"
[
  {
    "propertyid": 1,
    "name": "Omni",
    "category": "N/A",
    "subcategory": "N/A",
    "data": "Omni serve as the binding between Bitcoin, smart properties and contracts created on the Omni Layer.",
    "url": "http://www.omnilayer.org",
    "divisible": true
  }, 
  {
    "propertyid": 2,
    "name": "Test Omni",
    "category": "N/A",
    "subcategory": "N/A",
    "data": "Test Omni serve as the binding between Bitcoin, smart properties and contracts created on the Omni Layer.",
    "url": "http://www.omnilayer.org",
    "divisible": true
  }, 
  ...
  {
    "propertyid": 31,
    "name": "TetherUS",
    "category": "Financial and insurance activities",
    "subcategory": "Activities auxiliary to financial service and insurance activities",
    "data": "The next paradigm of money.",
    "url": "https://tether.to",
    "divisible": true
  },
  ... 


详细查看propertyid=31的数据:

 

Chaim:bin Chaim$ ./omnicore-cli "omni_getproperty" 31
{
  "propertyid": 31,
  "name": "TetherUS",
  "category": "Financial and insurance activities",
  "subcategory": "Activities auxiliary to financial service and insurance activities",
  "data": "The next paradigm of money.",
  "url": "https://tether.to",
  "divisible": true,
  "issuer": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL",
  "creationtxid": "5ed3694e8a4fa8d3ec5c75eb6789492c69e65511522b220e94ab51da2b6dd53f",
  "fixedissuance": false,
  "managedissuance": true,
  "freezingenabled": true,
  "totaltokens": "2520000000.00000000"
}


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

 

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

 

 

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

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

 

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

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

 

importaddress 1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA

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

 

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


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

 

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

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


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

 

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


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

 

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


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

 

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
0100000002ffff236f1dd910a282b6fc7d2ec1765d72be62c110e27823568fe478cf70d79f0100000000ffffffffffff41f7febc3f7b3e5de5407a086712691f29d4fe61e423620391de1879db7b0100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000


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

 

Chaim:bin Chaim$ ./omnicore-cli "signrawtransaction" "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000"
{
  "hex": "0100000002de95b97cf4c67ec01485fd698ec154a325ff69dd3e58435d7024bae7f69534c20000000000ffffffffb3b60aaa69b860c9bf31e742e3b37e75a2a553fd0bebf8aaf7da0e9bb07316ee0200000000ffffffff036a5a0d00000000001976a914c6734676a08e3c6438bd95fa62c57939c988a17b88ac0000000000000000166a146f6d6e690000000000000002000000000098968022020000000000001976a914ee692ea81da1b12d3dd8f53fd504865c9d843f5288ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "c23495f6e7ba24705d43583edd69ff25a354c18e69fd8514c07ec6f47cb995de",
      "vout": 0,
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Input not found or already spent"
    }, 
    {
      "txid": "ee1673b09b0edaf7aaf8eb0bfd53a5a2757eb3e342e731bfc960b869aa0ab6b3",
      "vout": 2,
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Input not found or already spent"
    }
  ]
}


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

 

Chaim:bin Chaim$ ./omnicore-cli "listunspent" 0 999999 '["15aiNs86ntF8pMpYW7SaTYDZSgpZDte5Jz"]'
[
  {
    "txid": "16825d26fac2e433d7b3aff8b900e384f6d58784606f6813bee96105754cfd47",
    "vout": 1,
    "address": "15aiNs86ntF8pMpYW7SaTYDZSgpZDte5Jz",
    "account": "",
    "scriptPubKey": "76a9143240c506599c53dbc0bc86ab8f609139a1423de488ac",
    "amount": 0.00000546,
    "confirmations": 14,
    "spendable": true,
    "solvable": true
  }
]

 


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

Chaim:bin Chaim$ ./omnicore-cli "createrawtransaction" '[{"txid":"16825d26fac2e433d7b3aff8b900e384f6d58784606f6813bee96105754cfd47","vout":1}]' '{}'
010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff0000000000

Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_opreturn" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff0000000000" "000000000000001f0000000005f5e100"
010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff010000000000000000166a146f6d6e69000000000000001f0000000005f5e10000000000

Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_reference" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff010000000000000000166a146f6d6e69000000000000001f0000000005f5e10000000000" "128HHbgLdQ3tGKjUzLfWDCR6iCcHQVKfZu"
010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000

Chaim:bin Chaim$ ./omnicore-cli "omni_createrawtx_change" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000" '[{"txid":"16825d26fac2e433d7b3aff8b900e384f6d58784606f6813bee96105754cfd47","vout":1,"scriptPubKey":"76a9143240c506599c53dbc0bc86ab8f609139a1423de488ac","value":0.00000546}]' "15aiNs86ntF8pMpYW7SaTYDZSgpZDte5Jz" 0.00006
010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000

Chaim:bin Chaim$ ./omnicore-cli "signrawtransaction" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d82160100000000ffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000"
{
  "hex": "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d8216010000006a4730440220088124ba6c64985b0cb1029ba5c626257a6d40aeede249b55c810284b62b2dfb02201e124e81bcf0738fe8c80778117e9598c0d4399dbe31d84bf1bdd08bae8d83e90121035ef84c0f6d725a4609902f69b90b6e233521c2514d0731139db8f786d1cb7cdaffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000",
  "complete": true
}

Chaim:bin Chaim$ ./omnicore-cli "sendrawtransaction" "010000000147fd4c750561e9be13686f608487d5f684e300b9f8afb3d733e4c2fa265d8216010000006a4730440220088124ba6c64985b0cb1029ba5c626257a6d40aeede249b55c810284b62b2dfb02201e124e81bcf0738fe8c80778117e9598c0d4399dbe31d84bf1bdd08bae8d83e90121035ef84c0f6d725a4609902f69b90b6e233521c2514d0731139db8f786d1cb7cdaffffffff020000000000000000166a146f6d6e69000000000000001f0000000005f5e10022020000000000001976a9140c58a1ed498a17f37d989427edc1c7150aea988988ac00000000"
error code: -26
error message:
66: insufficient priority


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

 

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

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

 

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

 

 

 

 

 

 

 

你可能感兴趣的:(区块链)