mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 22:58:49 +00:00
fix xtz transactions parsing
This commit is contained in:
parent
62c1628fa7
commit
de43baaaa0
2 changed files with 20 additions and 36 deletions
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:stackwallet/networking/http.dart';
|
import 'package:stackwallet/networking/http.dart';
|
||||||
import 'package:stackwallet/services/tor_service.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 {
|
abstract final class TezosAPI {
|
||||||
static final HTTP _client = HTTP();
|
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 {
|
static Future<List<TezosTransaction>?> getTransactions(String address) async {
|
||||||
try {
|
try {
|
||||||
final transactionsCall = "$_baseURL/explorer/account/$address/operations";
|
final transactionsCall =
|
||||||
|
"$_baseURL/v1/accounts/$address/operations?type=transaction";
|
||||||
|
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
url: Uri.parse(transactionsCall),
|
url: Uri.parse(transactionsCall),
|
||||||
|
@ -29,52 +29,38 @@ abstract final class TezosAPI {
|
||||||
List<TezosTransaction> txs = [];
|
List<TezosTransaction> txs = [];
|
||||||
for (var tx in result) {
|
for (var tx in result) {
|
||||||
if (tx["type"] == "transaction") {
|
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(
|
final theTx = TezosTransaction(
|
||||||
id: tx["id"] as int,
|
id: tx["id"] as int,
|
||||||
hash: tx["hash"] as String,
|
hash: tx["hash"] as String,
|
||||||
type: tx["type"] as String,
|
type: tx["type"] as String,
|
||||||
height: tx["height"] as int,
|
height: tx["level"] as int,
|
||||||
timestamp: DateTime.parse(tx["time"].toString())
|
timestamp: DateTime.parse(tx["timestamp"].toString())
|
||||||
.toUtc()
|
.toUtc()
|
||||||
.millisecondsSinceEpoch ~/
|
.millisecondsSinceEpoch ~/
|
||||||
1000,
|
1000,
|
||||||
cycle: tx["cycle"] as int,
|
cycle: tx["cycle"] as int?,
|
||||||
counter: tx["counter"] as int,
|
counter: tx["counter"] as int,
|
||||||
opN: tx["op_n"] as int,
|
opN: tx["op_n"] as int?,
|
||||||
opP: tx["op_p"] as int,
|
opP: tx["op_p"] as int?,
|
||||||
status: tx["status"] as String,
|
status: tx["status"] as String,
|
||||||
isSuccess: tx["is_success"] as bool,
|
gasLimit: tx["gasLimit"] as int,
|
||||||
gasLimit: tx["gas_limit"] as int,
|
gasUsed: tx["gasUsed"] as int,
|
||||||
gasUsed: tx["gas_used"] as int,
|
storageLimit: tx["storageLimit"] as int?,
|
||||||
storageLimit: storageLimit,
|
amountInMicroTez: tx["amount"] as int,
|
||||||
amountInMicroTez: double.parse(
|
feeInMicroTez: (tx["bakerFee"] as int? ?? 0) +
|
||||||
(tx["volume"] * pow(10, Coin.tezos.decimals)).toString())
|
(tx["storageFee"] as int? ?? 0) +
|
||||||
.toInt(),
|
(tx["allocationFee"] as int? ?? 0),
|
||||||
feeInMicroTez: double.parse(
|
burnedAmountInMicroTez: tx["burned"] as int?,
|
||||||
(tx["fee"] * pow(10, Coin.tezos.decimals)).toString())
|
senderAddress: tx["sender"]["address"] as String,
|
||||||
.toInt(),
|
receiverAddress: tx["target"]["address"] as String,
|
||||||
burnedAmountInMicroTez: burnedAmountInMicroTez,
|
|
||||||
senderAddress: tx["sender"] as String,
|
|
||||||
receiverAddress: tx["receiver"] as String,
|
|
||||||
confirmations: tx["confirmations"] as int,
|
|
||||||
);
|
);
|
||||||
txs.add(theTx);
|
txs.add(theTx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return txs;
|
return txs;
|
||||||
} catch (e) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
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,
|
level: LogLevel.Error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ class TezosTransaction {
|
||||||
final int? burnedAmountInMicroTez;
|
final int? burnedAmountInMicroTez;
|
||||||
final String senderAddress;
|
final String senderAddress;
|
||||||
final String receiverAddress;
|
final String receiverAddress;
|
||||||
final int? confirmations;
|
|
||||||
|
|
||||||
TezosTransaction({
|
TezosTransaction({
|
||||||
this.id,
|
this.id,
|
||||||
|
@ -40,6 +39,5 @@ class TezosTransaction {
|
||||||
this.burnedAmountInMicroTez,
|
this.burnedAmountInMicroTez,
|
||||||
required this.senderAddress,
|
required this.senderAddress,
|
||||||
required this.receiverAddress,
|
required this.receiverAddress,
|
||||||
this.confirmations,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue