简体   繁体   English

XRPL:如何获取账户余额的历史记录?

[英]XRPL: How to get the history of the balance of an account?

I would like to query the history of the balance of an XRPL account with the new WebSocket API.我想用新的 WebSocket API 查询 XRPL 账户的余额历史记录。

For example, how do I check the balance of an account on a particular day?例如,我如何查看某一天的账户余额?

I know with the v2 api, there was a possibility to query balance_changes.我知道使用 v2 api,可以查询 balance_changes。 But this doesn't seem to be part of the new version.但这似乎不是新版本的一部分。

For example:例如:

https://data.ripple.com/v2/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/balance_changes?start=2018-01-01T00:00:00Z

How is this done with the new Websocket API's?这是如何使用新的 Websocket API 完成的?

There's no convenient API call that the WebSocket API can do to get this.没有方便的 API 调用 WebSocket API 可以做到这一点。 I assume you want the XRP balance, not token/issued currency balances, which are in a different place.我假设您想要 XRP 余额,而不是代币/已发行货币余额,它们位于不同的位置。

One way to go about it is to make an account_tx call and then iterate through the metadata.关于它的 go 的一种方法是进行account_tx 调用,然后遍历元数据。 Many, but not all, transactions will have a ModifiedNode entry of type AccountRoot —if that transaction changed the account's XRP balance, you can see the difference in the PreviousFields vs. FinalFields for that entry.许多(但不是全部)交易都会有一个AccountRoot类型的ModifiedNode条目——如果该交易改变了账户的 XRP 余额,您可以看到该条目的PreviousFieldsFinalFields的差异。 The Look Up Transaction Results tutorial has some details on how to parse out metadata this way. 查找事务结果教程有一些关于如何以这种方式解析元数据的详细信息。 There are some kind of tricky edge cases here: for example, if you send a transaction that buys 10 drops of XRP in the exchange but burns 10 drops of XRP as a transaction cost, then the metadata won't show a balance change because the net change was zero (+10, -10).这里有一些棘手的边缘情况:例如,如果您发送的交易在交易所购买了 10 滴 XRP,但作为交易成本烧掉了 10 滴 XRP,那么元数据不会显示余额变化,因为净变化为零(+10,-10)。

Another approach could be to estimate what ledger_index was most recently closed at a given time, then use account_info to look up the account's balance as of that time.另一种方法可能是估计在给定时间最近关闭的ledger_index ,然后使用account_info来查找当时的帐户余额。 The hard part there is figuring out what the latest ledger index was at a given time.困难的部分是弄清楚在给定时间最新的分类帐索引是什么。 This is one of the places where the Data API was just more convenient than the WebSocket API—there's no way to look up by date in WebSocket so you have to try a ledger index, see what the close time of the ledger was, try another ledger index, see what the date is, etc.这是数据 API 比 WebSocket API 更方便的地方之一 - 无法在 WebSocket 中按日期查找日期分类帐索引,查看日期等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM