diff --git a/cw_bitcoin/lib/bitcoin_wallet.dart b/cw_bitcoin/lib/bitcoin_wallet.dart index f6d390389..653faddf4 100644 --- a/cw_bitcoin/lib/bitcoin_wallet.dart +++ b/cw_bitcoin/lib/bitcoin_wallet.dart @@ -150,9 +150,17 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { hdWallets[CWBitcoinDerivationType.electrum]!; } } else { - seedBytes = walletInfo.derivationInfo?.derivationType == DerivationType.electrum - ? ElectrumV2SeedGenerator.generateFromString(mnemonic, passphrase) - : Bip39SeedGenerator.generateFromString(mnemonic, passphrase); + switch (walletInfo.derivationInfo?.derivationType) { + case DerivationType.bip39: + seedBytes = await Bip39SeedGenerator.generateFromString(mnemonic, passphrase); + hdWallets[CWBitcoinDerivationType.bip39] = Bip32Slip10Secp256k1.fromSeed(seedBytes); + break; + case DerivationType.electrum: + default: + seedBytes = await ElectrumV2SeedGenerator.generateFromString(mnemonic, passphrase); + hdWallets[CWBitcoinDerivationType.electrum] = Bip32Slip10Secp256k1.fromSeed(seedBytes); + break; + } } return BitcoinWallet( diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index de14efadd..fb6fc92b1 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -1308,6 +1308,11 @@ abstract class ElectrumWalletBase Future onHistoriesResponse(List histories) async { if (histories.isEmpty || _updatingHistories) { _updatingHistories = false; + _syncedTimes++; + if (_syncedTimes == 3) { + syncStatus = SyncedSyncStatus(); + } + return; } diff --git a/cw_bitcoin/lib/electrum_wallet_addresses.dart b/cw_bitcoin/lib/electrum_wallet_addresses.dart index 15056fb67..64b49ba5b 100644 --- a/cw_bitcoin/lib/electrum_wallet_addresses.dart +++ b/cw_bitcoin/lib/electrum_wallet_addresses.dart @@ -467,7 +467,29 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { (element) => element.scriptType == addressType.toString(), ); - for (final derivationInfo in derivationInfos ?? []) { + if (derivationInfos == null || derivationInfos.isEmpty) { + final bitcoinDerivationInfo = BitcoinDerivationInfo( + derivationType: isElectrum ? BitcoinDerivationType.electrum : BitcoinDerivationType.bip39, + derivationPath: walletInfo.derivationInfo!.derivationPath!, + scriptType: addressType, + ); + + await discoverNewAddresses( + derivationType: derivationType, + isChange: false, + addressType: addressType, + derivationInfo: bitcoinDerivationInfo, + ); + await discoverNewAddresses( + derivationType: derivationType, + isChange: true, + addressType: addressType, + derivationInfo: bitcoinDerivationInfo, + ); + continue; + } + + for (final derivationInfo in derivationInfos) { final bitcoinDerivationInfo = BitcoinDerivationInfo( derivationType: isElectrum ? BitcoinDerivationType.electrum : BitcoinDerivationType.bip39, derivationPath: derivationInfo.derivationPath!, diff --git a/cw_bitcoin/lib/electrum_worker/electrum_worker.dart b/cw_bitcoin/lib/electrum_worker/electrum_worker.dart index 3a0cdf4cb..14bb0c4db 100644 --- a/cw_bitcoin/lib/electrum_worker/electrum_worker.dart +++ b/cw_bitcoin/lib/electrum_worker/electrum_worker.dart @@ -47,6 +47,8 @@ class ElectrumWorker { } void handleMessage(dynamic message) async { + print("Worker received message: $message"); + try { Map messageJson; if (message is String) { @@ -107,7 +109,6 @@ class ElectrumWorker { ElectrumWorkerStopScanningRequest.fromJson(messageJson), ); break; - case ElectrumRequestMethods.estimateFeeMethod: case ElectrumRequestMethods.tweaksSubscribeMethod: if (_isScanning) { _stopScanRequested = false; @@ -279,12 +280,8 @@ class ElectrumWorker { walletType: result.walletType, ); } - - return Future.value(null); })); } - - return histories; })); _sendResponse(ElectrumWorkerGetHistoryResponse( @@ -411,29 +408,36 @@ class ElectrumWorker { if (getTime) { if (mempoolAPIEnabled) { try { - final txVerbose = await http.get( - Uri.parse( - "http://mempool.cakewallet.com:8999/api/v1/tx/$hash/status", - ), - ); + // TODO: mempool api class + final txVerbose = await http + .get( + Uri.parse( + "https://mempool.cakewallet.com/api/v1/tx/$hash/status", + ), + ) + .timeout(const Duration(seconds: 5)); if (txVerbose.statusCode == 200 && txVerbose.body.isNotEmpty && jsonDecode(txVerbose.body) != null) { height = jsonDecode(txVerbose.body)['block_height'] as int; - final blockHash = await http.get( - Uri.parse( - "http://mempool.cakewallet.com:8999/api/v1/block-height/$height", - ), - ); + final blockHash = await http + .get( + Uri.parse( + "https://mempool.cakewallet.com/api/v1/block-height/$height", + ), + ) + .timeout(const Duration(seconds: 5)); if (blockHash.statusCode == 200 && blockHash.body.isNotEmpty) { - final blockResponse = await http.get( - Uri.parse( - "http://mempool.cakewallet.com:8999/api/v1/block/${blockHash.body}", - ), - ); + final blockResponse = await http + .get( + Uri.parse( + "https://mempool.cakewallet.com/api/v1/block/${blockHash.body}", + ), + ) + .timeout(const Duration(seconds: 5)); if (blockResponse.statusCode == 200 && blockResponse.body.isNotEmpty && diff --git a/cw_core/lib/get_height_by_date.dart b/cw_core/lib/get_height_by_date.dart index 15451f31f..dcf9c6675 100644 --- a/cw_core/lib/get_height_by_date.dart +++ b/cw_core/lib/get_height_by_date.dart @@ -273,7 +273,7 @@ const bitcoinDates = { Future getBitcoinHeightByDateAPI({required DateTime date}) async { final response = await http.get( Uri.parse( - "http://mempool.cakewallet.com:8999/api/v1/mining/blocks/timestamp/${(date.millisecondsSinceEpoch / 1000).round()}", + "https://mempool.cakewallet.com/api/v1/mining/blocks/timestamp/${(date.millisecondsSinceEpoch / 1000).round()}", ), );