mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Merge 50d23bdbc1
into 1a5601f755
This commit is contained in:
commit
be50963726
27 changed files with 1826 additions and 206 deletions
|
@ -1,3 +1,4 @@
|
|||
New themes and UI/UX improvements
|
||||
Ledger flow enhancements
|
||||
Add built-in Tor support (experimental)
|
||||
Ledger improvements
|
||||
UI/UX improvements
|
||||
Bug fixes
|
|
@ -1,4 +1,9 @@
|
|||
New themes and UI/UX improvements
|
||||
Payjoin enhancements
|
||||
Ledger flow enhancements
|
||||
Add built-in Tor support (experimental)
|
||||
Add dEuro investments
|
||||
Solana fixes/enhancements
|
||||
Polygon fixes/enhancements
|
||||
WalletConnect improvements
|
||||
Ledger improvements
|
||||
Payjoin improvements
|
||||
UI/UX improvements
|
||||
Bug fixes
|
|
@ -17,21 +17,16 @@ BitcoinBaseAddress addressFromScript(Script script,
|
|||
|
||||
switch (addressType) {
|
||||
case P2pkhAddressType.p2pkh:
|
||||
return P2pkhAddress.fromScriptPubkey(
|
||||
script: script, network: BitcoinNetwork.mainnet);
|
||||
return P2pkhAddress.fromScriptPubkey(script: script);
|
||||
case P2shAddressType.p2pkhInP2sh:
|
||||
case P2shAddressType.p2pkInP2sh:
|
||||
return P2shAddress.fromScriptPubkey(
|
||||
script: script, network: BitcoinNetwork.mainnet);
|
||||
case SegwitAddresType.p2wpkh:
|
||||
return P2wpkhAddress.fromScriptPubkey(
|
||||
script: script, network: BitcoinNetwork.mainnet);
|
||||
case SegwitAddresType.p2wsh:
|
||||
return P2wshAddress.fromScriptPubkey(
|
||||
script: script, network: BitcoinNetwork.mainnet);
|
||||
case SegwitAddresType.p2tr:
|
||||
return P2trAddress.fromScriptPubkey(
|
||||
script: script, network: BitcoinNetwork.mainnet);
|
||||
return P2shAddress.fromScriptPubkey(script: script);
|
||||
case SegwitAddressType.p2wpkh:
|
||||
return P2wpkhAddress.fromScriptPubkey(script: script);
|
||||
case SegwitAddressType.p2wsh:
|
||||
return P2wshAddress.fromScriptPubkey(script: script);
|
||||
case SegwitAddressType.p2tr:
|
||||
return P2trAddress.fromScriptPubkey(script: script);
|
||||
}
|
||||
|
||||
throw ArgumentError("Invalid script");
|
||||
|
|
|
@ -82,7 +82,7 @@ class BitcoinAddressRecord extends BaseBitcoinAddressRecord {
|
|||
type: decoded['type'] != null && decoded['type'] != ''
|
||||
? BitcoinAddressType.values
|
||||
.firstWhere((type) => type.toString() == decoded['type'] as String)
|
||||
: SegwitAddresType.p2wpkh,
|
||||
: SegwitAddressType.p2wpkh,
|
||||
scriptHash: decoded['scriptHash'] as String?,
|
||||
network: network,
|
||||
);
|
||||
|
|
|
@ -36,9 +36,9 @@ class BitcoinReceivePageOption implements ReceivePageOption {
|
|||
BitcoinAddressType toType() {
|
||||
switch (this) {
|
||||
case BitcoinReceivePageOption.p2tr:
|
||||
return SegwitAddresType.p2tr;
|
||||
return SegwitAddressType.p2tr;
|
||||
case BitcoinReceivePageOption.p2wsh:
|
||||
return SegwitAddresType.p2wsh;
|
||||
return SegwitAddressType.p2wsh;
|
||||
case BitcoinReceivePageOption.p2pkh:
|
||||
return P2pkhAddressType.p2pkh;
|
||||
case BitcoinReceivePageOption.p2sh:
|
||||
|
@ -46,20 +46,20 @@ class BitcoinReceivePageOption implements ReceivePageOption {
|
|||
case BitcoinReceivePageOption.silent_payments:
|
||||
return SilentPaymentsAddresType.p2sp;
|
||||
case BitcoinReceivePageOption.mweb:
|
||||
return SegwitAddresType.mweb;
|
||||
return SegwitAddressType.mweb;
|
||||
case BitcoinReceivePageOption.p2wpkh:
|
||||
default:
|
||||
return SegwitAddresType.p2wpkh;
|
||||
return SegwitAddressType.p2wpkh;
|
||||
}
|
||||
}
|
||||
|
||||
factory BitcoinReceivePageOption.fromType(BitcoinAddressType type) {
|
||||
switch (type) {
|
||||
case SegwitAddresType.p2tr:
|
||||
case SegwitAddressType.p2tr:
|
||||
return BitcoinReceivePageOption.p2tr;
|
||||
case SegwitAddresType.p2wsh:
|
||||
case SegwitAddressType.p2wsh:
|
||||
return BitcoinReceivePageOption.p2wsh;
|
||||
case SegwitAddresType.mweb:
|
||||
case SegwitAddressType.mweb:
|
||||
return BitcoinReceivePageOption.mweb;
|
||||
case P2pkhAddressType.p2pkh:
|
||||
return BitcoinReceivePageOption.p2pkh;
|
||||
|
@ -67,7 +67,7 @@ class BitcoinReceivePageOption implements ReceivePageOption {
|
|||
return BitcoinReceivePageOption.p2sh;
|
||||
case SilentPaymentsAddresType.p2sp:
|
||||
return BitcoinReceivePageOption.silent_payments;
|
||||
case SegwitAddresType.p2wpkh:
|
||||
case SegwitAddressType.p2wpkh:
|
||||
default:
|
||||
return BitcoinReceivePageOption.p2wpkh;
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
|||
final psbt = PsbtV2()..deserializeV0(base64Decode(preProcessedPsbt));
|
||||
|
||||
await psbt.signWithUTXO(utxos, (txDigest, utxo, key, sighash) {
|
||||
return utxo.utxo.isP2tr()
|
||||
return utxo.utxo.isP2tr
|
||||
? key.signTapRoot(
|
||||
txDigest,
|
||||
sighash: sighash,
|
||||
|
|
|
@ -45,10 +45,10 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
|
|||
if (addressType == P2pkhAddressType.p2pkh)
|
||||
return generateP2PKHAddress(hd: hd, index: index, network: network);
|
||||
|
||||
if (addressType == SegwitAddresType.p2tr)
|
||||
if (addressType == SegwitAddressType.p2tr)
|
||||
return generateP2TRAddress(hd: hd, index: index, network: network);
|
||||
|
||||
if (addressType == SegwitAddresType.p2wsh)
|
||||
if (addressType == SegwitAddressType.p2wsh)
|
||||
return generateP2WSHAddress(hd: hd, index: index, network: network);
|
||||
|
||||
if (addressType == P2shAddressType.p2wpkhInP2sh)
|
||||
|
|
|
@ -4,12 +4,11 @@ import 'dart:io';
|
|||
import 'dart:isolate';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cw_core/format_amount.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cw_bitcoin/litecoin_wallet.dart';
|
||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
@ -19,7 +18,7 @@ import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
|
|||
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_unspent.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet_keys.dart';
|
||||
import 'package:cw_bitcoin/electrum.dart';
|
||||
import 'package:cw_bitcoin/electrum.dart' as electrum;
|
||||
import 'package:cw_bitcoin/electrum_balance.dart';
|
||||
import 'package:cw_bitcoin/electrum_derivations.dart';
|
||||
import 'package:cw_bitcoin/electrum_transaction_history.dart';
|
||||
|
@ -69,7 +68,7 @@ abstract class ElectrumWalletBase
|
|||
Uint8List? seedBytes,
|
||||
this.passphrase,
|
||||
List<BitcoinAddressRecord>? initialAddresses,
|
||||
ElectrumClient? electrumClient,
|
||||
electrum.ElectrumClient? electrumClient,
|
||||
ElectrumBalance? initialBalance,
|
||||
CryptoCurrency? currency,
|
||||
this.alwaysScan,
|
||||
|
@ -96,7 +95,7 @@ abstract class ElectrumWalletBase
|
|||
this.isTestnet = !network.isMainnet,
|
||||
this._mnemonic = mnemonic,
|
||||
super(walletInfo) {
|
||||
this.electrumClient = electrumClient ?? ElectrumClient();
|
||||
this.electrumClient = electrumClient ?? electrum.ElectrumClient();
|
||||
this.walletInfo = walletInfo;
|
||||
transactionHistory = ElectrumTransactionHistory(
|
||||
walletInfo: walletInfo,
|
||||
|
@ -167,7 +166,7 @@ abstract class ElectrumWalletBase
|
|||
@observable
|
||||
bool isEnabledAutoGenerateSubaddress;
|
||||
|
||||
late ElectrumClient electrumClient;
|
||||
late electrum.ElectrumClient electrumClient;
|
||||
Box<UnspentCoinsInfo> unspentCoinsInfo;
|
||||
|
||||
@override
|
||||
|
@ -182,7 +181,7 @@ abstract class ElectrumWalletBase
|
|||
SyncStatus syncStatus;
|
||||
|
||||
Set<String> get addressesSet => walletAddresses.allAddresses
|
||||
.where((element) => element.type != SegwitAddresType.mweb)
|
||||
.where((element) => element.type != SegwitAddressType.mweb)
|
||||
.map((addr) => addr.address)
|
||||
.toSet();
|
||||
|
||||
|
@ -333,14 +332,14 @@ abstract class ElectrumWalletBase
|
|||
|
||||
final receivePort = ReceivePort();
|
||||
_isolate = Isolate.spawn(
|
||||
startRefresh,
|
||||
_handleScanSilentPayments,
|
||||
ScanData(
|
||||
sendPort: receivePort.sendPort,
|
||||
silentAddress: walletAddresses.silentAddress!,
|
||||
network: network,
|
||||
height: height,
|
||||
chainTip: chainTip,
|
||||
electrumClient: ElectrumClient(),
|
||||
electrumClient: electrum.ElectrumClient(),
|
||||
transactionHistoryIds: transactionHistory.transactions.keys.toList(),
|
||||
node: (await getNodeSupportsSilentPayments()) == true
|
||||
? ScanNode(node!.uri, node!.useSSL)
|
||||
|
@ -439,7 +438,6 @@ abstract class ElectrumWalletBase
|
|||
BigintUtils.fromBytes(BytesUtils.fromHexString(unspent.silentPaymentLabel!)),
|
||||
)
|
||||
: silentAddress.B_spend,
|
||||
network: network,
|
||||
);
|
||||
|
||||
final addressRecord = walletAddresses.silentAddresses
|
||||
|
@ -493,9 +491,10 @@ abstract class ElectrumWalletBase
|
|||
Future<void> updateFeeRates() async {
|
||||
if (await checkIfMempoolAPIIsEnabled() && type == WalletType.bitcoin) {
|
||||
try {
|
||||
final response = await ProxyWrapper()
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/fees/recommended"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
final response = await ProxyWrapper()
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/fees/recommended"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
|
||||
final result = json.decode(response.body) as Map<String, dynamic>;
|
||||
final slowFee = (result['economyFee'] as num?)?.toInt() ?? 0;
|
||||
int mediumFee = (result['hourFee'] as num?)?.toInt() ?? 0;
|
||||
|
@ -563,7 +562,7 @@ abstract class ElectrumWalletBase
|
|||
node!.save();
|
||||
return node!.supportsSilentPayments!;
|
||||
}
|
||||
} on RequestFailedTimeoutException catch (_) {
|
||||
} on electrum.RequestFailedTimeoutException catch (_) {
|
||||
node!.supportsSilentPayments = false;
|
||||
node!.save();
|
||||
return node!.supportsSilentPayments!;
|
||||
|
@ -624,9 +623,9 @@ abstract class ElectrumWalletBase
|
|||
|
||||
switch (coinTypeToSpendFrom) {
|
||||
case UnspentCoinType.mweb:
|
||||
return utx.bitcoinAddressRecord.type == SegwitAddresType.mweb;
|
||||
return utx.bitcoinAddressRecord.type == SegwitAddressType.mweb;
|
||||
case UnspentCoinType.nonMweb:
|
||||
return utx.bitcoinAddressRecord.type != SegwitAddresType.mweb;
|
||||
return utx.bitcoinAddressRecord.type != SegwitAddressType.mweb;
|
||||
case UnspentCoinType.any:
|
||||
return true;
|
||||
}
|
||||
|
@ -634,7 +633,7 @@ abstract class ElectrumWalletBase
|
|||
final unconfirmedCoins = availableInputs.where((utx) => utx.confirmations == 0).toList();
|
||||
|
||||
// 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++) {
|
||||
final utx = availableInputs[i];
|
||||
|
@ -642,7 +641,7 @@ abstract class ElectrumWalletBase
|
|||
|
||||
if (paysToSilentPayment) {
|
||||
// Check inputs for shared secret derivation
|
||||
if (utx.bitcoinAddressRecord.type == SegwitAddresType.p2wsh) {
|
||||
if (utx.bitcoinAddressRecord.type == SegwitAddressType.p2wsh) {
|
||||
throw BitcoinTransactionSilentPaymentsNotSupported();
|
||||
}
|
||||
}
|
||||
|
@ -677,7 +676,7 @@ abstract class ElectrumWalletBase
|
|||
if (privkey != null) {
|
||||
inputPrivKeyInfos.add(ECPrivateInfo(
|
||||
privkey,
|
||||
address.type == SegwitAddresType.p2tr,
|
||||
address.type == SegwitAddressType.p2tr,
|
||||
tweak: !isSilentPayment,
|
||||
));
|
||||
|
||||
|
@ -1163,7 +1162,7 @@ abstract class ElectrumWalletBase
|
|||
throw Exception(error);
|
||||
}
|
||||
|
||||
if (utxo.utxo.isP2tr()) {
|
||||
if (utxo.utxo.isP2tr) {
|
||||
hasTaprootInputs = true;
|
||||
return key.privkey.signTapRoot(
|
||||
txDigest,
|
||||
|
@ -1230,7 +1229,7 @@ abstract class ElectrumWalletBase
|
|||
'change_address_index': walletAddresses.currentChangeAddressIndexByType,
|
||||
'addresses': walletAddresses.allAddresses.map((addr) => addr.toJSON()).toList(),
|
||||
'address_page_type': walletInfo.addressPageType == null
|
||||
? SegwitAddresType.p2wpkh.toString()
|
||||
? SegwitAddressType.p2wpkh.toString()
|
||||
: walletInfo.addressPageType.toString(),
|
||||
'balance': balance[currency]?.toJSON(),
|
||||
'derivationTypeIndex': walletInfo.derivationInfo?.derivationType?.index,
|
||||
|
@ -1370,7 +1369,7 @@ abstract class ElectrumWalletBase
|
|||
List<BitcoinUnspent> updatedUnspentCoins = [];
|
||||
|
||||
final previousUnspentCoins = List<BitcoinUnspent>.from(unspentCoins.where((utxo) =>
|
||||
utxo.bitcoinAddressRecord.type != SegwitAddresType.mweb &&
|
||||
utxo.bitcoinAddressRecord.type != SegwitAddressType.mweb &&
|
||||
utxo.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord));
|
||||
|
||||
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
|
||||
walletAddresses.allAddresses
|
||||
.where((element) => element.type != SegwitAddresType.mweb)
|
||||
.where((element) => element.type != SegwitAddressType.mweb)
|
||||
.forEach((addr) {
|
||||
if (addr is! BitcoinSilentPaymentAddressRecord) addr.balance = 0;
|
||||
});
|
||||
|
||||
final addressFutures = walletAddresses.allAddresses
|
||||
.where((element) => element.type != SegwitAddresType.mweb)
|
||||
.where((element) => element.type != SegwitAddressType.mweb)
|
||||
.map((address) => fetchUnspent(address))
|
||||
.toList();
|
||||
|
||||
|
@ -1831,7 +1830,7 @@ abstract class ElectrumWalletBase
|
|||
throw Exception("Cannot find private key");
|
||||
}
|
||||
|
||||
if (utxo.utxo.isP2tr()) {
|
||||
if (utxo.utxo.isP2tr) {
|
||||
return key.signTapRoot(txDigest, sighash: sighash);
|
||||
} else {
|
||||
return key.signInput(txDigest, sigHash: sighash);
|
||||
|
@ -1878,8 +1877,8 @@ abstract class ElectrumWalletBase
|
|||
if (height != null && height > 0 && await checkIfMempoolAPIIsEnabled()) {
|
||||
try {
|
||||
final blockHash = await ProxyWrapper()
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block-height/$height"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block-height/$height"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
|
||||
if (blockHash.statusCode == 200 &&
|
||||
blockHash.body.isNotEmpty &&
|
||||
|
@ -1887,7 +1886,6 @@ abstract class ElectrumWalletBase
|
|||
final blockResponse = await ProxyWrapper()
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block/${blockHash}"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
|
||||
if (blockResponse.statusCode == 200 &&
|
||||
blockResponse.body.isNotEmpty &&
|
||||
jsonDecode(blockResponse.body)['timestamp'] != null) {
|
||||
|
@ -1978,7 +1976,7 @@ abstract class ElectrumWalletBase
|
|||
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
|
||||
} else if (type == WalletType.litecoin) {
|
||||
await Future.wait(LITECOIN_ADDRESS_TYPES
|
||||
.where((type) => type != SegwitAddresType.mweb)
|
||||
.where((type) => type != SegwitAddressType.mweb)
|
||||
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
|
||||
}
|
||||
|
||||
|
@ -2167,7 +2165,7 @@ abstract class ElectrumWalletBase
|
|||
final unsubscribedScriptHashes = walletAddresses.allAddresses.where(
|
||||
(address) =>
|
||||
!_scripthashesUpdateSubject.containsKey(address.getScriptHash(network)) &&
|
||||
address.type != SegwitAddresType.mweb,
|
||||
address.type != SegwitAddressType.mweb,
|
||||
);
|
||||
|
||||
await Future.wait(unsubscribedScriptHashes.map((address) async {
|
||||
|
@ -2390,9 +2388,9 @@ abstract class ElectrumWalletBase
|
|||
derivationPath.substring(0, derivationPath.lastIndexOf("'") + 1);
|
||||
|
||||
@action
|
||||
void _onConnectionStatusChange(ConnectionStatus status) {
|
||||
void _onConnectionStatusChange(electrum.ConnectionStatus status) {
|
||||
switch (status) {
|
||||
case ConnectionStatus.connected:
|
||||
case electrum.ConnectionStatus.connected:
|
||||
if (syncStatus is NotConnectedSyncStatus ||
|
||||
syncStatus is LostConnectionSyncStatus ||
|
||||
syncStatus is ConnectingSyncStatus) {
|
||||
|
@ -2400,19 +2398,19 @@ abstract class ElectrumWalletBase
|
|||
}
|
||||
|
||||
break;
|
||||
case ConnectionStatus.disconnected:
|
||||
case electrum.ConnectionStatus.disconnected:
|
||||
if (syncStatus is! NotConnectedSyncStatus &&
|
||||
syncStatus is! ConnectingSyncStatus &&
|
||||
syncStatus is! SyncronizingSyncStatus) {
|
||||
syncStatus = NotConnectedSyncStatus();
|
||||
}
|
||||
break;
|
||||
case ConnectionStatus.failed:
|
||||
case electrum.ConnectionStatus.failed:
|
||||
if (syncStatus is! LostConnectionSyncStatus) {
|
||||
syncStatus = LostConnectionSyncStatus();
|
||||
}
|
||||
break;
|
||||
case ConnectionStatus.connecting:
|
||||
case electrum.ConnectionStatus.connecting:
|
||||
if (syncStatus is! ConnectingSyncStatus) {
|
||||
syncStatus = ConnectingSyncStatus();
|
||||
}
|
||||
|
@ -2524,7 +2522,7 @@ class ScanData {
|
|||
final ScanNode? node;
|
||||
final BasedUtxoNetwork network;
|
||||
final int chainTip;
|
||||
final ElectrumClient electrumClient;
|
||||
final electrum.ElectrumClient electrumClient;
|
||||
final List<String> transactionHistoryIds;
|
||||
final Map<String, String> labels;
|
||||
final List<int> labelIndexes;
|
||||
|
@ -2568,6 +2566,235 @@ class SyncResponse {
|
|||
SyncResponse(this.height, this.syncStatus);
|
||||
}
|
||||
|
||||
Future<void> _handleScanSilentPayments(ScanData scanData) async {
|
||||
try {
|
||||
// if (scanData.shouldSwitchNodes) {
|
||||
var scanningClient = await ElectrumProvider.connect(
|
||||
ElectrumTCPService.connect(
|
||||
Uri.parse("tcp://electrs.cakewallet.com:50001"),
|
||||
),
|
||||
);
|
||||
// }
|
||||
|
||||
int syncHeight = scanData.height;
|
||||
int initialSyncHeight = syncHeight;
|
||||
|
||||
final receiver = Receiver(
|
||||
scanData.silentAddress.b_scan.toHex(),
|
||||
scanData.silentAddress.B_spend.toHex(),
|
||||
scanData.network == BitcoinNetwork.testnet,
|
||||
scanData.labelIndexes,
|
||||
scanData.labelIndexes.length,
|
||||
);
|
||||
|
||||
int getCountToScanPerRequest(int syncHeight) {
|
||||
if (scanData.isSingleScan) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
final amountLeft = scanData.chainTip - syncHeight + 1;
|
||||
return amountLeft;
|
||||
}
|
||||
|
||||
// Initial status UI update, send how many blocks in total to scan
|
||||
scanData.sendPort.send(SyncResponse(syncHeight, StartingScanSyncStatus(syncHeight)));
|
||||
|
||||
final req = ElectrumTweaksSubscribe(
|
||||
height: syncHeight,
|
||||
count: getCountToScanPerRequest(syncHeight),
|
||||
historicalMode: false,
|
||||
);
|
||||
|
||||
var _scanningStream = await scanningClient.subscribe(req);
|
||||
|
||||
void listenFn(Map<String, dynamic> event, ElectrumTweaksSubscribe req) {
|
||||
final response = req.onResponse(event);
|
||||
|
||||
if (response == null || _scanningStream == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// is success or error msg
|
||||
final noData = response.message != null;
|
||||
|
||||
if (noData) {
|
||||
if (scanData.isSingleScan) {
|
||||
return;
|
||||
}
|
||||
|
||||
// re-subscribe to continue receiving messages, starting from the next unscanned height
|
||||
final nextHeight = syncHeight + 1;
|
||||
|
||||
if (nextHeight <= scanData.chainTip) {
|
||||
final nextStream = scanningClient.subscribe(
|
||||
ElectrumTweaksSubscribe(
|
||||
height: nextHeight,
|
||||
count: getCountToScanPerRequest(nextHeight),
|
||||
historicalMode: false,
|
||||
),
|
||||
);
|
||||
|
||||
if (nextStream != null) {
|
||||
nextStream.listen((event) => listenFn(event, req));
|
||||
} else {
|
||||
scanData.sendPort.send(
|
||||
SyncResponse(scanData.height, LostConnectionSyncStatus()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final tweakHeight = response.block;
|
||||
|
||||
if (initialSyncHeight < tweakHeight) initialSyncHeight = tweakHeight;
|
||||
|
||||
// Continuous status UI update, send how many blocks left to scan
|
||||
final syncingStatus = scanData.isSingleScan
|
||||
? SyncingSyncStatus(1, 0)
|
||||
: SyncingSyncStatus.fromHeightValues(scanData.chainTip, initialSyncHeight, tweakHeight);
|
||||
|
||||
scanData.sendPort.send(SyncResponse(syncHeight, syncingStatus));
|
||||
|
||||
try {
|
||||
final blockTweaks = response.blockTweaks;
|
||||
|
||||
for (final txid in blockTweaks.keys) {
|
||||
final tweakData = blockTweaks[txid];
|
||||
final outputPubkeys = tweakData!.outputPubkeys;
|
||||
final tweak = tweakData.tweak;
|
||||
|
||||
try {
|
||||
final addToWallet = {};
|
||||
|
||||
// receivers.forEach((receiver) {
|
||||
// NOTE: scanOutputs, from sp_scanner package, called from rust here
|
||||
final scanResult = scanOutputs([outputPubkeys.keys.toList()], tweak, receiver);
|
||||
|
||||
if (scanResult.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (addToWallet[receiver.BSpend] == null) {
|
||||
addToWallet[receiver.BSpend] = scanResult;
|
||||
} else {
|
||||
addToWallet[receiver.BSpend].addAll(scanResult);
|
||||
}
|
||||
// });
|
||||
|
||||
if (addToWallet.isEmpty) {
|
||||
// no results tx, continue to next tx
|
||||
continue;
|
||||
}
|
||||
|
||||
// initial placeholder ElectrumTransactionInfo object to update values based on new scanned unspent(s) on the following loop
|
||||
final txInfo = ElectrumTransactionInfo(
|
||||
WalletType.bitcoin,
|
||||
id: txid,
|
||||
height: tweakHeight,
|
||||
amount: 0,
|
||||
fee: 0,
|
||||
direction: TransactionDirection.incoming,
|
||||
isReplaced: false,
|
||||
date: DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch * 1000,
|
||||
),
|
||||
confirmations: scanData.chainTip - tweakHeight + 1,
|
||||
isReceivedSilentPayment: true,
|
||||
isPending: false,
|
||||
unspents: [],
|
||||
);
|
||||
|
||||
List<BitcoinUnspent> unspents = [];
|
||||
|
||||
addToWallet.forEach((BSpend, scanResultPerLabel) {
|
||||
scanResultPerLabel.forEach((label, scanOutput) {
|
||||
final labelValue = label == "None" ? null : label.toString();
|
||||
|
||||
(scanOutput as Map<String, dynamic>).forEach((outputPubkey, tweak) {
|
||||
final t_k = tweak as String;
|
||||
|
||||
final receivingOutputAddress = ECPublic.fromHex(outputPubkey)
|
||||
.toTaprootAddress(tweak: false)
|
||||
.toAddress(scanData.network);
|
||||
|
||||
final matchingOutput = outputPubkeys[outputPubkey]!;
|
||||
final amount = matchingOutput.amount;
|
||||
final pos = matchingOutput.vout;
|
||||
|
||||
// final matchingSPWallet = scanData.silentPaymentsWallets.firstWhere(
|
||||
// (receiver) => receiver.B_spend.toHex() == BSpend.toString(),
|
||||
// );
|
||||
|
||||
// final labelIndex = labelValue != null ? scanData.labels[label] : 0;
|
||||
// final balance = ElectrumBalance();
|
||||
// balance.confirmed = amount;
|
||||
|
||||
final receivedAddressRecord = BitcoinSilentPaymentAddressRecord(
|
||||
receivingOutputAddress,
|
||||
index: 0,
|
||||
isHidden: false,
|
||||
isUsed: true,
|
||||
network: scanData.network,
|
||||
silentPaymentTweak: t_k,
|
||||
type: SegwitAddressType.p2tr,
|
||||
txCount: 1,
|
||||
balance: amount,
|
||||
);
|
||||
|
||||
final unspent = BitcoinSilentPaymentsUnspent(
|
||||
receivedAddressRecord,
|
||||
txid,
|
||||
amount,
|
||||
pos,
|
||||
silentPaymentTweak: t_k,
|
||||
silentPaymentLabel: labelValue,
|
||||
);
|
||||
|
||||
unspents.add(unspent);
|
||||
txInfo.unspents!.add(unspent);
|
||||
txInfo.amount += unspent.value;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
scanData.sendPort.send({txInfo.id: txInfo});
|
||||
} catch (e, stacktrace) {
|
||||
printV(stacktrace);
|
||||
printV(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (e, stacktrace) {
|
||||
printV(stacktrace);
|
||||
printV(e.toString());
|
||||
}
|
||||
|
||||
syncHeight = tweakHeight;
|
||||
|
||||
if ((tweakHeight >= scanData.chainTip) || scanData.isSingleScan) {
|
||||
if (tweakHeight >= scanData.chainTip)
|
||||
scanData.sendPort.send(
|
||||
SyncResponse(syncHeight, SyncedTipSyncStatus(scanData.chainTip)),
|
||||
);
|
||||
|
||||
if (scanData.isSingleScan) {
|
||||
scanData.sendPort.send(SyncResponse(syncHeight, SyncedSyncStatus()));
|
||||
}
|
||||
|
||||
_scanningStream?.close();
|
||||
_scanningStream = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_scanningStream?.listen((event) => listenFn(event, req));
|
||||
} catch (e) {
|
||||
printV("Error in _handleScanSilentPayments: $e");
|
||||
scanData.sendPort.send(SyncResponse(scanData.height, LostConnectionSyncStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> startRefresh(ScanData scanData) async {
|
||||
int syncHeight = scanData.height;
|
||||
int initialSyncHeight = syncHeight;
|
||||
|
@ -2580,7 +2807,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
|||
useSSL: scanData.node?.useSSL ?? false,
|
||||
);
|
||||
|
||||
int getCountPerRequest(int syncHeight) {
|
||||
int getCountToScanPerRequest(int syncHeight) {
|
||||
if (scanData.isSingleScan) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -2599,7 +2826,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
|||
);
|
||||
|
||||
// Initial status UI update, send how many blocks in total to scan
|
||||
final initialCount = getCountPerRequest(syncHeight);
|
||||
final initialCount = getCountToScanPerRequest(syncHeight);
|
||||
scanData.sendPort.send(SyncResponse(syncHeight, StartingScanSyncStatus(syncHeight)));
|
||||
|
||||
tweaksSubscription = await electrumClient.tweaksSubscribe(
|
||||
|
@ -2610,22 +2837,24 @@ Future<void> startRefresh(ScanData scanData) async {
|
|||
Future<void> listenFn(t) async {
|
||||
final tweaks = t as Map<String, dynamic>;
|
||||
final msg = tweaks["message"];
|
||||
// success or error msg
|
||||
|
||||
// is success or error msg
|
||||
final noData = msg != null;
|
||||
|
||||
if (noData) {
|
||||
if (scanData.isSingleScan) {
|
||||
return;
|
||||
}
|
||||
|
||||
// re-subscribe to continue receiving messages, starting from the next unscanned height
|
||||
final nextHeight = syncHeight + 1;
|
||||
final nextCount = getCountPerRequest(nextHeight);
|
||||
|
||||
if (nextCount > 0) {
|
||||
tweaksSubscription?.close();
|
||||
|
||||
final nextTweaksSubscription = electrumClient.tweaksSubscribe(
|
||||
if (nextHeight <= scanData.chainTip) {
|
||||
final nextStream = electrumClient.tweaksSubscribe(
|
||||
height: nextHeight,
|
||||
count: nextCount,
|
||||
count: getCountToScanPerRequest(nextHeight),
|
||||
);
|
||||
nextTweaksSubscription?.listen(listenFn);
|
||||
nextStream?.listen(listenFn);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -2707,7 +2936,7 @@ Future<void> startRefresh(ScanData scanData) async {
|
|||
isUsed: true,
|
||||
network: scanData.network,
|
||||
silentPaymentTweak: t_k,
|
||||
type: SegwitAddresType.p2tr,
|
||||
type: SegwitAddressType.p2tr,
|
||||
txCount: 1,
|
||||
balance: amount!,
|
||||
);
|
||||
|
@ -2800,15 +3029,15 @@ BitcoinAddressType _getScriptType(BitcoinBaseAddress type) {
|
|||
} else if (type is P2shAddress) {
|
||||
return P2shAddressType.p2wpkhInP2sh;
|
||||
} else if (type is P2wshAddress) {
|
||||
return SegwitAddresType.p2wsh;
|
||||
return SegwitAddressType.p2wsh;
|
||||
} else if (type is P2trAddress) {
|
||||
return SegwitAddresType.p2tr;
|
||||
return SegwitAddressType.p2tr;
|
||||
} else if (type is MwebAddress) {
|
||||
return SegwitAddresType.mweb;
|
||||
return SegwitAddressType.mweb;
|
||||
} else if (type is SilentPaymentsAddresType) {
|
||||
return SilentPaymentsAddresType.p2sp;
|
||||
} else {
|
||||
return SegwitAddresType.p2wpkh;
|
||||
return SegwitAddressType.p2wpkh;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'dart:io' show Platform;
|
|||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||
import 'package:cw_core/unspent_coin_type.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_unspent.dart';
|
||||
|
@ -17,16 +16,16 @@ part 'electrum_wallet_addresses.g.dart';
|
|||
class ElectrumWalletAddresses = ElectrumWalletAddressesBase with _$ElectrumWalletAddresses;
|
||||
|
||||
const List<BitcoinAddressType> BITCOIN_ADDRESS_TYPES = [
|
||||
SegwitAddresType.p2wpkh,
|
||||
SegwitAddressType.p2wpkh,
|
||||
P2pkhAddressType.p2pkh,
|
||||
SegwitAddresType.p2tr,
|
||||
SegwitAddresType.p2wsh,
|
||||
SegwitAddressType.p2tr,
|
||||
SegwitAddressType.p2wsh,
|
||||
P2shAddressType.p2wpkhInP2sh,
|
||||
];
|
||||
|
||||
const List<BitcoinAddressType> LITECOIN_ADDRESS_TYPES = [
|
||||
SegwitAddresType.p2wpkh,
|
||||
SegwitAddresType.mweb,
|
||||
SegwitAddressType.p2wpkh,
|
||||
SegwitAddressType.mweb,
|
||||
];
|
||||
|
||||
const List<BitcoinAddressType> BITCOIN_CASH_ADDRESS_TYPES = [
|
||||
|
@ -62,7 +61,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
_addressPageType = initialAddressPageType ??
|
||||
(walletInfo.addressPageType != null
|
||||
? BitcoinAddressType.fromValue(walletInfo.addressPageType!)
|
||||
: SegwitAddresType.p2wpkh),
|
||||
: SegwitAddressType.p2wpkh),
|
||||
silentAddresses = ObservableList<BitcoinSilentPaymentAddressRecord>.of(
|
||||
(initialSilentAddresses ?? []).toSet()),
|
||||
currentSilentAddressIndex = initialSilentAddressIndex,
|
||||
|
@ -71,9 +70,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
super(walletInfo) {
|
||||
if (masterHd != null) {
|
||||
silentAddress = SilentPaymentOwner.fromPrivateKeys(
|
||||
b_scan: ECPrivate.fromHex(masterHd.derivePath(SCAN_PATH).privateKey.toHex()),
|
||||
b_spend: ECPrivate.fromHex(masterHd.derivePath(SPEND_PATH).privateKey.toHex()),
|
||||
network: network,
|
||||
b_scan: ECPrivate.fromHex(
|
||||
masterHd.derivePath("m/352'/1'/0'/1'/0").privateKey.toHex(),
|
||||
),
|
||||
b_spend: ECPrivate.fromHex(
|
||||
masterHd.derivePath("m/352'/1'/0'/0'/0").privateKey.toHex(),
|
||||
),
|
||||
);
|
||||
|
||||
if (silentAddresses.length == 0) {
|
||||
|
@ -109,8 +111,10 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
final ObservableList<BaseBitcoinAddressRecord> addressesByReceiveType;
|
||||
final ObservableList<BitcoinAddressRecord> receiveAddresses;
|
||||
final ObservableList<BitcoinAddressRecord> changeAddresses;
|
||||
|
||||
// TODO: add this variable in `bitcoin_wallet_addresses` and just add a cast in cw_bitcoin to use it
|
||||
final ObservableList<BitcoinSilentPaymentAddressRecord> silentAddresses;
|
||||
|
||||
// TODO: add this variable in `litecoin_wallet_addresses` and just add a cast in cw_bitcoin to use it
|
||||
final ObservableList<BitcoinAddressRecord> mwebAddresses;
|
||||
final BasedUtxoNetwork network;
|
||||
|
@ -144,12 +148,13 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
return silentAddress.toString();
|
||||
}
|
||||
|
||||
final typeMatchingAddresses = _addresses.where((addr) => !addr.isHidden && _isAddressPageTypeMatch(addr)).toList();
|
||||
final typeMatchingReceiveAddresses = typeMatchingAddresses.where((addr) => !addr.isUsed).toList();
|
||||
final typeMatchingAddresses =
|
||||
_addresses.where((addr) => !addr.isHidden && _isAddressPageTypeMatch(addr)).toList();
|
||||
final typeMatchingReceiveAddresses =
|
||||
typeMatchingAddresses.where((addr) => !addr.isUsed).toList();
|
||||
|
||||
if (!isEnabledAutoGenerateSubaddress) {
|
||||
if (previousAddressRecord != null &&
|
||||
previousAddressRecord!.type == addressPageType) {
|
||||
if (previousAddressRecord != null && previousAddressRecord!.type == addressPageType) {
|
||||
return previousAddressRecord!.address;
|
||||
}
|
||||
|
||||
|
@ -249,17 +254,17 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
if (walletInfo.type == WalletType.bitcoinCash) {
|
||||
await _generateInitialAddresses(type: P2pkhAddressType.p2pkh);
|
||||
} else if (walletInfo.type == WalletType.litecoin) {
|
||||
await _generateInitialAddresses(type: SegwitAddresType.p2wpkh);
|
||||
await _generateInitialAddresses(type: SegwitAddressType.p2wpkh);
|
||||
if ((Platform.isAndroid || Platform.isIOS) && !isHardwareWallet) {
|
||||
await _generateInitialAddresses(type: SegwitAddresType.mweb);
|
||||
await _generateInitialAddresses(type: SegwitAddressType.mweb);
|
||||
}
|
||||
} else if (walletInfo.type == WalletType.bitcoin) {
|
||||
await _generateInitialAddresses();
|
||||
if (!isHardwareWallet) {
|
||||
await _generateInitialAddresses(type: P2pkhAddressType.p2pkh);
|
||||
await _generateInitialAddresses(type: P2shAddressType.p2wpkhInP2sh);
|
||||
await _generateInitialAddresses(type: SegwitAddresType.p2tr);
|
||||
await _generateInitialAddresses(type: SegwitAddresType.p2wsh);
|
||||
await _generateInitialAddresses(type: SegwitAddressType.p2tr);
|
||||
await _generateInitialAddresses(type: SegwitAddressType.p2wsh);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,7 +328,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
BaseBitcoinAddressRecord generateNewAddress({String label = ''}) {
|
||||
if (addressPageType == SilentPaymentsAddresType.p2sp && silentAddress != null) {
|
||||
final currentSilentAddressIndex = silentAddresses
|
||||
.where((addressRecord) => addressRecord.type != SegwitAddresType.p2tr)
|
||||
.where((addressRecord) => addressRecord.type != SegwitAddressType.p2tr)
|
||||
.length -
|
||||
1;
|
||||
|
||||
|
@ -381,7 +386,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
void addBitcoinAddressTypes() {
|
||||
final lastP2wpkh = _addresses
|
||||
.where((addressRecord) =>
|
||||
_isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wpkh))
|
||||
_isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2wpkh))
|
||||
.toList()
|
||||
.last;
|
||||
if (lastP2wpkh.address != address) {
|
||||
|
@ -407,7 +412,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}
|
||||
|
||||
final lastP2tr = _addresses.firstWhere(
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2tr));
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2tr));
|
||||
if (lastP2tr.address != address) {
|
||||
addressesMap[lastP2tr.address] = 'P2TR';
|
||||
} else {
|
||||
|
@ -415,7 +420,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}
|
||||
|
||||
final lastP2wsh = _addresses.firstWhere(
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wsh));
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2wsh));
|
||||
if (lastP2wsh.address != address) {
|
||||
addressesMap[lastP2wsh.address] = 'P2WSH';
|
||||
} else {
|
||||
|
@ -440,7 +445,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
void addLitecoinAddressTypes() {
|
||||
final lastP2wpkh = _addresses
|
||||
.where((addressRecord) =>
|
||||
_isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wpkh))
|
||||
_isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.p2wpkh))
|
||||
.toList()
|
||||
.last;
|
||||
if (lastP2wpkh.address != address) {
|
||||
|
@ -450,7 +455,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}
|
||||
|
||||
final lastMweb = _addresses.firstWhere(
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.mweb));
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddressType.mweb));
|
||||
if (lastMweb.address != address) {
|
||||
addressesMap[lastMweb.address] = 'MWEB';
|
||||
} else {
|
||||
|
@ -560,14 +565,14 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
addressRecord.isHidden &&
|
||||
!addressRecord.isUsed &&
|
||||
// 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);
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> discoverAddresses(List<BitcoinAddressRecord> addressList, bool isHidden,
|
||||
Future<String?> Function(BitcoinAddressRecord) getAddressHistory,
|
||||
{BitcoinAddressType type = SegwitAddresType.p2wpkh}) async {
|
||||
{BitcoinAddressType type = SegwitAddressType.p2wpkh}) async {
|
||||
final newAddresses = await _createNewAddresses(gap,
|
||||
startIndex: addressList.length, isHidden: isHidden, type: type);
|
||||
addAddresses(newAddresses);
|
||||
|
@ -581,7 +586,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}
|
||||
|
||||
Future<void> _generateInitialAddresses(
|
||||
{BitcoinAddressType type = SegwitAddresType.p2wpkh}) async {
|
||||
{BitcoinAddressType type = SegwitAddressType.p2wpkh}) async {
|
||||
var countOfReceiveAddresses = 0;
|
||||
var countOfHiddenAddresses = 0;
|
||||
|
||||
|
@ -658,7 +663,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
|
||||
void _validateAddresses() {
|
||||
_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
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -87,8 +87,8 @@ class ElectrumWalletSnapshot {
|
|||
|
||||
final balance = ElectrumBalance.fromJSON(data['balance'] as String?) ??
|
||||
ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0);
|
||||
var regularAddressIndexByType = {SegwitAddresType.p2wpkh.toString(): 0};
|
||||
var changeAddressIndexByType = {SegwitAddresType.p2wpkh.toString(): 0};
|
||||
var regularAddressIndexByType = {SegwitAddressType.p2wpkh.toString(): 0};
|
||||
var changeAddressIndexByType = {SegwitAddressType.p2wpkh.toString(): 0};
|
||||
var silentAddressIndex = 0;
|
||||
|
||||
final derivationType = DerivationType
|
||||
|
@ -97,10 +97,10 @@ class ElectrumWalletSnapshot {
|
|||
|
||||
try {
|
||||
regularAddressIndexByType = {
|
||||
SegwitAddresType.p2wpkh.toString(): int.parse(data['account_index'] as String? ?? '0')
|
||||
SegwitAddressType.p2wpkh.toString(): int.parse(data['account_index'] as String? ?? '0')
|
||||
};
|
||||
changeAddressIndexByType = {
|
||||
SegwitAddresType.p2wpkh.toString():
|
||||
SegwitAddressType.p2wpkh.toString():
|
||||
int.parse(data['change_address_index'] as String? ?? '0')
|
||||
};
|
||||
silentAddressIndex = int.parse(data['silent_address_index'] as String? ?? '0');
|
||||
|
|
64
cw_bitcoin/lib/litecoin_address_record.dart
Normal file
64
cw_bitcoin/lib/litecoin_address_record.dart
Normal file
|
@ -0,0 +1,64 @@
|
|||
import 'dart:convert';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
|
||||
class LitecoinAddressRecord extends BitcoinAddressRecord {
|
||||
LitecoinAddressRecord(
|
||||
super.address, {
|
||||
required super.index,
|
||||
super.isHidden = false,
|
||||
super.txCount = 0,
|
||||
super.balance = 0,
|
||||
super.name = '',
|
||||
super.isUsed = false,
|
||||
required this.type,
|
||||
String? scriptHash,
|
||||
required this.network,
|
||||
}) : scriptHash = scriptHash ??
|
||||
(network != null ? BitcoinAddressUtils.scriptHash(address, network: network) : null);
|
||||
|
||||
factory LitecoinAddressRecord.fromJSON(String jsonSource, {BasedUtxoNetwork? network}) {
|
||||
final decoded = json.decode(jsonSource) as Map;
|
||||
|
||||
return LitecoinAddressRecord(
|
||||
decoded['address'] as String,
|
||||
index: decoded['index'] as int,
|
||||
isHidden: decoded['isHidden'] as bool? ?? false,
|
||||
isUsed: decoded['isUsed'] as bool? ?? false,
|
||||
txCount: decoded['txCount'] as int? ?? 0,
|
||||
name: decoded['name'] as String? ?? '',
|
||||
balance: decoded['balance'] as int? ?? 0,
|
||||
type: decoded['type'] != null && decoded['type'] != ''
|
||||
? BitcoinAddressType.values
|
||||
.firstWhere((type) => type.toString() == decoded['type'] as String)
|
||||
: SegwitAddresType.p2wpkh,
|
||||
scriptHash: decoded['scriptHash'] as String?,
|
||||
network: network,
|
||||
);
|
||||
}
|
||||
|
||||
String? scriptHash;
|
||||
|
||||
final BitcoinAddressType type;
|
||||
final BasedUtxoNetwork? network;
|
||||
|
||||
String getScriptHash(BasedUtxoNetwork network) {
|
||||
if (scriptHash != null) return scriptHash!;
|
||||
scriptHash = BitcoinAddressUtils.scriptHash(address, network: network);
|
||||
return scriptHash!;
|
||||
}
|
||||
|
||||
@override
|
||||
String toJSON() => json.encode({
|
||||
'address': address,
|
||||
'index': index,
|
||||
'isHidden': isHidden,
|
||||
'isUsed': isUsed,
|
||||
'txCount': txCount,
|
||||
'name': name,
|
||||
'balance': balance,
|
||||
'type': type.toString(),
|
||||
'scriptHash': scriptHash,
|
||||
});
|
||||
}
|
|
@ -6,15 +6,19 @@ import 'dart:math';
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
|
||||
import 'package:cw_bitcoin/exceptions.dart';
|
||||
import 'package:cw_bitcoin/litecoin_address_record.dart';
|
||||
import 'package:cw_core/cake_hive.dart';
|
||||
import 'package:cw_core/get_height_by_date.dart';
|
||||
import 'package:cw_core/mweb_utxo.dart';
|
||||
import 'package:cw_core/unspent_coin_type.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/node.dart';
|
||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
import 'package:cw_mweb/mwebd.pbgrpc.dart';
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:bip39/bip39.dart' as bip39;
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:blockchain_utils/signer/ecdsa_signing_key.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
|
@ -46,7 +50,7 @@ import 'package:ledger_litecoin/ledger_litecoin.dart';
|
|||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/wallet_type.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/curves/secp256k1.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
@ -66,8 +70,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
String? xpub,
|
||||
String? passphrase,
|
||||
String? addressPageType,
|
||||
List<BitcoinAddressRecord>? initialAddresses,
|
||||
List<BitcoinAddressRecord>? initialMwebAddresses,
|
||||
List<LitecoinAddressRecord>? initialAddresses,
|
||||
List<LitecoinAddressRecord>? initialMwebAddresses,
|
||||
ElectrumBalance? initialBalance,
|
||||
Map<String, int>? initialRegularAddressIndex,
|
||||
Map<String, int>? initialChangeAddressIndex,
|
||||
|
@ -151,6 +155,895 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
StreamSubscription<Utxo>? _utxoStream;
|
||||
late bool mwebEnabled;
|
||||
bool processingUtxos = false;
|
||||
|
||||
Bip32Slip10Secp256k1 get hd => accountHD.childKey(Bip32KeyIndex(0));
|
||||
|
||||
Bip32Slip10Secp256k1 get sideHd => accountHD.childKey(Bip32KeyIndex(1));
|
||||
|
||||
Set<String> get addressesSet => walletAddresses.allAddresses
|
||||
.where((element) => element.type != SegwitAddresType.mweb)
|
||||
.map((addr) => addr.address)
|
||||
.toSet();
|
||||
|
||||
List<String> get scriptHashes => walletAddresses.addressesByReceiveType
|
||||
.where((addr) => RegexUtils.addressTypeFromStr(addr.address, network) is! MwebAddress)
|
||||
.map((addr) => (addr as LitecoinAddressRecord).getScriptHash(network))
|
||||
.toList();
|
||||
|
||||
List<String> get publicScriptHashes => walletAddresses.allAddresses
|
||||
.where((addr) => !addr.isHidden)
|
||||
.where((addr) => RegexUtils.addressTypeFromStr(addr.address, network) is! MwebAddress)
|
||||
.map((addr) => addr.getScriptHash(network))
|
||||
.toList();
|
||||
|
||||
UtxoDetails _createUTXOS({
|
||||
required bool sendAll,
|
||||
required bool paysToSilentPayment,
|
||||
int credentialsAmount = 0,
|
||||
int? inputsCount,
|
||||
UnspentCoinType coinTypeToSpendFrom = UnspentCoinType.any,
|
||||
}) {
|
||||
List<UtxoWithAddress> utxos = [];
|
||||
List<Outpoint> vinOutpoints = [];
|
||||
List<ECPrivateInfo> inputPrivKeyInfos = [];
|
||||
final publicKeys = <String, PublicKeyWithDerivationPath>{};
|
||||
int allInputsAmount = 0;
|
||||
bool spendsSilentPayment = false;
|
||||
bool spendsUnconfirmedTX = false;
|
||||
|
||||
int leftAmount = credentialsAmount;
|
||||
var availableInputs = unspentCoins.where((utx) {
|
||||
if (!utx.isSending || utx.isFrozen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (coinTypeToSpendFrom) {
|
||||
case UnspentCoinType.mweb:
|
||||
return utx.bitcoinAddressRecord.type == SegwitAddresType.mweb;
|
||||
case UnspentCoinType.nonMweb:
|
||||
return utx.bitcoinAddressRecord.type != SegwitAddresType.mweb;
|
||||
case UnspentCoinType.any:
|
||||
return true;
|
||||
}
|
||||
}).toList();
|
||||
final unconfirmedCoins = availableInputs.where((utx) => utx.confirmations == 0).toList();
|
||||
|
||||
// sort the unconfirmed coins so that mweb coins are last:
|
||||
availableInputs.sort((a, b) => a.bitcoinAddressRecord.type == SegwitAddresType.mweb ? 1 : -1);
|
||||
|
||||
for (int i = 0; i < availableInputs.length; i++) {
|
||||
final utx = availableInputs[i];
|
||||
if (!spendsUnconfirmedTX) spendsUnconfirmedTX = utx.confirmations == 0;
|
||||
|
||||
allInputsAmount += utx.value;
|
||||
leftAmount = leftAmount - utx.value;
|
||||
|
||||
final address = RegexUtils.addressTypeFromStr(utx.address, network);
|
||||
ECPrivate? privkey;
|
||||
bool? isSilentPayment = false;
|
||||
|
||||
final hd =
|
||||
utx.bitcoinAddressRecord.isHidden ? walletAddresses.sideHd : walletAddresses.mainHd;
|
||||
|
||||
if (utx.bitcoinAddressRecord is BitcoinSilentPaymentAddressRecord) {
|
||||
final unspentAddress = utx.bitcoinAddressRecord as BitcoinSilentPaymentAddressRecord;
|
||||
privkey = walletAddresses.silentAddress!.b_spend.tweakAdd(
|
||||
BigintUtils.fromBytes(
|
||||
BytesUtils.fromHexString(unspentAddress.silentPaymentTweak!),
|
||||
),
|
||||
);
|
||||
spendsSilentPayment = true;
|
||||
isSilentPayment = true;
|
||||
} else if (!isHardwareWallet) {
|
||||
privkey =
|
||||
generateECPrivate(hd: hd, index: utx.bitcoinAddressRecord.index, network: network);
|
||||
}
|
||||
|
||||
vinOutpoints.add(Outpoint(txid: utx.hash, index: utx.vout));
|
||||
String pubKeyHex;
|
||||
|
||||
if (privkey != null) {
|
||||
inputPrivKeyInfos.add(ECPrivateInfo(
|
||||
privkey,
|
||||
address.type == SegwitAddresType.p2tr,
|
||||
tweak: !isSilentPayment,
|
||||
));
|
||||
|
||||
pubKeyHex = privkey.getPublic().toHex();
|
||||
} else {
|
||||
pubKeyHex = hd.childKey(Bip32KeyIndex(utx.bitcoinAddressRecord.index)).publicKey.toHex();
|
||||
}
|
||||
|
||||
final derivationPath =
|
||||
"${_hardenedDerivationPath(walletInfo.derivationInfo?.derivationPath ?? electrum_path)}"
|
||||
"/${utx.bitcoinAddressRecord.isHidden ? "1" : "0"}"
|
||||
"/${utx.bitcoinAddressRecord.index}";
|
||||
publicKeys[address.pubKeyHash()] = PublicKeyWithDerivationPath(pubKeyHex, derivationPath);
|
||||
|
||||
utxos.add(
|
||||
UtxoWithAddress(
|
||||
utxo: BitcoinUtxo(
|
||||
txHash: utx.hash,
|
||||
value: BigInt.from(utx.value),
|
||||
vout: utx.vout,
|
||||
scriptType: _getScriptType(address),
|
||||
isSilentPayment: isSilentPayment,
|
||||
),
|
||||
ownerDetails: UtxoAddressDetails(
|
||||
publicKey: pubKeyHex,
|
||||
address: address,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// sendAll continues for all inputs
|
||||
if (!sendAll) {
|
||||
bool amountIsAcquired = leftAmount <= 0;
|
||||
if ((inputsCount == null && amountIsAcquired) || inputsCount == i + 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (utxos.isEmpty) {
|
||||
throw BitcoinTransactionNoInputsException();
|
||||
}
|
||||
|
||||
return UtxoDetails(
|
||||
availableInputs: availableInputs,
|
||||
unconfirmedCoins: unconfirmedCoins,
|
||||
utxos: utxos,
|
||||
vinOutpoints: vinOutpoints,
|
||||
inputPrivKeyInfos: inputPrivKeyInfos,
|
||||
publicKeys: publicKeys,
|
||||
allInputsAmount: allInputsAmount,
|
||||
spendsSilentPayment: spendsSilentPayment,
|
||||
spendsUnconfirmedTX: spendsUnconfirmedTX,
|
||||
);
|
||||
}
|
||||
|
||||
Future<EstimatedTxResult> estimateSendAllTx(
|
||||
List<BitcoinOutput> outputs,
|
||||
int feeRate, {
|
||||
String? memo,
|
||||
bool hasSilentPayment = false,
|
||||
UnspentCoinType coinTypeToSpendFrom = UnspentCoinType.any,
|
||||
}) async {
|
||||
final utxoDetails = _createUTXOS(
|
||||
sendAll: true,
|
||||
paysToSilentPayment: hasSilentPayment,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
|
||||
int fee = await calcFee(
|
||||
utxos: utxoDetails.utxos,
|
||||
outputs: outputs,
|
||||
network: network,
|
||||
memo: memo,
|
||||
feeRate: feeRate,
|
||||
inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos,
|
||||
vinOutpoints: utxoDetails.vinOutpoints,
|
||||
);
|
||||
|
||||
if (fee == 0) {
|
||||
throw BitcoinTransactionNoFeeException();
|
||||
}
|
||||
|
||||
// Here, when sending all, the output amount equals to the input value - fee to fully spend every input on the transaction and have no amount left for change
|
||||
int amount = utxoDetails.allInputsAmount - fee;
|
||||
|
||||
if (amount <= 0) {
|
||||
throw BitcoinTransactionWrongBalanceException(amount: utxoDetails.allInputsAmount + fee);
|
||||
}
|
||||
|
||||
// Attempting to send less than the dust limit
|
||||
if (_isBelowDust(amount)) {
|
||||
throw BitcoinTransactionNoDustException();
|
||||
}
|
||||
|
||||
if (outputs.length == 1) {
|
||||
outputs[0] = BitcoinOutput(address: outputs.last.address, value: BigInt.from(amount));
|
||||
}
|
||||
|
||||
return EstimatedTxResult(
|
||||
utxos: utxoDetails.utxos,
|
||||
inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos,
|
||||
publicKeys: utxoDetails.publicKeys,
|
||||
fee: fee,
|
||||
amount: amount,
|
||||
isSendAll: true,
|
||||
hasChange: false,
|
||||
memo: memo,
|
||||
spendsUnconfirmedTX: utxoDetails.spendsUnconfirmedTX,
|
||||
spendsSilentPayment: utxoDetails.spendsSilentPayment,
|
||||
);
|
||||
}
|
||||
|
||||
int get _dustAmount => 546;
|
||||
|
||||
bool _isBelowDust(int amount) => amount <= _dustAmount && network != BitcoinNetwork.testnet;
|
||||
|
||||
Future<EstimatedTxResult> estimateTxForAmount(
|
||||
int credentialsAmount,
|
||||
List<BitcoinOutput> outputs,
|
||||
List<BitcoinOutput> updatedOutputs,
|
||||
int feeRate, {
|
||||
int? inputsCount,
|
||||
String? memo,
|
||||
bool? useUnconfirmed,
|
||||
bool hasSilentPayment = false,
|
||||
UnspentCoinType coinTypeToSpendFrom = UnspentCoinType.any,
|
||||
}) async {
|
||||
// Attempting to send less than the dust limit
|
||||
if (_isBelowDust(credentialsAmount)) {
|
||||
throw BitcoinTransactionNoDustException();
|
||||
}
|
||||
|
||||
final utxoDetails = _createUTXOS(
|
||||
sendAll: false,
|
||||
credentialsAmount: credentialsAmount,
|
||||
inputsCount: inputsCount,
|
||||
paysToSilentPayment: hasSilentPayment,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
|
||||
final spendingAllCoins = utxoDetails.availableInputs.length == utxoDetails.utxos.length;
|
||||
final spendingAllConfirmedCoins = !utxoDetails.spendsUnconfirmedTX &&
|
||||
utxoDetails.utxos.length ==
|
||||
utxoDetails.availableInputs.length - utxoDetails.unconfirmedCoins.length;
|
||||
|
||||
// How much is being spent - how much is being sent
|
||||
int amountLeftForChangeAndFee = utxoDetails.allInputsAmount - credentialsAmount;
|
||||
|
||||
if (amountLeftForChangeAndFee <= 0) {
|
||||
if (!spendingAllCoins) {
|
||||
return estimateTxForAmount(
|
||||
credentialsAmount,
|
||||
outputs,
|
||||
updatedOutputs,
|
||||
feeRate,
|
||||
inputsCount: utxoDetails.utxos.length + 1,
|
||||
memo: memo,
|
||||
hasSilentPayment: hasSilentPayment,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
}
|
||||
|
||||
throw BitcoinTransactionWrongBalanceException();
|
||||
}
|
||||
|
||||
final changeAddress = await walletAddresses.getChangeAddress(
|
||||
inputs: utxoDetails.availableInputs,
|
||||
outputs: updatedOutputs,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
final address = RegexUtils.addressTypeFromStr(changeAddress.address, network);
|
||||
updatedOutputs.add(BitcoinOutput(
|
||||
address: address,
|
||||
value: BigInt.from(amountLeftForChangeAndFee),
|
||||
isChange: true,
|
||||
));
|
||||
outputs.add(BitcoinOutput(
|
||||
address: address,
|
||||
value: BigInt.from(amountLeftForChangeAndFee),
|
||||
isChange: true,
|
||||
));
|
||||
|
||||
// Get Derivation path for change Address since it is needed in Litecoin and BitcoinCash hardware Wallets
|
||||
final changeDerivationPath =
|
||||
"${_hardenedDerivationPath(walletInfo.derivationInfo?.derivationPath ?? "m/0'")}"
|
||||
"/${changeAddress.isHidden ? "1" : "0"}"
|
||||
"/${changeAddress.index}";
|
||||
utxoDetails.publicKeys[address.pubKeyHash()] =
|
||||
PublicKeyWithDerivationPath('', changeDerivationPath);
|
||||
|
||||
// calcFee updates the silent payment outputs to calculate the tx size accounting
|
||||
// for taproot addresses, but if more inputs are needed to make up for fees,
|
||||
// the silent payment outputs need to be recalculated for the new inputs
|
||||
var temp = outputs.map((output) => output).toList();
|
||||
int fee = await calcFee(
|
||||
utxos: utxoDetails.utxos,
|
||||
// Always take only not updated bitcoin outputs here so for every estimation
|
||||
// the SP outputs are re-generated to the proper taproot addresses
|
||||
outputs: temp,
|
||||
network: network,
|
||||
memo: memo,
|
||||
feeRate: feeRate,
|
||||
inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos,
|
||||
vinOutpoints: utxoDetails.vinOutpoints,
|
||||
);
|
||||
|
||||
updatedOutputs.clear();
|
||||
updatedOutputs.addAll(temp);
|
||||
|
||||
if (fee == 0) {
|
||||
throw BitcoinTransactionNoFeeException();
|
||||
}
|
||||
|
||||
int amount = credentialsAmount;
|
||||
final lastOutput = updatedOutputs.last;
|
||||
final amountLeftForChange = amountLeftForChangeAndFee - fee;
|
||||
|
||||
if (_isBelowDust(amountLeftForChange)) {
|
||||
// If has change that is lower than dust, will end up with tx rejected by network rules
|
||||
// so remove the change amount
|
||||
updatedOutputs.removeLast();
|
||||
outputs.removeLast();
|
||||
|
||||
if (amountLeftForChange < 0) {
|
||||
if (!spendingAllCoins) {
|
||||
return estimateTxForAmount(
|
||||
credentialsAmount,
|
||||
outputs,
|
||||
updatedOutputs,
|
||||
feeRate,
|
||||
inputsCount: utxoDetails.utxos.length + 1,
|
||||
memo: memo,
|
||||
useUnconfirmed: useUnconfirmed ?? spendingAllConfirmedCoins,
|
||||
hasSilentPayment: hasSilentPayment,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
} else {
|
||||
throw BitcoinTransactionWrongBalanceException();
|
||||
}
|
||||
}
|
||||
|
||||
// if the amount left for change is less than dust, but not less than 0
|
||||
// then add it to the fees
|
||||
fee += amountLeftForChange;
|
||||
|
||||
return EstimatedTxResult(
|
||||
utxos: utxoDetails.utxos,
|
||||
inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos,
|
||||
publicKeys: utxoDetails.publicKeys,
|
||||
fee: fee,
|
||||
amount: amount,
|
||||
hasChange: false,
|
||||
isSendAll: spendingAllCoins,
|
||||
memo: memo,
|
||||
spendsUnconfirmedTX: utxoDetails.spendsUnconfirmedTX,
|
||||
spendsSilentPayment: utxoDetails.spendsSilentPayment,
|
||||
);
|
||||
} else {
|
||||
// Here, lastOutput already is change, return the amount left without the fee to the user's address.
|
||||
updatedOutputs[updatedOutputs.length - 1] = BitcoinOutput(
|
||||
address: lastOutput.address,
|
||||
value: BigInt.from(amountLeftForChange),
|
||||
isSilentPayment: lastOutput.isSilentPayment,
|
||||
isChange: true,
|
||||
);
|
||||
outputs[outputs.length - 1] = BitcoinOutput(
|
||||
address: lastOutput.address,
|
||||
value: BigInt.from(amountLeftForChange),
|
||||
isSilentPayment: lastOutput.isSilentPayment,
|
||||
isChange: true,
|
||||
);
|
||||
|
||||
return EstimatedTxResult(
|
||||
utxos: utxoDetails.utxos,
|
||||
inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos,
|
||||
publicKeys: utxoDetails.publicKeys,
|
||||
fee: fee,
|
||||
amount: amount,
|
||||
hasChange: true,
|
||||
isSendAll: spendingAllCoins,
|
||||
memo: memo,
|
||||
spendsUnconfirmedTX: utxoDetails.spendsUnconfirmedTX,
|
||||
spendsSilentPayment: utxoDetails.spendsSilentPayment,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<PendingTransaction> createTransactionSuper(Object credentials) async {
|
||||
try {
|
||||
// start by updating unspent coins
|
||||
await updateAllUnspents();
|
||||
|
||||
final outputs = <BitcoinOutput>[];
|
||||
final transactionCredentials = credentials as BitcoinTransactionCredentials;
|
||||
final hasMultiDestination = transactionCredentials.outputs.length > 1;
|
||||
final sendAll = !hasMultiDestination && transactionCredentials.outputs.first.sendAll;
|
||||
final memo = transactionCredentials.outputs.first.memo;
|
||||
final coinTypeToSpendFrom = transactionCredentials.coinTypeToSpendFrom;
|
||||
|
||||
int credentialsAmount = 0;
|
||||
bool hasSilentPayment = false;
|
||||
|
||||
for (final out in transactionCredentials.outputs) {
|
||||
final outputAmount = out.formattedCryptoAmount!;
|
||||
|
||||
if (!sendAll && _isBelowDust(outputAmount)) {
|
||||
throw BitcoinTransactionNoDustException();
|
||||
}
|
||||
|
||||
if (hasMultiDestination) {
|
||||
if (out.sendAll) {
|
||||
throw BitcoinTransactionWrongBalanceException();
|
||||
}
|
||||
}
|
||||
|
||||
credentialsAmount += outputAmount;
|
||||
|
||||
final address = RegexUtils.addressTypeFromStr(
|
||||
out.isParsedAddress ? out.extractedAddress! : out.address, network);
|
||||
final isSilentPayment = address is SilentPaymentAddress;
|
||||
|
||||
if (isSilentPayment) {
|
||||
hasSilentPayment = true;
|
||||
}
|
||||
|
||||
if (sendAll) {
|
||||
// The value will be changed after estimating the Tx size and deducting the fee from the total to be sent
|
||||
outputs.add(BitcoinOutput(
|
||||
address: address,
|
||||
value: BigInt.from(0),
|
||||
isSilentPayment: isSilentPayment,
|
||||
));
|
||||
} else {
|
||||
outputs.add(BitcoinOutput(
|
||||
address: address,
|
||||
value: BigInt.from(outputAmount),
|
||||
isSilentPayment: isSilentPayment,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
final feeRateInt = transactionCredentials.feeRate != null
|
||||
? transactionCredentials.feeRate!
|
||||
: feeRate(transactionCredentials.priority!);
|
||||
|
||||
EstimatedTxResult estimatedTx;
|
||||
final updatedOutputs = outputs
|
||||
.map((e) => BitcoinOutput(
|
||||
address: e.address,
|
||||
value: e.value,
|
||||
isSilentPayment: e.isSilentPayment,
|
||||
isChange: e.isChange,
|
||||
))
|
||||
.toList();
|
||||
|
||||
if (sendAll) {
|
||||
estimatedTx = await estimateSendAllTx(
|
||||
updatedOutputs,
|
||||
feeRateInt,
|
||||
memo: memo,
|
||||
hasSilentPayment: hasSilentPayment,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
} else {
|
||||
estimatedTx = await estimateTxForAmount(
|
||||
credentialsAmount,
|
||||
outputs,
|
||||
updatedOutputs,
|
||||
feeRateInt,
|
||||
memo: memo,
|
||||
hasSilentPayment: hasSilentPayment,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
}
|
||||
|
||||
if (walletInfo.isHardwareWallet) {
|
||||
final transaction = await buildHardwareWalletTransaction(
|
||||
utxos: estimatedTx.utxos,
|
||||
outputs: updatedOutputs,
|
||||
publicKeys: estimatedTx.publicKeys,
|
||||
fee: BigInt.from(estimatedTx.fee),
|
||||
network: network,
|
||||
memo: estimatedTx.memo,
|
||||
outputOrdering: BitcoinOrdering.none,
|
||||
enableRBF: true,
|
||||
);
|
||||
|
||||
return PendingBitcoinTransaction(
|
||||
transaction,
|
||||
type,
|
||||
electrumClient: electrumClient,
|
||||
amount: estimatedTx.amount,
|
||||
fee: estimatedTx.fee,
|
||||
feeRate: feeRateInt.toString(),
|
||||
network: network,
|
||||
hasChange: estimatedTx.hasChange,
|
||||
isSendAll: estimatedTx.isSendAll,
|
||||
hasTaprootInputs: false, // ToDo: (Konsti) Support Taproot
|
||||
)..addListener((transaction) async {
|
||||
transactionHistory.addOne(transaction);
|
||||
await updateBalance();
|
||||
await updateAllUnspents();
|
||||
});
|
||||
}
|
||||
|
||||
BasedBitcoinTransacationBuilder txb = BitcoinTransactionBuilder(
|
||||
utxos: estimatedTx.utxos,
|
||||
outputs: updatedOutputs,
|
||||
fee: BigInt.from(estimatedTx.fee),
|
||||
network: network,
|
||||
memo: estimatedTx.memo,
|
||||
outputOrdering: BitcoinOrdering.none,
|
||||
enableRBF: !estimatedTx.spendsUnconfirmedTX,
|
||||
);
|
||||
|
||||
bool hasTaprootInputs = false;
|
||||
|
||||
final transaction = txb.buildTransaction((txDigest, utxo, publicKey, sighash) {
|
||||
String error = "Cannot find private key.";
|
||||
|
||||
ECPrivateInfo? key;
|
||||
|
||||
if (estimatedTx.inputPrivKeyInfos.isEmpty) {
|
||||
error += "\nNo private keys generated.";
|
||||
} else {
|
||||
error += "\nAddress: ${utxo.ownerDetails.address.toAddress(network)}";
|
||||
|
||||
key = estimatedTx.inputPrivKeyInfos.firstWhereOrNull((element) {
|
||||
final elemPubkey = element.privkey.getPublic().toHex();
|
||||
if (elemPubkey == publicKey) {
|
||||
return true;
|
||||
} else {
|
||||
error += "\nExpected: $publicKey";
|
||||
error += "\nPubkey: $elemPubkey";
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (key == null) {
|
||||
throw Exception(error);
|
||||
}
|
||||
|
||||
return key.privkey.signInput(txDigest, sigHash: sighash);
|
||||
});
|
||||
|
||||
return PendingBitcoinTransaction(transaction, type,
|
||||
electrumClient: electrumClient,
|
||||
amount: estimatedTx.amount,
|
||||
fee: estimatedTx.fee,
|
||||
feeRate: feeRateInt.toString(),
|
||||
network: network,
|
||||
hasChange: estimatedTx.hasChange,
|
||||
isSendAll: estimatedTx.isSendAll,
|
||||
hasTaprootInputs: hasTaprootInputs,
|
||||
utxos: estimatedTx.utxos,
|
||||
publicKeys: estimatedTx.publicKeys)
|
||||
..addListener((transaction) async {
|
||||
transactionHistory.addOne(transaction);
|
||||
if (estimatedTx.spendsSilentPayment) {
|
||||
transactionHistory.transactions.values.forEach((tx) {
|
||||
tx.unspents?.removeWhere(
|
||||
(unspent) => estimatedTx.utxos.any((e) => e.utxo.txHash == unspent.hash));
|
||||
transactionHistory.addOne(tx);
|
||||
});
|
||||
}
|
||||
|
||||
unspentCoins
|
||||
.removeWhere((utxo) => estimatedTx.utxos.any((e) => e.utxo.txHash == utxo.hash));
|
||||
|
||||
await updateBalance();
|
||||
await updateAllUnspents();
|
||||
});
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
String toJSON() => json.encode({
|
||||
'mnemonic': super.seed,
|
||||
'xpub': xpub,
|
||||
'passphrase': passphrase ?? '',
|
||||
'account_index': walletAddresses.currentReceiveAddressIndexByType,
|
||||
'change_address_index': walletAddresses.currentChangeAddressIndexByType,
|
||||
'addresses': walletAddresses.allAddresses.map((addr) => addr.toJSON()).toList(),
|
||||
'address_page_type': walletInfo.addressPageType == null
|
||||
? SegwitAddresType.p2wpkh.toString()
|
||||
: walletInfo.addressPageType.toString(),
|
||||
'balance': balance[currency]?.toJSON(),
|
||||
'derivationTypeIndex': walletInfo.derivationInfo?.derivationType?.index,
|
||||
'derivationPath': walletInfo.derivationInfo?.derivationPath,
|
||||
'silent_addresses': walletAddresses.silentAddresses.map((addr) => addr.toJSON()).toList(),
|
||||
'silent_address_index': walletAddresses.currentSilentAddressIndex.toString(),
|
||||
'mweb_addresses': walletAddresses.mwebAddresses.map((addr) => addr.toJSON()).toList(),
|
||||
'alwaysScan': alwaysScan,
|
||||
});
|
||||
|
||||
@action
|
||||
Future<List<BitcoinUnspent>?> fetchUnspent(covariant LitecoinAddressRecord address) async {
|
||||
List<BitcoinUnspent> updatedUnspentCoins = [];
|
||||
|
||||
final unspents = await electrumClient.getListUnspent(address.getScriptHash(network));
|
||||
|
||||
// Failed to fetch unspents
|
||||
if (unspents == null) return null;
|
||||
|
||||
await Future.wait(unspents.map((unspent) async {
|
||||
try {
|
||||
final coin = BitcoinUnspent.fromJSON(address, unspent);
|
||||
final tx = await fetchTransactionInfo(hash: coin.hash);
|
||||
coin.isChange = address.isHidden;
|
||||
coin.confirmations = tx?.confirmations;
|
||||
|
||||
updatedUnspentCoins.add(coin);
|
||||
} catch (_) {}
|
||||
}));
|
||||
|
||||
return updatedUnspentCoins;
|
||||
}
|
||||
|
||||
Future<void> _refreshUnspentCoinsInfo() async {
|
||||
try {
|
||||
final List<dynamic> keys = [];
|
||||
final currentWalletUnspentCoins =
|
||||
unspentCoinsInfo.values.where((record) => record.walletId == id);
|
||||
|
||||
for (final element in currentWalletUnspentCoins) {
|
||||
if (RegexUtils.addressTypeFromStr(element.address, network) is MwebAddress) continue;
|
||||
|
||||
final existUnspentCoins = unspentCoins.where((coin) => element == coin);
|
||||
|
||||
if (existUnspentCoins.isEmpty) {
|
||||
keys.add(element.key);
|
||||
}
|
||||
}
|
||||
|
||||
if (keys.isNotEmpty) {
|
||||
await unspentCoinsInfo.deleteAll(keys);
|
||||
}
|
||||
} catch (e) {
|
||||
printV("refreshUnspentCoinsInfo $e");
|
||||
}
|
||||
}
|
||||
|
||||
int transactionVSize(String transactionHex) => BtcTransaction.fromRaw(transactionHex).getVSize();
|
||||
|
||||
Future<ElectrumTransactionBundle> getTransactionExpanded(
|
||||
{required String hash, int? height}) async {
|
||||
String transactionHex;
|
||||
int? time;
|
||||
int? confirmations;
|
||||
|
||||
final verboseTransaction = await electrumClient.getTransactionVerbose(hash: hash);
|
||||
|
||||
if (verboseTransaction.isEmpty) {
|
||||
transactionHex = await electrumClient.getTransactionHex(hash: hash);
|
||||
|
||||
if (height != null && height > 0 && await checkIfMempoolAPIIsEnabled()) {
|
||||
try {
|
||||
final blockHash = await ProxyWrapper()
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block-height/$height"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
|
||||
if (blockHash.statusCode == 200 &&
|
||||
blockHash.body.isNotEmpty &&
|
||||
jsonDecode(blockHash.body) != null) {
|
||||
final blockResponse = await ProxyWrapper()
|
||||
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block/${blockHash}"))
|
||||
.timeout(Duration(seconds: 15));
|
||||
|
||||
if (blockResponse.statusCode == 200 &&
|
||||
blockResponse.body.isNotEmpty &&
|
||||
jsonDecode(blockResponse.body)['timestamp'] != null) {
|
||||
time = int.parse(jsonDecode(blockResponse.body)['timestamp'].toString());
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
} else {
|
||||
transactionHex = verboseTransaction['hex'] as String;
|
||||
time = verboseTransaction['time'] as int?;
|
||||
confirmations = verboseTransaction['confirmations'] as int?;
|
||||
}
|
||||
|
||||
if (height != null) {
|
||||
if (time == null && height > 0) {
|
||||
time = (getDateByBitcoinHeight(height).millisecondsSinceEpoch / 1000).round();
|
||||
}
|
||||
|
||||
if (confirmations == null) {
|
||||
final tip = await getUpdatedChainTip();
|
||||
if (tip > 0 && height > 0) {
|
||||
// Add one because the block itself is the first confirmation
|
||||
confirmations = tip - height + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final original = BtcTransaction.fromRaw(transactionHex);
|
||||
final ins = <BtcTransaction>[];
|
||||
|
||||
for (final vin in original.inputs) {
|
||||
final verboseTransaction = await electrumClient.getTransactionVerbose(hash: vin.txId);
|
||||
|
||||
final String inputTransactionHex;
|
||||
|
||||
if (verboseTransaction.isEmpty) {
|
||||
inputTransactionHex = await electrumClient.getTransactionHex(hash: hash);
|
||||
} else {
|
||||
inputTransactionHex = verboseTransaction['hex'] as String;
|
||||
}
|
||||
|
||||
ins.add(BtcTransaction.fromRaw(inputTransactionHex));
|
||||
}
|
||||
|
||||
return ElectrumTransactionBundle(
|
||||
original,
|
||||
ins: ins,
|
||||
time: time,
|
||||
confirmations: confirmations ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
Future<ElectrumTransactionInfo?> fetchTransactionInfo(
|
||||
{required String hash, int? height, bool? retryOnFailure}) async {
|
||||
try {
|
||||
return ElectrumTransactionInfo.fromElectrumBundle(
|
||||
await getTransactionExpanded(hash: hash, height: height),
|
||||
walletInfo.type,
|
||||
network,
|
||||
addresses: addressesSet,
|
||||
height: height,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e is FormatException && retryOnFailure == true) {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
return fetchTransactionInfo(hash: hash, height: height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, ElectrumTransactionInfo>> fetchTransactions() async {
|
||||
try {
|
||||
final Map<String, ElectrumTransactionInfo> historiesWithDetails = {};
|
||||
if (type == WalletType.litecoin) {
|
||||
await Future.wait(LITECOIN_ADDRESS_TYPES
|
||||
.where((type) => type != SegwitAddresType.mweb)
|
||||
.map((type) => fetchTransactionsForAddressType(historiesWithDetails, type)));
|
||||
}
|
||||
|
||||
transactionHistory.transactions.values.forEach((tx) async {
|
||||
final isPendingSilentPaymentUtxo =
|
||||
(tx.isPending || tx.confirmations == 0) && historiesWithDetails[tx.id] == null;
|
||||
|
||||
if (isPendingSilentPaymentUtxo) {
|
||||
final info =
|
||||
await fetchTransactionInfo(hash: tx.id, height: tx.height, retryOnFailure: true);
|
||||
|
||||
if (info != null) {
|
||||
tx.confirmations = info.confirmations;
|
||||
tx.isPending = tx.confirmations == 0;
|
||||
transactionHistory.addOne(tx);
|
||||
await transactionHistory.save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return historiesWithDetails;
|
||||
} catch (e) {
|
||||
printV("fetchTransactions $e");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, ElectrumTransactionInfo>> _fetchAddressHistory(
|
||||
BitcoinAddressRecord addressRecord, int? currentHeight) async {
|
||||
String txid = "";
|
||||
|
||||
try {
|
||||
final Map<String, ElectrumTransactionInfo> historiesWithDetails = {};
|
||||
|
||||
final history = await electrumClient.getHistory(addressRecord.getScriptHash(network));
|
||||
|
||||
if (history.isNotEmpty) {
|
||||
addressRecord.setAsUsed();
|
||||
|
||||
await Future.wait(history.map((transaction) async {
|
||||
txid = transaction['tx_hash'] as String;
|
||||
final height = transaction['height'] as int;
|
||||
final storedTx = transactionHistory.transactions[txid];
|
||||
|
||||
if (storedTx != null) {
|
||||
if (height > 0) {
|
||||
storedTx.height = height;
|
||||
// the tx's block itself is the first confirmation so add 1
|
||||
if ((currentHeight ?? 0) > 0) {
|
||||
storedTx.confirmations = currentHeight! - height + 1;
|
||||
}
|
||||
storedTx.isPending = storedTx.confirmations == 0;
|
||||
}
|
||||
|
||||
historiesWithDetails[txid] = storedTx;
|
||||
} else {
|
||||
final tx = await fetchTransactionInfo(hash: txid, height: height, retryOnFailure: true);
|
||||
|
||||
if (tx != null) {
|
||||
historiesWithDetails[txid] = tx;
|
||||
|
||||
// Got a new transaction fetched, add it to the transaction history
|
||||
// instead of waiting all to finish, and next time it will be faster
|
||||
|
||||
if (this is LitecoinWallet) {
|
||||
// if we have a peg out transaction with the same value
|
||||
// that matches this received transaction, mark it as being from a peg out:
|
||||
for (final tx2 in transactionHistory.transactions.values) {
|
||||
final heightDiff = ((tx2.height ?? 0) - (tx.height ?? 0)).abs();
|
||||
// this isn't a perfect matching algorithm since we don't have the right input/output information from these transaction models (the addresses are in different formats), but this should be more than good enough for now as it's extremely unlikely a user receives the EXACT same amount from 2 different sources and one of them is a peg out and the other isn't WITHIN 5 blocks of each other
|
||||
if (tx2.additionalInfo["isPegOut"] == true &&
|
||||
tx2.amount == tx.amount &&
|
||||
heightDiff <= 5) {
|
||||
tx.additionalInfo["fromPegOut"] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
transactionHistory.addOne(tx);
|
||||
await transactionHistory.save();
|
||||
}
|
||||
}
|
||||
|
||||
return Future.value(null);
|
||||
}));
|
||||
}
|
||||
|
||||
return historiesWithDetails;
|
||||
} catch (e) {
|
||||
// _onError?.call(FlutterErrorDetails(
|
||||
// exception: "$txid - $e",
|
||||
// stack: stacktrace,
|
||||
// library: this.runtimeType.toString(),
|
||||
// ));
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> fetchTransactionsForAddressType(
|
||||
Map<String, ElectrumTransactionInfo> historiesWithDetails,
|
||||
BitcoinAddressType type,
|
||||
) async {
|
||||
final addressesByType = walletAddresses.allAddresses.where((addr) => addr.type == type);
|
||||
final hiddenAddresses = addressesByType.where((addr) => addr.isHidden == true);
|
||||
final receiveAddresses = addressesByType.where((addr) => addr.isHidden == false);
|
||||
walletAddresses.hiddenAddresses.addAll(hiddenAddresses.map((e) => e.address));
|
||||
await walletAddresses.saveAddressesInBox();
|
||||
await Future.wait(addressesByType.map((addressRecord) async {
|
||||
final history = await _fetchAddressHistory(addressRecord, await getCurrentChainTip());
|
||||
|
||||
if (history.isNotEmpty) {
|
||||
addressRecord.txCount = history.length;
|
||||
historiesWithDetails.addAll(history);
|
||||
|
||||
final matchedAddresses = addressRecord.isHidden ? hiddenAddresses : receiveAddresses;
|
||||
final isUsedAddressUnderGap = matchedAddresses.toList().indexOf(addressRecord) >=
|
||||
matchedAddresses.length -
|
||||
(addressRecord.isHidden
|
||||
? LitecoinWalletAddressesBase.defaultChangeAddressesCount
|
||||
: LitecoinWalletAddressesBase.defaultReceiveAddressesCount);
|
||||
|
||||
if (isUsedAddressUnderGap) {
|
||||
final prevLength = walletAddresses.allAddresses.length;
|
||||
|
||||
// Discover new addresses for the same address type until the gap limit is respected
|
||||
await walletAddresses.discoverAddresses(
|
||||
matchedAddresses.toList(),
|
||||
addressRecord.isHidden,
|
||||
(address) async {
|
||||
await subscribeForUpdates();
|
||||
return _fetchAddressHistory(address, await getCurrentChainTip())
|
||||
.then((history) => history.isNotEmpty ? address.address : null);
|
||||
},
|
||||
type: type,
|
||||
);
|
||||
|
||||
final newLength = walletAddresses.allAddresses.length;
|
||||
|
||||
if (newLength > prevLength) {
|
||||
await fetchTransactionsForAddressType(historiesWithDetails, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
static String _hardenedDerivationPath(String derivationPath) =>
|
||||
derivationPath.substring(0, derivationPath.lastIndexOf("'") + 1);
|
||||
|
||||
@observable
|
||||
SyncStatus mwebSyncStatus = NotConnectedSyncStatus();
|
||||
|
@ -169,8 +1062,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
required EncryptionFileUtils encryptionFileUtils,
|
||||
String? passphrase,
|
||||
String? addressPageType,
|
||||
List<BitcoinAddressRecord>? initialAddresses,
|
||||
List<BitcoinAddressRecord>? initialMwebAddresses,
|
||||
List<LitecoinAddressRecord>? initialAddresses,
|
||||
List<LitecoinAddressRecord>? initialMwebAddresses,
|
||||
ElectrumBalance? initialBalance,
|
||||
Map<String, int>? initialRegularAddressIndex,
|
||||
Map<String, int>? initialChangeAddressIndex}) async {
|
||||
|
@ -274,8 +1167,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
password: password,
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfo,
|
||||
initialAddresses: snp?.addresses,
|
||||
initialMwebAddresses: snp?.mwebAddresses,
|
||||
initialAddresses: snp?.addresses as List<LitecoinAddressRecord>?,
|
||||
initialMwebAddresses: snp?.mwebAddresses as List<LitecoinAddressRecord>?,
|
||||
initialBalance: snp?.balance,
|
||||
seedBytes: seedBytes,
|
||||
passphrase: passphrase,
|
||||
|
@ -1060,7 +1953,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
@override
|
||||
Future<PendingTransaction> createTransaction(Object credentials) async {
|
||||
try {
|
||||
var tx = await super.createTransaction(credentials) as PendingBitcoinTransaction;
|
||||
var tx = await createTransactionSuper(credentials) as PendingBitcoinTransaction;
|
||||
tx.isMweb = mwebEnabled;
|
||||
|
||||
if (!mwebEnabled) {
|
||||
|
@ -1425,4 +2318,27 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
|
||||
return BtcTransaction.fromRaw(rawHex);
|
||||
}
|
||||
|
||||
BitcoinAddressType _getScriptType(BitcoinBaseAddress type) {
|
||||
if (type is P2pkhAddress) {
|
||||
return P2pkhAddressType.p2pkh;
|
||||
} else if (type is P2shAddress) {
|
||||
return P2shAddressType.p2wpkhInP2sh;
|
||||
} else if (type is P2wshAddress) {
|
||||
return SegwitAddresType.p2wsh;
|
||||
} else if (type is P2trAddress) {
|
||||
return SegwitAddresType.p2tr;
|
||||
} else if (type is MwebAddress) {
|
||||
return SegwitAddresType.mweb;
|
||||
} else if (type is SilentPaymentsAddresType) {
|
||||
return SilentPaymentsAddresType.p2sp;
|
||||
} else {
|
||||
return SegwitAddresType.p2wpkh;
|
||||
}
|
||||
}
|
||||
|
||||
static const List<BitcoinAddressType> LITECOIN_ADDRESS_TYPES = [
|
||||
SegwitAddresType.p2wpkh,
|
||||
SegwitAddresType.mweb,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -2,16 +2,17 @@ import 'dart:async';
|
|||
import 'dart:io' show Platform;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_unspent.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||
import 'package:cw_bitcoin/litecoin_address_record.dart';
|
||||
import 'package:cw_bitcoin/utils.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
|
||||
import 'package:cw_core/unspent_coin_type.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:cw_mweb/cw_mweb.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
@ -33,7 +34,10 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
super.initialMwebAddresses,
|
||||
super.initialRegularAddressIndex,
|
||||
super.initialChangeAddressIndex,
|
||||
}) : super(walletInfo) {
|
||||
}) : _addressPageType =
|
||||
(walletInfo.addressPageType != null
|
||||
? BitcoinAddressType.fromValue(walletInfo.addressPageType!)
|
||||
: SegwitAddresType.p2wpkh), super(walletInfo) {
|
||||
for (int i = 0; i < mwebAddresses.length; i++) {
|
||||
mwebAddrs.add(mwebAddresses[i].address);
|
||||
}
|
||||
|
@ -103,7 +107,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
List<BitcoinAddressRecord> addressRecords = mwebAddrs
|
||||
.asMap()
|
||||
.entries
|
||||
.map((e) => BitcoinAddressRecord(
|
||||
.map((e) => LitecoinAddressRecord(
|
||||
e.value,
|
||||
index: e.key,
|
||||
type: SegwitAddresType.mweb,
|
||||
|
@ -210,4 +214,403 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
.where((element) => element.type == SegwitAddresType.p2wpkh && !element.isUsed);
|
||||
return addresses.first.address;
|
||||
}
|
||||
|
||||
static const defaultReceiveAddressesCount = 22;
|
||||
static const defaultChangeAddressesCount = 17;
|
||||
static const gap = 20;
|
||||
|
||||
@observable
|
||||
late BitcoinAddressType _addressPageType;
|
||||
|
||||
@computed
|
||||
BitcoinAddressType get addressPageType => _addressPageType;
|
||||
|
||||
|
||||
@override
|
||||
@computed
|
||||
String get address {
|
||||
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
||||
if (activeSilentAddress != null) {
|
||||
return activeSilentAddress!;
|
||||
}
|
||||
|
||||
return silentAddress.toString();
|
||||
}
|
||||
|
||||
final typeMatchingAddresses = super.allAddresses.where((addr) => !addr.isHidden && _isAddressPageTypeMatch(addr)).toList();
|
||||
final typeMatchingReceiveAddresses = typeMatchingAddresses.where((addr) => !addr.isUsed).toList();
|
||||
|
||||
if (!isEnabledAutoGenerateSubaddress) {
|
||||
if (previousAddressRecord != null &&
|
||||
previousAddressRecord!.type == addressPageType) {
|
||||
return previousAddressRecord!.address;
|
||||
}
|
||||
|
||||
if (typeMatchingAddresses.isNotEmpty) {
|
||||
return typeMatchingAddresses.first.address;
|
||||
}
|
||||
|
||||
return generateNewAddress().address;
|
||||
}
|
||||
|
||||
if (typeMatchingAddresses.isEmpty || typeMatchingReceiveAddresses.isEmpty) {
|
||||
return generateNewAddress().address;
|
||||
}
|
||||
|
||||
final prev = previousAddressRecord;
|
||||
if (prev != null && prev.type == addressPageType && !prev.isUsed) {
|
||||
return prev.address;
|
||||
}
|
||||
|
||||
return typeMatchingReceiveAddresses.first.address;
|
||||
}
|
||||
|
||||
@observable
|
||||
bool isEnabledAutoGenerateSubaddress = true;
|
||||
|
||||
@override
|
||||
set address(String addr) {
|
||||
if (addr == "Silent Payments" && SilentPaymentsAddresType.p2sp != addressPageType) {
|
||||
return;
|
||||
}
|
||||
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
||||
final selected = silentAddresses.firstWhere((addressRecord) => addressRecord.address == addr);
|
||||
|
||||
if (selected.silentPaymentTweak != null && silentAddress != null) {
|
||||
activeSilentAddress =
|
||||
silentAddress!.toLabeledSilentPaymentAddress(selected.index).toString();
|
||||
} else {
|
||||
activeSilentAddress = silentAddress!.toString();
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final addressRecord = super.allAddresses.firstWhere(
|
||||
(addressRecord) => addressRecord.address == addr,
|
||||
);
|
||||
|
||||
previousAddressRecord = addressRecord;
|
||||
receiveAddresses.remove(addressRecord);
|
||||
receiveAddresses.insert(0, addressRecord);
|
||||
} catch (e) {
|
||||
printV("ElectrumWalletAddressBase: set address ($addr): $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String get primaryAddress => getAddress(index: 0, hd: mainHd, addressType: addressPageType);
|
||||
|
||||
int get currentReceiveAddressIndex =>
|
||||
currentReceiveAddressIndexByType[_addressPageType.toString()] ?? 0;
|
||||
|
||||
void set currentReceiveAddressIndex(int index) =>
|
||||
currentReceiveAddressIndexByType[_addressPageType.toString()] = index;
|
||||
|
||||
int get currentChangeAddressIndex =>
|
||||
currentChangeAddressIndexByType[_addressPageType.toString()] ?? 0;
|
||||
|
||||
void set currentChangeAddressIndex(int index) =>
|
||||
currentChangeAddressIndexByType[_addressPageType.toString()] = index;
|
||||
|
||||
@observable
|
||||
BitcoinAddressRecord? previousAddressRecord;
|
||||
|
||||
@computed
|
||||
int get totalCountOfReceiveAddresses => addressesByReceiveType.fold(0, (acc, addressRecord) {
|
||||
if (!addressRecord.isHidden) {
|
||||
return acc + 1;
|
||||
}
|
||||
return acc;
|
||||
});
|
||||
|
||||
@computed
|
||||
int get totalCountOfChangeAddresses => addressesByReceiveType.fold(0, (acc, addressRecord) {
|
||||
if (addressRecord.isHidden) {
|
||||
return acc + 1;
|
||||
}
|
||||
return acc;
|
||||
});
|
||||
|
||||
Map<String, String> get labels {
|
||||
final G = ECPublic.fromBytes(BigintUtils.toBytes(Curves.generatorSecp256k1.x, length: 32));
|
||||
final labels = <String, String>{};
|
||||
for (int i = 0; i < silentAddresses.length; i++) {
|
||||
final silentAddressRecord = silentAddresses[i];
|
||||
final silentPaymentTweak = silentAddressRecord.silentPaymentTweak;
|
||||
|
||||
if (silentPaymentTweak != null &&
|
||||
SilentPaymentAddress.regex.hasMatch(silentAddressRecord.address)) {
|
||||
labels[G
|
||||
.tweakMul(BigintUtils.fromBytes(BytesUtils.fromHexString(silentPaymentTweak)))
|
||||
.toHex()] = silentPaymentTweak;
|
||||
}
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
@action
|
||||
BaseBitcoinAddressRecord generateNewAddress({String label = ''}) {
|
||||
final newAddressIndex = addressesByReceiveType.fold(
|
||||
0, (int acc, addressRecord) => addressRecord.isHidden == false ? acc + 1 : acc);
|
||||
|
||||
final address = BitcoinAddressRecord(
|
||||
getAddress(index: newAddressIndex, hd: mainHd, addressType: addressPageType),
|
||||
index: newAddressIndex,
|
||||
isHidden: false,
|
||||
name: label,
|
||||
type: addressPageType,
|
||||
network: network,
|
||||
);
|
||||
Future.delayed(Duration.zero, () {
|
||||
super.allAddresses.add(address);
|
||||
updateAddressesByMatch();
|
||||
});
|
||||
return address;
|
||||
}
|
||||
|
||||
void addLitecoinAddressTypes() {
|
||||
final lastP2wpkh = super.allAddresses
|
||||
.where((addressRecord) =>
|
||||
_isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.p2wpkh))
|
||||
.toList()
|
||||
.last;
|
||||
if (lastP2wpkh.address != address) {
|
||||
addressesMap[lastP2wpkh.address] = 'P2WPKH';
|
||||
} else {
|
||||
addressesMap[address] = 'Active - P2WPKH';
|
||||
}
|
||||
|
||||
final lastMweb = super.allAddresses.firstWhere(
|
||||
(addressRecord) => _isUnusedReceiveAddressByType(addressRecord, SegwitAddresType.mweb));
|
||||
if (lastMweb.address != address) {
|
||||
addressesMap[lastMweb.address] = 'MWEB';
|
||||
} else {
|
||||
addressesMap[address] = 'Active - MWEB';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateAddressesInBox() async {
|
||||
try {
|
||||
addressesMap.clear();
|
||||
addressesMap[address] = 'Active';
|
||||
|
||||
allAddressesMap.clear();
|
||||
super.allAddresses.forEach((addressRecord) {
|
||||
allAddressesMap[addressRecord.address] = addressRecord.name;
|
||||
});
|
||||
|
||||
switch (walletInfo.type) {
|
||||
case WalletType.bitcoin:
|
||||
addBitcoinAddressTypes();
|
||||
break;
|
||||
case WalletType.litecoin:
|
||||
addLitecoinAddressTypes();
|
||||
break;
|
||||
case WalletType.bitcoinCash:
|
||||
addBitcoinCashAddressTypes();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
await saveAddressesInBox();
|
||||
} catch (e) {
|
||||
printV("updateAddresses $e");
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void updateAddress(String address, String label) {
|
||||
BaseBitcoinAddressRecord? foundAddress;
|
||||
super.allAddresses.forEach((addressRecord) {
|
||||
if (addressRecord.address == address) {
|
||||
foundAddress = addressRecord;
|
||||
}
|
||||
});
|
||||
silentAddresses.forEach((addressRecord) {
|
||||
if (addressRecord.address == address) {
|
||||
foundAddress = addressRecord;
|
||||
}
|
||||
});
|
||||
mwebAddresses.forEach((addressRecord) {
|
||||
if (addressRecord.address == address) {
|
||||
foundAddress = addressRecord;
|
||||
}
|
||||
});
|
||||
|
||||
if (foundAddress != null) {
|
||||
foundAddress!.setNewName(label);
|
||||
|
||||
if (foundAddress is BitcoinAddressRecord) {
|
||||
final index = super.allAddresses.indexOf(foundAddress as BitcoinAddressRecord);
|
||||
super.allAddresses.remove(foundAddress);
|
||||
super.allAddresses.insert(index, foundAddress as BitcoinAddressRecord);
|
||||
} else {
|
||||
final index = silentAddresses.indexOf(foundAddress as BitcoinSilentPaymentAddressRecord);
|
||||
silentAddresses.remove(foundAddress);
|
||||
silentAddresses.insert(index, foundAddress as BitcoinSilentPaymentAddressRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void updateAddressesByMatch() {
|
||||
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
||||
addressesByReceiveType.clear();
|
||||
addressesByReceiveType.addAll(silentAddresses);
|
||||
return;
|
||||
}
|
||||
|
||||
addressesByReceiveType.clear();
|
||||
addressesByReceiveType.addAll(super.allAddresses.where(_isAddressPageTypeMatch).toList());
|
||||
}
|
||||
|
||||
@action
|
||||
void updateReceiveAddresses() {
|
||||
receiveAddresses.removeRange(0, receiveAddresses.length);
|
||||
final newAddresses =
|
||||
super.allAddresses.where((addressRecord) => !addressRecord.isHidden && !addressRecord.isUsed);
|
||||
receiveAddresses.addAll(newAddresses);
|
||||
}
|
||||
|
||||
@action
|
||||
void updateChangeAddresses() {
|
||||
changeAddresses.removeRange(0, changeAddresses.length);
|
||||
final newAddresses = super.allAddresses.where((addressRecord) =>
|
||||
addressRecord.isHidden &&
|
||||
!addressRecord.isUsed &&
|
||||
// TODO: feature to change change address type. For now fixed to p2wpkh, the cheapest type
|
||||
(walletInfo.type != WalletType.bitcoin || addressRecord.type == SegwitAddresType.p2wpkh));
|
||||
changeAddresses.addAll(newAddresses);
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> discoverAddresses(List<BitcoinAddressRecord> addressList, bool isHidden,
|
||||
Future<String?> Function(BitcoinAddressRecord) getAddressHistory,
|
||||
{BitcoinAddressType type = SegwitAddresType.p2wpkh}) async {
|
||||
final newAddresses = await _createNewAddresses(gap,
|
||||
startIndex: addressList.length, isHidden: isHidden, type: type);
|
||||
addAddresses(newAddresses);
|
||||
|
||||
final addressesWithHistory = await Future.wait(newAddresses.map(getAddressHistory));
|
||||
final isLastAddressUsed = addressesWithHistory.last == addressList.last.address;
|
||||
|
||||
if (isLastAddressUsed) {
|
||||
discoverAddresses(addressList, isHidden, getAddressHistory, type: type);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _generateInitialAddresses(
|
||||
{BitcoinAddressType type = SegwitAddresType.p2wpkh}) async {
|
||||
var countOfReceiveAddresses = 0;
|
||||
var countOfHiddenAddresses = 0;
|
||||
|
||||
super.allAddresses.forEach((addr) {
|
||||
if (addr.type == type) {
|
||||
if (addr.isHidden) {
|
||||
countOfHiddenAddresses += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
countOfReceiveAddresses += 1;
|
||||
}
|
||||
});
|
||||
|
||||
if (countOfReceiveAddresses < defaultReceiveAddressesCount) {
|
||||
final addressesCount = defaultReceiveAddressesCount - countOfReceiveAddresses;
|
||||
final newAddresses = await _createNewAddresses(addressesCount,
|
||||
startIndex: countOfReceiveAddresses, isHidden: false, type: type);
|
||||
addAddresses(newAddresses);
|
||||
}
|
||||
|
||||
if (countOfHiddenAddresses < defaultChangeAddressesCount) {
|
||||
final addressesCount = defaultChangeAddressesCount - countOfHiddenAddresses;
|
||||
final newAddresses = await _createNewAddresses(addressesCount,
|
||||
startIndex: countOfHiddenAddresses, isHidden: true, type: type);
|
||||
addAddresses(newAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<BitcoinAddressRecord>> _createNewAddresses(int count,
|
||||
{int startIndex = 0, bool isHidden = false, BitcoinAddressType? type}) async {
|
||||
final list = <BitcoinAddressRecord>[];
|
||||
|
||||
for (var i = startIndex; i < count + startIndex; i++) {
|
||||
final address = BitcoinAddressRecord(
|
||||
await getAddressAsync(index: i, hd: _getHd(isHidden), addressType: type ?? addressPageType),
|
||||
index: i,
|
||||
isHidden: isHidden,
|
||||
type: type ?? addressPageType,
|
||||
network: network,
|
||||
);
|
||||
list.add(address);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@action
|
||||
void addAddresses(Iterable<BitcoinAddressRecord> addresses) {
|
||||
final addressesSet = super.allAddresses.toSet();
|
||||
addressesSet.addAll(addresses);
|
||||
super.allAddresses.clear();
|
||||
super.allAddresses.addAll(addressesSet);
|
||||
updateAddressesByMatch();
|
||||
}
|
||||
|
||||
@action
|
||||
void addSilentAddresses(Iterable<BitcoinSilentPaymentAddressRecord> addresses) {
|
||||
final addressesSet = this.silentAddresses.toSet();
|
||||
addressesSet.addAll(addresses);
|
||||
this.silentAddresses.clear();
|
||||
this.silentAddresses.addAll(addressesSet);
|
||||
updateAddressesByMatch();
|
||||
}
|
||||
|
||||
@action
|
||||
void addMwebAddresses(Iterable<BitcoinAddressRecord> addresses) {
|
||||
final addressesSet = this.mwebAddresses.toSet();
|
||||
addressesSet.addAll(addresses);
|
||||
this.mwebAddresses.clear();
|
||||
this.mwebAddresses.addAll(addressesSet);
|
||||
updateAddressesByMatch();
|
||||
}
|
||||
|
||||
void _validateAddresses() {
|
||||
super.allAddresses.forEach((element) async {
|
||||
if (element.type == SegwitAddresType.mweb) {
|
||||
// this would add a ton of startup lag for mweb addresses since we have 1000 of them
|
||||
return;
|
||||
}
|
||||
if (!element.isHidden &&
|
||||
element.address !=
|
||||
await getAddressAsync(index: element.index, hd: mainHd, addressType: element.type)) {
|
||||
element.isHidden = true;
|
||||
} else if (element.isHidden &&
|
||||
element.address !=
|
||||
await getAddressAsync(index: element.index, hd: sideHd, addressType: element.type)) {
|
||||
element.isHidden = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> setAddressType(BitcoinAddressType type) async {
|
||||
_addressPageType = type;
|
||||
updateAddressesByMatch();
|
||||
walletInfo.addressPageType = addressPageType.toString();
|
||||
await walletInfo.save();
|
||||
}
|
||||
|
||||
bool _isAddressPageTypeMatch(BitcoinAddressRecord addressRecord) {
|
||||
return _isAddressByType(addressRecord, addressPageType);
|
||||
}
|
||||
|
||||
Bip32Slip10Secp256k1 _getHd(bool isHidden) => isHidden ? sideHd : mainHd;
|
||||
|
||||
bool _isAddressByType(BitcoinAddressRecord addr, BitcoinAddressType type) => addr.type == type;
|
||||
|
||||
bool _isUnusedReceiveAddressByType(BitcoinAddressRecord addr, BitcoinAddressType type) =>
|
||||
!addr.isHidden && !addr.isUsed && addr.type == type;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'dart:isolate';
|
|||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet_addresses.dart';
|
||||
import 'package:cw_bitcoin/payjoin/payjoin_persister.dart';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:ledger_bitcoin/psbt.dart';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:bitcoin_base_old/bitcoin_base.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cw_bitcoin/psbt/v0_deserialize.dart';
|
||||
|
|
|
@ -34,10 +34,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: asn1lib
|
||||
sha256: "1c296cd268f486cabcc3930e9b93a8133169305f18d722916e675959a88f6d2c"
|
||||
sha256: "9a8f69025044eb466b9b60ef3bc3ac99b4dc6c158ae9c56d25eeccf5bc56d024"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.5.9"
|
||||
version: "1.6.5"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -84,8 +84,17 @@ packages:
|
|||
dependency: "direct overridden"
|
||||
description:
|
||||
path: "."
|
||||
ref: cake-update-v9
|
||||
resolved-ref: bb4318511312a454fd91bf49042e25ecc855e4ac
|
||||
ref: "2ab3437bd5a671e3f5833e5613eb98751e108bb7"
|
||||
resolved-ref: "2ab3437bd5a671e3f5833e5613eb98751e108bb7"
|
||||
url: "https://github.com/cake-tech/bitcoin_base"
|
||||
source: git
|
||||
version: "6.1.0"
|
||||
bitcoin_base_old:
|
||||
dependency: "direct overridden"
|
||||
description:
|
||||
path: "."
|
||||
ref: "4917d51caa02c6d1cb095769859b1ec563bf26ee"
|
||||
resolved-ref: "4917d51caa02c6d1cb095769859b1ec563bf26ee"
|
||||
url: "https://github.com/cake-tech/bitcoin_base"
|
||||
source: git
|
||||
version: "4.7.0"
|
||||
|
@ -98,6 +107,15 @@ packages:
|
|||
url: "https://github.com/cake-tech/blockchain_utils"
|
||||
source: git
|
||||
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:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -468,10 +486,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: grpc
|
||||
sha256: "30e1edae6846b163a64f6d8716e3443980fe1f7d2d1f086f011d24ea186f2582"
|
||||
sha256: "2dde469ddd8bbd7a33a0765da417abe1ad2142813efce3a86c512041294e2b26"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.4"
|
||||
version: "4.1.0"
|
||||
hex:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -589,7 +607,7 @@ packages:
|
|||
description:
|
||||
path: "packages/ledger-bitcoin"
|
||||
ref: trunk
|
||||
resolved-ref: e93254f3ff3f996fb91f65a1e7ceffb9f510b4c8
|
||||
resolved-ref: eab179d487cddda3f647f6608115a89662facde4
|
||||
url: "https://github.com/cake-tech/ledger-flutter-plus-plugins"
|
||||
source: git
|
||||
version: "0.0.3"
|
||||
|
@ -606,7 +624,7 @@ packages:
|
|||
description:
|
||||
path: "packages/ledger-litecoin"
|
||||
ref: HEAD
|
||||
resolved-ref: e93254f3ff3f996fb91f65a1e7ceffb9f510b4c8
|
||||
resolved-ref: eab179d487cddda3f647f6608115a89662facde4
|
||||
url: "https://github.com/cake-tech/ledger-flutter-plus-plugins"
|
||||
source: git
|
||||
version: "0.0.2"
|
||||
|
@ -695,7 +713,7 @@ packages:
|
|||
description:
|
||||
path: "."
|
||||
ref: cake-update-v2
|
||||
resolved-ref: "93440dc5126369b873ca1fccc13c3c1240b1c5c2"
|
||||
resolved-ref: "096865a8c6b89c260beadfec04f7e184c40a3273"
|
||||
url: "https://github.com/cake-tech/on_chain.git"
|
||||
source: git
|
||||
version: "3.7.0"
|
||||
|
@ -1048,10 +1066,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: timing
|
||||
sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32"
|
||||
sha256: "62ee18aca144e4a9f29d212f5a4c6a053be252b895ab14b5821996cff4ed90fe"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "1.0.2"
|
||||
tor_binary:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1097,10 +1115,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: unorm_dart
|
||||
sha256: "23d8bf65605401a6a32cff99435fed66ef3dab3ddcad3454059165df46496a3b"
|
||||
sha256: "8e3870a1caa60bde8352f9597dd3535d8068613269444f8e35ea8925ec84c1f5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
version: "0.3.1+1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1121,10 +1139,10 @@ packages:
|
|||
dependency: "direct overridden"
|
||||
description:
|
||||
name: watcher
|
||||
sha256: "69da27e49efa56a15f8afe8f4438c4ec02eff0a117df1b22ea4aad194fe1c104"
|
||||
sha256: "0b7fd4a0bbc4b92641dbf20adfd7e3fd1398fe17102d94b674234563e110088a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
version: "1.1.2"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -70,10 +70,14 @@ dev_dependencies:
|
|||
dependency_overrides:
|
||||
watcher: ^1.1.0
|
||||
protobuf: ^3.1.0
|
||||
bitcoin_base_old:
|
||||
git:
|
||||
url: https://github.com/cake-tech/bitcoin_base
|
||||
ref: 4917d51caa02c6d1cb095769859b1ec563bf26ee
|
||||
bitcoin_base:
|
||||
git:
|
||||
url: https://github.com/cake-tech/bitcoin_base
|
||||
ref: cake-update-v9
|
||||
ref: 2ab3437bd5a671e3f5833e5613eb98751e108bb7
|
||||
pointycastle: 3.7.4
|
||||
ffi: 2.1.0
|
||||
|
||||
|
|
|
@ -2,10 +2,6 @@ PODS:
|
|||
- connectivity_plus (0.0.1):
|
||||
- Flutter
|
||||
- CryptoSwift (1.8.4)
|
||||
- cw_decred (0.0.1):
|
||||
- Flutter
|
||||
- cw_mweb (0.0.1):
|
||||
- Flutter
|
||||
- device_display_brightness (0.0.1):
|
||||
- Flutter
|
||||
- device_info_plus (0.0.1):
|
||||
|
@ -76,7 +72,6 @@ PODS:
|
|||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- payjoin_flutter (0.20.0)
|
||||
- permission_handler_apple (9.3.0):
|
||||
- Flutter
|
||||
- reown_yttrium (0.0.1):
|
||||
|
@ -92,8 +87,6 @@ PODS:
|
|||
- shared_preferences_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- sp_scanner (0.0.1):
|
||||
- Flutter
|
||||
- SwiftyGif (5.4.5)
|
||||
- uni_links (0.0.1):
|
||||
- Flutter
|
||||
|
@ -109,8 +102,6 @@ PODS:
|
|||
DEPENDENCIES:
|
||||
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
|
||||
- CryptoSwift
|
||||
- cw_decred (from `.symlinks/plugins/cw_decred/ios`)
|
||||
- cw_mweb (from `.symlinks/plugins/cw_mweb/ios`)
|
||||
- device_display_brightness (from `.symlinks/plugins/device_display_brightness/ios`)
|
||||
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
|
||||
- devicelocale (from `.symlinks/plugins/devicelocale/ios`)
|
||||
|
@ -127,13 +118,11 @@ DEPENDENCIES:
|
|||
- integration_test (from `.symlinks/plugins/integration_test/ios`)
|
||||
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
|
||||
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
|
||||
- payjoin_flutter (from `.symlinks/plugins/payjoin_flutter/ios`)
|
||||
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
||||
- reown_yttrium (from `.symlinks/plugins/reown_yttrium/ios`)
|
||||
- sensitive_clipboard (from `.symlinks/plugins/sensitive_clipboard/ios`)
|
||||
- share_plus (from `.symlinks/plugins/share_plus/ios`)
|
||||
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
|
||||
- sp_scanner (from `.symlinks/plugins/sp_scanner/ios`)
|
||||
- uni_links (from `.symlinks/plugins/uni_links/ios`)
|
||||
- universal_ble (from `.symlinks/plugins/universal_ble/darwin`)
|
||||
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
|
||||
|
@ -152,10 +141,6 @@ SPEC REPOS:
|
|||
EXTERNAL SOURCES:
|
||||
connectivity_plus:
|
||||
:path: ".symlinks/plugins/connectivity_plus/ios"
|
||||
cw_decred:
|
||||
:path: ".symlinks/plugins/cw_decred/ios"
|
||||
cw_mweb:
|
||||
:path: ".symlinks/plugins/cw_mweb/ios"
|
||||
device_display_brightness:
|
||||
:path: ".symlinks/plugins/device_display_brightness/ios"
|
||||
device_info_plus:
|
||||
|
@ -188,8 +173,6 @@ EXTERNAL SOURCES:
|
|||
:path: ".symlinks/plugins/package_info_plus/ios"
|
||||
path_provider_foundation:
|
||||
:path: ".symlinks/plugins/path_provider_foundation/darwin"
|
||||
payjoin_flutter:
|
||||
:path: ".symlinks/plugins/payjoin_flutter/ios"
|
||||
permission_handler_apple:
|
||||
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
||||
reown_yttrium:
|
||||
|
@ -200,8 +183,6 @@ EXTERNAL SOURCES:
|
|||
:path: ".symlinks/plugins/share_plus/ios"
|
||||
shared_preferences_foundation:
|
||||
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
|
||||
sp_scanner:
|
||||
:path: ".symlinks/plugins/sp_scanner/ios"
|
||||
uni_links:
|
||||
:path: ".symlinks/plugins/uni_links/ios"
|
||||
universal_ble:
|
||||
|
@ -214,8 +195,6 @@ EXTERNAL SOURCES:
|
|||
SPEC CHECKSUMS:
|
||||
connectivity_plus: 2a701ffec2c0ae28a48cf7540e279787e77c447d
|
||||
CryptoSwift: e64e11850ede528a02a0f3e768cec8e9d92ecb90
|
||||
cw_decred: 9c0e1df74745b51a1289ec5e91fb9e24b68fa14a
|
||||
cw_mweb: 22cd01dfb8ad2d39b15332006f22046aaa8352a3
|
||||
device_display_brightness: 1510e72c567a1f6ce6ffe393dcd9afd1426034f7
|
||||
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
|
||||
devicelocale: 35ba84dc7f45f527c3001535d8c8d104edd5d926
|
||||
|
@ -235,14 +214,12 @@ SPEC CHECKSUMS:
|
|||
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
|
||||
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
|
||||
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
|
||||
payjoin_flutter: 6397d7b698cdad6453be4949ab6aca1863f6c5e5
|
||||
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
|
||||
reown_yttrium: c0e87e5965fa60a3559564cc35cffbba22976089
|
||||
SDWebImage: 73c6079366fea25fa4bb9640d5fb58f0893facd8
|
||||
sensitive_clipboard: d4866e5d176581536c27bb1618642ee83adca986
|
||||
share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
|
||||
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
|
||||
sp_scanner: eaa617fa827396b967116b7f1f43549ca62e9a12
|
||||
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
|
||||
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
|
||||
universal_ble: cf52a7b3fd2e7c14d6d7262e9fdadb72ab6b88a6
|
||||
|
|
|
@ -511,7 +511,7 @@
|
|||
"$(PROJECT_DIR)/Flutter",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.1;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.monero;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
@ -660,7 +660,7 @@
|
|||
);
|
||||
MARKETING_VERSION = 1.0.1;
|
||||
ONLY_ACTIVE_ARCH = NO;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.monero;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
|
@ -700,7 +700,7 @@
|
|||
"$(PROJECT_DIR)/Flutter",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.1;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.monero;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
|
|
@ -10,11 +10,11 @@ import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
|||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class CakeFeaturesPage extends StatelessWidget {
|
||||
CakeFeaturesPage(
|
||||
{required this.dashboardViewModel, required this.cakeFeaturesViewModel});
|
||||
CakeFeaturesPage({required this.dashboardViewModel, required this.cakeFeaturesViewModel});
|
||||
|
||||
final DashboardViewModel dashboardViewModel;
|
||||
final CakeFeaturesViewModel cakeFeaturesViewModel;
|
||||
|
@ -59,23 +59,26 @@ class CakeFeaturesPage extends StatelessWidget {
|
|||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
if (dashboardViewModel.type == WalletType.ethereum) ...[
|
||||
DashBoardRoundedCardWidget(
|
||||
isDarkTheme: dashboardViewModel.isDarkTheme,
|
||||
shadowBlur: dashboardViewModel.getShadowBlur(),
|
||||
shadowSpread: dashboardViewModel.getShadowSpread(),
|
||||
onTap: () =>
|
||||
Navigator.of(context).pushNamed(Routes.dEuroSavings),
|
||||
title: S.of(context).deuro_savings,
|
||||
subTitle: S.of(context).deuro_savings_subtitle,
|
||||
image: Image.asset(
|
||||
'assets/images/deuro_icon.png',
|
||||
height: 80,
|
||||
width: 80,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
],
|
||||
Observer(builder: (_) {
|
||||
if (dashboardViewModel.type == WalletType.ethereum) {
|
||||
return DashBoardRoundedCardWidget(
|
||||
isDarkTheme: dashboardViewModel.isDarkTheme,
|
||||
shadowBlur: dashboardViewModel.getShadowBlur(),
|
||||
shadowSpread: dashboardViewModel.getShadowSpread(),
|
||||
onTap: () => Navigator.of(context).pushNamed(Routes.dEuroSavings),
|
||||
title: S.of(context).deuro_savings,
|
||||
subTitle: S.of(context).deuro_savings_subtitle,
|
||||
image: Image.asset(
|
||||
'assets/images/deuro_icon.png',
|
||||
height: 80,
|
||||
width: 80,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox();
|
||||
}),
|
||||
DashBoardRoundedCardWidget(
|
||||
isDarkTheme: dashboardViewModel.isDarkTheme,
|
||||
shadowBlur: dashboardViewModel.getShadowBlur(),
|
||||
|
|
|
@ -14,15 +14,15 @@ TYPES=($MONERO_COM $CAKEWALLET)
|
|||
APP_ANDROID_TYPE=$1
|
||||
|
||||
MONERO_COM_NAME="Monero.com"
|
||||
MONERO_COM_VERSION="5.0.0"
|
||||
MONERO_COM_BUILD_NUMBER=125
|
||||
MONERO_COM_VERSION="5.1.0"
|
||||
MONERO_COM_BUILD_NUMBER=126
|
||||
MONERO_COM_BUNDLE_ID="com.monero.app"
|
||||
MONERO_COM_PACKAGE="com.monero.app"
|
||||
MONERO_COM_SCHEME="monero.com"
|
||||
|
||||
CAKEWALLET_NAME="Cake Wallet"
|
||||
CAKEWALLET_VERSION="5.0.1"
|
||||
CAKEWALLET_BUILD_NUMBER=264
|
||||
CAKEWALLET_VERSION="5.1.0"
|
||||
CAKEWALLET_BUILD_NUMBER=266
|
||||
CAKEWALLET_BUNDLE_ID="com.cakewallet.cake_wallet"
|
||||
CAKEWALLET_PACKAGE="com.cakewallet.cake_wallet"
|
||||
CAKEWALLET_SCHEME="cakewallet"
|
||||
|
|
|
@ -12,13 +12,13 @@ TYPES=($MONERO_COM $CAKEWALLET)
|
|||
APP_IOS_TYPE=$1
|
||||
|
||||
MONERO_COM_NAME="Monero.com"
|
||||
MONERO_COM_VERSION="5.0.0"
|
||||
MONERO_COM_BUILD_NUMBER=125
|
||||
MONERO_COM_VERSION="5.1.0"
|
||||
MONERO_COM_BUILD_NUMBER=126
|
||||
MONERO_COM_BUNDLE_ID="com.cakewallet.monero"
|
||||
|
||||
CAKEWALLET_NAME="Cake Wallet"
|
||||
CAKEWALLET_VERSION="5.0.1"
|
||||
CAKEWALLET_BUILD_NUMBER=322
|
||||
CAKEWALLET_VERSION="5.1.0"
|
||||
CAKEWALLET_BUILD_NUMBER=323
|
||||
CAKEWALLET_BUNDLE_ID="com.fotolockr.cakewallet"
|
||||
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ if [ -n "$1" ]; then
|
|||
fi
|
||||
|
||||
CAKEWALLET_NAME="Cake Wallet"
|
||||
CAKEWALLET_VERSION="5.0.0"
|
||||
CAKEWALLET_BUILD_NUMBER=56
|
||||
CAKEWALLET_VERSION="5.1.0"
|
||||
CAKEWALLET_BUILD_NUMBER=57
|
||||
|
||||
if ! [[ " ${TYPES[*]} " =~ " ${APP_LINUX_TYPE} " ]]; then
|
||||
echo "Wrong app type."
|
||||
|
|
|
@ -16,13 +16,13 @@ if [ -n "$1" ]; then
|
|||
fi
|
||||
|
||||
MONERO_COM_NAME="Monero.com"
|
||||
MONERO_COM_VERSION="5.0.0"
|
||||
MONERO_COM_BUILD_NUMBER=54
|
||||
MONERO_COM_VERSION="5.1.0"
|
||||
MONERO_COM_BUILD_NUMBER=55
|
||||
MONERO_COM_BUNDLE_ID="com.cakewallet.monero"
|
||||
|
||||
CAKEWALLET_NAME="Cake Wallet"
|
||||
CAKEWALLET_VERSION="5.0.0"
|
||||
CAKEWALLET_BUILD_NUMBER=116
|
||||
CAKEWALLET_VERSION="5.1.0"
|
||||
CAKEWALLET_BUILD_NUMBER=118
|
||||
CAKEWALLET_BUNDLE_ID="com.fotolockr.cakewallet"
|
||||
|
||||
if ! [[ " ${TYPES[*]} " =~ " ${APP_MACOS_TYPE} " ]]; then
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#define MyAppName "Cake Wallet"
|
||||
#define MyAppVersion "5.0.0"
|
||||
#define MyAppVersion "5.1.0"
|
||||
#define MyAppPublisher "Cake Labs LLC"
|
||||
#define MyAppURL "https://cakewallet.com/"
|
||||
#define MyAppExeName "CakeWallet.exe"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue