mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
last updates
This commit is contained in:
parent
58e505944c
commit
dda6d4c750
26 changed files with 734 additions and 330 deletions
|
@ -200,7 +200,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
|
||||||
static const dydx = CryptoCurrency(title: 'DYDX', tag: 'ETH', fullName: 'dYdX', raw: 84, name: 'dydx', iconPath: 'assets/images/dydx_icon.png');
|
static const dydx = CryptoCurrency(title: 'DYDX', tag: 'ETH', fullName: 'dYdX', raw: 84, name: 'dydx', iconPath: 'assets/images/dydx_icon.png');
|
||||||
static const steth = CryptoCurrency(title: 'STETH', tag: 'ETH', fullName: 'Lido Staked Ethereum', raw: 85, name: 'steth', iconPath: 'assets/images/steth_icon.png');
|
static const steth = CryptoCurrency(title: 'STETH', tag: 'ETH', fullName: 'Lido Staked Ethereum', raw: 85, name: 'steth', iconPath: 'assets/images/steth_icon.png');
|
||||||
static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 86, name: 'zano', iconPath: 'assets/images/zano_icon.png');
|
static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 86, name: 'zano', iconPath: 'assets/images/zano_icon.png');
|
||||||
static const dummy = CryptoCurrency(title: 'DUMMY', tag: 'DUMMY', fullName: 'Dummy', raw: 87, name: 'dummy', iconPath: 'assets/images/dummy_icon.png');
|
static const dummy = CryptoCurrency(title: 'DUMMY', tag: 'DUMMY', fullName: 'Dummy', raw: 87, name: 'dummy', iconPath: 'assets/images/zano_icon.png');
|
||||||
|
|
||||||
|
|
||||||
static final Map<int, CryptoCurrency> _rawCurrencyMap =
|
static final Map<int, CryptoCurrency> _rawCurrencyMap =
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Node extends HiveObject with Keyable {
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
return requestMoneroNode();
|
return requestMoneroNode();
|
||||||
case WalletType.zano:
|
case WalletType.zano:
|
||||||
return requestMoneroNode();
|
return requestZanoNode();
|
||||||
case WalletType.ethereum:
|
case WalletType.ethereum:
|
||||||
return requestElectrumServer();
|
return requestElectrumServer();
|
||||||
case WalletType.dummy:
|
case WalletType.dummy:
|
||||||
|
@ -145,6 +145,11 @@ class Node extends HiveObject with Keyable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> requestZanoNode() async {
|
||||||
|
// TODO: fix it
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> requestMoneroNode() async {
|
Future<bool> requestMoneroNode() async {
|
||||||
final path = '/json_rpc';
|
final path = '/json_rpc';
|
||||||
final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
|
final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
|
||||||
|
|
|
@ -428,6 +428,11 @@ extern "C"
|
||||||
return strdup(plain_wallet::try_pull_result(job_id).c_str());
|
return strdup(plain_wallet::try_pull_result(job_id).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* sync_call(const std::string& method_name, uint64_t instance_id, const std::string& params)
|
||||||
|
{
|
||||||
|
return strdup(plain_wallet::sync_call(method_name, instance_id, params).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
char* get_connectivity_status()
|
char* get_connectivity_status()
|
||||||
{
|
{
|
||||||
return strdup(plain_wallet::get_connectivity_status().c_str());
|
return strdup(plain_wallet::get_connectivity_status().c_str());
|
||||||
|
@ -847,6 +852,11 @@ extern "C"
|
||||||
//return m_wallet->trustedDaemon();
|
//return m_wallet->trustedDaemon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* get_version()
|
||||||
|
{
|
||||||
|
return strdup(plain_wallet::get_version().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,29 +7,29 @@ import 'package:cw_zano/api/structs/account_row.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:cw_zano/api/wallet.dart';
|
import 'package:cw_zano/api/wallet.dart';
|
||||||
|
|
||||||
final accountSizeNative = zanoApi
|
// final accountSizeNative = zanoApi
|
||||||
.lookup<NativeFunction<account_size>>('account_size')
|
// .lookup<NativeFunction<account_size>>('account_size')
|
||||||
.asFunction<SubaddressSize>();
|
// .asFunction<SubaddressSize>();
|
||||||
|
|
||||||
final accountRefreshNative = zanoApi
|
// final accountRefreshNative = zanoApi
|
||||||
.lookup<NativeFunction<account_refresh>>('account_refresh')
|
// .lookup<NativeFunction<account_refresh>>('account_refresh')
|
||||||
.asFunction<AccountRefresh>();
|
// .asFunction<AccountRefresh>();
|
||||||
|
|
||||||
final accountGetAllNative = zanoApi
|
// final accountGetAllNative = zanoApi
|
||||||
.lookup<NativeFunction<account_get_all>>('account_get_all')
|
// .lookup<NativeFunction<account_get_all>>('account_get_all')
|
||||||
.asFunction<AccountGetAll>();
|
// .asFunction<AccountGetAll>();
|
||||||
|
|
||||||
final accountAddNewNative = zanoApi
|
// final accountAddNewNative = zanoApi
|
||||||
.lookup<NativeFunction<account_add_new>>('account_add_row')
|
// .lookup<NativeFunction<account_add_new>>('account_add_row')
|
||||||
.asFunction<AccountAddNew>();
|
// .asFunction<AccountAddNew>();
|
||||||
|
|
||||||
final accountSetLabelNative = zanoApi
|
// final accountSetLabelNative = zanoApi
|
||||||
.lookup<NativeFunction<account_set_label>>('account_set_label_row')
|
// .lookup<NativeFunction<account_set_label>>('account_set_label_row')
|
||||||
.asFunction<AccountSetLabel>();
|
// .asFunction<AccountSetLabel>();
|
||||||
|
|
||||||
bool isUpdating = false;
|
bool isUpdating = false;
|
||||||
|
|
||||||
void refreshAccounts() {
|
/**void refreshAccounts() {
|
||||||
try {
|
try {
|
||||||
isUpdating = true;
|
isUpdating = true;
|
||||||
accountRefreshNative();
|
accountRefreshNative();
|
||||||
|
@ -38,9 +38,9 @@ void refreshAccounts() {
|
||||||
isUpdating = false;
|
isUpdating = false;
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
List<AccountRow> getAllAccount() {
|
/**List<AccountRow> getAllAccount() {
|
||||||
final size = accountSizeNative();
|
final size = accountSizeNative();
|
||||||
final accountAddressesPointer = accountGetAllNative();
|
final accountAddressesPointer = accountGetAllNative();
|
||||||
final accountAddresses = accountAddressesPointer.asTypedList(size);
|
final accountAddresses = accountAddressesPointer.asTypedList(size);
|
||||||
|
@ -48,38 +48,38 @@ List<AccountRow> getAllAccount() {
|
||||||
return accountAddresses
|
return accountAddresses
|
||||||
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
|
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void addAccountSync({required String label}) {
|
/**void addAccountSync({required String label}) {
|
||||||
final labelPointer = label.toNativeUtf8();
|
final labelPointer = label.toNativeUtf8();
|
||||||
accountAddNewNative(labelPointer);
|
accountAddNewNative(labelPointer);
|
||||||
calloc.free(labelPointer);
|
calloc.free(labelPointer);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void setLabelForAccountSync(
|
/**void setLabelForAccountSync(
|
||||||
{required int accountIndex, required String label}) {
|
{required int accountIndex, required String label}) {
|
||||||
final labelPointer = label.toNativeUtf8();
|
final labelPointer = label.toNativeUtf8();
|
||||||
accountSetLabelNative(accountIndex, labelPointer);
|
accountSetLabelNative(accountIndex, labelPointer);
|
||||||
calloc.free(labelPointer);
|
calloc.free(labelPointer);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void _addAccount(String label) => addAccountSync(label: label);
|
/**void _addAccount(String label) => addAccountSync(label: label);*/
|
||||||
|
|
||||||
void _setLabelForAccount(Map<String, dynamic> args) {
|
/**void _setLabelForAccount(Map<String, dynamic> args) {
|
||||||
final label = args['label'] as String;
|
final label = args['label'] as String;
|
||||||
final accountIndex = args['accountIndex'] as int;
|
final accountIndex = args['accountIndex'] as int;
|
||||||
|
|
||||||
setLabelForAccountSync(label: label, accountIndex: accountIndex);
|
setLabelForAccountSync(label: label, accountIndex: accountIndex);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Future<void> addAccount({required String label}) async {
|
/**Future<void> addAccount({required String label}) async {
|
||||||
await compute(_addAccount, label);
|
await compute(_addAccount, label);
|
||||||
await store();
|
await store();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Future<void> setLabelForAccount(
|
/**Future<void> setLabelForAccount(
|
||||||
{required int accountIndex, required String label}) async {
|
{required int accountIndex, required String label}) async {
|
||||||
await compute(
|
await compute(
|
||||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
||||||
await store();
|
await store();
|
||||||
}
|
}*/
|
||||||
|
|
189
cw_zano/lib/api/calls.dart
Normal file
189
cw_zano/lib/api/calls.dart
Normal file
|
@ -0,0 +1,189 @@
|
||||||
|
import 'dart:ffi';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:cw_zano/api/convert_utf8_to_string.dart';
|
||||||
|
import 'package:cw_zano/api/model.dart';
|
||||||
|
import 'package:cw_zano/api/zano_api.dart';
|
||||||
|
import 'package:ffi/ffi.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
final _asyncCallNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_async_call>>('async_call')
|
||||||
|
.asFunction<_AsyncCall>();
|
||||||
|
typedef _async_call = Pointer<Utf8> Function(
|
||||||
|
Pointer<Utf8>, Int64, Pointer<Utf8>);
|
||||||
|
typedef _AsyncCall = Pointer<Utf8> Function(
|
||||||
|
Pointer<Utf8> methodName, int hWallet, Pointer<Utf8> params);
|
||||||
|
|
||||||
|
// get_wallet_status
|
||||||
|
final _getWalletStatusNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_get_wallet_status>>('get_wallet_status')
|
||||||
|
.asFunction<_GetWalletStatus>();
|
||||||
|
typedef _get_wallet_status = Pointer<Utf8> Function(Int64);
|
||||||
|
typedef _GetWalletStatus = Pointer<Utf8> Function(int hWallet);
|
||||||
|
|
||||||
|
// get_wallet_info
|
||||||
|
final _getWalletInfoNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_get_wallet_info>>('get_wallet_info')
|
||||||
|
.asFunction<_GetWalletInfo>();
|
||||||
|
typedef _get_wallet_info = Pointer<Utf8> Function(Int64);
|
||||||
|
typedef _GetWalletInfo = Pointer<Utf8> Function(int hWallet);
|
||||||
|
|
||||||
|
// get_connectivity_status
|
||||||
|
final _getConnectivityStatusNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_get_connectivity_status>>('get_connectivity_status')
|
||||||
|
.asFunction<_GetConnectivityStatus>();
|
||||||
|
typedef _get_connectivity_status = Pointer<Utf8> Function();
|
||||||
|
typedef _GetConnectivityStatus = Pointer<Utf8> Function();
|
||||||
|
|
||||||
|
// get_version
|
||||||
|
final _getVersionNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_get_version>>('get_version')
|
||||||
|
.asFunction<_GetVersion>();
|
||||||
|
typedef _get_version = Pointer<Utf8> Function();
|
||||||
|
typedef _GetVersion = Pointer<Utf8> Function();
|
||||||
|
|
||||||
|
// load_wallet
|
||||||
|
final _loadWalletNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_load_wallet>>('load_wallet')
|
||||||
|
.asFunction<_LoadWallet>();
|
||||||
|
typedef _load_wallet = Pointer<Utf8> Function(
|
||||||
|
Pointer<Utf8>, Pointer<Utf8>, Int8);
|
||||||
|
typedef _LoadWallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int);
|
||||||
|
|
||||||
|
// try_pull_result
|
||||||
|
final _tryPullResultNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_try_pull_result>>('try_pull_result')
|
||||||
|
.asFunction<_TryPullResult>();
|
||||||
|
typedef _try_pull_result = Pointer<Utf8> Function(Int64);
|
||||||
|
typedef _TryPullResult = Pointer<Utf8> Function(int hWallet);
|
||||||
|
|
||||||
|
// close_wallet
|
||||||
|
final _closeWalletNative = zanoApi
|
||||||
|
.lookup<NativeFunction<_close_wallet>>('close_wallet')
|
||||||
|
.asFunction<_closeWalletStatus>();
|
||||||
|
typedef _close_wallet = Void Function(Int64);
|
||||||
|
typedef _closeWalletStatus = void Function(int hWallet);
|
||||||
|
|
||||||
|
String doAsyncCall(
|
||||||
|
{required String methodName,
|
||||||
|
required int hWallet,
|
||||||
|
required String params}) {
|
||||||
|
final methodNamePointer = methodName.toNativeUtf8();
|
||||||
|
final paramsPointer = params.toNativeUtf8();
|
||||||
|
|
||||||
|
debugPrint(
|
||||||
|
"async_call method_name $methodName hWallet $hWallet params $params");
|
||||||
|
final result = convertUTF8ToString(
|
||||||
|
pointer: _asyncCallNative(methodNamePointer, hWallet, paramsPointer));
|
||||||
|
|
||||||
|
calloc.free(methodNamePointer);
|
||||||
|
calloc.free(paramsPointer);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> invokeMethod(
|
||||||
|
int hWallet, String methodName, String params) async {
|
||||||
|
debugPrint('invoke method $methodName params $params');
|
||||||
|
final invokeResult = doAsyncCall(
|
||||||
|
methodName: 'invoke',
|
||||||
|
hWallet: hWallet,
|
||||||
|
params: json.encode({
|
||||||
|
'method': methodName,
|
||||||
|
'params': params,
|
||||||
|
}));
|
||||||
|
debugPrint('invoke result $invokeResult');
|
||||||
|
final map = json.decode(invokeResult);
|
||||||
|
if (map["job_id"] != null) {
|
||||||
|
bool done = false;
|
||||||
|
do {
|
||||||
|
await Future.delayed(Duration(seconds: 3));
|
||||||
|
final result = tryPullResult(map["job_id"] as int);
|
||||||
|
final map2 = json.decode(result);
|
||||||
|
done = map2["result"] == null || map2["result"]["error"] == null;
|
||||||
|
} while (!done);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> store(int hWallet) async {
|
||||||
|
// debugPrint("store hWallet $hWallet");
|
||||||
|
// final result = doAsyncCall(
|
||||||
|
// methodName: 'invoke',
|
||||||
|
// hWallet: hWallet,
|
||||||
|
// params: "{method: 'store', params: {}}");
|
||||||
|
// debugPrint('store result $result');
|
||||||
|
// final map = json.decode(result);
|
||||||
|
// if (map["job_id"] != null) {
|
||||||
|
// await Future.delayed(Duration(seconds: 1));
|
||||||
|
// tryPullResult(map["job_id"] as int);
|
||||||
|
// }
|
||||||
|
return await invokeMethod(hWallet, 'store', '{}');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> getRecentTxsAndInfo(
|
||||||
|
{required int hWallet,
|
||||||
|
required int offset,
|
||||||
|
required int count,
|
||||||
|
bool updateProvisionInfo = true}) async {
|
||||||
|
return await invokeMethod(
|
||||||
|
hWallet,
|
||||||
|
'get_recent_txs_and_info',
|
||||||
|
json.encode(
|
||||||
|
GetRecentTxsAndInfoParams(
|
||||||
|
offset: offset,
|
||||||
|
count: count,
|
||||||
|
updateProvisionInfo: updateProvisionInfo),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getWalletStatus(int hWallet) {
|
||||||
|
debugPrint("get_wallet_status hWallet $hWallet");
|
||||||
|
final result = convertUTF8ToString(pointer: _getWalletStatusNative(hWallet));
|
||||||
|
debugPrint('get_wallet_status result $result');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeWallet(int hWallet) {
|
||||||
|
debugPrint("close_wallet hWallet $hWallet");
|
||||||
|
_closeWalletNative(hWallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getWalletInfo(int hWallet) {
|
||||||
|
debugPrint('get_wallet_info hWallet $hWallet');
|
||||||
|
final result = convertUTF8ToString(pointer: _getWalletInfoNative(hWallet));
|
||||||
|
debugPrint('get_wallet_info result $result');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getConnectivityStatus() {
|
||||||
|
final result = convertUTF8ToString(pointer: _getConnectivityStatusNative());
|
||||||
|
debugPrint('get_connectivity_status result $result');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getVersion() {
|
||||||
|
final result = convertUTF8ToString(pointer: _getVersionNative());
|
||||||
|
debugPrint('get_version result $result');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String loadWallet(String path, String password, int nettype) {
|
||||||
|
debugPrint("load_wallet path $path password $password nettype $nettype");
|
||||||
|
final pathPointer = path.toNativeUtf8();
|
||||||
|
final passwordPointer = password.toNativeUtf8();
|
||||||
|
final result = convertUTF8ToString(
|
||||||
|
pointer: _loadWalletNative(pathPointer, passwordPointer, nettype),
|
||||||
|
);
|
||||||
|
debugPrint("load_wallet result $result");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String tryPullResult(int jobId) {
|
||||||
|
debugPrint('try_pull_result jobId $jobId');
|
||||||
|
final result = convertUTF8ToString(pointer: _tryPullResultNative(jobId));
|
||||||
|
debugPrint('try_pull_result result $result');
|
||||||
|
return result;
|
||||||
|
}
|
49
cw_zano/lib/api/model.dart
Normal file
49
cw_zano/lib/api/model.dart
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
class Destination {
|
||||||
|
final String amount;
|
||||||
|
final String address;
|
||||||
|
final String assetId;
|
||||||
|
|
||||||
|
Destination({required this.amount, required this.address, required this.assetId});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"amount": amount,
|
||||||
|
"address": address,
|
||||||
|
"asset_id": assetId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransferParams {
|
||||||
|
final List<Destination> destinations;
|
||||||
|
final int fee;
|
||||||
|
final int mixin;
|
||||||
|
final String paymentId;
|
||||||
|
final String comment;
|
||||||
|
final bool pushPayer;
|
||||||
|
final bool hideReceiver;
|
||||||
|
|
||||||
|
TransferParams({required this.destinations, required this.fee, required this.mixin, required this.paymentId, required this.comment, required this.pushPayer, required this.hideReceiver});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"destinations": destinations,
|
||||||
|
"fee": fee,
|
||||||
|
"mixin": mixin,
|
||||||
|
"payment_id": paymentId,
|
||||||
|
"comment": comment,
|
||||||
|
"push_payer": pushPayer,
|
||||||
|
"hide_receiver": hideReceiver,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetRecentTxsAndInfoParams {
|
||||||
|
final int offset;
|
||||||
|
final int count;
|
||||||
|
final bool updateProvisionInfo;
|
||||||
|
|
||||||
|
GetRecentTxsAndInfoParams({required this.offset, required this.count, required this.updateProvisionInfo});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"offset": offset,
|
||||||
|
"count": count,
|
||||||
|
"update_provision_info": updateProvisionInfo,
|
||||||
|
};
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ import 'package:cw_zano/api/structs/pending_transaction.dart';
|
||||||
import 'package:cw_zano/api/structs/ut8_box.dart';
|
import 'package:cw_zano/api/structs/ut8_box.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
|
|
||||||
typedef create_wallet = Int8 Function(
|
typedef create_wallet = Pointer<Utf8> Function(
|
||||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>);
|
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>);
|
||||||
|
|
||||||
typedef restore_wallet_from_seed = Int8 Function(
|
typedef restore_wallet_from_seed = Int8 Function(
|
||||||
|
@ -47,7 +47,7 @@ typedef get_node_height = Int64 Function();
|
||||||
typedef is_connected = Int8 Function();
|
typedef is_connected = Int8 Function();
|
||||||
|
|
||||||
typedef setup_node = Int8 Function(Pointer<Utf8>, Pointer<Utf8>?,
|
typedef setup_node = Int8 Function(Pointer<Utf8>, Pointer<Utf8>?,
|
||||||
Pointer<Utf8>?, Int8, Int8, Pointer<Utf8>?, Pointer<Utf8>);
|
Pointer<Utf8>?, Int8, Int8, Pointer<Utf8>);
|
||||||
|
|
||||||
typedef start_refresh = Void Function();
|
typedef start_refresh = Void Function();
|
||||||
|
|
||||||
|
@ -107,7 +107,6 @@ typedef transaction_create = Int8 Function(
|
||||||
Pointer<Utf8> paymentId,
|
Pointer<Utf8> paymentId,
|
||||||
Pointer<Utf8> amount,
|
Pointer<Utf8> amount,
|
||||||
Int8 priorityRaw,
|
Int8 priorityRaw,
|
||||||
Int32 subaddrAccount,
|
|
||||||
Pointer<Utf8Box> error,
|
Pointer<Utf8Box> error,
|
||||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||||
|
|
||||||
|
@ -118,7 +117,6 @@ typedef transaction_create_mult_dest = Int8 Function(
|
||||||
Pointer<Pointer<Utf8>> amounts,
|
Pointer<Pointer<Utf8>> amounts,
|
||||||
Int32 size,
|
Int32 size,
|
||||||
Int8 priorityRaw,
|
Int8 priorityRaw,
|
||||||
Int32 subaddrAccount,
|
|
||||||
Pointer<Utf8Box> error,
|
Pointer<Utf8Box> error,
|
||||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:cw_zano/api/zano_api.dart';
|
||||||
import 'package:cw_zano/api/structs/subaddress_row.dart';
|
import 'package:cw_zano/api/structs/subaddress_row.dart';
|
||||||
import 'package:cw_zano/api/wallet.dart';
|
import 'package:cw_zano/api/wallet.dart';
|
||||||
|
|
||||||
|
/**
|
||||||
final subaddressSizeNative = zanoApi
|
final subaddressSizeNative = zanoApi
|
||||||
.lookup<NativeFunction<subaddrress_size>>('subaddrress_size')
|
.lookup<NativeFunction<subaddrress_size>>('subaddrress_size')
|
||||||
.asFunction<SubaddressSize>();
|
.asFunction<SubaddressSize>();
|
||||||
|
@ -99,3 +100,4 @@ Future setLabelForSubaddress(
|
||||||
});
|
});
|
||||||
await store();
|
await store();
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -1,6 +1,6 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'package:cw_zano/api/convert_utf8_to_string.dart';
|
import 'package:cw_zano/api/convert_utf8_to_string.dart';
|
||||||
import 'package:cw_zano/api/monero_output.dart';
|
import 'package:cw_zano/api/zano_output.dart';
|
||||||
import 'package:cw_zano/api/structs/ut8_box.dart';
|
import 'package:cw_zano/api/structs/ut8_box.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -11,13 +11,13 @@ import 'package:cw_zano/api/structs/transaction_info_row.dart';
|
||||||
import 'package:cw_zano/api/structs/pending_transaction.dart';
|
import 'package:cw_zano/api/structs/pending_transaction.dart';
|
||||||
import 'package:cw_zano/api/exceptions/creation_transaction_exception.dart';
|
import 'package:cw_zano/api/exceptions/creation_transaction_exception.dart';
|
||||||
|
|
||||||
final transactionsRefreshNative = zanoApi
|
/**final transactionsRefreshNative = zanoApi
|
||||||
.lookup<NativeFunction<transactions_refresh>>('transactions_refresh')
|
.lookup<NativeFunction<transactions_refresh>>('transactions_refresh')
|
||||||
.asFunction<TransactionsRefresh>();
|
.asFunction<TransactionsRefresh>();*/
|
||||||
|
|
||||||
final transactionsCountNative = zanoApi
|
/**final transactionsCountNative = zanoApi
|
||||||
.lookup<NativeFunction<transactions_count>>('transactions_count')
|
.lookup<NativeFunction<transactions_count>>('transactions_count')
|
||||||
.asFunction<TransactionsCount>();
|
.asFunction<TransactionsCount>();*/
|
||||||
|
|
||||||
final transactionsGetAllNative = zanoApi
|
final transactionsGetAllNative = zanoApi
|
||||||
.lookup<NativeFunction<transactions_get_all>>('transactions_get_all')
|
.lookup<NativeFunction<transactions_get_all>>('transactions_get_all')
|
||||||
|
@ -53,18 +53,29 @@ String getTxKey(String txId) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshTransactions() => transactionsRefreshNative();
|
void refreshTransactions() {
|
||||||
|
// TODO: fix it
|
||||||
|
//transactionsRefreshNative();
|
||||||
|
debugPrint("refreshing transactions");
|
||||||
|
}
|
||||||
|
|
||||||
int countOfTransactions() => transactionsCountNative();
|
int countOfTransactions() {
|
||||||
|
//return transactionsCountNative();
|
||||||
|
// TODO: fix it
|
||||||
|
debugPrint("count of transactions");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
List<TransactionInfoRow> getAllTransations() {
|
List<TransactionInfoRow> getAllTransations() {
|
||||||
final size = transactionsCountNative();
|
// TODO: fix it
|
||||||
|
return [];
|
||||||
|
/*final size = transactionsCountNative();
|
||||||
final transactionsPointer = transactionsGetAllNative();
|
final transactionsPointer = transactionsGetAllNative();
|
||||||
final transactionsAddresses = transactionsPointer.asTypedList(size);
|
final transactionsAddresses = transactionsPointer.asTypedList(size);
|
||||||
|
|
||||||
return transactionsAddresses
|
return transactionsAddresses
|
||||||
.map((addr) => Pointer<TransactionInfoRow>.fromAddress(addr).ref)
|
.map((addr) => Pointer<TransactionInfoRow>.fromAddress(addr).ref)
|
||||||
.toList();
|
.toList();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingTransactionDescription createTransactionSync(
|
PendingTransactionDescription createTransactionSync(
|
||||||
|
@ -72,8 +83,7 @@ PendingTransactionDescription createTransactionSync(
|
||||||
required String assetType,
|
required String assetType,
|
||||||
required String paymentId,
|
required String paymentId,
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
String? amount,
|
String? amount}) {
|
||||||
int accountIndex = 0}) {
|
|
||||||
final addressPointer = address.toNativeUtf8();
|
final addressPointer = address.toNativeUtf8();
|
||||||
final assetTypePointer = assetType.toNativeUtf8();
|
final assetTypePointer = assetType.toNativeUtf8();
|
||||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
final paymentIdPointer = paymentId.toNativeUtf8();
|
||||||
|
@ -86,7 +96,6 @@ PendingTransactionDescription createTransactionSync(
|
||||||
paymentIdPointer,
|
paymentIdPointer,
|
||||||
amountPointer,
|
amountPointer,
|
||||||
priorityRaw,
|
priorityRaw,
|
||||||
accountIndex,
|
|
||||||
errorMessagePointer,
|
errorMessagePointer,
|
||||||
pendingTransactionRawPointer) !=
|
pendingTransactionRawPointer) !=
|
||||||
0;
|
0;
|
||||||
|
@ -113,11 +122,10 @@ PendingTransactionDescription createTransactionSync(
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingTransactionDescription createTransactionMultDestSync(
|
PendingTransactionDescription createTransactionMultDestSync(
|
||||||
{required List<MoneroOutput> outputs,
|
{required List<ZanoOutput> outputs,
|
||||||
required String assetType,
|
required String assetType,
|
||||||
required String paymentId,
|
required String paymentId,
|
||||||
required int priorityRaw,
|
required int priorityRaw}) {
|
||||||
int accountIndex = 0}) {
|
|
||||||
final int size = outputs.length;
|
final int size = outputs.length;
|
||||||
final List<Pointer<Utf8>> addressesPointers =
|
final List<Pointer<Utf8>> addressesPointers =
|
||||||
outputs.map((output) => output.address.toNativeUtf8()).toList();
|
outputs.map((output) => output.address.toNativeUtf8()).toList();
|
||||||
|
@ -142,7 +150,6 @@ PendingTransactionDescription createTransactionMultDestSync(
|
||||||
amountsPointerPointer,
|
amountsPointerPointer,
|
||||||
size,
|
size,
|
||||||
priorityRaw,
|
priorityRaw,
|
||||||
accountIndex,
|
|
||||||
errorMessagePointer,
|
errorMessagePointer,
|
||||||
pendingTransactionRawPointer) !=
|
pendingTransactionRawPointer) !=
|
||||||
0;
|
0;
|
||||||
|
@ -193,30 +200,26 @@ PendingTransactionDescription _createTransactionSync(Map args) {
|
||||||
final paymentId = args['paymentId'] as String;
|
final paymentId = args['paymentId'] as String;
|
||||||
final amount = args['amount'] as String;
|
final amount = args['amount'] as String;
|
||||||
final priorityRaw = args['priorityRaw'] as int;
|
final priorityRaw = args['priorityRaw'] as int;
|
||||||
final accountIndex = args['accountIndex'] as int;
|
|
||||||
|
|
||||||
return createTransactionSync(
|
return createTransactionSync(
|
||||||
address: address,
|
address: address,
|
||||||
assetType: assetType,
|
assetType: assetType,
|
||||||
paymentId: paymentId,
|
paymentId: paymentId,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
priorityRaw: priorityRaw,
|
priorityRaw: priorityRaw);
|
||||||
accountIndex: accountIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingTransactionDescription _createTransactionMultDestSync(Map args) {
|
PendingTransactionDescription _createTransactionMultDestSync(Map args) {
|
||||||
final outputs = args['outputs'] as List<MoneroOutput>;
|
final outputs = args['outputs'] as List<ZanoOutput>;
|
||||||
final assetType = args['assetType'] as String;
|
final assetType = args['assetType'] as String;
|
||||||
final paymentId = args['paymentId'] as String;
|
final paymentId = args['paymentId'] as String;
|
||||||
final priorityRaw = args['priorityRaw'] as int;
|
final priorityRaw = args['priorityRaw'] as int;
|
||||||
final accountIndex = args['accountIndex'] as int;
|
|
||||||
|
|
||||||
return createTransactionMultDestSync(
|
return createTransactionMultDestSync(
|
||||||
outputs: outputs,
|
outputs: outputs,
|
||||||
assetType: assetType,
|
assetType: assetType,
|
||||||
paymentId: paymentId,
|
paymentId: paymentId,
|
||||||
priorityRaw: priorityRaw,
|
priorityRaw: priorityRaw);
|
||||||
accountIndex: accountIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<PendingTransactionDescription> createTransaction(
|
Future<PendingTransactionDescription> createTransaction(
|
||||||
|
@ -224,27 +227,23 @@ Future<PendingTransactionDescription> createTransaction(
|
||||||
required String assetType,
|
required String assetType,
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
String? amount,
|
String? amount,
|
||||||
String paymentId = '',
|
String paymentId = ''}) =>
|
||||||
int accountIndex = 0}) =>
|
|
||||||
compute(_createTransactionSync, {
|
compute(_createTransactionSync, {
|
||||||
'address': address,
|
'address': address,
|
||||||
'assetType': assetType,
|
'assetType': assetType,
|
||||||
'paymentId': paymentId,
|
'paymentId': paymentId,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'priorityRaw': priorityRaw,
|
'priorityRaw': priorityRaw,
|
||||||
'accountIndex': accountIndex
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<PendingTransactionDescription> createTransactionMultDest(
|
Future<PendingTransactionDescription> createTransactionMultDest(
|
||||||
{required List<MoneroOutput> outputs,
|
{required List<ZanoOutput> outputs,
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
String? assetType,
|
String? assetType,
|
||||||
String paymentId = '',
|
String paymentId = ''}) =>
|
||||||
int accountIndex = 0}) =>
|
|
||||||
compute(_createTransactionMultDestSync, {
|
compute(_createTransactionMultDestSync, {
|
||||||
'outputs': outputs,
|
'outputs': outputs,
|
||||||
'assetType': assetType,
|
'assetType': assetType,
|
||||||
'paymentId': paymentId,
|
'paymentId': paymentId,
|
||||||
'priorityRaw': priorityRaw,
|
'priorityRaw': priorityRaw,
|
||||||
'accountIndex': accountIndex
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'package:cw_zano/api/structs/pending_transaction.dart';
|
||||||
import 'package:cw_zano/api/structs/ut8_box.dart';
|
import 'package:cw_zano/api/structs/ut8_box.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
|
|
||||||
typedef CreateWallet = int Function(
|
typedef CreateWallet = Pointer<Utf8> Function(
|
||||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>);
|
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>);
|
||||||
|
|
||||||
typedef RestoreWalletFromSeed = int Function(
|
typedef RestoreWalletFromSeed = int Function(
|
||||||
|
@ -47,7 +47,7 @@ typedef GetNodeHeight = int Function();
|
||||||
typedef IsConnected = int Function();
|
typedef IsConnected = int Function();
|
||||||
|
|
||||||
typedef SetupNode = int Function(Pointer<Utf8>, Pointer<Utf8>?, Pointer<Utf8>?,
|
typedef SetupNode = int Function(Pointer<Utf8>, Pointer<Utf8>?, Pointer<Utf8>?,
|
||||||
int, int, Pointer<Utf8>?, Pointer<Utf8>);
|
int, int, Pointer<Utf8>);
|
||||||
|
|
||||||
typedef StartRefresh = void Function();
|
typedef StartRefresh = void Function();
|
||||||
|
|
||||||
|
@ -105,7 +105,6 @@ typedef TransactionCreate = int Function(
|
||||||
Pointer<Utf8> paymentId,
|
Pointer<Utf8> paymentId,
|
||||||
Pointer<Utf8> amount,
|
Pointer<Utf8> amount,
|
||||||
int priorityRaw,
|
int priorityRaw,
|
||||||
int subaddrAccount,
|
|
||||||
Pointer<Utf8Box> error,
|
Pointer<Utf8Box> error,
|
||||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||||
|
|
||||||
|
@ -116,7 +115,6 @@ typedef TransactionCreateMultDest = int Function(
|
||||||
Pointer<Pointer<Utf8>> amounts,
|
Pointer<Pointer<Utf8>> amounts,
|
||||||
int size,
|
int size,
|
||||||
int priorityRaw,
|
int priorityRaw,
|
||||||
int subaddrAccount,
|
|
||||||
Pointer<Utf8Box> error,
|
Pointer<Utf8Box> error,
|
||||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:cw_zano/api/convert_utf8_to_string.dart';
|
||||||
import 'package:cw_zano/api/signatures.dart';
|
import 'package:cw_zano/api/signatures.dart';
|
||||||
import 'package:cw_zano/api/types.dart';
|
import 'package:cw_zano/api/types.dart';
|
||||||
import 'package:cw_zano/api/zano_api.dart';
|
import 'package:cw_zano/api/zano_api.dart';
|
||||||
|
import 'package:cw_zano/api/calls.dart' as calls;
|
||||||
import 'package:cw_zano/api/exceptions/setup_wallet_exception.dart';
|
import 'package:cw_zano/api/exceptions/setup_wallet_exception.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
@ -16,8 +17,8 @@ final getFileNameNative = zanoApi
|
||||||
.lookup<NativeFunction<get_filename>>('get_filename')
|
.lookup<NativeFunction<get_filename>>('get_filename')
|
||||||
.asFunction<GetFilename>();
|
.asFunction<GetFilename>();
|
||||||
|
|
||||||
final getSeedNative =
|
/*final getSeedNative =
|
||||||
zanoApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
|
zanoApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();*/
|
||||||
|
|
||||||
final getAddressNative = zanoApi
|
final getAddressNative = zanoApi
|
||||||
.lookup<NativeFunction<get_address>>('get_address')
|
.lookup<NativeFunction<get_address>>('get_address')
|
||||||
|
@ -31,9 +32,9 @@ final getUnlockedBalanceNative = zanoApi
|
||||||
.lookup<NativeFunction<get_unlocked_balanace>>('get_unlocked_balance')
|
.lookup<NativeFunction<get_unlocked_balanace>>('get_unlocked_balance')
|
||||||
.asFunction<GetUnlockedBalance>();
|
.asFunction<GetUnlockedBalance>();
|
||||||
|
|
||||||
final getCurrentHeightNative = zanoApi
|
/**final getCurrentHeightNative = zanoApi
|
||||||
.lookup<NativeFunction<get_current_height>>('get_current_height')
|
.lookup<NativeFunction<get_current_height>>('get_current_height')
|
||||||
.asFunction<GetCurrentHeight>();
|
.asFunction<GetCurrentHeight>();*/
|
||||||
|
|
||||||
final getNodeHeightNative = zanoApi
|
final getNodeHeightNative = zanoApi
|
||||||
.lookup<NativeFunction<get_node_height>>('get_node_height')
|
.lookup<NativeFunction<get_node_height>>('get_node_height')
|
||||||
|
@ -72,9 +73,9 @@ final setPasswordNative = zanoApi
|
||||||
.lookup<NativeFunction<set_password>>('set_password')
|
.lookup<NativeFunction<set_password>>('set_password')
|
||||||
.asFunction<SetPassword>();
|
.asFunction<SetPassword>();
|
||||||
|
|
||||||
final setListenerNative = zanoApi
|
/**final setListenerNative = zanoApi
|
||||||
.lookup<NativeFunction<set_listener>>('set_listener')
|
.lookup<NativeFunction<set_listener>>('set_listener')
|
||||||
.asFunction<SetListener>();
|
.asFunction<SetListener>();*/
|
||||||
|
|
||||||
final getSyncingHeightNative = zanoApi
|
final getSyncingHeightNative = zanoApi
|
||||||
.lookup<NativeFunction<get_syncing_height>>('get_syncing_height')
|
.lookup<NativeFunction<get_syncing_height>>('get_syncing_height')
|
||||||
|
@ -133,7 +134,7 @@ bool isNewTransactionExist() => isNewTransactionExistNative() != 0;
|
||||||
|
|
||||||
String getFilename() => convertUTF8ToString(pointer: getFileNameNative());
|
String getFilename() => convertUTF8ToString(pointer: getFileNameNative());
|
||||||
|
|
||||||
String getSeed() => convertUTF8ToString(pointer: getSeedNative());
|
/**String getSeed() => convertUTF8ToString(pointer: getSeedNative());*/
|
||||||
|
|
||||||
String getAddress({int accountIndex = 0, int addressIndex = 0}) =>
|
String getAddress({int accountIndex = 0, int addressIndex = 0}) =>
|
||||||
convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex));
|
convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex));
|
||||||
|
@ -144,7 +145,11 @@ int getFullBalance({int accountIndex = 0}) =>
|
||||||
int getUnlockedBalance({int accountIndex = 0}) =>
|
int getUnlockedBalance({int accountIndex = 0}) =>
|
||||||
getUnlockedBalanceNative(accountIndex);
|
getUnlockedBalanceNative(accountIndex);
|
||||||
|
|
||||||
int getCurrentHeight() => getCurrentHeightNative();
|
int getCurrentHeight(int hWallet) {
|
||||||
|
calls.getWalletStatus(hWallet);
|
||||||
|
return -1;
|
||||||
|
//return getCurrentHeightNative();
|
||||||
|
}
|
||||||
|
|
||||||
int getNodeHeightSync() => getNodeHeightNative();
|
int getNodeHeightSync() => getNodeHeightNative();
|
||||||
|
|
||||||
|
@ -156,7 +161,7 @@ bool setupNodeSync(
|
||||||
String? password,
|
String? password,
|
||||||
bool useSSL = false,
|
bool useSSL = false,
|
||||||
bool isLightWallet = false,
|
bool isLightWallet = false,
|
||||||
String? socksProxyAddress}) {
|
/*String? socksProxyAddress*/}) {
|
||||||
final addressPointer = address.toNativeUtf8();
|
final addressPointer = address.toNativeUtf8();
|
||||||
Pointer<Utf8>? loginPointer;
|
Pointer<Utf8>? loginPointer;
|
||||||
Pointer<Utf8>? socksProxyAddressPointer;
|
Pointer<Utf8>? socksProxyAddressPointer;
|
||||||
|
@ -170,20 +175,23 @@ bool setupNodeSync(
|
||||||
passwordPointer = password.toNativeUtf8();
|
passwordPointer = password.toNativeUtf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socksProxyAddress != null) {
|
/*if (socksProxyAddress != null) {
|
||||||
socksProxyAddressPointer = socksProxyAddress.toNativeUtf8();
|
socksProxyAddressPointer = socksProxyAddress.toNativeUtf8();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
final errorMessagePointer = ''.toNativeUtf8();
|
final errorMessagePointer = ''.toNativeUtf8();
|
||||||
|
debugPrint("setup_node address $address login $login password $password useSSL $useSSL isLightWallet $isLightWallet");
|
||||||
|
// TODO: here can be ZERO! upd: no
|
||||||
final isSetupNode = setupNodeNative(
|
final isSetupNode = setupNodeNative(
|
||||||
addressPointer,
|
addressPointer,
|
||||||
loginPointer,
|
loginPointer,
|
||||||
passwordPointer,
|
passwordPointer,
|
||||||
_boolToInt(useSSL),
|
_boolToInt(useSSL),
|
||||||
_boolToInt(isLightWallet),
|
_boolToInt(isLightWallet),
|
||||||
socksProxyAddressPointer,
|
/*socksProxyAddressPointer,*/
|
||||||
errorMessagePointer) !=
|
errorMessagePointer) !=
|
||||||
0;
|
0;
|
||||||
|
debugPrint("setup_node result $isSetupNode");
|
||||||
|
|
||||||
calloc.free(addressPointer);
|
calloc.free(addressPointer);
|
||||||
|
|
||||||
|
@ -195,10 +203,11 @@ bool setupNodeSync(
|
||||||
calloc.free(passwordPointer);
|
calloc.free(passwordPointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSetupNode) {
|
// TODO: fix it
|
||||||
|
/**if (!isSetupNode) {
|
||||||
throw SetupWalletException(
|
throw SetupWalletException(
|
||||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return isSetupNode;
|
return isSetupNode;
|
||||||
}
|
}
|
||||||
|
@ -213,10 +222,12 @@ void setRefreshFromBlockHeight({required int height}) =>
|
||||||
void setRecoveringFromSeed({required bool isRecovery}) =>
|
void setRecoveringFromSeed({required bool isRecovery}) =>
|
||||||
setRecoveringFromSeedNative(_boolToInt(isRecovery));
|
setRecoveringFromSeedNative(_boolToInt(isRecovery));
|
||||||
|
|
||||||
void storeSync() {
|
void storeSync(int hWallet) {
|
||||||
final pathPointer = ''.toNativeUtf8();
|
calls.store(hWallet);
|
||||||
|
// TODO: fixit
|
||||||
|
/*final pathPointer = ''.toNativeUtf8();
|
||||||
storeNative(pathPointer);
|
storeNative(pathPointer);
|
||||||
calloc.free(pathPointer);
|
calloc.free(pathPointer);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPasswordSync(String password) {
|
void setPasswordSync(String password) {
|
||||||
|
@ -283,7 +294,8 @@ class SyncListener {
|
||||||
var syncHeight = getSyncingHeight();
|
var syncHeight = getSyncingHeight();
|
||||||
|
|
||||||
if (syncHeight <= 0) {
|
if (syncHeight <= 0) {
|
||||||
syncHeight = getCurrentHeight();
|
// TODO: fix it
|
||||||
|
syncHeight = getCurrentHeight(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_initialSyncHeight <= 0) {
|
if (_initialSyncHeight <= 0) {
|
||||||
|
@ -317,13 +329,13 @@ class SyncListener {
|
||||||
SyncListener setListeners(void Function(int, int, double) onNewBlock,
|
SyncListener setListeners(void Function(int, int, double) onNewBlock,
|
||||||
void Function() onNewTransaction) {
|
void Function() onNewTransaction) {
|
||||||
final listener = SyncListener(onNewBlock, onNewTransaction);
|
final listener = SyncListener(onNewBlock, onNewTransaction);
|
||||||
setListenerNative();
|
/**setListenerNative();*/
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStartup() => onStartupNative();
|
void onStartup() => onStartupNative();
|
||||||
|
|
||||||
void _storeSync(Object _) => storeSync();
|
void _storeSync(int hWallet) => storeSync(hWallet);
|
||||||
|
|
||||||
bool _setupNodeSync(Map args) {
|
bool _setupNodeSync(Map args) {
|
||||||
final address = args['address'] as String;
|
final address = args['address'] as String;
|
||||||
|
@ -331,7 +343,7 @@ bool _setupNodeSync(Map args) {
|
||||||
final password = (args['password'] ?? '') as String;
|
final password = (args['password'] ?? '') as String;
|
||||||
final useSSL = args['useSSL'] as bool;
|
final useSSL = args['useSSL'] as bool;
|
||||||
final isLightWallet = args['isLightWallet'] as bool;
|
final isLightWallet = args['isLightWallet'] as bool;
|
||||||
final socksProxyAddress = (args['socksProxyAddress'] ?? '') as String;
|
/*final socksProxyAddress = (args['socksProxyAddress'] ?? '') as String;*/
|
||||||
|
|
||||||
return setupNodeSync(
|
return setupNodeSync(
|
||||||
address: address,
|
address: address,
|
||||||
|
@ -339,7 +351,7 @@ bool _setupNodeSync(Map args) {
|
||||||
password: password,
|
password: password,
|
||||||
useSSL: useSSL,
|
useSSL: useSSL,
|
||||||
isLightWallet: isLightWallet,
|
isLightWallet: isLightWallet,
|
||||||
socksProxyAddress: socksProxyAddress);
|
/*socksProxyAddress: socksProxyAddress*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isConnected(Object _) => isConnectedSync();
|
bool _isConnected(Object _) => isConnectedSync();
|
||||||
|
@ -348,23 +360,23 @@ int _getNodeHeight(Object _) => getNodeHeightSync();
|
||||||
|
|
||||||
void startRefresh() => startRefreshSync();
|
void startRefresh() => startRefreshSync();
|
||||||
|
|
||||||
Future<void> setupNode(
|
Future<bool> setupNode(
|
||||||
{required String address,
|
{required String address,
|
||||||
String? login,
|
String? login,
|
||||||
String? password,
|
String? password,
|
||||||
bool useSSL = false,
|
bool useSSL = false,
|
||||||
String? socksProxyAddress,
|
/*String? socksProxyAddress,*/
|
||||||
bool isLightWallet = false}) =>
|
bool isLightWallet = false}) =>
|
||||||
compute<Map<String, Object?>, void>(_setupNodeSync, {
|
compute<Map<String, Object?>, bool>(_setupNodeSync, {
|
||||||
'address': address,
|
'address': address,
|
||||||
'login': login,
|
'login': login,
|
||||||
'password': password,
|
'password': password,
|
||||||
'useSSL': useSSL,
|
'useSSL': useSSL,
|
||||||
'isLightWallet': isLightWallet,
|
'isLightWallet': isLightWallet,
|
||||||
'socksProxyAddress': socksProxyAddress
|
//'socksProxyAddress': socksProxyAddress
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> store() => compute<int, void>(_storeSync, 0);
|
Future<void> store(int hWallet) => compute<int, void>(_storeSync, 0);
|
||||||
|
|
||||||
Future<bool> isConnected() => compute(_isConnected, 0);
|
Future<bool> isConnected() => compute(_isConnected, 0);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ final errorStringNative = zanoApi
|
||||||
.lookup<NativeFunction<error_string>>('error_string')
|
.lookup<NativeFunction<error_string>>('error_string')
|
||||||
.asFunction<ErrorString>();
|
.asFunction<ErrorString>();
|
||||||
|
|
||||||
void createWalletSync(
|
String createWalletSync(
|
||||||
{required String path,
|
{required String path,
|
||||||
required String password,
|
required String password,
|
||||||
required String language,
|
required String language,
|
||||||
|
@ -46,20 +46,23 @@ void createWalletSync(
|
||||||
final passwordPointer = password.toNativeUtf8();
|
final passwordPointer = password.toNativeUtf8();
|
||||||
final languagePointer = language.toNativeUtf8();
|
final languagePointer = language.toNativeUtf8();
|
||||||
final errorMessagePointer = ''.toNativeUtf8();
|
final errorMessagePointer = ''.toNativeUtf8();
|
||||||
final isWalletCreated = createWalletNative(pathPointer, passwordPointer,
|
debugPrint("create_wallet path $path password $password language $language");
|
||||||
languagePointer, nettype, errorMessagePointer) !=
|
final result = convertUTF8ToString(pointer: createWalletNative(pathPointer, passwordPointer,
|
||||||
0;
|
languagePointer, nettype, errorMessagePointer));
|
||||||
|
//debugPrint("create_wallet $result");
|
||||||
|
|
||||||
calloc.free(pathPointer);
|
calloc.free(pathPointer);
|
||||||
calloc.free(passwordPointer);
|
calloc.free(passwordPointer);
|
||||||
calloc.free(languagePointer);
|
calloc.free(languagePointer);
|
||||||
|
|
||||||
if (!isWalletCreated) {
|
return result;
|
||||||
|
/*if (hWallet == 0) {
|
||||||
throw WalletCreationException(
|
throw WalletCreationException(
|
||||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupNodeSync(address: "node.moneroworld.com:18089");
|
return hWallet;
|
||||||
|
// setupNodeSync(address: "node.moneroworld.com:18089");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWalletExistSync({required String path}) {
|
bool isWalletExistSync({required String path}) {
|
||||||
|
@ -155,12 +158,12 @@ void loadWallet(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _createWallet(Map<String, dynamic> args) {
|
String _createWallet(Map<String, dynamic> args) {
|
||||||
final path = args['path'] as String;
|
final path = args['path'] as String;
|
||||||
final password = args['password'] as String;
|
final password = args['password'] as String;
|
||||||
final language = args['language'] as String;
|
final language = args['language'] as String;
|
||||||
|
|
||||||
createWalletSync(path: path, password: password, language: language);
|
return createWalletSync(path: path, password: password, language: language);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _restoreFromSeed(Map<String, dynamic> args) {
|
void _restoreFromSeed(Map<String, dynamic> args) {
|
||||||
|
@ -206,12 +209,12 @@ void openWallet(
|
||||||
Future<void> openWalletAsync(Map<String, String> args) async =>
|
Future<void> openWalletAsync(Map<String, String> args) async =>
|
||||||
compute(_openWallet, args);
|
compute(_openWallet, args);
|
||||||
|
|
||||||
Future<void> createWallet(
|
Future<String> createWallet(
|
||||||
{required String path,
|
{required String path,
|
||||||
required String password,
|
required String password,
|
||||||
required String language,
|
required String language,
|
||||||
int nettype = 0}) async =>
|
int nettype = 0}) async =>
|
||||||
compute(_createWallet, {
|
compute<Map<String, dynamic>, String>(_createWallet, {
|
||||||
'path': path,
|
'path': path,
|
||||||
'password': password,
|
'password': password,
|
||||||
'language': language,
|
'language': language,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
class MoneroOutput {
|
class ZanoOutput {
|
||||||
MoneroOutput({required this.address, required this.amount});
|
ZanoOutput({required this.address, required this.amount});
|
||||||
|
|
||||||
final String address;
|
final String address;
|
||||||
final String amount;
|
final String amount;
|
|
@ -3,11 +3,16 @@ import 'package:cw_core/account.dart';
|
||||||
import 'package:cw_core/account_list.dart';
|
import 'package:cw_core/account_list.dart';
|
||||||
import 'package:cw_zano/api/account_list.dart' as account_list;
|
import 'package:cw_zano/api/account_list.dart' as account_list;
|
||||||
|
|
||||||
part 'zano_account_list.g.dart';
|
//part 'zano_account_list.g.dart';
|
||||||
|
/*
|
||||||
class ZanoAccountList = ZanoAccountListBase with _$ZanoAccountList;
|
class ZanoAccountList = ZanoAccountListBase with _$ZanoAccountList;
|
||||||
|
|
||||||
abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
||||||
|
ZanoAccountListBase.simple()
|
||||||
|
: accounts = ObservableList<Account>(),
|
||||||
|
_isRefreshing = false,
|
||||||
|
_isUpdating = false {}
|
||||||
|
|
||||||
ZanoAccountListBase()
|
ZanoAccountListBase()
|
||||||
: accounts = ObservableList<Account>(),
|
: accounts = ObservableList<Account>(),
|
||||||
_isRefreshing = false,
|
_isRefreshing = false,
|
||||||
|
@ -67,7 +72,7 @@ abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void refresh() {
|
void refresh() {
|
||||||
if (_isRefreshing) {
|
/**if (_isRefreshing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,5 +85,5 @@ abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
||||||
print(e);
|
print(e);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}*/
|
||||||
|
|
|
@ -1,16 +1,34 @@
|
||||||
|
import 'package:cw_core/balance.dart';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cw_core/monero_balance.dart';
|
import 'package:cw_core/monero_balance.dart';
|
||||||
import 'package:cw_zano/api/balance_list.dart';
|
import 'package:cw_zano/api/balance_list.dart';
|
||||||
import 'package:cw_zano/api/structs/zano_balance_row.dart';
|
import 'package:cw_zano/api/structs/zano_balance_row.dart';
|
||||||
|
|
||||||
const inactiveBalances = [
|
class ZanoBalance extends Balance {
|
||||||
CryptoCurrency.xcad,
|
ZanoBalance(super.available, super.additional);
|
||||||
CryptoCurrency.xjpy,
|
late int unlockedBalance;
|
||||||
CryptoCurrency.xnok,
|
@override
|
||||||
CryptoCurrency.xnzd
|
// TODO: implement formattedAdditionalBalance
|
||||||
];
|
String get formattedAdditionalBalance {
|
||||||
|
// TODO: fix it
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
Map<CryptoCurrency, MoneroBalance> getZanoBalance({required int accountIndex}) {
|
@override
|
||||||
|
// TODO: implement formattedAvailableBalance
|
||||||
|
String get formattedAvailableBalance {
|
||||||
|
// TODO: fix it
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<CryptoCurrency, ZanoBalance> getZanoBalance() {
|
||||||
|
// TODO: fix it
|
||||||
|
return { CryptoCurrency.zano: ZanoBalance(0, 0) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Map<CryptoCurrency, MoneroBalance> getZanoBalance({required int accountIndex}) {
|
||||||
final fullBalances = getZanoFullBalance(accountIndex: accountIndex);
|
final fullBalances = getZanoFullBalance(accountIndex: accountIndex);
|
||||||
final unlockedBalances = getZanoUnlockedBalance(accountIndex: accountIndex);
|
final unlockedBalances = getZanoUnlockedBalance(accountIndex: accountIndex);
|
||||||
final zanoBalances = <CryptoCurrency, MoneroBalance>{};
|
final zanoBalances = <CryptoCurrency, MoneroBalance>{};
|
||||||
|
@ -32,4 +50,4 @@ Map<CryptoCurrency, MoneroBalance> getZanoBalance({required int accountIndex}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return zanoBalances;
|
return zanoBalances;
|
||||||
}
|
}*/
|
||||||
|
|
|
@ -4,9 +4,9 @@ import 'package:mobx/mobx.dart';
|
||||||
import 'package:cw_zano/api/subaddress_list.dart' as subaddress_list;
|
import 'package:cw_zano/api/subaddress_list.dart' as subaddress_list;
|
||||||
import 'package:cw_core/subaddress.dart';
|
import 'package:cw_core/subaddress.dart';
|
||||||
|
|
||||||
part 'zano_subaddress_list.g.dart';
|
//part 'zano_subaddress_list.g.dart';
|
||||||
|
|
||||||
class ZanoSubaddressList = ZanoSubaddressListBase with _$ZanoSubaddressList;
|
/*class ZanoSubaddressList = ZanoSubaddressListBase with _$ZanoSubaddressList;
|
||||||
|
|
||||||
abstract class ZanoSubaddressListBase with Store {
|
abstract class ZanoSubaddressListBase with Store {
|
||||||
ZanoSubaddressListBase()
|
ZanoSubaddressListBase()
|
||||||
|
@ -85,4 +85,4 @@ abstract class ZanoSubaddressListBase with Store {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
|
@ -3,11 +3,13 @@ import 'dart:io';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cw_core/pathForWallet.dart';
|
import 'package:cw_core/pathForWallet.dart';
|
||||||
import 'package:cw_core/transaction_priority.dart';
|
import 'package:cw_core/transaction_priority.dart';
|
||||||
|
import 'package:cw_zano/api/zano_output.dart';
|
||||||
import 'package:cw_zano/zano_transaction_creation_credentials.dart';
|
import 'package:cw_zano/zano_transaction_creation_credentials.dart';
|
||||||
import 'package:cw_core/monero_amount_format.dart';
|
import 'package:cw_core/monero_amount_format.dart';
|
||||||
import 'package:cw_zano/zano_transaction_creation_exception.dart';
|
import 'package:cw_zano/zano_transaction_creation_exception.dart';
|
||||||
import 'package:cw_zano/zano_transaction_info.dart';
|
import 'package:cw_zano/zano_transaction_info.dart';
|
||||||
import 'package:cw_zano/zano_wallet_addresses.dart';
|
import 'package:cw_zano/zano_wallet_addresses.dart';
|
||||||
|
import 'package:cw_zano/api/calls.dart' as calls;
|
||||||
import 'package:cw_core/monero_wallet_utils.dart';
|
import 'package:cw_core/monero_wallet_utils.dart';
|
||||||
import 'package:cw_zano/api/structs/pending_transaction.dart';
|
import 'package:cw_zano/api/structs/pending_transaction.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -17,7 +19,7 @@ import 'package:cw_zano/api/transaction_history.dart'
|
||||||
//import 'package:cw_zano/wallet.dart';
|
//import 'package:cw_zano/wallet.dart';
|
||||||
import 'package:cw_zano/api/wallet.dart' as zano_wallet;
|
import 'package:cw_zano/api/wallet.dart' as zano_wallet;
|
||||||
import 'package:cw_zano/api/transaction_history.dart' as transaction_history;
|
import 'package:cw_zano/api/transaction_history.dart' as transaction_history;
|
||||||
import 'package:cw_zano/api/monero_output.dart';
|
import 'package:cw_zano/api/zano_output.dart';
|
||||||
import 'package:cw_zano/pending_zano_transaction.dart';
|
import 'package:cw_zano/pending_zano_transaction.dart';
|
||||||
import 'package:cw_core/monero_wallet_keys.dart';
|
import 'package:cw_core/monero_wallet_keys.dart';
|
||||||
import 'package:cw_core/monero_balance.dart';
|
import 'package:cw_core/monero_balance.dart';
|
||||||
|
@ -37,24 +39,35 @@ const moneroBlockSize = 1000;
|
||||||
|
|
||||||
class ZanoWallet = ZanoWalletBase with _$ZanoWallet;
|
class ZanoWallet = ZanoWalletBase with _$ZanoWallet;
|
||||||
|
|
||||||
abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
abstract class ZanoWalletBase
|
||||||
ZanoTransactionHistory, ZanoTransactionInfo> with Store {
|
extends WalletBase<ZanoBalance, ZanoTransactionHistory, ZanoTransactionInfo>
|
||||||
ZanoWalletBase({required WalletInfo walletInfo})
|
with Store {
|
||||||
: balance = ObservableMap.of(getZanoBalance(accountIndex: 0)),
|
ZanoWalletBase.simple({required WalletInfo walletInfo})
|
||||||
|
: balance = ObservableMap(),
|
||||||
_isTransactionUpdating = false,
|
_isTransactionUpdating = false,
|
||||||
_hasSyncAfterStartup = false,
|
_hasSyncAfterStartup = false,
|
||||||
walletAddresses = ZanoWalletAddresses(walletInfo),
|
walletAddresses = ZanoWalletAddresses(walletInfo),
|
||||||
syncStatus = NotConnectedSyncStatus(),
|
syncStatus = NotConnectedSyncStatus(),
|
||||||
super(walletInfo) {
|
super(walletInfo) {
|
||||||
transactionHistory = ZanoTransactionHistory();
|
transactionHistory = ZanoTransactionHistory();
|
||||||
_onAccountChangeReaction =
|
}
|
||||||
|
|
||||||
|
ZanoWalletBase({required WalletInfo walletInfo})
|
||||||
|
: balance = ObservableMap.of({CryptoCurrency.zano: ZanoBalance(0, 0)}),
|
||||||
|
_isTransactionUpdating = false,
|
||||||
|
_hasSyncAfterStartup = false,
|
||||||
|
walletAddresses = ZanoWalletAddresses(walletInfo),
|
||||||
|
syncStatus = NotConnectedSyncStatus(),
|
||||||
|
super(walletInfo) {
|
||||||
|
transactionHistory = ZanoTransactionHistory();
|
||||||
|
/*_onAccountChangeReaction =
|
||||||
reaction((_) => walletAddresses.account, (Account? account) {
|
reaction((_) => walletAddresses.account, (Account? account) {
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
balance.addAll(getZanoBalance(accountIndex: account.id));
|
balance.addAll(getZanoBalance(accountIndex: account.id));
|
||||||
walletAddresses.updateSubaddressList(accountIndex: account.id);
|
/**walletAddresses.updateSubaddressList(accountIndex: account.id);*/
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int _autoSaveInterval = 30;
|
static const int _autoSaveInterval = 30;
|
||||||
|
@ -68,12 +81,18 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@observable
|
@observable
|
||||||
ObservableMap<CryptoCurrency, MoneroBalance> balance;
|
ObservableMap<CryptoCurrency, ZanoBalance> balance;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get seed => zano_wallet.getSeed();
|
String get seed {
|
||||||
|
// TODO: fix it
|
||||||
|
//return calls.seed(hWallet);
|
||||||
|
return "test";
|
||||||
|
/**zano_wallet.getSeed();*/
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
// TODO: ?? why monero
|
||||||
MoneroWalletKeys get keys => MoneroWalletKeys(
|
MoneroWalletKeys get keys => MoneroWalletKeys(
|
||||||
privateSpendKey: zano_wallet.getSecretSpendKey(),
|
privateSpendKey: zano_wallet.getSecretSpendKey(),
|
||||||
privateViewKey: zano_wallet.getSecretViewKey(),
|
privateViewKey: zano_wallet.getSecretViewKey(),
|
||||||
|
@ -81,22 +100,30 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
publicViewKey: zano_wallet.getPublicViewKey());
|
publicViewKey: zano_wallet.getPublicViewKey());
|
||||||
|
|
||||||
zano_wallet.SyncListener? _listener;
|
zano_wallet.SyncListener? _listener;
|
||||||
ReactionDisposer? _onAccountChangeReaction;
|
/**ReactionDisposer? _onAccountChangeReaction;*/
|
||||||
bool _isTransactionUpdating;
|
bool _isTransactionUpdating;
|
||||||
bool _hasSyncAfterStartup;
|
bool _hasSyncAfterStartup;
|
||||||
Timer? _autoSaveTimer;
|
Timer? _autoSaveTimer;
|
||||||
|
|
||||||
|
int _hWallet = 0;
|
||||||
|
|
||||||
|
int get hWallet => _hWallet;
|
||||||
|
|
||||||
|
set hWallet(int value) {
|
||||||
|
_hWallet = value;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await walletAddresses.init();
|
await walletAddresses.init();
|
||||||
balance
|
balance
|
||||||
.addAll(getZanoBalance(accountIndex: walletAddresses.account?.id ?? 0));
|
.addAll(getZanoBalance(/**accountIndex: walletAddresses.account?.id ?? 0*/));
|
||||||
_setListeners();
|
_setListeners();
|
||||||
await updateTransactions();
|
await updateTransactions();
|
||||||
|
|
||||||
if (walletInfo.isRecovery) {
|
if (walletInfo.isRecovery) {
|
||||||
zano_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
|
zano_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
|
||||||
|
|
||||||
if (zano_wallet.getCurrentHeight() <= 1) {
|
if (zano_wallet.getCurrentHeight(hWallet) <= 1) {
|
||||||
zano_wallet.setRefreshFromBlockHeight(height: walletInfo.restoreHeight);
|
zano_wallet.setRefreshFromBlockHeight(height: walletInfo.restoreHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +138,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
@override
|
@override
|
||||||
void close() {
|
void close() {
|
||||||
_listener?.stop();
|
_listener?.stop();
|
||||||
_onAccountChangeReaction?.reaction.dispose();
|
/**_onAccountChangeReaction?.reaction.dispose();*/
|
||||||
_autoSaveTimer?.cancel();
|
_autoSaveTimer?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +147,13 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
try {
|
try {
|
||||||
syncStatus = ConnectingSyncStatus();
|
syncStatus = ConnectingSyncStatus();
|
||||||
await zano_wallet.setupNode(
|
await zano_wallet.setupNode(
|
||||||
address: node.uriRaw,
|
address: "195.201.107.230:33336", // node.uriRaw,
|
||||||
login: node.login,
|
login: "", // node.login,
|
||||||
password: node.password,
|
password: "", // node.password,
|
||||||
useSSL: node.useSSL ?? false,
|
useSSL: false, // node.useSSL ?? false,
|
||||||
isLightWallet: false, // FIXME: hardcoded value
|
isLightWallet: false, // FIXME: hardcoded value
|
||||||
socksProxyAddress: node.socksProxyAddress);
|
/*socksProxyAddress: node.socksProxyAddress*/
|
||||||
|
);
|
||||||
|
|
||||||
zano_wallet.setTrustedDaemon(node.trusted);
|
zano_wallet.setTrustedDaemon(node.trusted);
|
||||||
syncStatus = ConnectedSyncStatus();
|
syncStatus = ConnectedSyncStatus();
|
||||||
|
@ -160,7 +188,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
final hasMultiDestination = outputs.length > 1;
|
final hasMultiDestination = outputs.length > 1;
|
||||||
final assetType =
|
final assetType =
|
||||||
CryptoCurrency.fromString(_credentials.assetType.toLowerCase());
|
CryptoCurrency.fromString(_credentials.assetType.toLowerCase());
|
||||||
final balances = getZanoBalance(accountIndex: walletAddresses.account!.id);
|
final balances = getZanoBalance(/*accountIndex: walletAddresses.account!.id*/);
|
||||||
final unlockedBalance = balances[assetType]!.unlockedBalance;
|
final unlockedBalance = balances[assetType]!.unlockedBalance;
|
||||||
|
|
||||||
PendingTransactionDescription pendingTransactionDescription;
|
PendingTransactionDescription pendingTransactionDescription;
|
||||||
|
@ -184,17 +212,16 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
'You do not have enough coins to send this amount.');
|
'You do not have enough coins to send this amount.');
|
||||||
}
|
}
|
||||||
|
|
||||||
final moneroOutputs = outputs
|
final zanoOutputs = outputs
|
||||||
.map((output) => MoneroOutput(
|
.map((output) => ZanoOutput(
|
||||||
address: output.address,
|
address: output.address,
|
||||||
amount: output.cryptoAmount!.replaceAll(',', '.')))
|
amount: output.cryptoAmount!.replaceAll(',', '.')))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
pendingTransactionDescription =
|
pendingTransactionDescription =
|
||||||
await transaction_history.createTransactionMultDest(
|
await transaction_history.createTransactionMultDest(
|
||||||
outputs: moneroOutputs,
|
outputs: zanoOutputs,
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
priorityRaw: _credentials.priority.serialize());
|
||||||
accountIndex: walletAddresses.account!.id);
|
|
||||||
} else {
|
} else {
|
||||||
final output = outputs.first;
|
final output = outputs.first;
|
||||||
final address = output.isParsedAddress &&
|
final address = output.isParsedAddress &&
|
||||||
|
@ -219,8 +246,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
address: address,
|
address: address,
|
||||||
assetType: _credentials.assetType,
|
assetType: _credentials.assetType,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
priorityRaw: _credentials.priority.serialize());
|
||||||
accountIndex: walletAddresses.account!.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PendingZanoTransaction(pendingTransactionDescription, assetType);
|
return PendingZanoTransaction(pendingTransactionDescription, assetType);
|
||||||
|
@ -252,7 +278,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
Future<void> save() async {
|
Future<void> save() async {
|
||||||
await walletAddresses.updateAddressesInBox();
|
await walletAddresses.updateAddressesInBox();
|
||||||
await backupWalletFiles(name);
|
await backupWalletFiles(name);
|
||||||
await zano_wallet.store();
|
await zano_wallet.store(hWallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -301,7 +327,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
zano_wallet.rescanBlockchainAsync();
|
zano_wallet.rescanBlockchainAsync();
|
||||||
await startSync();
|
await startSync();
|
||||||
_askForUpdateBalance();
|
_askForUpdateBalance();
|
||||||
walletAddresses.accountList.update();
|
/**walletAddresses.accountList.update();*/
|
||||||
await _askForUpdateTransactionHistory();
|
await _askForUpdateTransactionHistory();
|
||||||
await save();
|
await save();
|
||||||
await walletInfo.save();
|
await walletInfo.save();
|
||||||
|
@ -355,7 +381,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final currentHeight = zano_wallet.getCurrentHeight();
|
final currentHeight = zano_wallet.getCurrentHeight(hWallet);
|
||||||
|
|
||||||
if (currentHeight <= 1) {
|
if (currentHeight <= 1) {
|
||||||
final height = _getHeightByDate(walletInfo.date);
|
final height = _getHeightByDate(walletInfo.date);
|
||||||
|
@ -385,7 +411,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
void _askForUpdateBalance() =>
|
void _askForUpdateBalance() =>
|
||||||
balance.addAll(getZanoBalance(accountIndex: walletAddresses.account!.id));
|
balance.addAll(getZanoBalance());
|
||||||
|
|
||||||
Future<void> _askForUpdateTransactionHistory() async =>
|
Future<void> _askForUpdateTransactionHistory() async =>
|
||||||
await updateTransactions();
|
await updateTransactions();
|
||||||
|
@ -395,13 +421,13 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||||
if (walletInfo.isRecovery) {
|
if (walletInfo.isRecovery) {
|
||||||
await _askForUpdateTransactionHistory();
|
await _askForUpdateTransactionHistory();
|
||||||
_askForUpdateBalance();
|
_askForUpdateBalance();
|
||||||
walletAddresses.accountList.update();
|
/*walletAddresses.accountList.update();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocksLeft < 1000) {
|
if (blocksLeft < 1000) {
|
||||||
await _askForUpdateTransactionHistory();
|
await _askForUpdateTransactionHistory();
|
||||||
_askForUpdateBalance();
|
_askForUpdateBalance();
|
||||||
walletAddresses.accountList.update();
|
/*walletAddresses.accountList.update();*/
|
||||||
syncStatus = SyncedSyncStatus();
|
syncStatus = SyncedSyncStatus();
|
||||||
|
|
||||||
if (!_hasSyncAfterStartup) {
|
if (!_hasSyncAfterStartup) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import 'package:cw_core/wallet_addresses_with_account.dart';
|
import 'package:cw_core/wallet_addresses.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:cw_core/account.dart';
|
import 'package:cw_core/account.dart';
|
||||||
import 'package:cw_zano/zano_account_list.dart';
|
import 'package:cw_zano/zano_account_list.dart';
|
||||||
|
@ -10,12 +10,10 @@ part 'zano_wallet_addresses.g.dart';
|
||||||
|
|
||||||
class ZanoWalletAddresses = ZanoWalletAddressesBase with _$ZanoWalletAddresses;
|
class ZanoWalletAddresses = ZanoWalletAddressesBase with _$ZanoWalletAddresses;
|
||||||
|
|
||||||
abstract class ZanoWalletAddressesBase
|
/**abstract class ZanoWalletAddressesBase extends WalletAddressesWithAccount<Account> with Store {*/
|
||||||
extends WalletAddressesWithAccount<Account> with Store {
|
abstract class ZanoWalletAddressesBase extends WalletAddresses with Store {
|
||||||
ZanoWalletAddressesBase(WalletInfo walletInfo)
|
ZanoWalletAddressesBase(WalletInfo walletInfo)
|
||||||
: accountList = ZanoAccountList(),
|
: address = '',
|
||||||
subaddressList = ZanoSubaddressList(),
|
|
||||||
address = '',
|
|
||||||
super(walletInfo);
|
super(walletInfo);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -23,65 +21,68 @@ abstract class ZanoWalletAddressesBase
|
||||||
String address;
|
String address;
|
||||||
|
|
||||||
// @override
|
// @override
|
||||||
@observable
|
/**@observable
|
||||||
Account? account;
|
Account? account;*/
|
||||||
|
|
||||||
@observable
|
/**@observable
|
||||||
Subaddress? subaddress;
|
Subaddress? subaddress;*/
|
||||||
|
|
||||||
ZanoSubaddressList subaddressList;
|
/**ZanoSubaddressList subaddressList;*/
|
||||||
|
|
||||||
ZanoAccountList accountList;
|
/**ZanoAccountList accountList;*/
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
accountList.update();
|
/*accountList.update();
|
||||||
account = accountList.accounts.first;
|
account = accountList.accounts.first;*/
|
||||||
updateSubaddressList(accountIndex: account?.id ?? 0);
|
/**updateSubaddressList(accountIndex: account?.id ?? 0);*/
|
||||||
|
address = walletInfo.address;
|
||||||
await updateAddressesInBox();
|
await updateAddressesInBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateAddressesInBox() async {
|
Future<void> updateAddressesInBox() async {
|
||||||
try {
|
try {
|
||||||
final _subaddressList = ZanoSubaddressList();
|
/**final _subaddressList = ZanoSubaddressList();*/
|
||||||
|
|
||||||
addressesMap.clear();
|
addressesMap.clear();
|
||||||
|
addressesMap[address] = '';
|
||||||
|
await saveAddressesInBox();
|
||||||
|
|
||||||
accountList.accounts.forEach((account) {
|
/*accountList.accounts.forEach((account) {
|
||||||
_subaddressList.update(accountIndex: account.id);
|
_subaddressList.update(accountIndex: account.id);
|
||||||
_subaddressList.subaddresses.forEach((subaddress) {
|
_subaddressList.subaddresses.forEach((subaddress) {
|
||||||
addressesMap[subaddress.address] = subaddress.label;
|
addressesMap[subaddress.address] = subaddress.label;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await saveAddressesInBox();
|
await saveAddressesInBox();*/
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validate() {
|
// bool validate() {
|
||||||
accountList.update();
|
// accountList.update();
|
||||||
final accountListLength = accountList.accounts.length ?? 0;
|
// final accountListLength = accountList.accounts.length ?? 0;
|
||||||
|
|
||||||
if (accountListLength <= 0) {
|
// if (accountListLength <= 0) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
subaddressList.update(accountIndex: accountList.accounts.first.id);
|
// /**subaddressList.update(accountIndex: accountList.accounts.first.id);
|
||||||
final subaddressListLength = subaddressList.subaddresses.length ?? 0;
|
// final subaddressListLength = subaddressList.subaddresses.length ?? 0;
|
||||||
|
|
||||||
if (subaddressListLength <= 0) {
|
// if (subaddressListLength <= 0) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }*/
|
||||||
|
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
void updateSubaddressList({required int accountIndex}) {
|
/*void updateSubaddressList({required int accountIndex}) {
|
||||||
subaddressList.update(accountIndex: accountIndex);
|
subaddressList.update(accountIndex: accountIndex);
|
||||||
subaddress = subaddressList.subaddresses.first;
|
subaddress = subaddressList.subaddresses.first;
|
||||||
address = subaddress!.address;
|
address = subaddress!.address;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:cw_core/node.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/monero_wallet_utils.dart';
|
import 'package:cw_core/monero_wallet_utils.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:cw_zano/api/wallet_manager.dart' as zano_wallet_manager;
|
import 'package:cw_zano/api/wallet_manager.dart' as zano_wallet_manager;
|
||||||
import 'package:cw_zano/api/wallet.dart' as zano_wallet;
|
import 'package:cw_zano/api/wallet.dart' as zano_wallet;
|
||||||
|
import 'package:cw_zano/api/calls.dart' as calls;
|
||||||
import 'package:cw_zano/api/exceptions/wallet_opening_exception.dart';
|
import 'package:cw_zano/api/exceptions/wallet_opening_exception.dart';
|
||||||
import 'package:cw_zano/zano_wallet.dart';
|
import 'package:cw_zano/zano_wallet.dart';
|
||||||
import 'package:cw_core/wallet_credentials.dart';
|
import 'package:cw_core/wallet_credentials.dart';
|
||||||
|
@ -14,11 +16,8 @@ import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
|
||||||
class ZanoNewWalletCredentials extends WalletCredentials {
|
class ZanoNewWalletCredentials extends WalletCredentials {
|
||||||
ZanoNewWalletCredentials(
|
ZanoNewWalletCredentials({required String name, String? password})
|
||||||
{required String name, required this.language, String? password})
|
|
||||||
: super(name: name, password: password);
|
: super(name: name, password: password);
|
||||||
|
|
||||||
final String language;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ZanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
class ZanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||||
|
@ -65,18 +64,23 @@ class ZanoWalletService extends WalletService<
|
||||||
static bool walletFilesExist(String path) =>
|
static bool walletFilesExist(String path) =>
|
||||||
!File(path).existsSync() && !File('$path.keys').existsSync();
|
!File(path).existsSync() && !File('$path.keys').existsSync();
|
||||||
|
|
||||||
|
int hWallet = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletType getType() => WalletType.zano;
|
WalletType getType() => WalletType.zano;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ZanoWallet> create(ZanoNewWalletCredentials credentials) async {
|
Future<ZanoWallet> create(ZanoNewWalletCredentials credentials) async {
|
||||||
try {
|
try {
|
||||||
|
final wallet = ZanoWallet.simple(walletInfo: credentials.walletInfo!);
|
||||||
|
wallet.connectToNode(node: Node());
|
||||||
final path = await pathForWallet(name: credentials.name, type: getType());
|
final path = await pathForWallet(name: credentials.name, type: getType());
|
||||||
await zano_wallet_manager.createWallet(
|
final result = await zano_wallet_manager.createWallet(
|
||||||
path: path,
|
language: "", path: path, password: credentials.password!);
|
||||||
password: credentials.password!,
|
hWallet = -1;
|
||||||
language: credentials.language);
|
wallet.hWallet = hWallet;
|
||||||
final wallet = ZanoWallet(walletInfo: credentials.walletInfo!);
|
// TODO: remove it
|
||||||
|
calls.store(hWallet);
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
return wallet;
|
return wallet;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -112,13 +116,13 @@ class ZanoWalletService extends WalletService<
|
||||||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||||
(info) => info.id == WalletBase.idFor(name, getType()))!;
|
(info) => info.id == WalletBase.idFor(name, getType()))!;
|
||||||
final wallet = ZanoWallet(walletInfo: walletInfo);
|
final wallet = ZanoWallet(walletInfo: walletInfo);
|
||||||
final isValid = wallet.walletAddresses.validate();
|
/*final isValid = wallet.walletAddresses.validate();
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
await restoreOrResetWalletFiles(name);
|
await restoreOrResetWalletFiles(name);
|
||||||
wallet.close();
|
wallet.close();
|
||||||
return openWallet(name, password);
|
return openWallet(name, password);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
|
||||||
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
||||||
final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24);
|
final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24);
|
||||||
final zanoIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24);
|
final zanoIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24);
|
||||||
final dummyIcon = Image.asset('assets/images/dummy_icon.png', height: 24, width: 24);
|
final dummyIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24);
|
||||||
final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24);
|
final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24);
|
||||||
|
|
||||||
Image _newWalletImage(BuildContext context) => Image.asset(
|
Image _newWalletImage(BuildContext context) => Image.asset(
|
||||||
|
|
|
@ -31,7 +31,7 @@ class MenuWidgetState extends State<MenuWidget> {
|
||||||
this.havenIcon = Image.asset('assets/images/haven_menu.png'),
|
this.havenIcon = Image.asset('assets/images/haven_menu.png'),
|
||||||
this.ethereumIcon = Image.asset('assets/images/eth_icon.png'),
|
this.ethereumIcon = Image.asset('assets/images/eth_icon.png'),
|
||||||
this.zanoIcon = Image.asset('assets/images/zano_icon.png'),
|
this.zanoIcon = Image.asset('assets/images/zano_icon.png'),
|
||||||
this.dummyIcon = Image.asset('assets/images/dummy_icon.png');
|
this.dummyIcon = Image.asset('assets/images/zano_icon.png');
|
||||||
|
|
||||||
final largeScreen = 731;
|
final largeScreen = 731;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class WalletListBodyState extends State<WalletListBody> {
|
||||||
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
||||||
final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24);
|
final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24);
|
||||||
final zanoIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24);
|
final zanoIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24);
|
||||||
final dummyIcon = Image.asset('assets/images/dummy_icon.png', height: 24, width: 24);
|
final dummyIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24);
|
||||||
final scrollController = ScrollController();
|
final scrollController = ScrollController();
|
||||||
final double tileHeight = 60;
|
final double tileHeight = 60;
|
||||||
Flushbar<void>? _progressBar;
|
Flushbar<void>? _progressBar;
|
||||||
|
|
|
@ -48,8 +48,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
||||||
case WalletType.ethereum:
|
case WalletType.ethereum:
|
||||||
return ethereum!.createEthereumNewWalletCredentials(name: name);
|
return ethereum!.createEthereumNewWalletCredentials(name: name);
|
||||||
case WalletType.zano:
|
case WalletType.zano:
|
||||||
return zano!.createZanoNewWalletCredentials(
|
return zano!.createZanoNewWalletCredentials(name: name);
|
||||||
name: name, language: "en");
|
|
||||||
case WalletType.dummy:
|
case WalletType.dummy:
|
||||||
return dummy!.createDummyNewWalletCredentials(name: name);
|
return dummy!.createDummyNewWalletCredentials(name: name);
|
||||||
default:
|
default:
|
||||||
|
|
146
lib/zano.dart
Normal file
146
lib/zano.dart
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:cake_wallet/core/generate_wallet_password.dart';
|
||||||
|
import 'package:cake_wallet/core/key_service.dart';
|
||||||
|
import 'package:cake_wallet/utils/exception_handler.dart';
|
||||||
|
import 'package:cw_core/pathForWallet.dart';
|
||||||
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
import 'package:cw_zano/api/wallet.dart' as zano_wallet;
|
||||||
|
import 'package:cw_zano/api/wallet_manager.dart' as zano_wallet_manager;
|
||||||
|
import 'package:cw_zano/api/calls.dart' as calls;
|
||||||
|
import 'package:cw_zano/zano_wallet_service.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
import 'package:get_it/get_it.dart';
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
await runZonedGuarded(() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
FlutterError.onError = ExceptionHandler.onError;
|
||||||
|
|
||||||
|
/// A callback that is invoked when an unhandled error occurs in the root
|
||||||
|
/// isolate.
|
||||||
|
PlatformDispatcher.instance.onError = (error, stack) {
|
||||||
|
ExceptionHandler.onError(
|
||||||
|
FlutterErrorDetails(exception: error, stack: stack));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
await setup();
|
||||||
|
runApp(App());
|
||||||
|
}, (error, stackTrace) async {
|
||||||
|
ExceptionHandler.onError(
|
||||||
|
FlutterErrorDetails(exception: error, stack: stackTrace));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
final getIt = GetIt.instance;
|
||||||
|
|
||||||
|
Future<void> setup() async {
|
||||||
|
getIt.registerFactory<KeyService>(
|
||||||
|
() => KeyService(getIt.get<FlutterSecureStorage>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
class App extends StatefulWidget {
|
||||||
|
const App({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<App> createState() => _AppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class HomeWidget extends StatefulWidget {
|
||||||
|
const HomeWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomeWidget> createState() => _HomeWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AppState extends State<App> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(home: HomeWidget());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeWidgetState extends State<HomeWidget> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: FutureBuilder(
|
||||||
|
future: connect(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (!snapshot.hasData) return CircularProgressIndicator();
|
||||||
|
return Center(child: Text("connected"));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const name = "leo1";
|
||||||
|
|
||||||
|
Future<bool> connect() async {
|
||||||
|
calls.getVersion();
|
||||||
|
final setupNode = await zano_wallet.setupNode(
|
||||||
|
address: "195.201.107.230:33336",
|
||||||
|
login: "",
|
||||||
|
password: "",
|
||||||
|
useSSL: false,
|
||||||
|
isLightWallet: false);
|
||||||
|
final path = await pathForWallet(name: name, type: WalletType.zano);
|
||||||
|
final credentials = ZanoNewWalletCredentials(name: name);
|
||||||
|
final keyService = KeyService(FlutterSecureStorage());
|
||||||
|
final password = await keyService.getWalletPassword(walletName: credentials.name);
|
||||||
|
debugPrint("path $path password $password");
|
||||||
|
final result = await calls.loadWallet(path, password, 0);
|
||||||
|
final map = json.decode(result) as Map<String, dynamic>;
|
||||||
|
int hWallet = 0;
|
||||||
|
if (map["result"] != null) {
|
||||||
|
hWallet = (map["result"] as Map<String, dynamic>)["wallet_id"] as int;
|
||||||
|
debugPrint("hWallet $hWallet");
|
||||||
|
}
|
||||||
|
Future.delayed(Duration(seconds: 10));
|
||||||
|
await calls.getWalletStatus(hWallet);
|
||||||
|
Future.delayed(Duration(seconds: 10));
|
||||||
|
await calls.getRecentTxsAndInfo(hWallet: hWallet, offset: 0, count: 30);
|
||||||
|
Future.delayed(Duration(seconds: 2));
|
||||||
|
calls.closeWallet(hWallet);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _connect() async {
|
||||||
|
calls.getVersion();
|
||||||
|
final result = await zano_wallet.setupNode(
|
||||||
|
address: "195.201.107.230:33336",
|
||||||
|
login: "",
|
||||||
|
password: "",
|
||||||
|
useSSL: false,
|
||||||
|
isLightWallet: false);
|
||||||
|
//debugPrint("setup node result ${result}");
|
||||||
|
//final name = "leo1";
|
||||||
|
final path = await pathForWallet(name: name, type: WalletType.zano);
|
||||||
|
final credentials = ZanoNewWalletCredentials(name: name);
|
||||||
|
final keyService = KeyService(FlutterSecureStorage());
|
||||||
|
final password = generateWalletPassword();
|
||||||
|
credentials.password = password;
|
||||||
|
await keyService.saveWalletPassword(
|
||||||
|
password: password, walletName: credentials.name);
|
||||||
|
final createResult = await zano_wallet_manager.createWallet(
|
||||||
|
language: "", path: path, password: credentials.password!);
|
||||||
|
debugPrint("createWallet result $createResult");
|
||||||
|
final map = json.decode(createResult) as Map<String, dynamic>;
|
||||||
|
int hWallet = -1;
|
||||||
|
if (map["result"] != null) {
|
||||||
|
hWallet = (map["result"] as Map<String, dynamic>)["wallet_id"] as int;
|
||||||
|
debugPrint("hWallet $hWallet");
|
||||||
|
}
|
||||||
|
//await calls.loadWallet(path, password, 0);
|
||||||
|
calls.getConnectivityStatus();
|
||||||
|
await calls.store(hWallet);
|
||||||
|
calls.getWalletInfo(hWallet);
|
||||||
|
calls.getWalletStatus(hWallet);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
part of 'zano.dart';
|
part of 'zano.dart';
|
||||||
|
|
||||||
class CWZanoAccountList extends ZanoAccountList {
|
/**class CWZanoAccountList extends ZanoAccountList {
|
||||||
CWZanoAccountList(this._wallet);
|
CWZanoAccountList(this._wallet);
|
||||||
|
|
||||||
final Object _wallet;
|
final Object _wallet;
|
||||||
|
@ -49,73 +49,20 @@ class CWZanoAccountList extends ZanoAccountList {
|
||||||
await zanoWallet.walletAddresses.accountList
|
await zanoWallet.walletAddresses.accountList
|
||||||
.setLabelAccount(accountIndex: accountIndex, label: label);
|
.setLabelAccount(accountIndex: accountIndex, label: label);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
class CWZanoSubaddressList extends MoneroSubaddressList {
|
|
||||||
CWZanoSubaddressList(this._wallet);
|
|
||||||
|
|
||||||
final Object _wallet;
|
|
||||||
|
|
||||||
@override
|
|
||||||
@computed
|
|
||||||
ObservableList<Subaddress> get subaddresses {
|
|
||||||
final zanoWallet = _wallet as ZanoWallet;
|
|
||||||
final subAddresses = zanoWallet.walletAddresses.subaddressList.subaddresses
|
|
||||||
.map((sub) => Subaddress(id: sub.id, address: sub.address, label: sub.label))
|
|
||||||
.toList();
|
|
||||||
return ObservableList<Subaddress>.of(subAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void update(Object wallet, {required int accountIndex}) {
|
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
|
||||||
zanoWallet.walletAddresses.subaddressList.update(accountIndex: accountIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void refresh(Object wallet, {required int accountIndex}) {
|
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
|
||||||
zanoWallet.walletAddresses.subaddressList.refresh(accountIndex: accountIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Subaddress> getAll(Object wallet) {
|
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
|
||||||
return zanoWallet.walletAddresses.subaddressList
|
|
||||||
.getAll()
|
|
||||||
.map((sub) => Subaddress(id: sub.id, label: sub.label, address: sub.address))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> addSubaddress(Object wallet,
|
|
||||||
{required int accountIndex, required String label}) async {
|
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
|
||||||
await zanoWallet.walletAddresses.subaddressList
|
|
||||||
.addSubaddress(accountIndex: accountIndex, label: label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> setLabelSubaddress(Object wallet,
|
|
||||||
{required int accountIndex, required int addressIndex, required String label}) async {
|
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
|
||||||
await zanoWallet.walletAddresses.subaddressList
|
|
||||||
.setLabelSubaddress(accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CWZanoWalletDetails extends ZanoWalletDetails {
|
class CWZanoWalletDetails extends ZanoWalletDetails {
|
||||||
CWZanoWalletDetails(this._wallet);
|
CWZanoWalletDetails(this._wallet);
|
||||||
|
|
||||||
final Object _wallet;
|
final Object _wallet;
|
||||||
|
|
||||||
@computed
|
// @computed
|
||||||
@override
|
// @override
|
||||||
Account get account {
|
// Account get account {
|
||||||
final zanoWallet = _wallet as ZanoWallet;
|
// final zanoWallet = _wallet as ZanoWallet;
|
||||||
final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
// final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||||
return Account(id: acc.id, label: acc.label);
|
// return Account(id: acc.id, label: acc.label);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
@override
|
@override
|
||||||
|
@ -130,15 +77,10 @@ class CWZanoWalletDetails extends ZanoWalletDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CWZano extends Zano {
|
class CWZano extends Zano {
|
||||||
@override
|
/**@override
|
||||||
ZanoAccountList getAccountList(Object wallet) {
|
ZanoAccountList getAccountList(Object wallet) {
|
||||||
return CWZanoAccountList(wallet);
|
return CWZanoAccountList(wallet);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@override
|
|
||||||
MoneroSubaddressList getSubaddressList(Object wallet) {
|
|
||||||
return CWZanoSubaddressList(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
||||||
|
@ -147,7 +89,7 @@ class CWZano extends Zano {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ZanoWalletDetails getMoneroWalletDetails(Object wallet) {
|
ZanoWalletDetails getZanoWalletDetails(Object wallet) {
|
||||||
return CWZanoWalletDetails(wallet);
|
return CWZanoWalletDetails(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,8 +173,8 @@ class CWZano extends Zano {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletCredentials createZanoNewWalletCredentials(
|
WalletCredentials createZanoNewWalletCredentials(
|
||||||
{required String name, required String language, String? password}) {
|
{required String name, String? password}) {
|
||||||
return ZanoNewWalletCredentials(name: name, password: password, language: language);
|
return ZanoNewWalletCredentials(name: name, password: password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -283,18 +225,18 @@ class CWZano extends Zano {
|
||||||
return moneroParseAmount(amount: amount);
|
return moneroParseAmount(amount: amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
Account getCurrentAccount(Object wallet) {
|
// Account getCurrentAccount(Object wallet) {
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
// final zanoWallet = wallet as ZanoWallet;
|
||||||
final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
// final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||||
return Account(id: acc.id, label: acc.label);
|
// return Account(id: acc.id, label: acc.label);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
void setCurrentAccount(Object wallet, int id, String label) {
|
// void setCurrentAccount(Object wallet, int id, String label) {
|
||||||
final zanoWallet = wallet as ZanoWallet;
|
// final zanoWallet = wallet as ZanoWallet;
|
||||||
zanoWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
|
// zanoWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onStartup() {
|
void onStartup() {
|
||||||
|
|
|
@ -37,21 +37,21 @@ part 'cw_zano.dart';
|
||||||
|
|
||||||
Zano? zano = CWZano();
|
Zano? zano = CWZano();
|
||||||
|
|
||||||
class Account {
|
// class Account {
|
||||||
Account({required this.id, required this.label});
|
// Account({required this.id, required this.label});
|
||||||
final int id;
|
// final int id;
|
||||||
final String label;
|
// final String label;
|
||||||
}
|
// }
|
||||||
|
|
||||||
class Subaddress {
|
// class Subaddress {
|
||||||
Subaddress({
|
// Subaddress({
|
||||||
required this.id,
|
// required this.id,
|
||||||
required this.label,
|
// required this.label,
|
||||||
required this.address});
|
// required this.address});
|
||||||
final int id;
|
// final int id;
|
||||||
final String label;
|
// final String label;
|
||||||
final String address;
|
// final String address;
|
||||||
}
|
// }
|
||||||
|
|
||||||
class ZanoBalance extends Balance {
|
class ZanoBalance extends Balance {
|
||||||
ZanoBalance({required this.fullBalance, required this.unlockedBalance})
|
ZanoBalance({required this.fullBalance, required this.unlockedBalance})
|
||||||
|
@ -89,21 +89,19 @@ class AssetRate {
|
||||||
|
|
||||||
abstract class ZanoWalletDetails {
|
abstract class ZanoWalletDetails {
|
||||||
// FIX-ME: it's abstruct class
|
// FIX-ME: it's abstruct class
|
||||||
@observable
|
// @observable
|
||||||
late Account account;
|
// late Account account;
|
||||||
// FIX-ME: it's abstruct class
|
// FIX-ME: it's abstruct class
|
||||||
@observable
|
@observable
|
||||||
late ZanoBalance balance;
|
late ZanoBalance balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Zano {
|
abstract class Zano {
|
||||||
ZanoAccountList getAccountList(Object wallet);
|
/**ZanoAccountList getAccountList(Object wallet);*/
|
||||||
|
|
||||||
MoneroSubaddressList getSubaddressList(Object wallet);
|
|
||||||
|
|
||||||
TransactionHistoryBase getTransactionHistory(Object wallet);
|
TransactionHistoryBase getTransactionHistory(Object wallet);
|
||||||
|
|
||||||
ZanoWalletDetails getMoneroWalletDetails(Object wallet);
|
ZanoWalletDetails getZanoWalletDetails(Object wallet);
|
||||||
|
|
||||||
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex);
|
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex);
|
||||||
|
|
||||||
|
@ -123,14 +121,14 @@ abstract class Zano {
|
||||||
required String language,
|
required String language,
|
||||||
required int height});
|
required int height});
|
||||||
WalletCredentials createZanoRestoreWalletFromSeedCredentials({required String name, required String password, required int height, required String mnemonic});
|
WalletCredentials createZanoRestoreWalletFromSeedCredentials({required String name, required String password, required int height, required String mnemonic});
|
||||||
WalletCredentials createZanoNewWalletCredentials({required String name, required String language, String password});
|
WalletCredentials createZanoNewWalletCredentials({required String name, String password});
|
||||||
Map<String, String> getKeys(Object wallet);
|
Map<String, String> getKeys(Object wallet);
|
||||||
Object createZanoTransactionCreationCredentials({required List<Output> outputs, required TransactionPriority priority, required String assetType});
|
Object createZanoTransactionCreationCredentials({required List<Output> outputs, required TransactionPriority priority, required String assetType});
|
||||||
String formatterMoneroAmountToString({required int amount});
|
String formatterMoneroAmountToString({required int amount});
|
||||||
double formatterMoneroAmountToDouble({required int amount});
|
double formatterMoneroAmountToDouble({required int amount});
|
||||||
int formatterMoneroParseAmount({required String amount});
|
int formatterMoneroParseAmount({required String amount});
|
||||||
Account getCurrentAccount(Object wallet);
|
// Account getCurrentAccount(Object wallet);
|
||||||
void setCurrentAccount(Object wallet, int id, String label);
|
// void setCurrentAccount(Object wallet, int id, String label);
|
||||||
void onStartup();
|
void onStartup();
|
||||||
int getTransactionInfoAccountId(TransactionInfo tx);
|
int getTransactionInfoAccountId(TransactionInfo tx);
|
||||||
WalletService createZanoWalletService(Box<WalletInfo> walletInfoSource);
|
WalletService createZanoWalletService(Box<WalletInfo> walletInfoSource);
|
||||||
|
@ -138,22 +136,22 @@ abstract class Zano {
|
||||||
List<AssetRate> getAssetRate();
|
List<AssetRate> getAssetRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class MoneroSubaddressList {
|
// abstract class MoneroSubaddressList {
|
||||||
ObservableList<Subaddress> get subaddresses;
|
// ObservableList<Subaddress> get subaddresses;
|
||||||
void update(Object wallet, {required int accountIndex});
|
// void update(Object wallet, {required int accountIndex});
|
||||||
void refresh(Object wallet, {required int accountIndex});
|
// void refresh(Object wallet, {required int accountIndex});
|
||||||
List<Subaddress> getAll(Object wallet);
|
// List<Subaddress> getAll(Object wallet);
|
||||||
Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label});
|
// Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label});
|
||||||
Future<void> setLabelSubaddress(Object wallet,
|
// Future<void> setLabelSubaddress(Object wallet,
|
||||||
{required int accountIndex, required int addressIndex, required String label});
|
// {required int accountIndex, required int addressIndex, required String label});
|
||||||
}
|
// }
|
||||||
|
|
||||||
abstract class ZanoAccountList {
|
// abstract class ZanoAccountList {
|
||||||
ObservableList<Account> get accounts;
|
// ObservableList<Account> get accounts;
|
||||||
void update(Object wallet);
|
// void update(Object wallet);
|
||||||
void refresh(Object wallet);
|
// void refresh(Object wallet);
|
||||||
List<Account> getAll(Object wallet);
|
// List<Account> getAll(Object wallet);
|
||||||
Future<void> addAccount(Object wallet, {required String label});
|
// Future<void> addAccount(Object wallet, {required String label});
|
||||||
Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
|
// Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
|
||||||
}
|
// }
|
||||||
|
|
Loading…
Reference in a new issue