mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 19:55:52 +00:00
xtz: filter other operations
This commit is contained in:
parent
68f3bc8731
commit
f4688bd041
1 changed files with 51 additions and 50 deletions
|
@ -332,60 +332,61 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
|
|
||||||
Future<void> updateTransactions() async {
|
Future<void> updateTransactions() async {
|
||||||
// TODO: Use node RPC instead of tzstats API
|
// TODO: Use node RPC instead of tzstats API
|
||||||
var api =
|
var api = "https://api.tzstats.com/tables/op?address=${await currentReceivingAddress}";
|
||||||
"https://api.tzstats.com/tables/op?address=${await currentReceivingAddress}";
|
var jsonResponse = jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
|
||||||
var jsonResponse =
|
|
||||||
jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
|
|
||||||
List<Tuple2<Transaction, Address>> txs = [];
|
List<Tuple2<Transaction, Address>> txs = [];
|
||||||
for (var tx in jsonResponse as List) {
|
for (var tx in jsonResponse as List) {
|
||||||
var txApi = "https://api.tzstats.com/explorer/op/${tx["hash"]}";
|
if (tx[1] == "transaction") {
|
||||||
var txJsonResponse = jsonDecode(
|
var txApi = "https://api.tzstats.com/explorer/op/${tx[2]}";
|
||||||
await get(Uri.parse(txApi)).then((value) => value.body))[0];
|
var txJsonResponse = jsonDecode(await get(Uri.parse(txApi)).then((value) => value.body));
|
||||||
TransactionType txType;
|
// Check if list is larger than 1 (if it is, it's a batch transaction)
|
||||||
if (txJsonResponse["sender"] == (await currentReceivingAddress)) {
|
if (!((txJsonResponse as List).length > 1)) {
|
||||||
txType = TransactionType.outgoing;
|
for (var (opJson as Map) in txJsonResponse) {
|
||||||
} else {
|
if (opJson.containsKey("volume")) { // This is to check if transaction is a token transfer
|
||||||
txType = TransactionType.incoming;
|
TransactionType txType;
|
||||||
|
if (opJson["sender"] == (await currentReceivingAddress)) {
|
||||||
|
txType = TransactionType.outgoing;
|
||||||
|
} else {
|
||||||
|
txType = TransactionType.incoming;
|
||||||
|
}
|
||||||
|
var theTx = Transaction(
|
||||||
|
walletId: walletId,
|
||||||
|
txid: opJson["hash"].toString(),
|
||||||
|
timestamp: DateTime.parse(opJson["time"].toString()).toUtc().millisecondsSinceEpoch ~/ 1000,
|
||||||
|
type: txType,
|
||||||
|
subType: TransactionSubType.none,
|
||||||
|
amount: (float.parse(opJson["volume"].toString()) * 1000000).toInt(),
|
||||||
|
amountString: Amount(
|
||||||
|
rawValue: BigInt.parse((float.parse(opJson["volume"].toString()) * 1000000).toInt().toString()),
|
||||||
|
fractionDigits: 6
|
||||||
|
).toJsonString(),
|
||||||
|
fee: (float.parse(opJson["fee"].toString()) * 1000000).toInt(),
|
||||||
|
height: int.parse(opJson["height"].toString()),
|
||||||
|
isCancelled: false,
|
||||||
|
isLelantus: false,
|
||||||
|
slateId: "",
|
||||||
|
otherData: "",
|
||||||
|
inputs: [],
|
||||||
|
outputs: [],
|
||||||
|
nonce: 0,
|
||||||
|
numberOfMessages: null,
|
||||||
|
);
|
||||||
|
var theAddress = Address(
|
||||||
|
walletId: walletId,
|
||||||
|
value: opJson["receiver"].toString(),
|
||||||
|
publicKey: [], // TODO: Add public key
|
||||||
|
derivationIndex: 0,
|
||||||
|
derivationPath: null,
|
||||||
|
type: AddressType.unknown,
|
||||||
|
subType: AddressSubType.unknown,
|
||||||
|
);
|
||||||
|
txs.add(Tuple2(theTx, theAddress));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var theTx = Transaction(
|
|
||||||
walletId: walletId,
|
|
||||||
txid: txJsonResponse["hash"].toString(),
|
|
||||||
timestamp: DateTime.parse(txJsonResponse["time"].toString())
|
|
||||||
.toUtc()
|
|
||||||
.millisecondsSinceEpoch ~/
|
|
||||||
1000,
|
|
||||||
type: txType,
|
|
||||||
subType: TransactionSubType.none,
|
|
||||||
amount: (float.parse(txJsonResponse["volume"].toString()) * 1000000)
|
|
||||||
.toInt(),
|
|
||||||
amountString: Amount(
|
|
||||||
rawValue: BigInt.parse(
|
|
||||||
(float.parse(txJsonResponse["volume"].toString()) * 1000000)
|
|
||||||
.toString()),
|
|
||||||
fractionDigits: 6)
|
|
||||||
.toJsonString(),
|
|
||||||
fee: (float.parse(txJsonResponse["fee"].toString()) * 1000000).toInt(),
|
|
||||||
height: int.parse(txJsonResponse["height"].toString()),
|
|
||||||
isCancelled: false,
|
|
||||||
isLelantus: false,
|
|
||||||
slateId: "",
|
|
||||||
otherData: "",
|
|
||||||
inputs: [],
|
|
||||||
outputs: [],
|
|
||||||
nonce: 0,
|
|
||||||
numberOfMessages: null,
|
|
||||||
);
|
|
||||||
var theAddress = Address(
|
|
||||||
walletId: walletId,
|
|
||||||
value: txJsonResponse["receiver"].toString(),
|
|
||||||
publicKey: [], // TODO: Add public key
|
|
||||||
derivationIndex: 0,
|
|
||||||
derivationPath: null,
|
|
||||||
type: AddressType.unknown,
|
|
||||||
subType: AddressSubType.unknown,
|
|
||||||
);
|
|
||||||
txs.add(Tuple2(theTx, theAddress));
|
|
||||||
}
|
}
|
||||||
|
Logging.instance.log("Transactions: $txs", level: LogLevel.Info);
|
||||||
await db.addNewTransactionData(txs, walletId);
|
await db.addNewTransactionData(txs, walletId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue