From 5e7bd0d8aef16bd5b6c4121ca1c9e7ba8bec8c14 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 13 Jan 2023 14:50:43 -0600 Subject: [PATCH] fix bitcoin transaction refresh --- .../coins/bitcoin/bitcoin_wallet.dart | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index e121347b9..73a9808c5 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:developer'; import 'dart:io'; import 'package:bech32/bech32.dart'; @@ -1998,15 +1997,15 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB { } } - // bool _duplicateTxCheck( - // List> allTransactions, String txid) { - // for (int i = 0; i < allTransactions.length; i++) { - // if (allTransactions[i]["txid"] == txid) { - // return true; - // } - // } - // return false; - // } + bool _duplicateTxCheck( + List> allTransactions, String txid) { + for (int i = 0; i < allTransactions.length; i++) { + if (allTransactions[i]["txid"] == txid) { + return true; + } + } + return false; + } Future _refreshTransactions() async { final List allAddresses = @@ -2041,14 +2040,14 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB { coin: coin, ); - // if (!_duplicateTxCheck(allTransactions, tx["txid"] as String)) { - tx["address"] = await isar.addresses - .filter() - .valueEqualTo(txHash["address"] as String) - .findFirst(); - tx["height"] = txHash["height"]; - allTransactions.add(tx); - // } + if (!_duplicateTxCheck(allTransactions, tx["txid"] as String)) { + tx["address"] = await isar.addresses + .filter() + .valueEqualTo(txHash["address"] as String) + .findFirst(); + tx["height"] = txHash["height"]; + allTransactions.add(tx); + } } } @@ -2064,13 +2063,10 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB { // await fastFetch(vHashes.toList()); final List< - Tuple3, - List>> txnsData = []; + Tuple4, + List, isar_models.Address>> txnsData = []; for (final txObject in allTransactions) { - print("========================================================="); - log(txObject.toString()); - final data = await parseTransaction( txObject, cachedElectrumXClient, @@ -2102,6 +2098,16 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB { await tx.inputs.save(); } + // check if address exists in db and add if it does not + if (await isar.addresses + .where() + .valueEqualTo(data.item4.value) + .findFirst() == + null) { + await isar.addresses.put(data.item4); + } + // link and save address + tx.address.value = data.item4; await tx.address.save(); } });