From d12e874b75abe65b9f459d0dbafb4c61ed103043 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 13 Jan 2023 03:47:24 +0200 Subject: [PATCH] Change ethereum node Fix connection issues --- assets/ethereum_server_list.yml | 2 +- cw_core/lib/node.dart | 2 ++ cw_ethereum/lib/ethereum_client.dart | 12 ++++++------ cw_ethereum/lib/ethereum_wallet.dart | 4 ++++ lib/entities/default_settings_migration.dart | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/assets/ethereum_server_list.yml b/assets/ethereum_server_list.yml index 805e9af60..c7e23ad0e 100644 --- a/assets/ethereum_server_list.yml +++ b/assets/ethereum_server_list.yml @@ -1,2 +1,2 @@ - - uri: 10.0.2.2:7545 \ No newline at end of file + uri: ethereum.publicnode.com \ No newline at end of file diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 1322c5b78..8d17bbaf1 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -68,6 +68,8 @@ class Node extends HiveObject with Keyable { return createUriFromElectrumAddress(uriRaw); case WalletType.haven: return Uri.http(uriRaw, ''); + case WalletType.ethereum: + return Uri.https(uriRaw, ''); default: throw Exception('Unexpected type ${type.toString()} for Node uri'); } diff --git a/cw_ethereum/lib/ethereum_client.dart b/cw_ethereum/lib/ethereum_client.dart index 6e0481f7a..8f8721ced 100644 --- a/cw_ethereum/lib/ethereum_client.dart +++ b/cw_ethereum/lib/ethereum_client.dart @@ -4,11 +4,11 @@ import 'package:http/http.dart'; import 'package:web3dart/web3dart.dart'; class EthereumClient { - late final Web3Client _client; + Web3Client? _client; Future connect(Node node) async { try { - _client = Web3Client(node.uriRaw, Client()); + _client = Web3Client(node.uri.toString(), Client()); return true; } catch (e) { @@ -19,17 +19,17 @@ class EthereumClient { Future getBalance(String privateKey) async { final private = EthPrivateKey.fromHex(privateKey); - return _client.getBalance(private.address); + return _client!.getBalance(private.address); } Future getGasUnitPrice() async { - final gasPrice = await _client.getGasPrice(); + final gasPrice = await _client!.getGasPrice(); return gasPrice.getInWei.toInt(); } Future> getEstimatedGasForPriorities() async { - final result = await Future.wait(EthereumTransactionPriority.all.map((priority) => - _client.estimateGas( + final result = await Future.wait(EthereumTransactionPriority.all.map((priority) => _client! + .estimateGas( maxPriorityFeePerGas: EtherAmount.fromUnitAndValue(EtherUnit.gwei, priority.tip)))); return result.map((e) => e.toInt()).toList(); diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index 2800e35ef..a95558009 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -39,6 +39,7 @@ abstract class EthereumWalletBase _password = password, _mnemonic = mnemonic, _feeRates = [], + _client = EthereumClient(), walletAddresses = EthereumWalletAddresses(walletInfo), balance = ObservableMap.of( {CryptoCurrency.eth: initialBalance ?? EthereumBalance(available: 0, additional: 0)}), @@ -60,6 +61,7 @@ abstract class EthereumWalletBase WalletAddresses walletAddresses; @override + @observable SyncStatus syncStatus; @override @@ -85,6 +87,7 @@ abstract class EthereumWalletBase @override void close() {} + @action @override Future connectToNode({required Node node}) async { try { @@ -132,6 +135,7 @@ abstract class EthereumWalletBase @override String get seed => _mnemonic; + @action @override Future startSync() async { try { diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 990909c87..17f1d518e 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -24,7 +24,7 @@ const newCakeWalletMoneroUri = 'xmr-node.cakewallet.com:18081'; const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002'; const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002'; const havenDefaultNodeUri = 'nodes.havenprotocol.org:443'; -const ethereumDefaultNodeUri = '10.0.2.2:7545'; +const ethereumDefaultNodeUri = 'ethereum.publicnode.com'; Future defaultSettingsMigration( {required int version,