From 83778bb121cdf22d2d5c10d3a4fdffd1eefa342f Mon Sep 17 00:00:00 2001 From: likho Date: Sun, 28 May 2023 14:57:05 +0200 Subject: [PATCH] Fix Epiccash caching issue, add additional status messages as in Epicpay --- .../models/blockchain_data/transaction.dart | 11 ++++++- .../models/blockchain_data/transaction.g.dart | 1 + lib/models/paymint/transactions_model.dart | 9 +++++- .../sub_widgets/transactions_list.dart | 14 ++------- .../transaction_details_view.dart | 31 +++++++++++++++++++ .../coins/bitcoin/bitcoin_wallet.dart | 1 + .../coins/bitcoincash/bitcoincash_wallet.dart | 2 ++ .../coins/dogecoin/dogecoin_wallet.dart | 1 + lib/services/coins/ecash/ecash_wallet.dart | 2 ++ .../coins/epiccash/epiccash_wallet.dart | 9 +++--- .../coins/ethereum/ethereum_wallet.dart | 2 ++ lib/services/coins/firo/firo_wallet.dart | 7 +++++ .../coins/litecoin/litecoin_wallet.dart | 1 + lib/services/coins/monero/monero_wallet.dart | 1 + .../coins/namecoin/namecoin_wallet.dart | 1 + .../coins/particl/particl_wallet.dart | 2 ++ .../coins/wownero/wownero_wallet.dart | 1 + .../ethereum/ethereum_token_service.dart | 2 ++ lib/services/mixins/electrum_x_parsing.dart | 1 + lib/utilities/db_version_migration.dart | 1 + 20 files changed, 81 insertions(+), 19 deletions(-) diff --git a/lib/models/isar/models/blockchain_data/transaction.dart b/lib/models/isar/models/blockchain_data/transaction.dart index 39d2cc0af..e3e3d0595 100644 --- a/lib/models/isar/models/blockchain_data/transaction.dart +++ b/lib/models/isar/models/blockchain_data/transaction.dart @@ -12,6 +12,7 @@ part 'transaction.g.dart'; @Collection() class Transaction { + Transaction({ required this.walletId, required this.txid, @@ -29,6 +30,7 @@ class Transaction { required this.inputs, required this.outputs, required this.nonce, + required this.numberOfMessages, }); Tuple2 copyWith({ @@ -50,6 +52,7 @@ class Transaction { int? nonce, Id? id, Address? address, + int? numberOfMessages, }) { return Tuple2( Transaction( @@ -68,7 +71,8 @@ class Transaction { otherData: otherData ?? this.otherData, nonce: nonce ?? this.nonce, inputs: inputs ?? this.inputs, - outputs: outputs ?? this.outputs) + outputs: outputs ?? this.outputs, + numberOfMessages: numberOfMessages ?? this.numberOfMessages) ..id = id ?? this.id, address ?? this.address.value, ); @@ -114,6 +118,8 @@ class Transaction { late final List outputs; + late final int? numberOfMessages; + @Backlink(to: "transactions") final address = IsarLink
(); @@ -154,6 +160,7 @@ class Transaction { "address: ${address.value}, " "inputsLength: ${inputs.length}, " "outputsLength: ${outputs.length}, " + "numberOfMessages: $numberOfMessages, " "}"; String toJsonString() { @@ -175,6 +182,7 @@ class Transaction { "address": address.value?.toJsonString(), "inputs": inputs.map((e) => e.toJsonString()).toList(), "outputs": outputs.map((e) => e.toJsonString()).toList(), + "numberOfMessages": numberOfMessages, }; return jsonEncode(result); } @@ -205,6 +213,7 @@ class Transaction { outputs: List.from(json["outputs"] as List) .map((e) => Output.fromJsonString(e)) .toList(), + numberOfMessages: json["numberOfMessages"] as int, ); if (json["address"] == null) { return Tuple2(transaction, null); diff --git a/lib/models/isar/models/blockchain_data/transaction.g.dart b/lib/models/isar/models/blockchain_data/transaction.g.dart index 74a5a1652..ba603b250 100644 --- a/lib/models/isar/models/blockchain_data/transaction.g.dart +++ b/lib/models/isar/models/blockchain_data/transaction.g.dart @@ -286,6 +286,7 @@ Transaction _transactionDeserialize( type: _TransactiontypeValueEnumMap[reader.readByteOrNull(offsets[14])] ?? TransactionType.outgoing, walletId: reader.readString(offsets[15]), + numberOfMessages: reader.readLong(offsets[2]), ); object.id = id; return object; diff --git a/lib/models/paymint/transactions_model.dart b/lib/models/paymint/transactions_model.dart index cee48b8eb..4982f1ec1 100644 --- a/lib/models/paymint/transactions_model.dart +++ b/lib/models/paymint/transactions_model.dart @@ -155,6 +155,9 @@ class Transaction { // @HiveField(18) final String? otherData; + // @HiveField(16) + final int? numberOfMessages; + Transaction({ required this.txid, required this.confirmedStatus, @@ -176,6 +179,7 @@ class Transaction { this.isCancelled = false, this.slateId, this.otherData, + this.numberOfMessages, }); factory Transaction.fromJson(Map json) { @@ -211,6 +215,7 @@ class Transaction { isCancelled: json["isCancelled"] as bool? ?? false, slateId: json["slateId"] as String?, otherData: json["otherData"] as String?, + numberOfMessages: json["numberOfMessages"] as int?, ); } @@ -269,6 +274,7 @@ class Transaction { bool? isCancelled, String? slateId, String? otherData, + int? numberOfMessages, }) { return Transaction( txid: txid ?? this.txid, @@ -292,13 +298,14 @@ class Transaction { isCancelled: isCancelled ?? this.isCancelled, slateId: slateId ?? this.slateId, otherData: otherData ?? this.otherData, + numberOfMessages: numberOfMessages ?? this.numberOfMessages, ); } @override String toString() { String transaction = - "{txid: $txid, type: $txType, subType: $subType, value: $amount, fee: $fees, height: $height, confirm: $confirmedStatus, confirmations: $confirmations, address: $address, timestamp: $timestamp, worthNow: $worthNow, inputs: $inputs, slateid: $slateId }"; + "{txid: $txid, type: $txType, subType: $subType, value: $amount, fee: $fees, height: $height, confirm: $confirmedStatus, confirmations: $confirmations, address: $address, timestamp: $timestamp, worthNow: $worthNow, inputs: $inputs, slateid: $slateId, numberOfMessages: $numberOfMessages }"; return transaction; } } diff --git a/lib/pages/wallet_view/sub_widgets/transactions_list.dart b/lib/pages/wallet_view/sub_widgets/transactions_list.dart index e68b443ed..559906af7 100644 --- a/lib/pages/wallet_view/sub_widgets/transactions_list.dart +++ b/lib/pages/wallet_view/sub_widgets/transactions_list.dart @@ -93,12 +93,7 @@ class _TransactionsListState extends ConsumerState { children: [ TransactionCard( // this may mess with combined firo transactions - key: isConfirmed - ? Key(tx.txid + - tx.type.name + - tx.address.value.toString() + - tx.height.toString()) - : UniqueKey(), // + key: UniqueKey(), // transaction: tx, walletId: widget.walletId, ), @@ -193,12 +188,7 @@ class _TransactionsListState extends ConsumerState { ), child: TransactionCard( // this may mess with combined firo transactions - key: isConfirmed - ? Key(tx.txid + - tx.type.name + - tx.address.value.toString() + - tx.height.toString()) - : UniqueKey(), + key: UniqueKey(), transaction: tx, walletId: widget.walletId, ), diff --git a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart index d3f8467cd..d4165f811 100644 --- a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart @@ -126,6 +126,37 @@ class _TransactionDetailsViewState } } + if (coin == Coin.epicCash) { + if (_transaction.isCancelled) { + return "Cancelled"; + } else if (type == TransactionType.incoming) { + if (tx.isConfirmed(height, coin.requiredConfirmations)) { + return "Received"; + } else { + if (_transaction.numberOfMessages == 1) { + return "Receiving (waiting for sender)"; + } else if ((_transaction.numberOfMessages ?? 0) > 1) { + return + "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no) + } else { + return "Receiving"; + } + } + } else if (type == TransactionType.outgoing) { + if (tx.isConfirmed(height, coin.requiredConfirmations)) { + return "Sent (confirmed)"; + } else { + if (_transaction.numberOfMessages == 1) { + return "Sending (waiting for receiver)"; + } else if ((_transaction.numberOfMessages ?? 0) > 1) { + return "Sending (waiting for confirmations)"; + } else { + return "Sending"; + } + } + } + } + if (type == TransactionType.incoming) { // if (_transaction.isMinting) { // return "Minting"; diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 0c7c86059..7d44af5dc 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -1288,6 +1288,7 @@ class BitcoinWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 47458a7d8..6ff56fd26 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -1153,6 +1153,7 @@ class BitcoinCashWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String @@ -2137,6 +2138,7 @@ class BitcoinCashWallet extends CoinServiceAPI nonce: null, inputs: inputs, outputs: outputs, + numberOfMessages: null, ); txns.add(Tuple2(tx, transactionAddress)); diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index cc081539c..cb4c17ed3 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -1140,6 +1140,7 @@ class DogecoinWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String diff --git a/lib/services/coins/ecash/ecash_wallet.dart b/lib/services/coins/ecash/ecash_wallet.dart index 4459c3fbc..62a2a8648 100644 --- a/lib/services/coins/ecash/ecash_wallet.dart +++ b/lib/services/coins/ecash/ecash_wallet.dart @@ -1365,6 +1365,7 @@ class ECashWallet extends CoinServiceAPI nonce: null, inputs: inputs, outputs: outputs, + numberOfMessages: null, ); txns.add(Tuple2(tx, transactionAddress)); @@ -2770,6 +2771,7 @@ class ECashWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String diff --git a/lib/services/coins/epiccash/epiccash_wallet.dart b/lib/services/coins/epiccash/epiccash_wallet.dart index 137be8001..acdd172cf 100644 --- a/lib/services/coins/epiccash/epiccash_wallet.dart +++ b/lib/services/coins/epiccash/epiccash_wallet.dart @@ -1153,10 +1153,6 @@ class EpicCashWallet extends CoinServiceAPI Future startScans() async { try { if (ListenerManager.pointer != null) { - Logging.instance - .log("LISTENER HANDLER IS NOT NULL ....", level: LogLevel.Info); - Logging.instance - .log("STOPPING ANY WALLET LISTENER ....", level: LogLevel.Info); epicboxListenerStop(ListenerManager.pointer!); } @@ -1643,7 +1639,7 @@ class EpicCashWallet extends CoinServiceAPI Future _refreshTransactions() async { // final currentChainHeight = await chainHeight; final wallet = await _secureStore.read(key: '${_walletId}_wallet'); - const refreshFromNode = 0; + const refreshFromNode = 1; dynamic message; await m.protect(() async { @@ -1709,6 +1705,7 @@ class EpicCashWallet extends CoinServiceAPI ?[tx["tx_type"] == "TxReceived" ? "from" : "to"] as String? ?? ""; String? commitId = slatesToCommits[slateId]?['commitId'] as String?; + tx['numberOfMessages'] = tx['messages']?['messages']?.length; int? height; @@ -1721,6 +1718,7 @@ class EpicCashWallet extends CoinServiceAPI final isIncoming = (tx["tx_type"] == "TxReceived" || tx["tx_type"] == "TxReceivedCancelled"); + final txn = isar_models.Transaction( walletId: walletId, txid: commitId ?? tx["id"].toString(), @@ -1744,6 +1742,7 @@ class EpicCashWallet extends CoinServiceAPI otherData: tx["id"].toString(), inputs: [], outputs: [], + numberOfMessages: ((tx["numberOfMessages"] == null) ? 0 : tx["numberOfMessages"]) as int, ); // txn.address = diff --git a/lib/services/coins/ethereum/ethereum_wallet.dart b/lib/services/coins/ethereum/ethereum_wallet.dart index 2052ead4b..5ea669b7a 100644 --- a/lib/services/coins/ethereum/ethereum_wallet.dart +++ b/lib/services/coins/ethereum/ethereum_wallet.dart @@ -944,6 +944,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB { response.value?.nonce.toBigIntFromHex.toInt(), inputs: [], outputs: [], + numberOfMessages: null, ); Address? address = await db.getAddress( @@ -1035,6 +1036,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB { nonce: tuple.item2, inputs: [], outputs: [], + numberOfMessages: null, ); Address? transactionAddress = await db diff --git a/lib/services/coins/firo/firo_wallet.dart b/lib/services/coins/firo/firo_wallet.dart index fa9cfca5c..be25c4188 100644 --- a/lib/services/coins/firo/firo_wallet.dart +++ b/lib/services/coins/firo/firo_wallet.dart @@ -449,6 +449,7 @@ Future> staticProcessRestore( nonce: null, inputs: element.inputs, outputs: element.outputs, + numberOfMessages: null, )..address.value = element.address.value; } }); @@ -891,6 +892,7 @@ class FiroWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String @@ -3033,6 +3035,7 @@ class FiroWallet extends CoinServiceAPI otherData: transactionInfo["otherData"] as String?, inputs: [], outputs: [], + numberOfMessages: null, ); final transactionAddress = await db @@ -3513,6 +3516,7 @@ class FiroWallet extends CoinServiceAPI nonce: null, inputs: ins, outputs: [], + numberOfMessages: null, ); txnsData.add(Tuple2(tx, null)); @@ -3635,6 +3639,7 @@ class FiroWallet extends CoinServiceAPI nonce: null, inputs: ins, outputs: outs, + numberOfMessages: null, ); txnsData.add(Tuple2(tx, transactionAddress)); @@ -3786,6 +3791,7 @@ class FiroWallet extends CoinServiceAPI nonce: null, inputs: ins, outputs: outs, + numberOfMessages: null, ); txnsData.add(Tuple2(tx, transactionAddress)); @@ -5064,6 +5070,7 @@ class FiroWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = await db diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index 765f3d81a..c55566a34 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -1271,6 +1271,7 @@ class LitecoinWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String diff --git a/lib/services/coins/monero/monero_wallet.dart b/lib/services/coins/monero/monero_wallet.dart index 29debe753..248f60b84 100644 --- a/lib/services/coins/monero/monero_wallet.dart +++ b/lib/services/coins/monero/monero_wallet.dart @@ -954,6 +954,7 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB { nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); txnsData.add(Tuple2(txn, address)); diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 640b2cba0..09984733b 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -1260,6 +1260,7 @@ class NamecoinWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index 34e5ede45..f6aa32532 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -1188,6 +1188,7 @@ class ParticlWallet extends CoinServiceAPI nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); final address = txData["address"] is String @@ -2391,6 +2392,7 @@ class ParticlWallet extends CoinServiceAPI nonce: null, slateId: null, otherData: null, + numberOfMessages: null, ); txns.add(Tuple2(tx, transactionAddress)); diff --git a/lib/services/coins/wownero/wownero_wallet.dart b/lib/services/coins/wownero/wownero_wallet.dart index c07582fa5..71b6bc295 100644 --- a/lib/services/coins/wownero/wownero_wallet.dart +++ b/lib/services/coins/wownero/wownero_wallet.dart @@ -1041,6 +1041,7 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB { nonce: null, inputs: [], outputs: [], + numberOfMessages: null, ); txnsData.add(Tuple2(txn, address)); diff --git a/lib/services/ethereum/ethereum_token_service.dart b/lib/services/ethereum/ethereum_token_service.dart index c7007c905..f9faf1859 100644 --- a/lib/services/ethereum/ethereum_token_service.dart +++ b/lib/services/ethereum/ethereum_token_service.dart @@ -169,6 +169,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache { response.value?.nonce.toBigIntFromHex.toInt(), inputs: [], outputs: [], + numberOfMessages: null, ); Address? address = await ethWallet.db.getAddress( @@ -519,6 +520,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache { otherData: tuple.item1.address, inputs: [], outputs: [], + numberOfMessages: null, ); Address? transactionAddress = await ethWallet.db diff --git a/lib/services/mixins/electrum_x_parsing.dart b/lib/services/mixins/electrum_x_parsing.dart index 92cf86305..2827690c5 100644 --- a/lib/services/mixins/electrum_x_parsing.dart +++ b/lib/services/mixins/electrum_x_parsing.dart @@ -258,6 +258,7 @@ mixin ElectrumXParsing { nonce: null, inputs: ins, outputs: outs, + numberOfMessages: null, ); return Tuple2(tx, transactionAddress); diff --git a/lib/utilities/db_version_migration.dart b/lib/utilities/db_version_migration.dart index a83ea4305..c07ed5438 100644 --- a/lib/utilities/db_version_migration.dart +++ b/lib/utilities/db_version_migration.dart @@ -397,6 +397,7 @@ class DbVersionMigrator with WalletDB { nonce: null, inputs: [], outputs: [], + numberOfMessages: tx.numberOfMessages, ); if (tx.address.isEmpty) {