iT邦幫忙

2022 iThome 鐵人賽

DAY 21
0
Web 3

如何打造屬於自己的區塊鏈錢包服務系列 第 22

[Day 21] Elrond full node (十二)

  • 分享至 

  • xImage
  •  

今天來看一下HyperBlock裡面是放什麼資訊,
呼叫的url是

{{rpc-server}}/hyperblock/by-nonce/:nonce?withTxs=true

withTxs=true的話就會顯示transactions,:nonce帶的是block hight,我們看一下explorer跟api回傳的資訊。
API response

{
    "data": {
        "hyperblock": {
            "hash": "dd8ec25b4f093d75fdddfe387a730d6c1a9698efef0f41362eb88bacb6897f2a",
            "prevBlockHash": "07ec98d85627a8f4ce1bff0a61e17a0d8bf9898a02aa0866f6c943399109c918",
            "stateRootHash": "070eed40c53844f011de5e593bd649178adf9c206e85c556af55b2a32b125902",
            "nonce": 1131724,
            "round": 1134496,
            "epoch": 944,
            "numTxs": 2,
            "accumulatedFees": "0",
            "developerFees": "0",
            "accumulatedFeesInEpoch": "96864929070200000",
            "developerFeesInEpoch": "6338321721000000",
            "timestamp": 1660128576,
            "shardBlocks": [
                {
                    "hash": "d63fcbf3ac9b45971a6afc92f07a94b1d0800da5d388301b550cefdf541510df",
                    "nonce": 1130228,
                    "round": 1134494,
                    "shard": 0
                },
                {
                    "hash": "75f1fd50a596ddce34941d75b8a6e06df7067105eb593a346e6ce0e87faf7d2d",
                    "nonce": 1130460,
                    "round": 1134494,
                    "shard": 1
                },
                {
                    "hash": "77f961bc16a278b0ed9b2f46c3ef3264b3eafc0ec735d96a7ab0938c7fde68b4",
                    "nonce": 1130967,
                    "round": 1134494,
                    "shard": 2
                }
            ],
            "transactions": [
                {
                    "type": "unsigned",
                    "processingTypeOnSource": "BuiltInFunctionCall",
                    "processingTypeOnDestination": "BuiltInFunctionCall",
                    "hash": "bb0b787b6316d3041695f46a42c48a87aafa300ad9727dd90618fe685aee6776",
                    "nonce": 0,
                    "round": 0,
                    "epoch": 944,
                    "value": "0",
                    "receiver": "erd12pdht5c6fckn9d50lxalt4g8qvrmfzr9qkkcfrmnek07vt9jgzxqtzsvcg",
                    "sender": "erd1qqqqqqqqqqqqqpgqrtwq3k7uhwdlaltmssynp65uhnky452cdzds8py4sj",
                    "gasPrice": 1000000000,
                    "data": "RVNEVFRyYW5zZmVyQDQzNTI1NDJkMzYzNTM5MzA2MTYzQDc0MDRhZmI0ZjI0NDAwMDBANjI2OTY0MjA3MjY1NjY3NTZlNjQ=",
                    "previousTransactionHash": "a18234d05e905fb95b316b7679b0304d85111b3a83c2ae9983069311f3700d14",
                    "originalTransactionHash": "a18234d05e905fb95b316b7679b0304d85111b3a83c2ae9983069311f3700d14",
                    "sourceShard": 1,
                    "destinationShard": 0,
                    "miniblockType": "SmartContractResultBlock",
                    "miniblockHash": "237265d0c81e90c8b2c47423e76b980646bb6ea6b022a1cb9b4b4d27f3e18528",
                    "status": "success",
                    "tokens": [
                        "CRT-6590ac"
                    ],
                    "esdtValues": [
                        "8360000000000000000"
                    ],
                    "operation": "ESDTTransfer"
                },
                {
                    "type": "normal",
                    "processingTypeOnSource": "MoveBalance",
                    "processingTypeOnDestination": "MoveBalance",
                    "hash": "a2ef6ffb159b4f10f3169acee190f3ec8f858074a1b0a4808f0dbb4129281a3f",
                    "nonce": 9730,
                    "round": 0,
                    "epoch": 944,
                    "value": "30000000000000000000",
                    "receiver": "erd1e5jayxfyjm4p07nfeepvc006swfzywzda7yvvhpwn5sg5rwpq00s7f4hfr",
                    "sender": "erd1pdv0h3ddqyzlraek02y5rhmjnwwapjyhqm983kfcdfzmr6axqhdsfg4akx",
                    "gasPrice": 1000000001,
                    "gasLimit": 50000,
                    "signature": "15235de3dbebe75f9f5a2417311963b0963b417ac964c43c695900ae19bf72645eaf14ab554d131eab0687e44eda543542297153f9890d1a53082feed7cf8504",
                    "sourceShard": 1,
                    "destinationShard": 1,
                    "miniblockType": "TxBlock",
                    "miniblockHash": "df927327e93f3f60b7b4f0aa9b93aa9660188ae971fd58ede898a751db2c1995",
                    "status": "success",
                    "operation": "transfer",
                    "initiallyPaidFee": "50000000050000"
                }
            ],
            "status": "on-chain"
        }
    },
    "code": "successful"
}

簡單介紹一些欄位定義

  • data.hyperblock.hash: hyperblock hash
  • data.hyperblock.nonce: hyperblock hight(metachain hight)
  • data.hyperblock.numTxs: 有幾筆交易
  • data.hyperblock.timestamp: block timestamp
  • data.hyperblock.shardBlocks: shard block hight and hash
  • data.hyperblock.transactions: all transaction in all shard

目前我們都只先看Elrond native token EGLD的交易,他的智能合約代幣ESDT token交易內容與EGLD交易內容不一樣,為了避免混淆目前先只講EGLD的交易,之後有時間再來談ESDT類型的交易。
對交易所來說鏈上行為只管轉帳,轉帳代表的是withdraw或是deposit,所以我們只會取幾個值來檢查

 {
                    "type": "normal",
                    "processingTypeOnSource": "MoveBalance",
                    "processingTypeOnDestination": "MoveBalance",
                    "hash": "a2ef6ffb159b4f10f3169acee190f3ec8f858074a1b0a4808f0dbb4129281a3f",
                    "nonce": 9730,
                    "round": 0,
                    "epoch": 944,
                    "value": "30000000000000000000",
                    "receiver": "erd1e5jayxfyjm4p07nfeepvc006swfzywzda7yvvhpwn5sg5rwpq00s7f4hfr",
                    "sender": "erd1pdv0h3ddqyzlraek02y5rhmjnwwapjyhqm983kfcdfzmr6axqhdsfg4akx",
                    "gasPrice": 1000000001,
                    "gasLimit": 50000,
                    "signature": "15235de3dbebe75f9f5a2417311963b0963b417ac964c43c695900ae19bf72645eaf14ab554d131eab0687e44eda543542297153f9890d1a53082feed7cf8504",
                    "sourceShard": 1,
                    "destinationShard": 1,
                    "miniblockType": "TxBlock",
                    "miniblockHash": "df927327e93f3f60b7b4f0aa9b93aa9660188ae971fd58ede898a751db2c1995",
                    "status": "success",
                    "operation": "transfer",
                    "initiallyPaidFee": "50000000050000"
                }
  1. 檢查hash是否存在DB中,這邊之前有說到交易所會把parse過的block資料儲存在DB中避免重複處理
  2. 如果不存在則檢查receiver or sender的address是否是交易所的address
  3. 如果是的話檢查operation是否為transfer
  4. 如果是的話檢查status是否為success
  5. 如果是的話取得value的值,這個就是轉帳的金額然後再將hash儲存於DB中

ps.你會看到value是30000000000000000000這是因為decimal,用來精確表示數量,因為加密貨幣可以切割成很小位數去做交易,例如0.000000001 ETH,因為每個token設定的decimal不同,所以要特別注意這點!
EGLD和ETH的decimal一樣是10的-18次方,所以需要將30000000000000000000去乘10的-18次方也就是這次轉帳的金額是30顆EGLD。
接觸過不同的區塊鏈後,看他們的block的資訊和提交交易所要帶的資料等等的,可以更加的瞭解不同區塊鏈的設計風格,之後如果還心有餘力,會想要去看每個鏈怎麼處理共識這塊。


上一篇
[Day 20] Elrond full node (十一)
下一篇
[Day 22] Elrond full node (十三)
系列文
如何打造屬於自己的區塊鏈錢包服務31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言