mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-25 20:16:05 +00:00
Change ethereum node
Fix connection issues
This commit is contained in:
parent
97f32019db
commit
d12e874b75
5 changed files with 14 additions and 8 deletions
|
@ -1,2 +1,2 @@
|
||||||
-
|
-
|
||||||
uri: 10.0.2.2:7545
|
uri: ethereum.publicnode.com
|
|
@ -68,6 +68,8 @@ class Node extends HiveObject with Keyable {
|
||||||
return createUriFromElectrumAddress(uriRaw);
|
return createUriFromElectrumAddress(uriRaw);
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
return Uri.http(uriRaw, '');
|
return Uri.http(uriRaw, '');
|
||||||
|
case WalletType.ethereum:
|
||||||
|
return Uri.https(uriRaw, '');
|
||||||
default:
|
default:
|
||||||
throw Exception('Unexpected type ${type.toString()} for Node uri');
|
throw Exception('Unexpected type ${type.toString()} for Node uri');
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import 'package:http/http.dart';
|
||||||
import 'package:web3dart/web3dart.dart';
|
import 'package:web3dart/web3dart.dart';
|
||||||
|
|
||||||
class EthereumClient {
|
class EthereumClient {
|
||||||
late final Web3Client _client;
|
Web3Client? _client;
|
||||||
|
|
||||||
Future<bool> connect(Node node) async {
|
Future<bool> connect(Node node) async {
|
||||||
try {
|
try {
|
||||||
_client = Web3Client(node.uriRaw, Client());
|
_client = Web3Client(node.uri.toString(), Client());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -19,17 +19,17 @@ class EthereumClient {
|
||||||
Future<EtherAmount> getBalance(String privateKey) async {
|
Future<EtherAmount> getBalance(String privateKey) async {
|
||||||
final private = EthPrivateKey.fromHex(privateKey);
|
final private = EthPrivateKey.fromHex(privateKey);
|
||||||
|
|
||||||
return _client.getBalance(private.address);
|
return _client!.getBalance(private.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getGasUnitPrice() async {
|
Future<int> getGasUnitPrice() async {
|
||||||
final gasPrice = await _client.getGasPrice();
|
final gasPrice = await _client!.getGasPrice();
|
||||||
return gasPrice.getInWei.toInt();
|
return gasPrice.getInWei.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<int>> getEstimatedGasForPriorities() async {
|
Future<List<int>> getEstimatedGasForPriorities() async {
|
||||||
final result = await Future.wait(EthereumTransactionPriority.all.map((priority) =>
|
final result = await Future.wait(EthereumTransactionPriority.all.map((priority) => _client!
|
||||||
_client.estimateGas(
|
.estimateGas(
|
||||||
maxPriorityFeePerGas: EtherAmount.fromUnitAndValue(EtherUnit.gwei, priority.tip))));
|
maxPriorityFeePerGas: EtherAmount.fromUnitAndValue(EtherUnit.gwei, priority.tip))));
|
||||||
|
|
||||||
return result.map((e) => e.toInt()).toList();
|
return result.map((e) => e.toInt()).toList();
|
||||||
|
|
|
@ -39,6 +39,7 @@ abstract class EthereumWalletBase
|
||||||
_password = password,
|
_password = password,
|
||||||
_mnemonic = mnemonic,
|
_mnemonic = mnemonic,
|
||||||
_feeRates = [],
|
_feeRates = [],
|
||||||
|
_client = EthereumClient(),
|
||||||
walletAddresses = EthereumWalletAddresses(walletInfo),
|
walletAddresses = EthereumWalletAddresses(walletInfo),
|
||||||
balance = ObservableMap<CryptoCurrency, EthereumBalance>.of(
|
balance = ObservableMap<CryptoCurrency, EthereumBalance>.of(
|
||||||
{CryptoCurrency.eth: initialBalance ?? EthereumBalance(available: 0, additional: 0)}),
|
{CryptoCurrency.eth: initialBalance ?? EthereumBalance(available: 0, additional: 0)}),
|
||||||
|
@ -60,6 +61,7 @@ abstract class EthereumWalletBase
|
||||||
WalletAddresses walletAddresses;
|
WalletAddresses walletAddresses;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@observable
|
||||||
SyncStatus syncStatus;
|
SyncStatus syncStatus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -85,6 +87,7 @@ abstract class EthereumWalletBase
|
||||||
@override
|
@override
|
||||||
void close() {}
|
void close() {}
|
||||||
|
|
||||||
|
@action
|
||||||
@override
|
@override
|
||||||
Future<void> connectToNode({required Node node}) async {
|
Future<void> connectToNode({required Node node}) async {
|
||||||
try {
|
try {
|
||||||
|
@ -132,6 +135,7 @@ abstract class EthereumWalletBase
|
||||||
@override
|
@override
|
||||||
String get seed => _mnemonic;
|
String get seed => _mnemonic;
|
||||||
|
|
||||||
|
@action
|
||||||
@override
|
@override
|
||||||
Future<void> startSync() async {
|
Future<void> startSync() async {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,7 +24,7 @@ const newCakeWalletMoneroUri = 'xmr-node.cakewallet.com:18081';
|
||||||
const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002';
|
const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002';
|
||||||
const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002';
|
const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002';
|
||||||
const havenDefaultNodeUri = 'nodes.havenprotocol.org:443';
|
const havenDefaultNodeUri = 'nodes.havenprotocol.org:443';
|
||||||
const ethereumDefaultNodeUri = '10.0.2.2:7545';
|
const ethereumDefaultNodeUri = 'ethereum.publicnode.com';
|
||||||
|
|
||||||
Future defaultSettingsMigration(
|
Future defaultSettingsMigration(
|
||||||
{required int version,
|
{required int version,
|
||||||
|
|
Loading…
Reference in a new issue