mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
Refactor Update transactions call
This commit is contained in:
parent
520ceabf79
commit
0a77dad7ec
1 changed files with 57 additions and 66 deletions
|
@ -198,7 +198,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Logging.instance.log(secretKey, level: LogLevel.Info);
|
||||
final sourceKeyStore = Keystore.fromSecretKey(secretKey);
|
||||
final client = TezartClient(getCurrentNode().host);
|
||||
//TODO - Update gas Limit
|
||||
|
||||
final operation = await client.transferOperation(
|
||||
source: sourceKeyStore,
|
||||
destination: destinationAddress,
|
||||
|
@ -431,50 +431,45 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
|
||||
Future<void> updateTransactions() async {
|
||||
// TODO: Use node RPC instead of tzstats API
|
||||
var api =
|
||||
"https://api.tzstats.com/tables/op?address=${await currentReceivingAddress}";
|
||||
var jsonResponse =
|
||||
jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
|
||||
|
||||
String transactionsCall = "https://api.mainnet.tzkt.io/v1/accounts/${await currentReceivingAddress}/operations";
|
||||
var response = jsonDecode(await get(Uri.parse(transactionsCall)).then((value) => value.body));
|
||||
List<Tuple2<Transaction, Address>> txs = [];
|
||||
|
||||
for (var tx in jsonResponse as List) {
|
||||
if (tx[1] == "transaction") {
|
||||
var txApi =
|
||||
"https://api.tzstats.com/explorer/op/${tx[0]}"; //Get transactions by Unique Id, this way we will only get txs
|
||||
var txJsonResponse =
|
||||
jsonDecode(await get(Uri.parse(txApi)).then((value) => value.body));
|
||||
// Check if list is larger than 1 (if it is, it's a batch transaction)
|
||||
if (!((txJsonResponse as List).length > 1)) {
|
||||
for (var (opJson as Map) in txJsonResponse) {
|
||||
if (opJson.containsKey("volume")) {
|
||||
// This is to check if transaction is a token transfer
|
||||
for (var tx in response as List) {
|
||||
if (tx["type"] == "transaction") {
|
||||
TransactionType txType;
|
||||
if (opJson["sender"] == (await currentReceivingAddress)) {
|
||||
if (tx["sender"]["address"] == (await currentReceivingAddress)) {
|
||||
txType = TransactionType.outgoing;
|
||||
} else {
|
||||
txType = TransactionType.incoming;
|
||||
}
|
||||
|
||||
final amount = tx["amount"] as int;
|
||||
final fee = tx["bakerFee"] as int;
|
||||
final amountInMicroTez =
|
||||
amount / 1000000;
|
||||
|
||||
final feeInMicroTez =
|
||||
fee / 1000000;
|
||||
|
||||
var theTx = Transaction(
|
||||
walletId: walletId,
|
||||
txid: opJson["hash"].toString(),
|
||||
timestamp: DateTime.parse(opJson["time"].toString())
|
||||
txid: tx["hash"].toString(),
|
||||
timestamp: DateTime.parse(tx["timestamp"].toString())
|
||||
.toUtc()
|
||||
.millisecondsSinceEpoch ~/
|
||||
1000,
|
||||
type: txType,
|
||||
subType: TransactionSubType.none,
|
||||
amount: (float.parse(opJson["volume"].toString()) * 1000000)
|
||||
.toInt(),
|
||||
amount: tx["amount"] as int,
|
||||
amountString: Amount(
|
||||
rawValue: BigInt.parse(
|
||||
(float.parse(opJson["volume"].toString()) * 1000000)
|
||||
(tx["amount"] as int)
|
||||
.toInt()
|
||||
.toString()),
|
||||
fractionDigits: coin.decimals)
|
||||
.toJsonString(),
|
||||
fee: (float.parse(opJson["fee"].toString()) * 1000000).toInt(),
|
||||
height: int.parse(opJson["height"].toString()),
|
||||
fee: tx["bakerFee"] as int,
|
||||
height: int.parse(tx["level"].toString()),
|
||||
isCancelled: false,
|
||||
isLelantus: false,
|
||||
slateId: "",
|
||||
|
@ -486,7 +481,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
);
|
||||
var theAddress = Address(
|
||||
walletId: walletId,
|
||||
value: opJson["receiver"].toString(),
|
||||
value: tx["target"]["address"].toString(),
|
||||
publicKey: [], // TODO: Add public key
|
||||
derivationIndex: 0,
|
||||
derivationPath: null,
|
||||
|
@ -496,16 +491,12 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
txs.add(Tuple2(theTx, theAddress));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Logging.instance.log("Transactions: $txs", level: LogLevel.Info);
|
||||
await db.addNewTransactionData(txs, walletId);
|
||||
}
|
||||
|
||||
Future<void> updateChainHeight() async {
|
||||
try {
|
||||
final client = TezartClient(getCurrentNode().host);
|
||||
var api = "${getCurrentNode().host}/chains/main/blocks/head/header/shell";
|
||||
var jsonParsedResponse =
|
||||
jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
|
||||
|
|
Loading…
Reference in a new issue