mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
detect hogex inputs and only require 6 confs if so (#2786)
This commit is contained in:
@@ -25,6 +25,7 @@ class BitcoinUnspent extends Unspent {
|
||||
}
|
||||
|
||||
final BaseBitcoinAddressRecord bitcoinAddressRecord;
|
||||
bool? isPegOut;
|
||||
}
|
||||
|
||||
class BitcoinSilentPaymentsUnspent extends BitcoinUnspent {
|
||||
|
||||
@@ -25,6 +25,7 @@ class ElectrumTransactionBundle {
|
||||
class ElectrumTransactionInfo extends TransactionInfo {
|
||||
List<BitcoinSilentPaymentsUnspent>? 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<String, dynamic>? 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (_) {}
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user