mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-31 16:09:49 +00:00
fix zano node selection, move other zano calls to separate isolate
This commit is contained in:
parent
20b116eda5
commit
2c855165fb
5 changed files with 21 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
|||
-
|
||||
uri: zano.org
|
||||
uri: 195.201.107.230:33340
|
||||
is_default: true
|
||||
useSSL: true
|
||||
useSSL: false
|
|
@ -44,6 +44,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
static const int _autoSaveIntervalSeconds = 30;
|
||||
static const int _pollIntervalMilliseconds = 2000;
|
||||
static const int _maxLoadAssetsRetries = 5;
|
||||
static const DO_NOT_MERGE_hardcodedNodeUri = '195.201.107.230:33340';
|
||||
|
||||
@override
|
||||
void setPassword(String password) {
|
||||
|
@ -123,7 +124,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
|
||||
static Future<ZanoWallet> create({required WalletCredentials credentials}) async {
|
||||
final wallet = ZanoWallet(credentials.walletInfo!, credentials.password!);
|
||||
await wallet.connectToNode(node: Node());
|
||||
await wallet.connectToNode(node: Node()..uriRaw = DO_NOT_MERGE_hardcodedNodeUri);
|
||||
final path = await pathForWallet(name: credentials.name, type: credentials.walletInfo!.type);
|
||||
final createWalletResult = await wallet.createWallet(path, credentials.password!);
|
||||
await wallet.parseCreateWalletResult(createWalletResult);
|
||||
|
@ -133,7 +134,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
|
||||
static Future<ZanoWallet> restore({required ZanoRestoreWalletFromSeedCredentials credentials}) async {
|
||||
final wallet = ZanoWallet(credentials.walletInfo!, credentials.password!);
|
||||
await wallet.connectToNode(node: Node());
|
||||
await wallet.connectToNode(node: Node()..uriRaw = DO_NOT_MERGE_hardcodedNodeUri);
|
||||
final path = await pathForWallet(name: credentials.name, type: credentials.walletInfo!.type);
|
||||
final createWalletResult = await wallet.restoreWalletFromSeed(path, credentials.password!, credentials.mnemonic);
|
||||
await wallet.parseCreateWalletResult(createWalletResult);
|
||||
|
@ -144,7 +145,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
static Future<ZanoWallet> open({required String name, required String password, required WalletInfo walletInfo}) async {
|
||||
final path = await pathForWallet(name: name, type: walletInfo.type);
|
||||
final wallet = ZanoWallet(walletInfo, password);
|
||||
await wallet.connectToNode(node: Node());
|
||||
await wallet.connectToNode(node: Node()..uriRaw = DO_NOT_MERGE_hardcodedNodeUri);
|
||||
final createWalletResult = await wallet.loadWallet(path, password);
|
||||
await wallet.parseCreateWalletResult(createWalletResult);
|
||||
await wallet.init(createWalletResult.wi.address);
|
||||
|
@ -183,7 +184,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
@override
|
||||
Future<void> connectToNode({required Node node}) async {
|
||||
syncStatus = ConnectingSyncStatus();
|
||||
await setupNode();
|
||||
await setupNode(node.uriRaw);
|
||||
syncStatus = ConnectedSyncStatus();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ import 'package:monero/zano.dart' as zano;
|
|||
import 'package:monero/src/generated_bindings_zano.g.dart' as zanoapi;
|
||||
|
||||
mixin ZanoWalletApi {
|
||||
static const _defaultNodeUri = '195.201.107.230:33340';
|
||||
static const _statusDelivered = 'delivered';
|
||||
static const _maxInvokeAttempts = 10;
|
||||
static const _maxReopenAttempts = 5;
|
||||
|
@ -47,21 +46,18 @@ mixin ZanoWalletApi {
|
|||
|
||||
int getCurrentTxFee(TransactionPriority priority) => zano.PlainWallet_getCurrentTxFee(priority.raw);
|
||||
|
||||
String getOpenedWallets() => zano.PlainWallet_getOpenWallets();
|
||||
String getConnectivityStatus() => zano.PlainWallet_getConnectivityStatus();
|
||||
|
||||
void setPassword(String password) => zano.PlainWallet_resetWalletPassword(hWallet, password);
|
||||
|
||||
void closeWallet([int? walletToClose]) {
|
||||
void closeWallet([int? walletToClose]) async {
|
||||
info('close_wallet ${walletToClose ?? hWallet}');
|
||||
final result = zano.PlainWallet_closeWallet(walletToClose ?? hWallet);
|
||||
final result = await _closeWallet(walletToClose ?? hWallet);
|
||||
info('close_wallet result $result');
|
||||
}
|
||||
|
||||
Future<bool> setupNode() async {
|
||||
info('init $_defaultNodeUri');
|
||||
Future<bool> setupNode(String nodeUri) async {
|
||||
info('init $nodeUri');
|
||||
// pathForWallet(name: , type: type)
|
||||
final result = zano.PlainWallet_init(_defaultNodeUri, "", 0);
|
||||
final result = zano.PlainWallet_init(nodeUri, "", 0);
|
||||
info('init result $result');
|
||||
return result == "OK";
|
||||
}
|
||||
|
@ -89,31 +85,14 @@ mixin ZanoWalletApi {
|
|||
}
|
||||
|
||||
Future<String> invokeMethod(String methodName, Object params) async {
|
||||
|
||||
// var invokeResult = zano.PlainWallet_syncCall(
|
||||
// 'invoke',
|
||||
// hWallet,
|
||||
// jsonEncode(
|
||||
// {
|
||||
// "method": "$methodName",
|
||||
// "params": params,
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
final request = jsonEncode({
|
||||
"method": methodName,
|
||||
"params": params,
|
||||
});
|
||||
final invokeResult = await callSyncMethod('invoke', hWallet, request);
|
||||
// final invokeResult = zano.PlainWallet_syncCall(
|
||||
// 'invoke',
|
||||
// hWallet,
|
||||
// request,
|
||||
// );
|
||||
// print("zano: <<< ${invokeResult}");
|
||||
Map<String, dynamic> map;
|
||||
try {
|
||||
map = jsonDecode(invokeResult) as Map<String, dynamic>;
|
||||
map = jsonDecode(invokeResult);
|
||||
} catch (e) {
|
||||
if (invokeResult.contains(Consts.errorWalletWrongId)) throw ZanoWalletException('Wrong wallet id');
|
||||
error('exception in parsing json in invokeMethod: $invokeResult');
|
||||
|
@ -325,7 +304,6 @@ mixin ZanoWalletApi {
|
|||
}
|
||||
final result = CreateWalletResult.fromJson(map!['result'] as Map<String, dynamic>);
|
||||
info('load_wallet3 ${result.name} ${result.wi.address}');
|
||||
zano.PlainWallet_init(_defaultNodeUri, path, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -470,4 +448,11 @@ Future<String> _getWalletInfo(int hWallet) async {
|
|||
json = "";
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
Future<String> _closeWallet(int hWallet) async {
|
||||
final str = await Isolate.run(() async {
|
||||
return zano.PlainWallet_closeWallet(hWallet);
|
||||
});
|
||||
return str;
|
||||
}
|
|
@ -46,7 +46,7 @@ const solanaDefaultNodeUri = 'rpc.ankr.com';
|
|||
const tronDefaultNodeUri = 'trx.nownodes.io';
|
||||
const newCakeWalletBitcoinUri = 'btc-electrum.cakewallet.com:50002';
|
||||
const wowneroDefaultNodeUri = 'node3.monerodevs.org:34568';
|
||||
const zanoDefaultNodeUri = 'zano.org';
|
||||
const zanoDefaultNodeUri = '195.201.107.230:33340';
|
||||
const moneroWorldNodeUri = '.moneroworld.com';
|
||||
|
||||
Future<void> defaultSettingsMigration(
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/node.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
|
||||
ReactionDisposer? _onCurrentNodeChangeReaction;
|
||||
|
|
Loading…
Reference in a new issue