detect hogex inputs and only require 6 confs if so (#2786)

This commit is contained in:
Hector Chu
2026-01-09 17:19:03 +01:00
committed by GitHub
parent b2c379fcb7
commit ff88fa8dc8
4 changed files with 16 additions and 9 deletions
+1
View File
@@ -25,6 +25,7 @@ class BitcoinUnspent extends Unspent {
} }
final BaseBitcoinAddressRecord bitcoinAddressRecord; final BaseBitcoinAddressRecord bitcoinAddressRecord;
bool? isPegOut;
} }
class BitcoinSilentPaymentsUnspent extends BitcoinUnspent { class BitcoinSilentPaymentsUnspent extends BitcoinUnspent {
@@ -25,6 +25,7 @@ class ElectrumTransactionBundle {
class ElectrumTransactionInfo extends TransactionInfo { class ElectrumTransactionInfo extends TransactionInfo {
List<BitcoinSilentPaymentsUnspent>? unspents; List<BitcoinSilentPaymentsUnspent>? unspents;
bool isReceivedSilentPayment; bool isReceivedSilentPayment;
bool isHogEx;
ElectrumTransactionInfo( ElectrumTransactionInfo(
this.type, { this.type, {
@@ -42,6 +43,7 @@ class ElectrumTransactionInfo extends TransactionInfo {
String? to, String? to,
this.unspents, this.unspents,
this.isReceivedSilentPayment = false, this.isReceivedSilentPayment = false,
this.isHogEx = false,
Map<String, dynamic>? additionalInfo, Map<String, dynamic>? additionalInfo,
}) { }) {
this.id = id; this.id = id;
@@ -174,6 +176,15 @@ class ElectrumTransactionInfo extends TransactionInfo {
amount = receivedAmounts.reduce((a, b) => a + b); 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; final fee = inputAmount - totalOutAmount;
return ElectrumTransactionInfo(type, return ElectrumTransactionInfo(type,
id: bundle.originalTransaction.txId(), id: bundle.originalTransaction.txId(),
@@ -186,6 +197,7 @@ class ElectrumTransactionInfo extends TransactionInfo {
direction: direction, direction: direction,
amount: amount, amount: amount,
date: date, date: date,
isHogEx: isHogEx,
confirmations: bundle.confirmations); confirmations: bundle.confirmations);
} }
+1
View File
@@ -1740,6 +1740,7 @@ abstract class ElectrumWalletBase
final tx = await fetchTransactionInfo(hash: coin.hash); final tx = await fetchTransactionInfo(hash: coin.hash);
coin.isChange = address.isHidden; coin.isChange = address.isHidden;
coin.confirmations = tx?.confirmations; coin.confirmations = tx?.confirmations;
coin.isPegOut = tx?.isHogEx;
updatedUnspentCoins.add(coin); updatedUnspentCoins.add(coin);
} catch (_) {} } catch (_) {}
+2 -9
View File
@@ -1214,21 +1214,14 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
} else { } else {
// check if any of the inputs of this transaction are hog-ex: // check if any of the inputs of this transaction are hog-ex:
// this list is only non-mweb inputs: // this list is only non-mweb inputs:
bool isHogEx = true;
final coin = unspentCoins final coin = unspentCoins
.firstWhere((coin) => coin.hash == utxo.utxo.txHash && coin.vout == utxo.utxo.vout); .firstWhere((coin) => coin.hash == utxo.utxo.txHash && coin.vout == utxo.utxo.vout);
if (coin.isPegOut != true) continue;
// TODO: detect actual hog-ex inputs
if (!isHogEx) {
continue;
}
int confirmations = coin.confirmations ?? 0; int confirmations = coin.confirmations ?? 0;
if (confirmations < 6) { if (confirmations < 6) {
throw Exception( 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.");
} }
} }
} }