diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 73f7e09f5..c29df3c4a 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -1707,7 +1707,7 @@ abstract class ElectrumWalletBase try { final blockHash = await http.get( Uri.parse( - "http://mempool.cakewallet.com:8999/api/v1/block-height/$height", + "https://mempool.cakewallet.com/api/v1/block-height/$height", ), ); @@ -1716,7 +1716,7 @@ abstract class ElectrumWalletBase jsonDecode(blockHash.body) != null) { final blockResponse = await http.get( Uri.parse( - "http://mempool.cakewallet.com:8999/api/v1/block/${blockHash.body}", + "https://mempool.cakewallet.com/api/v1/block/${blockHash.body}", ), ); if (blockResponse.statusCode == 200 && diff --git a/cw_core/lib/get_height_by_date.dart b/cw_core/lib/get_height_by_date.dart index 2b0b77a89..7929d7cbd 100644 --- a/cw_core/lib/get_height_by_date.dart +++ b/cw_core/lib/get_height_by_date.dart @@ -270,7 +270,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()}", ), ); diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 1094b6402..18d2ffc44 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -203,9 +203,30 @@ class Node extends HiveObject with Keyable { headers: {'Content-Type': 'application/json'}, body: json.encode(body), ); - client.close(); + if (( + response.body.contains("400 Bad Request") // Some other generic error + || response.body.contains("plain HTTP request was sent to HTTPS port") // Cloudflare + || response.headers["location"] != null // Generic reverse proxy + || response.body.contains("301 Moved Permanently") // Poorly configured generic reverse proxy + ) && !(useSSL??false) + ) { + + final oldUseSSL = useSSL; + useSSL = true; + try { + final ret = await requestMoneroNode(); + if (ret == true) { + await save(); + return ret; + } + useSSL = oldUseSSL; + } catch (e) { + useSSL = oldUseSSL; + } + } + final resBody = json.decode(response.body) as Map; return !(resBody['result']['offline'] as bool); } catch (_) { diff --git a/cw_monero/lib/api/transaction_history.dart b/cw_monero/lib/api/transaction_history.dart index 76a88a998..7c253509c 100644 --- a/cw_monero/lib/api/transaction_history.dart +++ b/cw_monero/lib/api/transaction_history.dart @@ -18,7 +18,7 @@ String getTxKey(String txId) { final status = monero.Wallet_status(wptr!); if (status != 0) { final error = monero.Wallet_errorString(wptr!); - return txId+"_"+error; + return ""; } return txKey; } @@ -92,7 +92,15 @@ Future createTransactionSync( List preferredInputs = const []}) async { final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount); - + + final waddr = wptr!.address; + + // force reconnection in case the os killed the connection? + // fixes failed to get block height error. + Isolate.run(() async { + monero.Wallet_synchronized(Pointer.fromAddress(waddr)); + }); + final address_ = address.toNativeUtf8(); final paymentId_ = paymentId.toNativeUtf8(); if (preferredInputs.isEmpty) { @@ -101,7 +109,6 @@ Future createTransactionSync( final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8(); - final waddr = wptr!.address; final addraddr = address_.address; final paymentIdAddr = paymentId_.address; final preferredInputsAddr = preferredInputs_.address; @@ -362,16 +369,7 @@ class Transaction { confirmations = monero.TransactionInfo_confirmations(txInfo), fee = monero.TransactionInfo_fee(txInfo), description = monero.TransactionInfo_description(txInfo), - key = getTxKey(txInfo); - - static String getTxKey(monero.TransactionInfo txInfo) { - final txKey = monero.Wallet_getTxKey(wptr!, txid: monero.TransactionInfo_hash(txInfo)); - final status = monero.Wallet_status(wptr!); - if (status != 0) { - return ""; - } - return txKey; - } + key = getTxKey(monero.TransactionInfo_hash(txInfo)); Transaction.dummy({ required this.displayLabel, diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 0581ccb94..667a1ff69 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -160,14 +160,15 @@ final storeMutex = Mutex(); int lastStorePointer = 0; int lastStoreHeight = 0; -void storeSync() async { +void storeSync({bool force = false}) async { final addr = wptr!.address; final synchronized = await Isolate.run(() { return monero.Wallet_synchronized(Pointer.fromAddress(addr)); }); if (lastStorePointer == wptr!.address && lastStoreHeight + 5000 > monero.Wallet_blockChainHeight(wptr!) && - !synchronized) { + !synchronized && + !force) { return; } lastStorePointer = wptr!.address; diff --git a/cw_monero/lib/pending_monero_transaction.dart b/cw_monero/lib/pending_monero_transaction.dart index eb714eeb3..1c01a60dc 100644 --- a/cw_monero/lib/pending_monero_transaction.dart +++ b/cw_monero/lib/pending_monero_transaction.dart @@ -6,6 +6,7 @@ import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/amount_converter.dart'; import 'package:cw_core/pending_transaction.dart'; +import 'package:cw_monero/api/wallet.dart'; class DoubleSpendException implements Exception { DoubleSpendException(); @@ -53,6 +54,7 @@ class PendingMoneroTransaction with PendingTransaction { rethrow; } + storeSync(force: true); } @override diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 9e0e3457d..7f0679625 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -273,7 +273,19 @@ Future defaultSettingsMigration( newDefaultUri: newCakeWalletBitcoinUri, currentNodePreferenceKey: PreferencesKey.currentBitcoinElectrumSererIdKey, useSSL: true, - oldUri: 'cakewallet.com', + oldUri: ['cakewallet.com'], + ); + _changeDefaultNode( + nodes: nodes, + sharedPreferences: sharedPreferences, + type: WalletType.tron, + newDefaultUri: tronDefaultNodeUri, + currentNodePreferenceKey: PreferencesKey.currentTronNodeIdKey, + useSSL: true, + oldUri: [ + 'tron-rpc.publicnode.com:443', + 'api.trongrid.io', + ], ); break; @@ -300,11 +312,11 @@ Future _changeDefaultNode({ required String newDefaultUri, required String currentNodePreferenceKey, required bool useSSL, - required String oldUri, // leave empty if you want to force replace the node regardless of the user's current node + required List oldUri, // leave empty if you want to force replace the node regardless of the user's current node }) async { final currentNodeId = sharedPreferences.getInt(currentNodePreferenceKey); final currentNode = nodes.values.firstWhere((node) => node.key == currentNodeId); - final shouldReplace = currentNode.uriRaw.contains(oldUri); + final shouldReplace = oldUri.any((e) => currentNode.uriRaw.contains(e)); if (shouldReplace) { var newNodeId = diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index a189ebe6c..e675acf17 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -159,7 +159,7 @@ abstract class TransactionDetailsViewModelBase with Store { case WalletType.monero: return 'https://monero.com/tx/${txId}'; case WalletType.bitcoin: - return 'https://mempool.space/${wallet.isTestnet ? "testnet/" : ""}tx/${txId}'; + return 'https://mempool.cakewallet.com/${wallet.isTestnet ? "testnet/" : ""}tx/${txId}'; case WalletType.litecoin: return 'https://blockchair.com/litecoin/transaction/${txId}'; case WalletType.bitcoinCash: