LCOV - code coverage report
Current view: top level - crypto/tron/repositories - tronscan_repository.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.3 % 60 53
Test Date: 2025-01-30 01:10:00 Functions: - 0 0

            Line data    Source code
       1              : import 'package:walletkit_dart/src/common/http_repository.dart';
       2              : import 'package:walletkit_dart/walletkit_dart.dart';
       3              : 
       4              : const _tronScanBaseUrl = "https://apilist.tronscanapi.com/api";
       5              : 
       6              : class TronScanRepository extends HTTPRepository {
       7            1 :   const TronScanRepository({
       8              :     required super.apiKeys,
       9            1 :   }) : super(baseURL: _tronScanBaseUrl, apiKeyHeader: "TRON-PRO-API-KEY");
      10              : 
      11            1 :   String getBlockEndpoint({
      12              :     required int start,
      13              :     required int limit,
      14              :     String? producer,
      15              :     bool descending = true,
      16              :     int? startTimestamp,
      17              :     int? endTimestamp,
      18              :   }) {
      19              :     // final sort = descending ? "-" : "+";
      20            7 :     return "$baseURL/block?sort=&start=${start.asQueryString}&limit=${limit.asQueryString}&producer=${producer.asQueryString}&start_timestamp=${startTimestamp.asQueryString}&end_timestamp=${endTimestamp.asQueryString}";
      21              :   }
      22              : 
      23            1 :   Future<JSON> getLatestBlock() async {
      24            1 :     final result = await getCall<JSON>(
      25            1 :       getBlockEndpoint(start: 0, limit: 1),
      26              :     );
      27              : 
      28              :     return result;
      29              :   }
      30              : 
      31            1 :   String getTransactionsEndpont({
      32              :     required int start,
      33              :     required String address,
      34              :     int limit = 10,
      35              :     int? startTimestamp,
      36              :     int? endTimestamp,
      37              :     String? type,
      38              :     String? method,
      39              :     int? block,
      40              :     List<String>? tokens,
      41              :   }) {
      42           11 :     return "$baseURL/transaction?start=${start.asQueryString}&limit=${limit.asQueryString}&address=${address.asQueryString}&start_timestamp=${startTimestamp.asQueryString}&end_timestamp=${endTimestamp.asQueryString}&type=${type.asQueryString}&method=${method.asQueryString}&block=${block.asQueryString}&tokens=${tokens.asQueryString}";
      43              :   }
      44              : 
      45            1 :   Future<Set<TronTransaction>> getTransactions({
      46              :     required String address,
      47              :     required CoinEntity token,
      48              :     int limit = 10,
      49              :     int? startTimestamp,
      50              :     int? endTimestamp,
      51              :     String? type,
      52              :     String? method,
      53              :     List<String>? tokens,
      54              :   }) async {
      55            2 :     assert(limit <= 50, "Limit must be less than or equal to 50");
      56              : 
      57            1 :     final data = [];
      58              : 
      59              :     int? totalLength;
      60            1 :     for (int i = 0; true; i += limit) {
      61            1 :       final endpoint = getTransactionsEndpont(
      62              :         start: i,
      63              :         address: address,
      64              :         limit: limit,
      65              :         startTimestamp: startTimestamp,
      66              :         endTimestamp: endTimestamp,
      67              :         type: type,
      68              :         method: method,
      69              :         tokens: tokens,
      70              :       );
      71              : 
      72            1 :       final result = await getCall<JSON>(endpoint);
      73              : 
      74            1 :       totalLength ??= result['total'] as int;
      75              : 
      76            1 :       final newData = result['data'];
      77              : 
      78            1 :       data.addAll(newData);
      79              : 
      80            2 :       if (data.length >= totalLength) {
      81              :         break;
      82              :       }
      83              :     }
      84              : 
      85              :     return {
      86            2 :       for (final item in data) TronTransaction.fromJson(item, token, address),
      87            2 :     }.whereType<TronTransaction>().toSet();
      88              :   }
      89              : 
      90            1 :   Future<JSON> getTokenPrice(String symbol) async {
      91            2 :     final endpoint = "$baseURL/token/price?token=${symbol}";
      92              : 
      93            1 :     final result = await getCall<JSON>(endpoint);
      94              : 
      95              :     return result;
      96              :   }
      97              : 
      98            0 :   Future<JSON> getAccountInfo(String address) async {
      99            0 :     final endpoint = "$baseURL/accountv2?address=${address}";
     100            0 :     final result = await getCall<JSON>(endpoint);
     101              : 
     102              :     return result;
     103              :   }
     104              : 
     105            1 :   Future<JSON> getCurrentTPS() {
     106            2 :     final endpoint = "$baseURL/system/tps";
     107            1 :     return getCall<JSON>(endpoint);
     108              :   }
     109              : 
     110            0 :   Future<JSON> getNodeMap() {
     111            0 :     final endpoint = "$baseURL/nodemap";
     112            0 :     return getCall<JSON>(endpoint);
     113              :   }
     114              : 
     115            1 :   Future<JSON> getWalletTokens({
     116              :     required String address,
     117              :     int asset_type = 0,
     118              :   }) {
     119              :     final endpoint =
     120            2 :         "$baseURL/account/wallet?address=${address}&asset_type=${asset_type}";
     121            1 :     return getCall<JSON>(endpoint);
     122              :   }
     123              : 
     124            1 :   Future<JSON> getTRXTransferList({
     125              :     required String address,
     126              :     int start = 0,
     127              :     int limit = 20,
     128              :     int direction = 0,
     129              :     bool fee = false,
     130              :     int? start_timestamp,
     131              :     int? end_timestamp,
     132              :   }) {
     133              :     final endpoint =
     134            8 :         "$baseURL/transfer/trx?address=${address}?start=${start.asQueryString}&limit=${limit.asQueryString}&direction=${direction.asQueryString}&fee=${fee.asQueryString}?start_timestamp=${start_timestamp.asQueryString}&end_timestamp=${end_timestamp.asQueryString}";
     135              : 
     136            1 :     return getCall<JSON>(endpoint);
     137              :   }
     138              : 
     139            1 :   Future<JSON> getTRC10TransferList({
     140              :     required String address,
     141              :     required String trc10Id,
     142              :     int start = 0,
     143              :     int limit = 20,
     144              :     int direction = 0,
     145              :     int? start_timestamp,
     146              :     int? end_timestamp,
     147              :   }) {
     148              :     final endpoint =
     149            7 :         "$baseURL/transfer/token10?address=${address}&trc10Id=${trc10Id}&start=${start.asQueryString}&limit=${limit.asQueryString}&direction=${direction.asQueryString}&start_timestamp=${start_timestamp.asQueryString}&end_timestamp=${end_timestamp.asQueryString}";
     150              : 
     151            1 :     return getCall<JSON>(endpoint);
     152              :   }
     153              : 
     154            1 :   Future<Set<TronTransaction>> getTRC20TransferList({
     155              :     required String address,
     156              :     required ERC20Entity trc20,
     157              :     int start = 0,
     158              :     int limit = 20,
     159              :     int direction = 0,
     160              :     int? start_timestamp,
     161              :     int? end_timestamp,
     162              :   }) async {
     163              :     final endpoint =
     164            8 :         "$baseURL/transfer/trc20?address=${address}&trc20Id=${trc20.contractAddress}&start=${start.asQueryString}&limit=${limit.asQueryString}&direction=${direction.asQueryString}&start_timestamp=${start_timestamp.asQueryString}&end_timestamp=${end_timestamp.asQueryString}";
     165              : 
     166            1 :     final result = await getCall<JSON>(endpoint);
     167            1 :     final code = result['code'] as int;
     168              : 
     169            1 :     if (code != 200) {
     170            0 :       throw Exception("Failed to fetch TRC20 Transfer List: $result");
     171              :     }
     172            1 :     final data = result['data'] as JsonList;
     173              : 
     174              :     return {
     175            2 :       for (final item in data) TronTransaction.fromJson(item, trc20, address),
     176            2 :     }.whereType<TronTransaction>().toSet();
     177              :   }
     178              : 
     179            1 :   Future<JSON> getUnfreezableBalance(String address) {
     180            2 :     final endpoint = "$baseURL/account/resource/unfreeze?address=${address}";
     181            1 :     return getCall<JSON>(endpoint);
     182              :   }
     183              : 
     184            1 :   Future<JSON> getAccountSecurity(String address) {
     185            2 :     final endpoint = "$baseURL/security/account/data?address=${address}";
     186            1 :     return getCall<JSON>(endpoint);
     187              :   }
     188              : 
     189            1 :   Future<JSON> getTokenSecurity(String tokenId) {
     190            2 :     final endpoint = "$baseURL/security/token/data?address=${tokenId}";
     191            1 :     return getCall<JSON>(endpoint);
     192              :   }
     193              : }
        

Generated by: LCOV version 2.0-1