Fix Epiccash caching issue, add additional status messages as in Epicpay

This commit is contained in:
likho 2023-05-28 14:57:05 +02:00
parent e526bb4fe6
commit 83778bb121
20 changed files with 81 additions and 19 deletions

View file

@ -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<Transaction, Address?> 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<Output> outputs;
late final int? numberOfMessages;
@Backlink(to: "transactions")
final address = IsarLink<Address>();
@ -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<String>.from(json["outputs"] as List)
.map((e) => Output.fromJsonString(e))
.toList(),
numberOfMessages: json["numberOfMessages"] as int,
);
if (json["address"] == null) {
return Tuple2(transaction, null);

View file

@ -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;

View file

@ -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<String, dynamic> 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;
}
}

View file

@ -93,12 +93,7 @@ class _TransactionsListState extends ConsumerState<TransactionsList> {
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<TransactionsList> {
),
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,
),

View file

@ -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";

View file

@ -1288,6 +1288,7 @@ class BitcoinWallet extends CoinServiceAPI
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: null,
);
final address = txData["address"] is String

View file

@ -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));

View file

@ -1140,6 +1140,7 @@ class DogecoinWallet extends CoinServiceAPI
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: null,
);
final address = txData["address"] is String

View file

@ -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

View file

@ -1153,10 +1153,6 @@ class EpicCashWallet extends CoinServiceAPI
Future<bool> 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<void> _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 =

View file

@ -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

View file

@ -449,6 +449,7 @@ Future<Map<dynamic, dynamic>> 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

View file

@ -1271,6 +1271,7 @@ class LitecoinWallet extends CoinServiceAPI
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: null,
);
final address = txData["address"] is String

View file

@ -954,6 +954,7 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: null,
);
txnsData.add(Tuple2(txn, address));

View file

@ -1260,6 +1260,7 @@ class NamecoinWallet extends CoinServiceAPI
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: null,
);
final address = txData["address"] is String

View file

@ -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));

View file

@ -1041,6 +1041,7 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: null,
);
txnsData.add(Tuple2(txn, address));

View file

@ -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

View file

@ -258,6 +258,7 @@ mixin ElectrumXParsing {
nonce: null,
inputs: ins,
outputs: outs,
numberOfMessages: null,
);
return Tuple2(tx, transactionAddress);

View file

@ -397,6 +397,7 @@ class DbVersionMigrator with WalletDB {
nonce: null,
inputs: [],
outputs: [],
numberOfMessages: tx.numberOfMessages,
);
if (tx.address.isEmpty) {