如何按周期查询KT1帐户的余额?
2 个回答
- 投票数
-
- 2019-01-30
<block_id>
-是您要求平衡的哈希值或块级别.如果您想在周期中的特定点获得简单的平衡:
(这是伪代码,希望您能弄清楚)
var cycle = 60; var p1 = (cycle * 4096 + 1) + 0; //beginning of the cycle var p2 = (cycle * 4096 + 1) + 4095; //end of the cycle var balance_at_p1 = get('/chains/main/blocks/{p1}/context/contracts/KT1.../balance'); var balance_at_p2 = get('/chains/main/blocks/{p2}/context/contracts/KT1.../balance');
但是,如果您想在计算授权奖励时获得平衡:
首先,您应该找到用于计数滚动的快照块.然后使用此块来获得上述余额.
var cycle = 60; var cycle_lvl = cycle * 4096 + 1; var snapshot = get('/chains/main/blocks/{cycle_lvl}/context/raw/json/cycle/{cycle}'); var snapshot_block = ((cycle - 7) * 4096 + 1) + (snapshot.roll_snapshot + 1) * 256 - 1; var balance = get('/chains/main/blocks/{snapshot_block}/context/contracts/KT1.../balance');
<block_id>
- is a hash or a level of the block at which you ask for balance.If you want to get a simple balance at the specific point in the cycle:
(this is pseudocode, I hope you figure it out)
var cycle = 60; var p1 = (cycle * 4096 + 1) + 0; //beginning of the cycle var p2 = (cycle * 4096 + 1) + 4095; //end of the cycle var balance_at_p1 = get('/chains/main/blocks/{p1}/context/contracts/KT1.../balance'); var balance_at_p2 = get('/chains/main/blocks/{p2}/context/contracts/KT1.../balance');
But if you are trying to get a balance for calculating delegation rewards:
At first you should find the snapshot block that was used to count the rolls. Then use this block to get the balance like above.
var cycle = 60; var cycle_lvl = cycle * 4096 + 1; var snapshot = get('/chains/main/blocks/{cycle_lvl}/context/raw/json/cycle/{cycle}'); var snapshot_block = ((cycle - 7) * 4096 + 1) + (snapshot.roll_snapshot + 1) * 256 - 1; var balance = get('/chains/main/blocks/{snapshot_block}/context/contracts/KT1.../balance');
-
- 2019-01-30
您可以为此使用TzScan API:/v3/balance_history/KT1 ...,文档位于此处:余额历史记录文件. 例如">://api6.tzscan.io/v3/balance_history/KT1GgUJwMQoFayRYN >
You can use TzScan API for this: /v3/balance_history/KT1..., the documentation is here: balance history doc. For example https://api6.tzscan.io/v3/balance_history/KT1GgUJwMQoFayRYNwamRAYCvHBLzgorLoGo
Tezos客户端中是否有一个RPC,可以逐周期查询KT1帐户的余额?
我已经尝试过使用此(TzScan Public-Node RPC):
但我不确定
<block_id>
是什么意思,也不确定此RPC是否将我引向我的结果.