Skip to content

Commit d13acd6

Browse files
committed
Silly hack(?) to temporarily show mweb spends.
Note: Unless wallet is open when the transaction confirms the tx details view will show the wrong transaction height.
1 parent 6c7231c commit d13acd6

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

lib/wallets/wallet/impl/litecoin_wallet.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ class LitecoinWallet<T extends ElectrumXCurrencyInterface>
361361
}
362362

363363
await mainDB.updateOrPutTransactionV2s(txns);
364+
365+
if (info.isMwebEnabled) {
366+
await checkMwebSpends();
367+
}
364368
}
365369

366370
@override

lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,23 @@ mixin ElectrumXInterface<T extends ElectrumXCurrencyInterface>
907907
// dirty shortcut for peercoin's weirdness
908908
vSize: this is PeercoinWallet ? clTx.size : clTx.vSize(),
909909
tempTx:
910-
txData.type.isMweb()
910+
txData.type == TxType.mwebPegIn
911911
? null
912+
: txData.type.isMweb()
913+
? TransactionV2(
914+
walletId: walletId,
915+
blockHash: null,
916+
hash: clTx.hashHex,
917+
txid: clTx.txid,
918+
height: null,
919+
timestamp: DateTime.timestamp().millisecondsSinceEpoch ~/ 1000,
920+
inputs: List.unmodifiable(tempInputs),
921+
outputs: List.unmodifiable(tempOutputs),
922+
version: clTx.version,
923+
type: TransactionType.outgoing,
924+
subType: TransactionSubType.mweb,
925+
otherData: null,
926+
)
912927
: TransactionV2(
913928
walletId: walletId,
914929
blockHash: null,

lib/wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,56 @@ mixin MwebInterface<T extends ElectrumXCurrencyInterface>
358358
);
359359
}
360360

361+
Future<void> checkMwebSpends() async {
362+
final pending =
363+
await mainDB.isar.transactionV2s
364+
.where()
365+
.walletIdEqualTo(walletId)
366+
.filter()
367+
.heightIsNull()
368+
.and()
369+
.blockHashIsNull()
370+
.and()
371+
.subTypeEqualTo(TransactionSubType.mweb)
372+
.and()
373+
.typeEqualTo(TransactionType.outgoing)
374+
.findAll();
375+
376+
Logging.instance.f(pending);
377+
378+
final client = await _client;
379+
for (final tx in pending) {
380+
for (final input in tx.inputs) {
381+
if (input.addresses.length == 1) {
382+
final address = await mainDB.getAddress(
383+
walletId,
384+
input.addresses.first,
385+
);
386+
if (address?.type == AddressType.mweb) {
387+
final response = await client.spent(
388+
SpentRequest(outputId: [input.outpoint!.txid]),
389+
);
390+
if (response.outputId.contains(input.outpoint!.txid)) {
391+
// dummy to show tx as confirmed. Need a better way to handle this as its kind of stupid, resulting in terrible UX
392+
final dummyHeight = await chainHeight;
393+
394+
TransactionV2? transaction =
395+
await mainDB.isar.transactionV2s
396+
.where()
397+
.txidWalletIdEqualTo(tx.txid, walletId)
398+
.findFirst();
399+
400+
if (transaction == null || transaction.height == null) {
401+
transaction = (transaction ?? tx).copyWith(height: dummyHeight);
402+
await mainDB.updateOrPutTransactionV2s([transaction]);
403+
}
404+
}
405+
}
406+
}
407+
}
408+
}
409+
}
410+
361411
Future<TxData> processMwebTransaction(TxData txData) async {
362412
final client = await _client;
363413
final response = await client.create(

0 commit comments

Comments
 (0)