Change ethereum node

Fix connection issues
This commit is contained in:
OmarHatem 2023-01-13 03:47:24 +02:00
parent 97f32019db
commit d12e874b75
5 changed files with 14 additions and 8 deletions

View file

@ -1,2 +1,2 @@
-
uri: 10.0.2.2:7545
uri: ethereum.publicnode.com

View file

@ -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');
}

View file

@ -4,11 +4,11 @@ import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
class EthereumClient {
late final Web3Client _client;
Web3Client? _client;
Future<bool> 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<EtherAmount> getBalance(String privateKey) async {
final private = EthPrivateKey.fromHex(privateKey);
return _client.getBalance(private.address);
return _client!.getBalance(private.address);
}
Future<int> getGasUnitPrice() async {
final gasPrice = await _client.getGasPrice();
final gasPrice = await _client!.getGasPrice();
return gasPrice.getInWei.toInt();
}
Future<List<int>> 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();

View file

@ -39,6 +39,7 @@ abstract class EthereumWalletBase
_password = password,
_mnemonic = mnemonic,
_feeRates = [],
_client = EthereumClient(),
walletAddresses = EthereumWalletAddresses(walletInfo),
balance = ObservableMap<CryptoCurrency, EthereumBalance>.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<void> connectToNode({required Node node}) async {
try {
@ -132,6 +135,7 @@ abstract class EthereumWalletBase
@override
String get seed => _mnemonic;
@action
@override
Future<void> startSync() async {
try {

View file

@ -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,