本文转载自微信公众号「区块链研究实验室」,作者链三丰。转载本文请联系区块链研究实验室公众号。
This post is reproduced from Weibo Public's Block Chain Research Laboratory, the author's chain of events. Please contact the Block Chain Research Laboratory's public number.
乙锁链交易是两个或多个地址之间交互的记录。
The B-chain transaction is an interactive record between two or more addresses.
在TRON区块链上,通常有两个交互地址,并且它们之间的交互可以采用许多不同的形式(例如,创建新帐户或资产,触发智能合约,资产转移等)。
On the TRON block chain, there are usually two interactive addresses, and the interaction between them can take many different forms (e.g. creation of new accounts or assets, triggering smart contracts, transfer of assets, etc.).
每个事务都可以通过其哈希ID(包含64个字母数字字符)来唯一识别。
Each transaction can be uniquely identified through its HashiID (which contains 64 alphanumeric characters).
获取有关交易或一组交易的信息是区块链数据分析的核心。
Access to information on transactions or a group of transactions is central to the analysis of block chain data.
本文演示了如何使用R包tronr(用于探索TRON网络的工具箱)收集此类信息。
This paper demonstrates how R-Back Tronr (a toolbox for exploring the Tron network) can be used to collect such information.
查询个人交易
Query personal transactions
tronr程序包中的几个功能允许查询事务数据。关键功能之一是get_tx_info_by_id(),它根据交易的ID(以嵌套tibble的形式)返回交易的属性。这样的ID可以利用其他几种可以获得tronr的功能,例如get_block_info(),get_blocks_for_time_range(),get_tx_for_time_range()等。这里是一个例子:
Several functions in the tronar package allow access to transaction data. One of the key functions is get_tx_info_by_id(), which returns the properties of the transaction according to the transaction ID (in the form of an embedded tibble). Such an ID can use several other functions that can be obtained from tronr, such as get_block_info(), get_blocks_for_time_range(), get_tx_for_time_range() etc. This is an example:
- require(tronr)
- require(dplyr)
- require(tidyr)
- #> R toolbox to explore the TRON blockchain
- #> Developed by Next Game Solutions (http://nextgamesolutions.com)
- # Get transactions of the latest block:
- latest_block <- get_block_info(latest = TRUE)
- # Pick an example transaction:
- tx_id <- latest_block$tx[[1]]$tx_id[1]
- tx_id
- # "074ce32ed2ca89c69e54e4ac4ff5ee825df33f6cf087d869c44dc3456f349855"
- # Retrieve transaction attributes (see documentation for their
- # definitions):
- r1 <- get_tx_info_by_id(tx_id = tx_id, add_contract_data = FALSE)
- glimpse(r1)
- #> Rows: 1
- #> Columns: 19
- #> $ request_time <dttm> 2021-03-31 19:22:57
- #> $ tx_id <chr> "074ce32ed2ca89c69e54e4ac4f...
- #> $ block_number <chr> "28941541"
- #> $ timestamp <dttm> 2021-03-31 19:19:06
- #> $ contract_result <chr> "SUCCESS"
- #> $ confirmed <lgl> TRUE
- #> $ confirmations_count <int> 71
- #> $ sr_confirm_list <list> [<tbl_df[19 x 3]>]
- #> $ contract_type <chr> "TriggerSmartContract"
- #> $ from_address <chr> "TSrS5zMUgzHe688XcZ4PnN5Y3c...
- #> $ to_address <chr> "TDxYAUHTw7Tk9NQfDJk9wmcsb2...
- #> $ is_contract_from_address <lgl> FALSE
- #> $ is_contract_to_address <lgl> TRUE
- #> $ costs <list> [<tbl_df[1 x 8]>]
- #> $ trx_transfer <dbl> 9.906872
- #> $ trc10_transfer <lgl> NA
- #> $ trc20_transfer <list> [<tbl_df[1 x 9]>]
- #> $ internal_tx <list> [<tbl_df[3 x 12]>]
- #> $ info <lgl> NA
如果将add_contact_data参数设置为TRUE,则生成的小标题还将具有名为的列contract_data。
If the add_contact_data parameter is set to TRUE, the subheading generated will also have a column named Contractor_data.
该列将包含一个列表,其中包含执行相关交易的智能合约生成的原始数据。该清单的实际内容取决于每笔交易和各自合同的性质:
The column will contain a list of the original data generated by the intelligent contract that executes the transaction. The actual content of the list depends on the nature of each transaction and the respective contract:
- r2 <- get_tx_info_by_id(tx_id = tx_id, add_contract_data = TRUE)
- glimpse(r1)
- #> Rows: 1
- #> Columns: 20
- #> $ request_time <dttm> 2021-03-31 19:28:23
- #> $ tx_id <chr> "074ce32ed2ca89c69e54e4ac4f...
- #> $ block_number <chr> "28941541"
- #> $ timestamp <dttm> 2021-03-31 19:19:06
- #> $ contract_result <chr> "SUCCESS"
- #> $ confirmed <lgl> TRUE
- #> $ confirmations_count <int> 180
- #> $ sr_confirm_list <list> [<tbl_df[19 x 3]>]
- #> $ contract_type <chr> "TriggerSmartContract"
- #> $ from_address <chr> "TSrS5zMUgzHe688XcZ4PnN5Y3c...
- #> $ to_address <chr> "TDxYAUHTw7Tk9NQfDJk9wmcsb2...
- #> $ is_contract_from_address <lgl> FALSE
- #> $ is_contract_to_address <lgl> TRUE
- #> $ costs <list> [<tbl_df[1 x 8]>]
- #> $ trx_transfer <dbl> 9.906872
- #> $ trc10_transfer <lgl> NA
- #> $ trc20_transfer <list> [<tbl_df[1 x 9]>]
- #> $ internal_tx <list> [<tbl_df[3 x 12]>]
- #> $ info <lgl> NA
- #> $ contract_data <list> [["422f1043000000000000000...
- r2$contract_data[[1]]
- #> $data
- #> [1]"422f1043000000000000000000000000000000000000000000000000...
- #>
- #> $owner_address
- #> [1] "TSrS5zMUgzHe688XcZ4PnN5Y3cHQA3euWt"
- #>
- #> $contract_address
- #> [1] "TDxYAUHTw7Tk9NQfDJk9wmcsb26S8kHbdF"
- #> $call_value
- #> [1] 9906872
请注意,在返回的tibbles所有令牌数量get_tx_info_by_id()(trx_transfer,trc10_transfer,trc20_transfer,和internal_tx)使用的整数和小数部分表示。
Please note that the integer and decimal parts used in the number of all tibbles returned (get_tx_info_by_id(trx_transfer, trc10_transfer, trc20_transfer, and internal_tx) are indicated.
但如果是add_contract_data=TRUE,则返回的原始合同数据按“原样”显示(即无需任何解析或其他处理),因此该数据中存在的任何令牌量都使用机器级精度表示。
However, if it is add_contract_data=TRUE, the original contract data returned are &ldquao; the original &rdquao; the display (i.e., there is no need for any parsing or other processing) so that any token amount that exists in the data is expressed using machine-grade accuracy.
查询时间范围
query time frame
要在特定时间段内检索交易及其属性的列表,可以使用该get_tx_for_time_range()功能。与相比get_tx_info_by_id(),此函数有两个附加参数定义了感兴趣的时间范围-min_timestamp和max_timestamp。这两个附加参数都期望Unix时间戳(包括毫秒):
To retrieve the list of transactions and their properties within a given time period, the get_tx_for_time_range() function can be used. Compared to the get_tx_info_by_id(), two additional parameters define the time range of interest -min_timestamp and max_timestamp. Both additional parameters expect Unix time stamp (including milliseconds):
- tx_df <- get_tx_for_time_range(min_timestamp = "1577836800000",
- max_timestamp = "1577836803000")
- glimpse(tx_df)
- #> Rows: 41
- #> Columns: 20
- #> $ request_time <dttm> 2021-03-31 19:45:21, 2...
- #> $ tx_id <chr> "5f131118e7e24725906a72...
- #> $ block_number <chr> "15860581", "15860581",...
- #> $ timestamp <dttm> 2020-01-01, 2020-01-01...
- #> $ contract_result <chr> "SUCCESS", "SUCCESS", "...
- #> $ confirmed <lgl> TRUE, TRUE, TRUE, TRUE,...
- #> $ confirmations_count <int> 13081480, 13081480, 130...
- #> $ sr_confirm_list <list> [<tbl_df[19 x 3]>, <tb...
- #> $ contract_type <chr> "TransferAssetContract"...
- #> $ from_address <chr> "TXmUfpBfxRTdbZXhzuqEJK...
- #> $ to_address <chr> "TCQBxaNNQ2h1HbrWxWSg7A...
- #> $ is_contract_from_address <lgl> FALSE, FALSE, FALSE, FA...
- #> $ is_contract_to_address <lgl> FALSE, TRUE, TRUE, TRUE...
- #> $ costs <list> [<tbl_df[1 x 8]>, <tbl...
- #> $ trx_transfer <dbl> 0.000, 200.000, 0.000, ...
- #> $ trc10_transfer <list> [<tbl_df[1 x 5]>, NULL...
- #> $ trc20_transfer <lgl> NA, NA, NA, NA, NA, NA,...
- #> $ internal_tx <list> [NULL, NULL, <tbl_df[1...
- #> $ info <lgl> NA, NA, NA, NA, NA, NA,...
- #> $ contract_data <list> [[10000000, "1002830",...
请注意,get_tx_for_time_range()在后台进行了多个Tronscan API调用。
Please note that Get_tx_for_time_range() has conducted multiple Tronscan API calls from backstage.
作为上发生的TRON blockchain交易的数量是非常大的,用户因此宜选择min_timestamp和max_timestamp是明智之举。如果请求的时间范围太大,则基础Tronscan API返回的最大事务数将被限制为10000,并且处理时间可能会变得过长。
If the requested time frame is too large, the maximum number of transactions that Tronscan API returns will be limited to 10,000 and the processing time may be excessive.
在这种情况下,将感兴趣的时间范围划分为较小的时间段可以帮助避免数据缺口。
In such cases, dividing the period of interest into smaller periods could help to avoid data gaps.
查询特定帐户的交易
transactions for particular accounts
还可以使用该get_tx_info_by_account_address()功能来检索特定帐户的交易数据。此外,可以在特定时间范围内完成此操作:
The get_tx_info_by_account_address() function can also be used to retrieve transaction data for a given account. In addition, this can be done within a specified time frame:
- tx_df_acc <- get_tx_info_by_account_address(
- address = "TAUN6FwrnwwmaEqYcckffC7wYmbaS6cBiX",
- min_timestamp = "1577836800000",
- max_timestamp = "1577838600000"
- )
- glimpse(tx_df_acc)
- #> Rows: 18
- #> Columns: 21
- #> $ request_time <dttm> 2021-03-31 19:55:31, 2...
- #> $ address <chr> "TAUN6FwrnwwmaEqYcckffC...
- #> $ tx_id <chr> "36ec18062510f22a469bfb...
- #> $ block_number <chr> "15860591", "15860591",...
- #> $ timestamp <dttm> 2020-01-01 00:00:36, 2...
- #> $ contract_result <chr> "SUCCESS", "SUCCESS", "...
- #> $ confirmed <lgl> TRUE, TRUE, TRUE, TRUE,...
- #> $ confirmations_count <int> 13081672, 13081672, 130...
- #> $ sr_confirm_list <list> [<tbl_df[19 x 3]>, <tb...
- #> $ contract_type <chr> "TransferContract", "Tr...
- #> $ from_address <chr> "TAUN6FwrnwwmaEqYcckffC...
- #> $ to_address <chr> "TDn2MK7n5SqVksSZtQDAhD...
- #> $ is_contract_from_address <lgl> FALSE, FALSE, FALSE, FA...
- #> $ is_contract_to_address <lgl> FALSE, FALSE, FALSE, FA...
- #> $ costs <list> [<tbl_df[1 x 8]>, <tbl...
- #> $ trx_transfer <dbl> 664296.00000, 925.55360...
- #> $ trc10_transfer <list> [NULL, NULL, NULL, NUL...
- #> $ trc20_transfer <lgl> NA, NA, NA, NA, NA, NA,...
- #> $ internal_tx <lgl> NA, NA, NA, NA, NA, NA,...
- #> $ info <lgl> NA, NA, NA, NA, NA, NA,...
- #> $ contract_data <list> [[6.64296e+11, "TAUN6F...
现在,我们成功的使用R包在TRON区块链查询交易数据,如有任何想法和疑问,欢迎在留言区留言。
Now, we have successfully used the R package to search for transaction data in the Tron block chain and are welcome to leave a message in the message area if you have any thoughts or questions.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论