apply some changes from SP Fix pr

This commit is contained in:
OmarHatem 2025-06-26 09:22:15 +03:00
parent 1da1f02a34
commit d2f0a97764
15 changed files with 99 additions and 101 deletions

View file

@ -17,21 +17,16 @@ BitcoinBaseAddress addressFromScript(Script script,
switch (addressType) { switch (addressType) {
case P2pkhAddressType.p2pkh: case P2pkhAddressType.p2pkh:
return P2pkhAddress.fromScriptPubkey( return P2pkhAddress.fromScriptPubkey(script: script);
script: script, network: BitcoinNetwork.mainnet);
case P2shAddressType.p2pkhInP2sh: case P2shAddressType.p2pkhInP2sh:
case P2shAddressType.p2pkInP2sh: case P2shAddressType.p2pkInP2sh:
return P2shAddress.fromScriptPubkey( return P2shAddress.fromScriptPubkey(script: script);
script: script, network: BitcoinNetwork.mainnet); case SegwitAddressType.p2wpkh:
case SegwitAddresType.p2wpkh: return P2wpkhAddress.fromScriptPubkey(script: script);
return P2wpkhAddress.fromScriptPubkey( case SegwitAddressType.p2wsh:
script: script, network: BitcoinNetwork.mainnet); return P2wshAddress.fromScriptPubkey(script: script);
case SegwitAddresType.p2wsh: case SegwitAddressType.p2tr:
return P2wshAddress.fromScriptPubkey( return P2trAddress.fromScriptPubkey(script: script);
script: script, network: BitcoinNetwork.mainnet);
case SegwitAddresType.p2tr:
return P2trAddress.fromScriptPubkey(
script: script, network: BitcoinNetwork.mainnet);
} }
throw ArgumentError("Invalid script"); throw ArgumentError("Invalid script");

View file

@ -82,7 +82,7 @@ class BitcoinAddressRecord extends BaseBitcoinAddressRecord {
type: decoded['type'] != null && decoded['type'] != '' type: decoded['type'] != null && decoded['type'] != ''
? BitcoinAddressType.values ? BitcoinAddressType.values
.firstWhere((type) => type.toString() == decoded['type'] as String) .firstWhere((type) => type.toString() == decoded['type'] as String)
: SegwitAddresType.p2wpkh, : SegwitAddressType.p2wpkh,
scriptHash: decoded['scriptHash'] as String?, scriptHash: decoded['scriptHash'] as String?,
network: network, network: network,
); );

View file

@ -36,9 +36,9 @@ class BitcoinReceivePageOption implements ReceivePageOption {
BitcoinAddressType toType() { BitcoinAddressType toType() {
switch (this) { switch (this) {
case BitcoinReceivePageOption.p2tr: case BitcoinReceivePageOption.p2tr:
return SegwitAddresType.p2tr; return SegwitAddressType.p2tr;
case BitcoinReceivePageOption.p2wsh: case BitcoinReceivePageOption.p2wsh:
return SegwitAddresType.p2wsh; return SegwitAddressType.p2wsh;
case BitcoinReceivePageOption.p2pkh: case BitcoinReceivePageOption.p2pkh:
return P2pkhAddressType.p2pkh; return P2pkhAddressType.p2pkh;
case BitcoinReceivePageOption.p2sh: case BitcoinReceivePageOption.p2sh:
@ -46,20 +46,20 @@ class BitcoinReceivePageOption implements ReceivePageOption {
case BitcoinReceivePageOption.silent_payments: case BitcoinReceivePageOption.silent_payments:
return SilentPaymentsAddresType.p2sp; return SilentPaymentsAddresType.p2sp;
case BitcoinReceivePageOption.mweb: case BitcoinReceivePageOption.mweb:
return SegwitAddresType.mweb; return SegwitAddressType.mweb;
case BitcoinReceivePageOption.p2wpkh: case BitcoinReceivePageOption.p2wpkh:
default: default:
return SegwitAddresType.p2wpkh; return SegwitAddressType.p2wpkh;
} }
} }
factory BitcoinReceivePageOption.fromType(BitcoinAddressType type) { factory BitcoinReceivePageOption.fromType(BitcoinAddressType type) {
switch (type) { switch (type) {
case SegwitAddresType.p2tr: case SegwitAddressType.p2tr:
return BitcoinReceivePageOption.p2tr; return BitcoinReceivePageOption.p2tr;
case SegwitAddresType.p2wsh: case SegwitAddressType.p2wsh:
return BitcoinReceivePageOption.p2wsh; return BitcoinReceivePageOption.p2wsh;
case SegwitAddresType.mweb: case SegwitAddressType.mweb:
return BitcoinReceivePageOption.mweb; return BitcoinReceivePageOption.mweb;
case P2pkhAddressType.p2pkh: case P2pkhAddressType.p2pkh:
return BitcoinReceivePageOption.p2pkh; return BitcoinReceivePageOption.p2pkh;
@ -67,7 +67,7 @@ class BitcoinReceivePageOption implements ReceivePageOption {
return BitcoinReceivePageOption.p2sh; return BitcoinReceivePageOption.p2sh;
case SilentPaymentsAddresType.p2sp: case SilentPaymentsAddresType.p2sp:
return BitcoinReceivePageOption.silent_payments; return BitcoinReceivePageOption.silent_payments;
case SegwitAddresType.p2wpkh: case SegwitAddressType.p2wpkh:
default: default:
return BitcoinReceivePageOption.p2wpkh; return BitcoinReceivePageOption.p2wpkh;
} }

View file

@ -413,7 +413,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
final psbt = PsbtV2()..deserializeV0(base64Decode(preProcessedPsbt)); final psbt = PsbtV2()..deserializeV0(base64Decode(preProcessedPsbt));
await psbt.signWithUTXO(utxos, (txDigest, utxo, key, sighash) { await psbt.signWithUTXO(utxos, (txDigest, utxo, key, sighash) {
return utxo.utxo.isP2tr() return utxo.utxo.isP2tr
? key.signTapRoot( ? key.signTapRoot(
txDigest, txDigest,
sighash: sighash, sighash: sighash,

View file

@ -45,10 +45,10 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
if (addressType == P2pkhAddressType.p2pkh) if (addressType == P2pkhAddressType.p2pkh)
return generateP2PKHAddress(hd: hd, index: index, network: network); return generateP2PKHAddress(hd: hd, index: index, network: network);
if (addressType == SegwitAddresType.p2tr) if (addressType == SegwitAddressType.p2tr)
return generateP2TRAddress(hd: hd, index: index, network: network); return generateP2TRAddress(hd: hd, index: index, network: network);
if (addressType == SegwitAddresType.p2wsh) if (addressType == SegwitAddressType.p2wsh)
return generateP2WSHAddress(hd: hd, index: index, network: network); return generateP2WSHAddress(hd: hd, index: index, network: network);
if (addressType == P2shAddressType.p2wpkhInP2sh) if (addressType == P2shAddressType.p2wpkhInP2sh)

View file

@ -182,7 +182,7 @@ abstract class ElectrumWalletBase
SyncStatus syncStatus; SyncStatus syncStatus;
Set<String> get addressesSet => walletAddresses.allAddresses Set<String> get addressesSet => walletAddresses.allAddresses
.where((element) => element.type != SegwitAddresType.mweb) .where((element) => element.type != SegwitAddressType.mweb)
.map((addr) => addr.address) .map((addr) => addr.address)
.toSet(); .toSet();
@ -439,7 +439,6 @@ abstract class ElectrumWalletBase
BigintUtils.fromBytes(BytesUtils.fromHexString(unspent.silentPaymentLabel!)), BigintUtils.fromBytes(BytesUtils.fromHexString(unspent.silentPaymentLabel!)),
) )
: silentAddress.B_spend, : silentAddress.B_spend,
network: network,
); );
final addressRecord = walletAddresses.silentAddresses final addressRecord = walletAddresses.silentAddresses
@ -624,9 +623,9 @@ abstract class ElectrumWalletBase
switch (coinTypeToSpendFrom) { switch (coinTypeToSpendFrom) {
case UnspentCoinType.mweb: case UnspentCoinType.mweb:
return utx.bitcoinAddressRecord.type == SegwitAddresType.mweb; return utx.bitcoinAddressRecord.type == SegwitAddressType.mweb;
case UnspentCoinType.nonMweb: case UnspentCoinType.nonMweb:
return utx.bitcoinAddressRecord.type != SegwitAddresType.mweb; return utx.bitcoinAddressRecord.type != SegwitAddressType.mweb;
case UnspentCoinType.any: case UnspentCoinType.any:
return true; return true;
} }
@ -634,7 +633,7 @@ abstract class ElectrumWalletBase
final unconfirmedCoins = availableInputs.where((utx) => utx.confirmations == 0).toList(); final unconfirmedCoins = availableInputs.where((utx) => utx.confirmations == 0).toList();
// sort the unconfirmed coins so that mweb coins are last: // sort the unconfirmed coins so that mweb coins are last:
availableInputs.sort((a, b) => a.bitcoinAddressRecord.type == SegwitAddresType.mweb ? 1 : -1); availableInputs.sort((a, b) => a.bitcoinAddressRecord.type == SegwitAddressType.mweb ? 1 : -1);
for (int i = 0; i < availableInputs.length; i++) { for (int i = 0; i < availableInputs.length; i++) {
final utx = availableInputs[i]; final utx = availableInputs[i];
@ -642,7 +641,7 @@ abstract class ElectrumWalletBase
if (paysToSilentPayment) { if (paysToSilentPayment) {
// Check inputs for shared secret derivation // Check inputs for shared secret derivation
if (utx.bitcoinAddressRecord.type == SegwitAddresType.p2wsh) { if (utx.bitcoinAddressRecord.type == SegwitAddressType.p2wsh) {
throw BitcoinTransactionSilentPaymentsNotSupported(); throw BitcoinTransactionSilentPaymentsNotSupported();
} }
} }
@ -677,7 +676,7 @@ abstract class ElectrumWalletBase
if (privkey != null) { if (privkey != null) {
inputPrivKeyInfos.add(ECPrivateInfo( inputPrivKeyInfos.add(ECPrivateInfo(
privkey, privkey,
address.type == SegwitAddresType.p2tr, address.type == SegwitAddressType.p2tr,
tweak: !isSilentPayment, tweak: !isSilentPayment,
)); ));
@ -1163,7 +1162,7 @@ abstract class ElectrumWalletBase
throw Exception(error); throw Exception(error);
} }
if (utxo.utxo.isP2tr()) { if (utxo.utxo.isP2tr) {
hasTaprootInputs = true; hasTaprootInputs = true;
return key.privkey.signTapRoot( return key.privkey.signTapRoot(
txDigest, txDigest,
@ -1230,7 +1229,7 @@ abstract class ElectrumWalletBase
'change_address_index': walletAddresses.currentChangeAddressIndexByType, 'change_address_index': walletAddresses.currentChangeAddressIndexByType,
'addresses': walletAddresses.allAddresses.map((addr) => addr.toJSON()).toList(), 'addresses': walletAddresses.allAddresses.map((addr) => addr.toJSON()).toList(),
'address_page_type': walletInfo.addressPageType == null 'address_page_type': walletInfo.addressPageType == null
? SegwitAddresType.p2wpkh.toString() ? SegwitAddressType.p2wpkh.toString()
: walletInfo.addressPageType.toString(), : walletInfo.addressPageType.toString(),
'balance': balance[currency]?.toJSON(), 'balance': balance[currency]?.toJSON(),
'derivationTypeIndex': walletInfo.derivationInfo?.derivationType?.index, 'derivationTypeIndex': walletInfo.derivationInfo?.derivationType?.index,
@ -1370,7 +1369,7 @@ abstract class ElectrumWalletBase
List<BitcoinUnspent> updatedUnspentCoins = []; List<BitcoinUnspent> updatedUnspentCoins = [];
final previousUnspentCoins = List<BitcoinUnspent>.from(unspentCoins.where((utxo) => final previousUnspentCoins = List<BitcoinUnspent>.from(unspentCoins.where((utxo) =>
utxo.bitcoinAddressRecord.type != SegwitAddresType.mweb && utxo.bitcoinAddressRecord.type != SegwitAddressType.mweb &&
utxo.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)); utxo.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord));
if (hasSilentPaymentsScanning) { if (hasSilentPaymentsScanning) {
@ -1384,13 +1383,13 @@ abstract class ElectrumWalletBase
// Set the balance of all non-silent payment and non-mweb addresses to 0 before updating // Set the balance of all non-silent payment and non-mweb addresses to 0 before updating
walletAddresses.allAddresses walletAddresses.allAddresses
.where((element) => element.type != SegwitAddresType.mweb) .where((element) => element.type != SegwitAddressType.mweb)
.forEach((addr) { .forEach((addr) {
if (addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0; if (addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0;
}); });
final addressFutures = walletAddresses.allAddresses final addressFutures = walletAddresses.allAddresses
.where((element) => element.type != SegwitAddresType.mweb) .where((element) => element.type != SegwitAddressType.mweb)
.map((address) => fetchUnspent(address)) .map((address) => fetchUnspent(address))
.toList(); .toList();
@ -1831,7 +1830,7 @@ abstract class ElectrumWalletBase
throw Exception("Cannot find private key"); throw Exception("Cannot find private key");
} }
if (utxo.utxo.isP2tr()) { if (utxo.utxo.isP2tr) {
return key.signTapRoot(txDigest, sighash: sighash); return key.signTapRoot(txDigest, sighash: sighash);
} else { } else {
return key.signInput(txDigest, sigHash: sighash); return key.signInput(txDigest, sigHash: sighash);
@ -1978,7 +1977,7 @@ abstract class ElectrumWalletBase
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type))); .map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
} else if (type == WalletType.litecoin) { } else if (type == WalletType.litecoin) {
await Future.wait(LITECOIN_ADDRESS_TYPES await Future.wait(LITECOIN_ADDRESS_TYPES
.where((type) => type != SegwitAddresType.mweb) .where((type) => type != SegwitAddressType.mweb)
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type))); .map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
} }
@ -2167,7 +2166,7 @@ abstract class ElectrumWalletBase
final unsubscribedScriptHashes = walletAddresses.allAddresses.where( final unsubscribedScriptHashes = walletAddresses.allAddresses.where(
(address) => (address) =>
!_scripthashesUpdateSubject.containsKey(address.getScriptHash(network)) && !_scripthashesUpdateSubject.containsKey(address.getScriptHash(network)) &&
address.type != SegwitAddresType.mweb, address.type != SegwitAddressType.mweb,
); );
await Future.wait(unsubscribedScriptHashes.map((address) async { await Future.wait(unsubscribedScriptHashes.map((address) async {
@ -2707,7 +2706,7 @@ Future<void> startRefresh(ScanData scanData) async {
isUsed: true, isUsed: true,
network: scanData.network, network: scanData.network,
silentPaymentTweak: t_k, silentPaymentTweak: t_k,
type: SegwitAddresType.p2tr, type: SegwitAddressType.p2tr,
txCount: 1, txCount: 1,
balance: amount!, balance: amount!,
); );
@ -2800,15 +2799,15 @@ BitcoinAddressType _getScriptType(BitcoinBaseAddress type) {
} else if (type is P2shAddress) { } else if (type is P2shAddress) {
return P2shAddressType.p2wpkhInP2sh; return P2shAddressType.p2wpkhInP2sh;
} else if (type is P2wshAddress) { } else if (type is P2wshAddress) {
return SegwitAddresType.p2wsh; return SegwitAddressType.p2wsh;
} else if (type is P2trAddress) { } else if (type is P2trAddress) {
return SegwitAddresType.p2tr; return SegwitAddressType.p2tr;
} else if (type is MwebAddress) { } else if (type is MwebAddress) {
return SegwitAddresType.mweb; return SegwitAddressType.mweb;
} else if (type is SilentPaymentsAddresType) { } else if (type is SilentPaymentsAddresType) {
return SilentPaymentsAddresType.p2sp; return SilentPaymentsAddresType.p2sp;
} else { } else {
return SegwitAddresType.p2wpkh; return SegwitAddressType.p2wpkh;
} }
} }

View file

@ -17,16 +17,16 @@ part 'electrum_wallet_addresses.g.dart';
class ElectrumWalletAddresses = ElectrumWalletAddressesBase with _$ElectrumWalletAddresses; class ElectrumWalletAddresses = ElectrumWalletAddressesBase with _$ElectrumWalletAddresses;
const List<BitcoinAddressType> BITCOIN_ADDRESS_TYPES = [ const List<BitcoinAddressType> BITCOIN_ADDRESS_TYPES = [
SegwitAddresType.p2wpkh, SegwitAddressType.p2wpkh,
P2pkhAddressType.p2pkh, P2pkhAddressType.p2pkh,
SegwitAddresType.p2tr, SegwitAddressType.p2tr,
SegwitAddresType.p2wsh, SegwitAddressType.p2wsh,
P2shAddressType.p2wpkhInP2sh, P2shAddressType.p2wpkhInP2sh,
]; ];
const List<BitcoinAddressType> LITECOIN_ADDRESS_TYPES = [ const List<BitcoinAddressType> LITECOIN_ADDRESS_TYPES = [
SegwitAddresType.p2wpkh, SegwitAddressType.p2wpkh,
SegwitAddresType.mweb, SegwitAddressType.mweb,
]; ];
const List<BitcoinAddressType> BITCOIN_CASH_ADDRESS_TYPES = [ const List<BitcoinAddressType> BITCOIN_CASH_ADDRESS_TYPES = [
@ -62,7 +62,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
_addressPageType = initialAddressPageType ?? _addressPageType = initialAddressPageType ??
(walletInfo.addressPageType != null (walletInfo.addressPageType != null
? BitcoinAddressType.fromValue(walletInfo.addressPageType!) ? BitcoinAddressType.fromValue(walletInfo.addressPageType!)
: SegwitAddresType.p2wpkh), : SegwitAddressType.p2wpkh),
silentAddresses = ObservableList<BitcoinSilentPaymentAddressRecord>.of( silentAddresses = ObservableList<BitcoinSilentPaymentAddressRecord>.of(
(initialSilentAddresses ?? []).toSet()), (initialSilentAddresses ?? []).toSet()),
currentSilentAddressIndex = initialSilentAddressIndex, currentSilentAddressIndex = initialSilentAddressIndex,
@ -249,17 +249,17 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
if (walletInfo.type == WalletType.bitcoinCash) { if (walletInfo.type == WalletType.bitcoinCash) {
await _generateInitialAddresses(type: P2pkhAddressType.p2pkh); await _generateInitialAddresses(type: P2pkhAddressType.p2pkh);
} else if (walletInfo.type == WalletType.litecoin) { } else if (walletInfo.type == WalletType.litecoin) {
await _generateInitialAddresses(type: SegwitAddresType.p2wpkh); await _generateInitialAddresses(type: SegwitAddressType.p2wpkh);
if ((Platform.isAndroid || Platform.isIOS) && !isHardwareWallet) { if ((Platform.isAndroid || Platform.isIOS) && !isHardwareWallet) {
await _generateInitialAddresses(type: SegwitAddresType.mweb); await _generateInitialAddresses(type: SegwitAddressType.mweb);
} }
} else if (walletInfo.type == WalletType.bitcoin) { } else if (walletInfo.type == WalletType.bitcoin) {
await _generateInitialAddresses(); await _generateInitialAddresses();
if (!isHardwareWallet) { if (!isHardwareWallet) {
await _generateInitialAddresses(type: P2pkhAddressType.p2pkh); await _generateInitialAddresses(type: P2pkhAddressType.p2pkh);
await _generateInitialAddresses(type: P2shAddressType.p2wpkhInP2sh); await _generateInitialAddresses(type: P2shAddressType.p2wpkhInP2sh);
await _generateInitialAddresses(type: SegwitAddresType.p2tr); await _generateInitialAddresses(type: SegwitAddressType.p2tr);
await _generateInitialAddresses(type: SegwitAddresType.p2wsh); await _generateInitialAddresses(type: SegwitAddressType.p2wsh);
} }
} }
@ -323,7 +323,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
BaseBitcoinAddressRecord generateNewAddress({String label = ''}) { BaseBitcoinAddressRecord generateNewAddress({String label = ''}) {
if (addressPageType == SilentPaymentsAddresType.p2sp && silentAddress != null) { if (addressPageType == SilentPaymentsAddresType.p2sp && silentAddress != null) {
final currentSilentAddressIndex = silentAddresses final currentSilentAddressIndex = silentAddresses
.where((addressRecord) => addressRecord.type != SegwitAddresType.p2tr) .where((addressRecord) => addressRecord.type != SegwitAddressType.p2tr)
.length - .length -
1; 1;
@ -381,7 +381,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
void addBitcoinAddressTypes() { void addBitcoinAddressTypes() {
final lastP2wpkh = _addresses final lastP2wpkh = _addresses
.where((addressRecord) => .where((addressRecord) =>
_isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wpkh)) _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2wpkh))
.toList() .toList()
.last; .last;
if (lastP2wpkh.address != address) { if (lastP2wpkh.address != address) {
@ -407,7 +407,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
} }
final lastP2tr = _addresses.firstWhere( final lastP2tr = _addresses.firstWhere(
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2tr)); (addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2tr));
if (lastP2tr.address != address) { if (lastP2tr.address != address) {
addressesMap[lastP2tr.address] = 'P2TR'; addressesMap[lastP2tr.address] = 'P2TR';
} else { } else {
@ -415,7 +415,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
} }
final lastP2wsh = _addresses.firstWhere( final lastP2wsh = _addresses.firstWhere(
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wsh)); (addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2wsh));
if (lastP2wsh.address != address) { if (lastP2wsh.address != address) {
addressesMap[lastP2wsh.address] = 'P2WSH'; addressesMap[lastP2wsh.address] = 'P2WSH';
} else { } else {
@ -440,7 +440,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
void addLitecoinAddressTypes() { void addLitecoinAddressTypes() {
final lastP2wpkh = _addresses final lastP2wpkh = _addresses
.where((addressRecord) => .where((addressRecord) =>
_isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wpkh)) _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2wpkh))
.toList() .toList()
.last; .last;
if (lastP2wpkh.address != address) { if (lastP2wpkh.address != address) {
@ -450,7 +450,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
} }
final lastMweb = _addresses.firstWhere( final lastMweb = _addresses.firstWhere(
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.mweb)); (addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.mweb));
if (lastMweb.address != address) { if (lastMweb.address != address) {
addressesMap[lastMweb.address] = 'MWEB'; addressesMap[lastMweb.address] = 'MWEB';
} else { } else {
@ -560,14 +560,14 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
addressRecord.isHidden && addressRecord.isHidden &&
!addressRecord.isUsed && !addressRecord.isUsed &&
// TODO: feature to change change address type. For now fixed to p2wpkh, the cheapest type // TODO: feature to change change address type. For now fixed to p2wpkh, the cheapest type
(walletInfo.type != WalletType.bitcoin || addressRecord.type == SegwitAddresType.p2wpkh)); (walletInfo.type != WalletType.bitcoin || addressRecord.type == SegwitAddressType.p2wpkh));
changeAddresses.addAll(newAddresses); changeAddresses.addAll(newAddresses);
} }
@action @action
Future<void> discoverAddresses(List<BitcoinAddressRecord> addressList, bool isHidden, Future<void> discoverAddresses(List<BitcoinAddressRecord> addressList, bool isHidden,
Future<String?> Function(BitcoinAddressRecord) getAddressHistory, Future<String?> Function(BitcoinAddressRecord) getAddressHistory,
{BitcoinAddressType type = SegwitAddresType.p2wpkh}) async { {BitcoinAddressType type = SegwitAddressType.p2wpkh}) async {
final newAddresses = await _createNewAddresses(gap, final newAddresses = await _createNewAddresses(gap,
startIndex: addressList.length, isHidden: isHidden, type: type); startIndex: addressList.length, isHidden: isHidden, type: type);
addAddresses(newAddresses); addAddresses(newAddresses);
@ -581,7 +581,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
} }
Future<void> _generateInitialAddresses( Future<void> _generateInitialAddresses(
{BitcoinAddressType type = SegwitAddresType.p2wpkh}) async { {BitcoinAddressType type = SegwitAddressType.p2wpkh}) async {
var countOfReceiveAddresses = 0; var countOfReceiveAddresses = 0;
var countOfHiddenAddresses = 0; var countOfHiddenAddresses = 0;
@ -658,7 +658,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
void _validateAddresses() { void _validateAddresses() {
_addresses.forEach((element) async { _addresses.forEach((element) async {
if (element.type == SegwitAddresType.mweb) { if (element.type == SegwitAddressType.mweb) {
// this would add a ton of startup lag for mweb addresses since we have 1000 of them // this would add a ton of startup lag for mweb addresses since we have 1000 of them
return; return;
} }

View file

@ -87,8 +87,8 @@ class ElectrumWalletSnapshot {
final balance = ElectrumBalance.fromJSON(data['balance'] as String?) ?? final balance = ElectrumBalance.fromJSON(data['balance'] as String?) ??
ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0); ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0);
var regularAddressIndexByType = {SegwitAddresType.p2wpkh.toString(): 0}; var regularAddressIndexByType = {SegwitAddressType.p2wpkh.toString(): 0};
var changeAddressIndexByType = {SegwitAddresType.p2wpkh.toString(): 0}; var changeAddressIndexByType = {SegwitAddressType.p2wpkh.toString(): 0};
var silentAddressIndex = 0; var silentAddressIndex = 0;
final derivationType = DerivationType final derivationType = DerivationType
@ -97,10 +97,10 @@ class ElectrumWalletSnapshot {
try { try {
regularAddressIndexByType = { regularAddressIndexByType = {
SegwitAddresType.p2wpkh.toString(): int.parse(data['account_index'] as String? ?? '0') SegwitAddressType.p2wpkh.toString(): int.parse(data['account_index'] as String? ?? '0')
}; };
changeAddressIndexByType = { changeAddressIndexByType = {
SegwitAddresType.p2wpkh.toString(): SegwitAddressType.p2wpkh.toString():
int.parse(data['change_address_index'] as String? ?? '0') int.parse(data['change_address_index'] as String? ?? '0')
}; };
silentAddressIndex = int.parse(data['silent_address_index'] as String? ?? '0'); silentAddressIndex = int.parse(data['silent_address_index'] as String? ?? '0');

View file

@ -50,7 +50,7 @@ import 'package:ledger_litecoin/ledger_litecoin.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:cw_mweb/cw_mweb.dart'; import 'package:cw_mweb/cw_mweb.dart';
import 'package:bitcoin_base/src/crypto/keypair/sign_utils.dart'; // import 'package:bitcoin_base/src/crypto/keypair/sign_utils.dart';
import 'package:pointycastle/ecc/api.dart'; import 'package:pointycastle/ecc/api.dart';
import 'package:pointycastle/ecc/curves/secp256k1.dart'; import 'package:pointycastle/ecc/curves/secp256k1.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -690,16 +690,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
throw Exception(error); throw Exception(error);
} }
if (utxo.utxo.isP2tr()) { return key.privkey.signInput(txDigest, sigHash: sighash);
hasTaprootInputs = true;
return key.privkey.signTapRoot(
txDigest,
sighash: sighash,
tweak: utxo.utxo.isSilentPayment != true,
);
} else {
return key.privkey.signInput(txDigest, sigHash: sighash);
}
}); });
return PendingBitcoinTransaction(transaction, type, return PendingBitcoinTransaction(transaction, type,

View file

@ -51,7 +51,7 @@ extension PsbtSigner on PsbtV2 {
List<BigInt> taprootAmounts = []; List<BigInt> taprootAmounts = [];
List<Script> taprootScripts = []; List<Script> taprootScripts = [];
if (utxos.any((e) => e.utxo.isP2tr())) { if (utxos.any((e) => e.utxo.isP2tr)) {
for (final input in tx.inputs) { for (final input in tx.inputs) {
final utxo = utxos.firstWhereOrNull( final utxo = utxos.firstWhereOrNull(
(u) => u.utxo.txHash == input.txId && u.utxo.vout == input.txIndex); (u) => u.utxo.txHash == input.txId && u.utxo.vout == input.txIndex);
@ -76,7 +76,7 @@ extension PsbtSigner on PsbtV2 {
/// We receive the owner's ScriptPubKey /// We receive the owner's ScriptPubKey
final script = _findLockingScript(utxo, false); final script = _findLockingScript(utxo, false);
final int sighash = utxo.utxo.isP2tr() final int sighash = utxo.utxo.isP2tr
? BitcoinOpCodeConst.TAPROOT_SIGHASH_ALL ? BitcoinOpCodeConst.TAPROOT_SIGHASH_ALL
: BitcoinOpCodeConst.SIGHASH_ALL; : BitcoinOpCodeConst.SIGHASH_ALL;
@ -87,7 +87,7 @@ extension PsbtSigner on PsbtV2 {
/// now we need sign the transaction digest /// now we need sign the transaction digest
final sig = signer(digest, utxo, utxo.privateKey, sighash); final sig = signer(digest, utxo, utxo.privateKey, sighash);
if (utxo.utxo.isP2tr()) { if (utxo.utxo.isP2tr) {
setInputTapKeySig(i, Uint8List.fromList(BytesUtils.fromHexString(sig))); setInputTapKeySig(i, Uint8List.fromList(BytesUtils.fromHexString(sig)));
} else { } else {
setInputPartialSig( setInputPartialSig(
@ -106,7 +106,7 @@ extension PsbtSigner on PsbtV2 {
List<BigInt> taprootAmounts, List<BigInt> taprootAmounts,
List<Script> tapRootPubKeys) { List<Script> tapRootPubKeys) {
if (utxo.isSegwit()) { if (utxo.isSegwit()) {
if (utxo.isP2tr()) { if (utxo.isP2tr) {
return transaction.getTransactionTaprootDigset( return transaction.getTransactionTaprootDigset(
txIndex: input, txIndex: input,
scriptPubKeys: tapRootPubKeys, scriptPubKeys: tapRootPubKeys,
@ -129,23 +129,23 @@ extension PsbtSigner on PsbtV2 {
switch (utxo.utxo.scriptType) { switch (utxo.utxo.scriptType) {
case PubKeyAddressType.p2pk: case PubKeyAddressType.p2pk:
return senderPub.toRedeemScript(); return senderPub.toRedeemScript();
case SegwitAddresType.p2wsh: case SegwitAddressType.p2wsh:
if (isTaproot) { if (isTaproot) {
return senderPub.toP2wshAddress().toScriptPubKey(); return senderPub.toP2wshAddress().toScriptPubKey();
} }
return senderPub.toP2wshRedeemScript(); return senderPub.toP2wshRedeemScript();
case P2pkhAddressType.p2pkh: case P2pkhAddressType.p2pkh:
return senderPub.toP2pkhAddress().toScriptPubKey(); return senderPub.toP2pkhAddress().toScriptPubKey();
case SegwitAddresType.p2wpkh: case SegwitAddressType.p2wpkh:
if (isTaproot) { if (isTaproot) {
return senderPub.toP2wpkhAddress().toScriptPubKey(); return senderPub.toP2wpkhAddress().toScriptPubKey();
} }
return senderPub.toP2pkhAddress().toScriptPubKey(); return senderPub.toP2pkhAddress().toScriptPubKey();
case SegwitAddresType.p2tr: case SegwitAddressType.p2tr:
return senderPub return senderPub
.toTaprootAddress(tweak: utxo.utxo.isSilentPayment != true) .toTaprootAddress(tweak: utxo.utxo.isSilentPayment != true)
.toScriptPubKey(); .toScriptPubKey();
case SegwitAddresType.mweb: case SegwitAddressType.mweb:
return Script(script: []); return Script(script: []);
case P2shAddressType.p2pkhInP2sh: case P2shAddressType.p2pkhInP2sh:
if (isTaproot) { if (isTaproot) {

View file

@ -17,7 +17,7 @@ class PSBTTransactionBuild {
for (var i = 0; i < inputs.length; i++) { for (var i = 0; i < inputs.length; i++) {
final input = inputs[i]; final input = inputs[i];
printV(input.utxo.isP2tr()); printV(input.utxo.isP2tr);
printV(input.utxo.isSegwit()); printV(input.utxo.isSegwit());
printV(input.utxo.isP2shSegwit()); printV(input.utxo.isP2shSegwit());
@ -30,7 +30,7 @@ class PSBTTransactionBuild {
setInputSegwit(i, input); setInputSegwit(i, input);
} else if (input.utxo.isP2shSegwit()) { } else if (input.utxo.isP2shSegwit()) {
setInputP2shSegwit(i, input); setInputP2shSegwit(i, input);
} else if (input.utxo.isP2tr()) { } else if (input.utxo.isP2tr) {
// ToDo: (Konsti) Handle Taproot Inputs // ToDo: (Konsti) Handle Taproot Inputs
} else { } else {
setInputP2pkh(i, input); setInputP2pkh(i, input);

View file

@ -81,20 +81,20 @@ packages:
source: git source: git
version: "1.0.1" version: "1.0.1"
bitcoin_base: bitcoin_base:
dependency: transitive dependency: "direct overridden"
description: description:
path: "." path: "."
ref: cake-update-v7 ref: "2ab3437bd5a671e3f5833e5613eb98751e108bb7"
resolved-ref: f577e83fe78766b2655ea0602baa9299b953a31b resolved-ref: "2ab3437bd5a671e3f5833e5613eb98751e108bb7"
url: "https://github.com/cake-tech/bitcoin_base" url: "https://github.com/cake-tech/bitcoin_base"
source: git source: git
version: "4.7.0" version: "6.1.0"
bitcoin_base_old: bitcoin_base_old:
dependency: "direct overridden" dependency: "direct overridden"
description: description:
path: "." path: "."
ref: cake-update-old ref: cd98de1d47895085e58fc8433b4ce41a157fc342
resolved-ref: f39aa0b62642eaf1e9de5b31e2395148e73c7fd2 resolved-ref: cd98de1d47895085e58fc8433b4ce41a157fc342
url: "https://github.com/cake-tech/bitcoin_base" url: "https://github.com/cake-tech/bitcoin_base"
source: git source: git
version: "4.7.0" version: "4.7.0"
@ -107,6 +107,15 @@ packages:
url: "https://github.com/cake-tech/blockchain_utils" url: "https://github.com/cake-tech/blockchain_utils"
source: git source: git
version: "3.3.0" version: "3.3.0"
blockchain_utils_new:
dependency: transitive
description:
path: "."
ref: cake-update-v4-renamed
resolved-ref: "8fdcf98f0ce8842517e33be7643dc45ffd18e455"
url: "https://github.com/cake-tech/blockchain_utils"
source: git
version: "4.3.0"
bluez: bluez:
dependency: transitive dependency: transitive
description: description:

View file

@ -73,7 +73,11 @@ dependency_overrides:
bitcoin_base_old: bitcoin_base_old:
git: git:
url: https://github.com/cake-tech/bitcoin_base url: https://github.com/cake-tech/bitcoin_base
ref: cake-update-old ref: cd98de1d47895085e58fc8433b4ce41a157fc342
bitcoin_base:
git:
url: https://github.com/cake-tech/bitcoin_base
ref: 2ab3437bd5a671e3f5833e5613eb98751e108bb7
pointycastle: 3.7.4 pointycastle: 3.7.4
ffi: 2.1.0 ffi: 2.1.0

View file

@ -39,10 +39,10 @@ dev_dependencies:
dependency_overrides: dependency_overrides:
watcher: ^1.1.0 watcher: ^1.1.0
bitcoin_base_old: bitcoin_base:
git: git:
url: https://github.com/cake-tech/bitcoin_base url: https://github.com/cake-tech/bitcoin_base
ref: cake-update-old ref: cake-update-v9
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View file

@ -161,10 +161,10 @@ dependency_overrides:
ref: cake ref: cake
flutter_secure_storage_platform_interface: 1.0.2 flutter_secure_storage_platform_interface: 1.0.2
protobuf: ^3.1.0 protobuf: ^3.1.0
bitcoin_base_old: bitcoin_base:
git: git:
url: https://github.com/cake-tech/bitcoin_base url: https://github.com/cake-tech/bitcoin_base
ref: cake-update-old ref: cake-update-v9
ffi: 2.1.0 ffi: 2.1.0
ledger_flutter_plus: ledger_flutter_plus:
git: git: