diff --git a/cw_bitcoin/lib/bitcoin_address_record.dart b/cw_bitcoin/lib/bitcoin_address_record.dart index afd7c34e1..f5731f0f1 100644 --- a/cw_bitcoin/lib/bitcoin_address_record.dart +++ b/cw_bitcoin/lib/bitcoin_address_record.dart @@ -124,10 +124,9 @@ class BitcoinSilentPaymentAddressRecord extends BaseBitcoinAddressRecord { super.balance = 0, super.name = '', super.isUsed = false, - required super.type, required this.silentPaymentTweak, required super.network, - }); + }) : super(type: SilentPaymentsAddresType.p2sp); factory BitcoinSilentPaymentAddressRecord.fromJSON(String jsonSource, {BasedUtxoNetwork? network}) { @@ -141,18 +140,14 @@ class BitcoinSilentPaymentAddressRecord extends BaseBitcoinAddressRecord { 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, network: (decoded['network'] as String?) == null ? network : BasedUtxoNetwork.fromName(decoded['network'] as String), - silentPaymentTweak: decoded['silentPaymentTweak'] as String, + silentPaymentTweak: decoded['silent_payment_tweak'] as String?, ); } - final String silentPaymentTweak; + final String? silentPaymentTweak; @override String toJSON() => json.encode({ @@ -165,6 +160,6 @@ class BitcoinSilentPaymentAddressRecord extends BaseBitcoinAddressRecord { 'balance': balance, 'type': type.toString(), 'network': network?.value, - 'silentPaymentTweak': silentPaymentTweak, + 'silent_payment_tweak': silentPaymentTweak, }); } diff --git a/cw_bitcoin/lib/bitcoin_unspent.dart b/cw_bitcoin/lib/bitcoin_unspent.dart index ce3c0da16..b2c1d90c4 100644 --- a/cw_bitcoin/lib/bitcoin_unspent.dart +++ b/cw_bitcoin/lib/bitcoin_unspent.dart @@ -1,10 +1,9 @@ -import 'package:bitcoin_base/bitcoin_base.dart'; import 'package:cw_bitcoin/bitcoin_address_record.dart'; import 'package:cw_core/unspent_transaction_output.dart'; class BitcoinUnspent extends Unspent { BitcoinUnspent(BaseBitcoinAddressRecord addressRecord, String hash, int value, int vout, - {this.silentPaymentTweak, this.type}) + {this.silentPaymentTweak}) : bitcoinAddressRecord = addressRecord, super(addressRecord.address, hash, value, vout, null); @@ -15,9 +14,6 @@ class BitcoinUnspent extends Unspent { json['value'] as int, json['tx_pos'] as int, silentPaymentTweak: json['silent_payment_tweak'] as String?, - type: json['type'] == null - ? null - : BitcoinAddressType.values.firstWhere((e) => e.toString() == json['type']), ); Map toJson() { @@ -27,12 +23,10 @@ class BitcoinUnspent extends Unspent { 'value': value, 'tx_pos': vout, 'silent_payment_tweak': silentPaymentTweak, - 'type': type.toString(), }; return json; } final BaseBitcoinAddressRecord bitcoinAddressRecord; String? silentPaymentTweak; - BitcoinAddressType? type; } diff --git a/cw_bitcoin/lib/bitcoin_wallet.dart b/cw_bitcoin/lib/bitcoin_wallet.dart index f24142493..fd45584ca 100644 --- a/cw_bitcoin/lib/bitcoin_wallet.dart +++ b/cw_bitcoin/lib/bitcoin_wallet.dart @@ -32,7 +32,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { Map? initialChangeAddressIndex, List? initialSilentAddresses, int initialSilentAddressIndex = 0, - SilentPaymentOwner? silentAddress, }) : super( mnemonic: mnemonic, password: password, @@ -54,10 +53,13 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialChangeAddressIndex: initialChangeAddressIndex, initialSilentAddresses: initialSilentAddresses, initialSilentAddressIndex: initialSilentAddressIndex, - silentAddress: silentAddress, mainHd: hd, sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath("m/0'/1"), network: networkParam ?? network, + masterHd: bitcoin.HDWallet.fromSeed( + seedBytes, + network: network == BitcoinNetwork.testnet ? bitcoin.testnet : bitcoin.bitcoin, + ), ); hasSilentPaymentsScanning = addressPageType == SilentPaymentsAddresType.p2sp.toString(); @@ -97,16 +99,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialAddresses: initialAddresses, initialSilentAddresses: initialSilentAddresses, initialSilentAddressIndex: initialSilentAddressIndex, - silentAddress: await SilentPaymentOwner.fromPrivateKeys( - b_scan: ECPrivate.fromHex(bitcoin.HDWallet.fromSeed( - seedBytes, - network: network == BitcoinNetwork.testnet ? bitcoin.testnet : bitcoin.bitcoin, - ).derivePath(SCAN_PATH).privKey!), - b_spend: ECPrivate.fromHex(bitcoin.HDWallet.fromSeed( - seedBytes, - network: network == BitcoinNetwork.testnet ? bitcoin.testnet : bitcoin.bitcoin, - ).derivePath(SPEND_PATH).privKey!), - hrp: network == BitcoinNetwork.testnet ? 'tsp' : 'sp'), initialBalance: initialBalance, seedBytes: seedBytes, initialRegularAddressIndex: initialRegularAddressIndex, @@ -134,16 +126,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialAddresses: snp.addresses, initialSilentAddresses: snp.silentAddresses, initialSilentAddressIndex: snp.silentAddressIndex, - silentAddress: await SilentPaymentOwner.fromPrivateKeys( - b_scan: ECPrivate.fromHex(bitcoin.HDWallet.fromSeed( - seedBytes, - network: snp.network == BitcoinNetwork.testnet ? bitcoin.testnet : bitcoin.bitcoin, - ).derivePath(SCAN_PATH).privKey!), - b_spend: ECPrivate.fromHex(bitcoin.HDWallet.fromSeed( - seedBytes, - network: snp.network == BitcoinNetwork.testnet ? bitcoin.testnet : bitcoin.bitcoin, - ).derivePath(SPEND_PATH).privKey!), - hrp: snp.network == BitcoinNetwork.testnet ? 'tsp' : 'sp'), initialBalance: snp.balance, seedBytes: seedBytes, initialRegularAddressIndex: snp.regularAddressIndex, diff --git a/cw_bitcoin/lib/bitcoin_wallet_addresses.dart b/cw_bitcoin/lib/bitcoin_wallet_addresses.dart index 48960ce3d..486e69b11 100644 --- a/cw_bitcoin/lib/bitcoin_wallet_addresses.dart +++ b/cw_bitcoin/lib/bitcoin_wallet_addresses.dart @@ -20,7 +20,7 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S super.initialChangeAddressIndex, super.initialSilentAddresses, super.initialSilentAddressIndex = 0, - super.silentAddress, + super.masterHd, }) : super(walletInfo); @override diff --git a/cw_bitcoin/lib/electrum.dart b/cw_bitcoin/lib/electrum.dart index 236dddaa2..d9e068d65 100644 --- a/cw_bitcoin/lib/electrum.dart +++ b/cw_bitcoin/lib/electrum.dart @@ -36,8 +36,8 @@ class ElectrumClient { _tasks = {}, unterminatedString = ''; - static const connectionTimeout = Duration(seconds: 5); - static const aliveTimerDuration = Duration(seconds: 4); + static const connectionTimeout = Duration(seconds: 300); + static const aliveTimerDuration = Duration(seconds: 300); bool get isConnected => _isConnected; Socket? socket; diff --git a/cw_bitcoin/lib/electrum_transaction_history.dart b/cw_bitcoin/lib/electrum_transaction_history.dart index d478c3b12..a7de414e4 100644 --- a/cw_bitcoin/lib/electrum_transaction_history.dart +++ b/cw_bitcoin/lib/electrum_transaction_history.dart @@ -11,13 +11,11 @@ part 'electrum_transaction_history.g.dart'; const transactionsHistoryFileName = 'transactions.json'; -class ElectrumTransactionHistory = ElectrumTransactionHistoryBase - with _$ElectrumTransactionHistory; +class ElectrumTransactionHistory = ElectrumTransactionHistoryBase with _$ElectrumTransactionHistory; abstract class ElectrumTransactionHistoryBase extends TransactionHistoryBase with Store { - ElectrumTransactionHistoryBase( - {required this.walletInfo, required String password}) + ElectrumTransactionHistoryBase({required this.walletInfo, required String password}) : _password = password, _height = 0 { transactions = ObservableMap(); @@ -30,8 +28,7 @@ abstract class ElectrumTransactionHistoryBase Future init() async => await _load(); @override - void addOne(ElectrumTransactionInfo transaction) => - transactions[transaction.id] = transaction; + void addOne(ElectrumTransactionInfo transaction) => transactions[transaction.id] = transaction; @override void addMany(Map transactions) => @@ -40,11 +37,13 @@ abstract class ElectrumTransactionHistoryBase @override Future save() async { try { - final dirPath = - await pathForWalletDir(name: walletInfo.name, type: walletInfo.type); + final dirPath = await pathForWalletDir(name: walletInfo.name, type: walletInfo.type); final path = '$dirPath/$transactionsHistoryFileName'; - final data = - json.encode({'height': _height, 'transactions': transactions}); + final txjson = {}; + for (final tx in transactions.entries) { + txjson[tx.key] = tx.value.toJson(); + } + final data = json.encode({'height': _height, 'transactions': txjson}); await writeData(path: path, password: _password, data: data); } catch (e) { print('Error while save bitcoin transaction history: ${e.toString()}'); @@ -57,8 +56,7 @@ abstract class ElectrumTransactionHistoryBase } Future> _read() async { - final dirPath = - await pathForWalletDir(name: walletInfo.name, type: walletInfo.type); + final dirPath = await pathForWalletDir(name: walletInfo.name, type: walletInfo.type); final path = '$dirPath/$transactionsHistoryFileName'; final content = await read(path: path, password: _password); return json.decode(content) as Map; @@ -84,7 +82,5 @@ abstract class ElectrumTransactionHistoryBase } } - void _update(ElectrumTransactionInfo transaction) => - transactions[transaction.id] = transaction; - + void _update(ElectrumTransactionInfo transaction) => transactions[transaction.id] = transaction; } diff --git a/cw_bitcoin/lib/electrum_transaction_info.dart b/cw_bitcoin/lib/electrum_transaction_info.dart index 50896c837..5564ce672 100644 --- a/cw_bitcoin/lib/electrum_transaction_info.dart +++ b/cw_bitcoin/lib/electrum_transaction_info.dart @@ -160,11 +160,11 @@ class ElectrumTransactionInfo extends TransactionInfo { isPending: data['isPending'] as bool, confirmations: data['confirmations'] as int, to: data['to'] as String?, - unspents: data['unspent'] != null - ? (data['unspent'] as List) + unspents: data['unspents'] != null + ? (data['unspents'] as List) .map((unspent) => BitcoinUnspent.fromJSON( - BitcoinAddressRecord.fromJSON(unspent['address_record'] as String), - data['unspent'] as Map)) + BitcoinAddressRecord.fromJSON(unspent['address_record'].toString()), + unspent as Map)) .toList() : null, ); @@ -212,7 +212,7 @@ class ElectrumTransactionInfo extends TransactionInfo { m['confirmations'] = confirmations; m['fee'] = fee; m['to'] = to; - m['unspent'] = unspents?.map((e) => e.toJson()) ?? []; + m['unspents'] = unspents?.map((e) => e.toJson()).toList() ?? []; return m; } diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 9f7e67564..8d68f6c8f 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -183,7 +183,7 @@ abstract class ElectrumWalletBase startRefresh, ScanData( sendPort: receivePort.sendPort, - primarySilentAddress: walletAddresses.primarySilentAddress!, + silentAddress: walletAddresses.silentAddress!, network: network, height: height, chainTip: currentChainTip, @@ -211,25 +211,36 @@ abstract class ElectrumWalletBase final existingTxInfo = transactionHistory.transactions[txid]; if (existingTxInfo != null) { final newUnspents = tx.unspents! - .where((unspent) => !existingTxInfo.unspents!.any((element) => - element.hash.contains(unspent.hash) && element.vout == unspent.vout)) + .where((unspent) => !(existingTxInfo.unspents?.any((element) => + element.hash.contains(unspent.hash) && element.vout == unspent.vout) ?? + false)) .toList(); if (newUnspents.isNotEmpty) { existingTxInfo.unspents ??= []; existingTxInfo.unspents!.addAll(newUnspents); - existingTxInfo.amount += newUnspents.length > 1 + + final amount = newUnspents.length > 1 ? newUnspents.map((e) => e.value).reduce((value, unspent) => value + unspent) : newUnspents[0].value; + + if (existingTxInfo.direction == TransactionDirection.incoming) { + existingTxInfo.amount += amount; + } else { + existingTxInfo.amount = amount; + existingTxInfo.direction = TransactionDirection.incoming; + } + transactionHistory.addOne(existingTxInfo); } } else { transactionHistory.addMany(message); - transactionHistory.save(); } + + await transactionHistory.save(); + await updateUnspent(); + await save(); } } - - updateUnspent(); } // check if is a SyncStatus type since "is SyncStatus" doesn't work here @@ -284,7 +295,6 @@ abstract class ElectrumWalletBase electrumClient.onConnectionStatusChange = (bool isConnected) async { if (!isConnected) { syncStatus = LostConnectionSyncStatus(); - await electrumClient.close(); if (attemptedReconnect == false) { await _electrumConnect(node, attemptedReconnect: true); } @@ -330,10 +340,10 @@ abstract class ElectrumWalletBase ECPrivate? privkey; if (utx.bitcoinAddressRecord is BitcoinSilentPaymentAddressRecord) { - privkey = walletAddresses.primarySilentAddress!.b_spend.clone().tweakAdd( + privkey = walletAddresses.silentAddress!.b_spend.clone().tweakAdd( BigintUtils.fromBytes(BytesUtils.fromHexString( (utx.bitcoinAddressRecord as BitcoinSilentPaymentAddressRecord) - .silentPaymentTweak)), + .silentPaymentTweak!)), ); } else { privkey = generateECPrivate( @@ -693,11 +703,7 @@ abstract class ElectrumWalletBase // Update unspents stored from scanned silent payment transactions transactionHistory.transactions.values.forEach((tx) { if (tx.unspents != null) { - if (!unspentCoins.any((utx) => - tx.unspents!.any((element) => utx.hash.contains(element.hash)) && - tx.unspents!.any((element) => utx.vout == element.vout))) { - updatedUnspentCoins.addAll(tx.unspents!); - } + updatedUnspentCoins.addAll(tx.unspents!); } }); @@ -799,8 +805,7 @@ abstract class ElectrumWalletBase (await http.get(Uri.parse("https://blockstream.info/testnet/api/tx/$hash/status"))).body); time = status["block_time"] as int?; - final tip = await electrumClient.getCurrentBlockChainTip() ?? 0; - confirmations = tip - (status["block_height"] as int? ?? 0); + confirmations = currentChainTip! - (status["block_height"] as int? ?? 0); } else { final verboseTransaction = await electrumClient.getTransactionRaw(hash: hash); @@ -843,13 +848,13 @@ abstract class ElectrumWalletBase try { final Map historiesWithDetails = {}; final addressesSet = walletAddresses.allAddresses.map((addr) => addr.address).toSet(); - final currentHeight = await electrumClient.getCurrentBlockChainTip() ?? 0; + currentChainTip ??= await electrumClient.getCurrentBlockChainTip() ?? 0; await Future.wait(ADDRESS_TYPES.map((type) { final addressesByType = walletAddresses.allAddresses.where((addr) => addr.type == type); return Future.wait(addressesByType.map((addressRecord) async { - final history = await _fetchAddressHistory(addressRecord, addressesSet, currentHeight); + final history = await _fetchAddressHistory(addressRecord, addressesSet, currentChainTip!); if (history.isNotEmpty) { addressRecord.txCount = history.length; @@ -866,7 +871,7 @@ abstract class ElectrumWalletBase matchedAddresses.toList(), addressRecord.isHidden, (address, addressesSet) => - _fetchAddressHistory(address, addressesSet, currentHeight) + _fetchAddressHistory(address, addressesSet, currentChainTip!) .then((history) => history.isNotEmpty ? address.address : null), type: type); } @@ -1064,16 +1069,14 @@ abstract class ElectrumWalletBase } Future _setInitialHeight() async { - if (walletInfo.restoreHeight == 0) { - currentChainTip = await electrumClient.getCurrentBlockChainTip(); - if (currentChainTip != null) walletInfo.restoreHeight = currentChainTip!; - } + currentChainTip = await electrumClient.getCurrentBlockChainTip(); + if (currentChainTip != null) walletInfo.restoreHeight = currentChainTip!; } } class ScanData { final SendPort sendPort; - final SilentPaymentOwner primarySilentAddress; + final SilentPaymentOwner silentAddress; final int height; final String node; final BasedUtxoNetwork network; @@ -1084,7 +1087,7 @@ class ScanData { ScanData({ required this.sendPort, - required this.primarySilentAddress, + required this.silentAddress, required this.height, required this.node, required this.network, @@ -1097,7 +1100,7 @@ class ScanData { factory ScanData.fromHeight(ScanData scanData, int newHeight) { return ScanData( sendPort: scanData.sendPort, - primarySilentAddress: scanData.primarySilentAddress, + silentAddress: scanData.silentAddress, height: newHeight, node: scanData.node, network: scanData.network, @@ -1119,7 +1122,7 @@ class SyncResponse { Future startRefresh(ScanData scanData) async { var cachedBlockchainHeight = scanData.chainTip; - Future connect() async { + Future getElectrumConnection() async { final electrumClient = scanData.electrumClient; if (!electrumClient.isConnected) { final node = scanData.node; @@ -1130,7 +1133,7 @@ Future startRefresh(ScanData scanData) async { Future getNodeHeightOrUpdate(int baseHeight) async { if (cachedBlockchainHeight < baseHeight || cachedBlockchainHeight == 0) { - final electrumClient = await connect(); + final electrumClient = await getElectrumConnection(); cachedBlockchainHeight = await electrumClient.getCurrentBlockChainTip() ?? cachedBlockchainHeight; @@ -1174,7 +1177,7 @@ Future startRefresh(ScanData scanData) async { } try { - final electrumClient = await connect(); + final electrumClient = await getElectrumConnection(); List? tweaks; try { @@ -1205,9 +1208,13 @@ Future startRefresh(ScanData scanData) async { final spb = SilentPaymentBuilder(receiverTweak: tweak); final result = spb.scanOutputs( - scanData.primarySilentAddress.b_scan, - scanData.primarySilentAddress.B_spend, - output_pubkeys.map((output) => output.toString()).toList(), + scanData.silentAddress.b_scan, + scanData.silentAddress.B_spend, + output_pubkeys + .map((output) => + BytesUtils.toHexString(BytesUtils.fromHexString(output.toString()).sublist(2)) + .toString()) + .toList(), precomputedLabels: scanData.labels, ); @@ -1226,15 +1233,12 @@ Future startRefresh(ScanData scanData) async { BitcoinUnspent? info; await Future.forEach>(listUnspent, (unspent) async { try { - final addressRecord = BitcoinSilentPaymentAddressRecord( - address, - index: 0, - isHidden: true, - isUsed: true, - network: scanData.network, - silentPaymentTweak: t_k, - type: SegwitAddresType.p2tr, - ); + final addressRecord = BitcoinSilentPaymentAddressRecord(address, + index: 0, + isHidden: true, + isUsed: true, + network: scanData.network, + silentPaymentTweak: t_k); info = BitcoinUnspent.fromJSON(addressRecord, unspent); } catch (_) {} }); @@ -1258,7 +1262,7 @@ Future startRefresh(ScanData scanData) async { isPending: false, date: DateTime.now(), confirmations: currentChainTip - syncHeight - 1, - to: scanData.primarySilentAddress.toString(), + to: scanData.silentAddress.toString(), unspents: [tx], ); @@ -1310,7 +1314,6 @@ Future startRefresh(ScanData scanData) async { }); } catch (_) {} } - // break; // Finished scanning block, add 1 to height and continue to next block in loop syncHeight += 1; diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index 2bfeeeea0..5a839e3a5 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -30,10 +30,9 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { Map? initialRegularAddressIndex, Map? initialChangeAddressIndex, List? initialSilentAddresses, - int initialSilentAddressIndex = 0, - SilentPaymentOwner? silentAddress, + int initialSilentAddressIndex = 1, + bitcoin.HDWallet? masterHd, }) : _addresses = ObservableList.of((initialAddresses ?? []).toSet()), - primarySilentAddress = silentAddress, addressesByReceiveType = ObservableList.of(([]).toSet()), receiveAddresses = ObservableList.of((initialAddresses ?? []) @@ -51,6 +50,17 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { (initialSilentAddresses ?? []).toSet()), currentSilentAddressIndex = initialSilentAddressIndex, super(walletInfo) { + if (masterHd != null) { + silentAddress = SilentPaymentOwner.fromPrivateKeys( + b_scan: ECPrivate.fromHex(masterHd.derivePath(SCAN_PATH).privKey!), + b_spend: ECPrivate.fromHex(masterHd.derivePath(SPEND_PATH).privKey!), + hrp: network == BitcoinNetwork.testnet ? 'tsp' : 'sp'); + + if (silentAddresses.length == 0) + silentAddresses.add(BitcoinSilentPaymentAddressRecord(silentAddress.toString(), + index: 1, isHidden: false, name: "", silentPaymentTweak: null, network: network)); + } + updateAddressesByMatch(); } @@ -70,7 +80,8 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { final bitcoin.HDWallet mainHd; final bitcoin.HDWallet sideHd; - final SilentPaymentOwner? primarySilentAddress; + @observable + SilentPaymentOwner? silentAddress; @observable BitcoinAddressType _addressPageType = SegwitAddresType.p2wpkh; @@ -92,7 +103,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { return activeSilentAddress!; } - return primarySilentAddress!.toString(); + return silentAddress.toString(); } String receiveAddress; @@ -123,7 +134,14 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { @override set address(String addr) { if (addressPageType == SilentPaymentsAddresType.p2sp) { - activeSilentAddress = addr; + 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; } @@ -225,27 +243,28 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { for (int i = 0; i < silentAddresses.length; i++) { final silentAddressRecord = silentAddresses[i]; final silentPaymentTweak = silentAddressRecord.silentPaymentTweak; - labels[G - .tweakMul(BigintUtils.fromBytes(BytesUtils.fromHexString(silentPaymentTweak))) - .toHex()] = silentPaymentTweak; + + if (silentPaymentTweak != null) + labels[G + .tweakMul(BigintUtils.fromBytes(BytesUtils.fromHexString(silentPaymentTweak))) + .toHex()] = silentPaymentTweak; } return labels; } @action BaseBitcoinAddressRecord generateNewAddress({String label = ''}) { - if (addressPageType == SilentPaymentsAddresType.p2sp) { + if (addressPageType == SilentPaymentsAddresType.p2sp && silentAddress != null) { currentSilentAddressIndex += 1; final address = BitcoinSilentPaymentAddressRecord( - primarySilentAddress!.toLabeledSilentPaymentAddress(currentSilentAddressIndex).toString(), + silentAddress!.toLabeledSilentPaymentAddress(currentSilentAddressIndex).toString(), index: currentSilentAddressIndex, isHidden: false, name: label, silentPaymentTweak: - BytesUtils.toHexString(primarySilentAddress!.generateLabel(currentSilentAddressIndex)), + BytesUtils.toHexString(silentAddress!.generateLabel(currentSilentAddressIndex)), network: network, - type: SilentPaymentsAddresType.p2sp, ); silentAddresses.add(address); diff --git a/cw_bitcoin/pubspec.lock b/cw_bitcoin/pubspec.lock index 3584b0fe3..464e23843 100644 --- a/cw_bitcoin/pubspec.lock +++ b/cw_bitcoin/pubspec.lock @@ -78,11 +78,9 @@ packages: bitcoin_base: dependency: "direct main" description: - path: "." - ref: cake-update-v2 - resolved-ref: "7634511b15e5a48bd18e3c19f81971628090c04f" - url: "https://github.com/cake-tech/bitcoin_base.git" - source: git + path: "/home/rafael/Working/bitcoin_base" + relative: false + source: path version: "4.0.0" bitcoin_flutter: dependency: "direct main" @@ -96,11 +94,9 @@ packages: blockchain_utils: dependency: "direct main" description: - path: "." - ref: cake-update-v1 - resolved-ref: "6a0b891db4d90c647ebf5fc3a9132e614c70e1c6" - url: "https://github.com/cake-tech/blockchain_utils" - source: git + path: "/home/rafael/Working/blockchain_utils" + relative: false + source: path version: "1.6.0" boolean_selector: dependency: transitive diff --git a/cw_bitcoin/pubspec.yaml b/cw_bitcoin/pubspec.yaml index bfa6c72e6..eafa00881 100644 --- a/cw_bitcoin/pubspec.yaml +++ b/cw_bitcoin/pubspec.yaml @@ -31,13 +31,9 @@ dependencies: unorm_dart: ^0.2.0 cryptography: ^2.0.5 bitcoin_base: - git: - url: https://github.com/cake-tech/bitcoin_base.git - ref: cake-update-v2 + path: /home/rafael/Working/bitcoin_base blockchain_utils: - git: - url: https://github.com/cake-tech/blockchain_utils - ref: cake-update-v1 + path: /home/rafael/Working/blockchain_utils dev_dependencies: flutter_test: diff --git a/cw_bitcoin_cash/pubspec.yaml b/cw_bitcoin_cash/pubspec.yaml index a96768150..c80df0458 100644 --- a/cw_bitcoin_cash/pubspec.yaml +++ b/cw_bitcoin_cash/pubspec.yaml @@ -30,13 +30,9 @@ dependencies: url: https://github.com/cake-tech/bitbox-flutter.git ref: master bitcoin_base: - git: - url: https://github.com/cake-tech/bitcoin_base.git - ref: cake-update-v2 + path: /home/rafael/Working/bitcoin_base blockchain_utils: - git: - url: https://github.com/cake-tech/blockchain_utils - ref: cake-update-v1 + path: /home/rafael/Working/blockchain_utils dev_dependencies: flutter_test: diff --git a/scripts/android/app_env.fish b/scripts/android/app_env.fish new file mode 100644 index 000000000..be82ab9e6 --- /dev/null +++ b/scripts/android/app_env.fish @@ -0,0 +1,75 @@ +#!/usr/bin/env fish + +set APP_ANDROID_NAME "" +set APP_ANDROID_VERSION "" +set APP_ANDROID_BUILD_VERSION "" +set APP_ANDROID_ID "" +set APP_ANDROID_PACKAGE "" +set APP_ANDROID_SCHEME "" + +set MONERO_COM "monero.com" +set CAKEWALLET "cakewallet" +set HAVEN "haven" + +set -l TYPES $MONERO_COM $CAKEWALLET $HAVEN +set APP_ANDROID_TYPE $argv[1] + +set MONERO_COM_NAME "Monero.com" +set MONERO_COM_VERSION "1.10.0" +set MONERO_COM_BUILD_NUMBER 72 +set MONERO_COM_BUNDLE_ID "com.monero.app" +set MONERO_COM_PACKAGE "com.monero.app" +set MONERO_COM_SCHEME "monero.com" + +set CAKEWALLET_NAME "Cake Wallet" +set CAKEWALLET_VERSION "4.13.0" +set CAKEWALLET_BUILD_NUMBER 189 +set CAKEWALLET_BUNDLE_ID "com.cakewallet.cake_wallet" +set CAKEWALLET_PACKAGE "com.cakewallet.cake_wallet" +set CAKEWALLET_SCHEME "cakewallet" + +set HAVEN_NAME "Haven" +set HAVEN_VERSION "1.0.0" +set HAVEN_BUILD_NUMBER 1 +set HAVEN_BUNDLE_ID "com.cakewallet.haven" +set HAVEN_PACKAGE "com.cakewallet.haven" + +if not contains $APP_ANDROID_TYPE $TYPES + echo "Wrong app type." + return 1 + exit 1 +end + +switch $APP_ANDROID_TYPE + case $MONERO_COM + set APP_ANDROID_NAME $MONERO_COM_NAME + set APP_ANDROID_VERSION $MONERO_COM_VERSION + set APP_ANDROID_BUILD_NUMBER $MONERO_COM_BUILD_NUMBER + set APP_ANDROID_BUNDLE_ID $MONERO_COM_BUNDLE_ID + set APP_ANDROID_PACKAGE $MONERO_COM_PACKAGE + set APP_ANDROID_SCHEME $MONERO_COM_SCHEME + ;; + case $CAKEWALLET + set APP_ANDROID_NAME $CAKEWALLET_NAME + set APP_ANDROID_VERSION $CAKEWALLET_VERSION + set APP_ANDROID_BUILD_NUMBER $CAKEWALLET_BUILD_NUMBER + set APP_ANDROID_BUNDLE_ID $CAKEWALLET_BUNDLE_ID + set APP_ANDROID_PACKAGE $CAKEWALLET_PACKAGE + set APP_ANDROID_SCHEME $CAKEWALLET_SCHEME + ;; + case $HAVEN + set APP_ANDROID_NAME $HAVEN_NAME + set APP_ANDROID_VERSION $HAVEN_VERSION + set APP_ANDROID_BUILD_NUMBER $HAVEN_BUILD_NUMBER + set APP_ANDROID_BUNDLE_ID $HAVEN_BUNDLE_ID + set APP_ANDROID_PACKAGE $HAVEN_PACKAGE + ;; +end + +export APP_ANDROID_TYPE +export APP_ANDROID_NAME +export APP_ANDROID_VERSION +export APP_ANDROID_BUILD_NUMBER +export APP_ANDROID_BUNDLE_ID +export APP_ANDROID_PACKAGE +export APP_ANDROID_SCHEME