From de43baaaa003028b5adeb5d3654a15012f024a5f Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 20 Nov 2023 16:16:07 -0600 Subject: [PATCH] fix xtz transactions parsing --- lib/wallets/api/tezos/tezos_api.dart | 54 ++++++++------------ lib/wallets/api/tezos/tezos_transaction.dart | 2 - 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/lib/wallets/api/tezos/tezos_api.dart b/lib/wallets/api/tezos/tezos_api.dart index 7e774c44b..c54b9004d 100644 --- a/lib/wallets/api/tezos/tezos_api.dart +++ b/lib/wallets/api/tezos/tezos_api.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:math'; import 'package:stackwallet/networking/http.dart'; import 'package:stackwallet/services/tor_service.dart'; @@ -10,11 +9,12 @@ import 'package:stackwallet/wallets/api/tezos/tezos_transaction.dart'; abstract final class TezosAPI { static final HTTP _client = HTTP(); - static const String _baseURL = 'https://api.mainnet.tzkt.io'; + static const String _baseURL = 'https://api.tzkt.io'; static Future?> getTransactions(String address) async { try { - final transactionsCall = "$_baseURL/explorer/account/$address/operations"; + final transactionsCall = + "$_baseURL/v1/accounts/$address/operations?type=transaction"; final response = await _client.get( url: Uri.parse(transactionsCall), @@ -29,52 +29,38 @@ abstract final class TezosAPI { List txs = []; for (var tx in result) { if (tx["type"] == "transaction") { - int? burnedAmountInMicroTez; - int? storageLimit; - if (tx["burned"] != null) { - burnedAmountInMicroTez = double.parse( - (tx["burned"] * pow(10, Coin.tezos.decimals)).toString()) - .toInt(); - } - if (tx["storage_limit"] != null) { - storageLimit = tx["storage_limit"] as int; - } final theTx = TezosTransaction( id: tx["id"] as int, hash: tx["hash"] as String, type: tx["type"] as String, - height: tx["height"] as int, - timestamp: DateTime.parse(tx["time"].toString()) + height: tx["level"] as int, + timestamp: DateTime.parse(tx["timestamp"].toString()) .toUtc() .millisecondsSinceEpoch ~/ 1000, - cycle: tx["cycle"] as int, + cycle: tx["cycle"] as int?, counter: tx["counter"] as int, - opN: tx["op_n"] as int, - opP: tx["op_p"] as int, + opN: tx["op_n"] as int?, + opP: tx["op_p"] as int?, status: tx["status"] as String, - isSuccess: tx["is_success"] as bool, - gasLimit: tx["gas_limit"] as int, - gasUsed: tx["gas_used"] as int, - storageLimit: storageLimit, - amountInMicroTez: double.parse( - (tx["volume"] * pow(10, Coin.tezos.decimals)).toString()) - .toInt(), - feeInMicroTez: double.parse( - (tx["fee"] * pow(10, Coin.tezos.decimals)).toString()) - .toInt(), - burnedAmountInMicroTez: burnedAmountInMicroTez, - senderAddress: tx["sender"] as String, - receiverAddress: tx["receiver"] as String, - confirmations: tx["confirmations"] as int, + gasLimit: tx["gasLimit"] as int, + gasUsed: tx["gasUsed"] as int, + storageLimit: tx["storageLimit"] as int?, + amountInMicroTez: tx["amount"] as int, + feeInMicroTez: (tx["bakerFee"] as int? ?? 0) + + (tx["storageFee"] as int? ?? 0) + + (tx["allocationFee"] as int? ?? 0), + burnedAmountInMicroTez: tx["burned"] as int?, + senderAddress: tx["sender"]["address"] as String, + receiverAddress: tx["target"]["address"] as String, ); txs.add(theTx); } } return txs; - } catch (e) { + } catch (e, s) { Logging.instance.log( - "Error occurred in tezos_api.dart while getting transactions for $address: $e", + "Error occurred in tezos_api.dart while getting transactions for $address: $e\n$s", level: LogLevel.Error, ); } diff --git a/lib/wallets/api/tezos/tezos_transaction.dart b/lib/wallets/api/tezos/tezos_transaction.dart index 28a21ad91..e1e6bc88b 100644 --- a/lib/wallets/api/tezos/tezos_transaction.dart +++ b/lib/wallets/api/tezos/tezos_transaction.dart @@ -18,7 +18,6 @@ class TezosTransaction { final int? burnedAmountInMicroTez; final String senderAddress; final String receiverAddress; - final int? confirmations; TezosTransaction({ this.id, @@ -40,6 +39,5 @@ class TezosTransaction { this.burnedAmountInMicroTez, required this.senderAddress, required this.receiverAddress, - this.confirmations, }); }