diff --git a/cw_bitcoin/lib/bitcoin_unspent.dart b/cw_bitcoin/lib/bitcoin_unspent.dart index 3691a7a22..53700a272 100644 --- a/cw_bitcoin/lib/bitcoin_unspent.dart +++ b/cw_bitcoin/lib/bitcoin_unspent.dart @@ -25,6 +25,7 @@ class BitcoinUnspent extends Unspent { } final BaseBitcoinAddressRecord bitcoinAddressRecord; + bool? isPegOut; } class BitcoinSilentPaymentsUnspent extends BitcoinUnspent { diff --git a/cw_bitcoin/lib/electrum_transaction_info.dart b/cw_bitcoin/lib/electrum_transaction_info.dart index 407e405e1..9c0beadde 100644 --- a/cw_bitcoin/lib/electrum_transaction_info.dart +++ b/cw_bitcoin/lib/electrum_transaction_info.dart @@ -25,6 +25,7 @@ class ElectrumTransactionBundle { class ElectrumTransactionInfo extends TransactionInfo { List? unspents; bool isReceivedSilentPayment; + bool isHogEx; ElectrumTransactionInfo( this.type, { @@ -42,6 +43,7 @@ class ElectrumTransactionInfo extends TransactionInfo { String? to, this.unspents, this.isReceivedSilentPayment = false, + this.isHogEx = false, Map? additionalInfo, }) { this.id = id; @@ -174,6 +176,15 @@ class ElectrumTransactionInfo extends TransactionInfo { amount = receivedAmounts.reduce((a, b) => a + b); } + // MWEB HogEx + final isHogExTx = (BtcTransaction tx) { + if (tx.inputs.isEmpty || tx.inputs.first.txIndex > 0 || tx.outputs.isEmpty) + return false; + final b = tx.outputs.first.scriptPubKey.toBytes(); + return b.length == 34 && b[0] == 88 && b[1] == 32; + }; + final isHogEx = isHogExTx(bundle.originalTransaction) && isHogExTx(bundle.ins.first); + final fee = inputAmount - totalOutAmount; return ElectrumTransactionInfo(type, id: bundle.originalTransaction.txId(), @@ -186,6 +197,7 @@ class ElectrumTransactionInfo extends TransactionInfo { direction: direction, amount: amount, date: date, + isHogEx: isHogEx, confirmations: bundle.confirmations); } diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 08ca9f234..4bcee04d0 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -1740,6 +1740,7 @@ abstract class ElectrumWalletBase final tx = await fetchTransactionInfo(hash: coin.hash); coin.isChange = address.isHidden; coin.confirmations = tx?.confirmations; + coin.isPegOut = tx?.isHogEx; updatedUnspentCoins.add(coin); } catch (_) {} diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index d80dedf92..0c2612a12 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -1214,21 +1214,14 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { } else { // check if any of the inputs of this transaction are hog-ex: // this list is only non-mweb inputs: - bool isHogEx = true; - final coin = unspentCoins .firstWhere((coin) => coin.hash == utxo.utxo.txHash && coin.vout == utxo.utxo.vout); - - // TODO: detect actual hog-ex inputs - - if (!isHogEx) { - continue; - } + if (coin.isPegOut != true) continue; int confirmations = coin.confirmations ?? 0; if (confirmations < 6) { throw Exception( - "A transaction input has less than 6 confirmations, please try again later."); + "A transaction input is an MWEB peg-out and has less than 6 confirmations, please try again later."); } } }