mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-24 12:29:37 +00:00
update to tezos operation
This commit is contained in:
parent
d755fb4182
commit
7c24e9e840
3 changed files with 61 additions and 14 deletions
|
@ -9,22 +9,43 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
class TezosAPI {
|
class TezosAPI {
|
||||||
static const String _baseURL = 'https://api.tzstats.com';
|
static const String _baseURL = 'https://api.tzstats.com';
|
||||||
|
|
||||||
Future<List<TezosTransaction>?> getTransactions(String address) async {
|
Future<List<TezosOperation>?> getTransactions(String address) async {
|
||||||
try {
|
try {
|
||||||
String transactionsCall = "$_baseURL/explorer/account/$address/operations";
|
String transactionsCall = "$_baseURL/explorer/account/$address/operations";
|
||||||
var response = jsonDecode(
|
var response = jsonDecode(
|
||||||
await get(Uri.parse(transactionsCall)).then((value) => value.body));
|
await get(Uri.parse(transactionsCall)).then((value) => value.body));
|
||||||
List<TezosTransaction> txs = [];
|
List<TezosOperation> txs = [];
|
||||||
for (var tx in response as List) {
|
for (var tx in response as List) {
|
||||||
if (tx["type"] == "transaction") {
|
if (tx["type"] == "transaction") {
|
||||||
final theTx = TezosTransaction(
|
int? burnedAmountInMicroTez;
|
||||||
|
int? storage_limit;
|
||||||
|
if (tx["burned"] != null) {
|
||||||
|
burnedAmountInMicroTez = double.parse((tx["burned"] * pow(10, Coin.tezos.decimals)).toString()).toInt();
|
||||||
|
}
|
||||||
|
if (tx["storage_limit"] != null) {
|
||||||
|
storage_limit = tx["storage_limit"] as int;
|
||||||
|
}
|
||||||
|
final theTx = TezosOperation(
|
||||||
|
id: tx["id"] as int,
|
||||||
hash: tx["hash"] as String,
|
hash: tx["hash"] as String,
|
||||||
|
type: tx["type"] as String,
|
||||||
height: tx["height"] as int,
|
height: tx["height"] as int,
|
||||||
timestamp: DateTime.parse(tx["time"].toString()).toUtc().millisecondsSinceEpoch ~/ 1000,
|
timestamp: DateTime.parse(tx["time"].toString()).toUtc().millisecondsSinceEpoch ~/ 1000,
|
||||||
|
cycle: tx["cycle"] as int,
|
||||||
|
counter: tx["counter"] as int,
|
||||||
|
op_n: tx["op_n"] as int,
|
||||||
|
op_p: tx["op_p"] as int,
|
||||||
|
status: tx["status"] as String,
|
||||||
|
is_success: tx["is_success"] as bool,
|
||||||
|
gas_limit: tx["gas_limit"] as int,
|
||||||
|
gas_used: tx["gas_used"] as int,
|
||||||
|
storage_limit: storage_limit,
|
||||||
amountInMicroTez: double.parse((tx["volume"] * pow(10, Coin.tezos.decimals)).toString()).toInt(),
|
amountInMicroTez: double.parse((tx["volume"] * pow(10, Coin.tezos.decimals)).toString()).toInt(),
|
||||||
feeInMicroTez: double.parse((tx["fee"] * 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,
|
senderAddress: tx["sender"] as String,
|
||||||
receiverAddress: tx["receiver"] as String
|
receiverAddress: tx["receiver"] as String,
|
||||||
|
confirmations: tx["confirmations"] as int,
|
||||||
);
|
);
|
||||||
txs.add(theTx);
|
txs.add(theTx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,45 @@
|
||||||
class TezosTransaction {
|
class TezosOperation {
|
||||||
final String hash;
|
int? id;
|
||||||
final int height;
|
String hash;
|
||||||
final int timestamp;
|
String? type;
|
||||||
final int amountInMicroTez;
|
int height;
|
||||||
final int feeInMicroTez;
|
int timestamp;
|
||||||
final String senderAddress;
|
int? cycle;
|
||||||
final String receiverAddress;
|
int? counter;
|
||||||
|
int? op_n;
|
||||||
|
int? op_p;
|
||||||
|
String? status;
|
||||||
|
bool? is_success;
|
||||||
|
int? gas_limit;
|
||||||
|
int? gas_used;
|
||||||
|
int? storage_limit;
|
||||||
|
int amountInMicroTez;
|
||||||
|
int feeInMicroTez;
|
||||||
|
int? burnedAmountInMicroTez;
|
||||||
|
String senderAddress;
|
||||||
|
String receiverAddress;
|
||||||
|
int? confirmations;
|
||||||
|
|
||||||
TezosTransaction({
|
TezosOperation({
|
||||||
|
this.id,
|
||||||
required this.hash,
|
required this.hash,
|
||||||
|
this.type,
|
||||||
required this.height,
|
required this.height,
|
||||||
required this.timestamp,
|
required this.timestamp,
|
||||||
|
this.cycle,
|
||||||
|
this.counter,
|
||||||
|
this.op_n,
|
||||||
|
this.op_p,
|
||||||
|
this.status,
|
||||||
|
this.is_success,
|
||||||
|
this.gas_limit,
|
||||||
|
this.gas_used,
|
||||||
|
this.storage_limit,
|
||||||
required this.amountInMicroTez,
|
required this.amountInMicroTez,
|
||||||
required this.feeInMicroTez,
|
required this.feeInMicroTez,
|
||||||
|
this.burnedAmountInMicroTez,
|
||||||
required this.senderAddress,
|
required this.senderAddress,
|
||||||
required this.receiverAddress,
|
required this.receiverAddress,
|
||||||
|
this.confirmations
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -517,7 +517,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateTransactions() async {
|
Future<void> updateTransactions() async {
|
||||||
List<TezosTransaction>? txs =
|
List<TezosOperation>? txs =
|
||||||
await tezosAPI.getTransactions(await currentReceivingAddress);
|
await tezosAPI.getTransactions(await currentReceivingAddress);
|
||||||
Logging.instance.log("Transactions: $txs", level: LogLevel.Info);
|
Logging.instance.log("Transactions: $txs", level: LogLevel.Info);
|
||||||
if (txs == null) {
|
if (txs == null) {
|
||||||
|
|
Loading…
Reference in a new issue