fix xtz transactions parsing

This commit is contained in:
julian 2023-11-20 16:16:07 -06:00
parent 62c1628fa7
commit de43baaaa0
2 changed files with 20 additions and 36 deletions

View file

@ -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<List<TezosTransaction>?> 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<TezosTransaction> 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,
);
}

View file

@ -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,
});
}