¿Cómo consulto el saldo de una cuenta KT1 ciclo por ciclo?
2 respuestas
- votos
-
- 2019-01-30
<block_id>
:es un hash o unnivel delbloqueen el que solicitael saldo.Si desea obtener un saldo simpleen unpuntoespecífico del ciclo:
(estoes unpseudocódigo,espero que lo averigües)
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');
Pero siestátratando de obtener un saldopara calcular las recompensas de delegación:
Alprincipio,deberíaencontrarelbloque deinstantáneas que se utilizópara contar los rollos. Luego useestebloquepara obtenerel saldo comoel anterior.
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
Puede usar la API de TzScanparaesto:/v3/balance_history/KT1 ...,la documentaciónestá aquí: documento de historial de saldos . Porejemplo, https://api6.tzscan.io/v3/balance_history/KTw1GLogUJgor
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
¿Existe un RPCen el cliente de Tezos,quepermita consultarel Saldo de una cuenta KT1 ciclopor ciclo?
Loprobé coneste (TzScan Public-Node RPC):
peronoestoy seguro de qué significa
<block_id>
ytampocoestoy seguro de sieste RPCme lleva ami resultado.