mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +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 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 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 =
|
||||
|
|
|
@ -132,7 +132,7 @@ class Node extends HiveObject with Keyable {
|
|||
case WalletType.haven:
|
||||
return requestMoneroNode();
|
||||
case WalletType.zano:
|
||||
return requestMoneroNode();
|
||||
return requestZanoNode();
|
||||
case WalletType.ethereum:
|
||||
return requestElectrumServer();
|
||||
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 {
|
||||
final path = '/json_rpc';
|
||||
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());
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return strdup(plain_wallet::get_connectivity_status().c_str());
|
||||
|
@ -847,6 +852,11 @@ extern "C"
|
|||
//return m_wallet->trustedDaemon();
|
||||
}
|
||||
|
||||
char* get_version()
|
||||
{
|
||||
return strdup(plain_wallet::get_version().c_str());
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -7,29 +7,29 @@ import 'package:cw_zano/api/structs/account_row.dart';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cw_zano/api/wallet.dart';
|
||||
|
||||
final accountSizeNative = zanoApi
|
||||
.lookup<NativeFunction<account_size>>('account_size')
|
||||
.asFunction<SubaddressSize>();
|
||||
// final accountSizeNative = zanoApi
|
||||
// .lookup<NativeFunction<account_size>>('account_size')
|
||||
// .asFunction<SubaddressSize>();
|
||||
|
||||
final accountRefreshNative = zanoApi
|
||||
.lookup<NativeFunction<account_refresh>>('account_refresh')
|
||||
.asFunction<AccountRefresh>();
|
||||
// final accountRefreshNative = zanoApi
|
||||
// .lookup<NativeFunction<account_refresh>>('account_refresh')
|
||||
// .asFunction<AccountRefresh>();
|
||||
|
||||
final accountGetAllNative = zanoApi
|
||||
.lookup<NativeFunction<account_get_all>>('account_get_all')
|
||||
.asFunction<AccountGetAll>();
|
||||
// final accountGetAllNative = zanoApi
|
||||
// .lookup<NativeFunction<account_get_all>>('account_get_all')
|
||||
// .asFunction<AccountGetAll>();
|
||||
|
||||
final accountAddNewNative = zanoApi
|
||||
.lookup<NativeFunction<account_add_new>>('account_add_row')
|
||||
.asFunction<AccountAddNew>();
|
||||
// final accountAddNewNative = zanoApi
|
||||
// .lookup<NativeFunction<account_add_new>>('account_add_row')
|
||||
// .asFunction<AccountAddNew>();
|
||||
|
||||
final accountSetLabelNative = zanoApi
|
||||
.lookup<NativeFunction<account_set_label>>('account_set_label_row')
|
||||
.asFunction<AccountSetLabel>();
|
||||
// final accountSetLabelNative = zanoApi
|
||||
// .lookup<NativeFunction<account_set_label>>('account_set_label_row')
|
||||
// .asFunction<AccountSetLabel>();
|
||||
|
||||
bool isUpdating = false;
|
||||
|
||||
void refreshAccounts() {
|
||||
/**void refreshAccounts() {
|
||||
try {
|
||||
isUpdating = true;
|
||||
accountRefreshNative();
|
||||
|
@ -38,9 +38,9 @@ void refreshAccounts() {
|
|||
isUpdating = false;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
List<AccountRow> getAllAccount() {
|
||||
/**List<AccountRow> getAllAccount() {
|
||||
final size = accountSizeNative();
|
||||
final accountAddressesPointer = accountGetAllNative();
|
||||
final accountAddresses = accountAddressesPointer.asTypedList(size);
|
||||
|
@ -48,38 +48,38 @@ List<AccountRow> getAllAccount() {
|
|||
return accountAddresses
|
||||
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
|
||||
.toList();
|
||||
}
|
||||
}*/
|
||||
|
||||
void addAccountSync({required String label}) {
|
||||
/**void addAccountSync({required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
accountAddNewNative(labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
}
|
||||
}*/
|
||||
|
||||
void setLabelForAccountSync(
|
||||
/**void setLabelForAccountSync(
|
||||
{required int accountIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
accountSetLabelNative(accountIndex, 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 accountIndex = args['accountIndex'] as int;
|
||||
|
||||
setLabelForAccountSync(label: label, accountIndex: accountIndex);
|
||||
}
|
||||
}*/
|
||||
|
||||
Future<void> addAccount({required String label}) async {
|
||||
/**Future<void> addAccount({required String label}) async {
|
||||
await compute(_addAccount, label);
|
||||
await store();
|
||||
}
|
||||
}*/
|
||||
|
||||
Future<void> setLabelForAccount(
|
||||
/**Future<void> setLabelForAccount(
|
||||
{required int accountIndex, required String label}) async {
|
||||
await compute(
|
||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
||||
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:ffi/ffi.dart';
|
||||
|
||||
typedef create_wallet = Int8 Function(
|
||||
typedef create_wallet = Pointer<Utf8> Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>);
|
||||
|
||||
typedef restore_wallet_from_seed = Int8 Function(
|
||||
|
@ -47,7 +47,7 @@ typedef get_node_height = Int64 Function();
|
|||
typedef is_connected = Int8 Function();
|
||||
|
||||
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();
|
||||
|
||||
|
@ -107,7 +107,6 @@ typedef transaction_create = Int8 Function(
|
|||
Pointer<Utf8> paymentId,
|
||||
Pointer<Utf8> amount,
|
||||
Int8 priorityRaw,
|
||||
Int32 subaddrAccount,
|
||||
Pointer<Utf8Box> error,
|
||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||
|
||||
|
@ -118,7 +117,6 @@ typedef transaction_create_mult_dest = Int8 Function(
|
|||
Pointer<Pointer<Utf8>> amounts,
|
||||
Int32 size,
|
||||
Int8 priorityRaw,
|
||||
Int32 subaddrAccount,
|
||||
Pointer<Utf8Box> error,
|
||||
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/wallet.dart';
|
||||
|
||||
/**
|
||||
final subaddressSizeNative = zanoApi
|
||||
.lookup<NativeFunction<subaddrress_size>>('subaddrress_size')
|
||||
.asFunction<SubaddressSize>();
|
||||
|
@ -99,3 +100,4 @@ Future setLabelForSubaddress(
|
|||
});
|
||||
await store();
|
||||
}
|
||||
*/
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:ffi';
|
||||
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:ffi/ffi.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/exceptions/creation_transaction_exception.dart';
|
||||
|
||||
final transactionsRefreshNative = zanoApi
|
||||
/**final transactionsRefreshNative = zanoApi
|
||||
.lookup<NativeFunction<transactions_refresh>>('transactions_refresh')
|
||||
.asFunction<TransactionsRefresh>();
|
||||
.asFunction<TransactionsRefresh>();*/
|
||||
|
||||
final transactionsCountNative = zanoApi
|
||||
/**final transactionsCountNative = zanoApi
|
||||
.lookup<NativeFunction<transactions_count>>('transactions_count')
|
||||
.asFunction<TransactionsCount>();
|
||||
.asFunction<TransactionsCount>();*/
|
||||
|
||||
final transactionsGetAllNative = zanoApi
|
||||
.lookup<NativeFunction<transactions_get_all>>('transactions_get_all')
|
||||
|
@ -53,18 +53,29 @@ String getTxKey(String txId) {
|
|||
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() {
|
||||
final size = transactionsCountNative();
|
||||
// TODO: fix it
|
||||
return [];
|
||||
/*final size = transactionsCountNative();
|
||||
final transactionsPointer = transactionsGetAllNative();
|
||||
final transactionsAddresses = transactionsPointer.asTypedList(size);
|
||||
|
||||
return transactionsAddresses
|
||||
.map((addr) => Pointer<TransactionInfoRow>.fromAddress(addr).ref)
|
||||
.toList();
|
||||
.toList();*/
|
||||
}
|
||||
|
||||
PendingTransactionDescription createTransactionSync(
|
||||
|
@ -72,8 +83,7 @@ PendingTransactionDescription createTransactionSync(
|
|||
required String assetType,
|
||||
required String paymentId,
|
||||
required int priorityRaw,
|
||||
String? amount,
|
||||
int accountIndex = 0}) {
|
||||
String? amount}) {
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
final assetTypePointer = assetType.toNativeUtf8();
|
||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
||||
|
@ -86,7 +96,6 @@ PendingTransactionDescription createTransactionSync(
|
|||
paymentIdPointer,
|
||||
amountPointer,
|
||||
priorityRaw,
|
||||
accountIndex,
|
||||
errorMessagePointer,
|
||||
pendingTransactionRawPointer) !=
|
||||
0;
|
||||
|
@ -113,11 +122,10 @@ PendingTransactionDescription createTransactionSync(
|
|||
}
|
||||
|
||||
PendingTransactionDescription createTransactionMultDestSync(
|
||||
{required List<MoneroOutput> outputs,
|
||||
{required List<ZanoOutput> outputs,
|
||||
required String assetType,
|
||||
required String paymentId,
|
||||
required int priorityRaw,
|
||||
int accountIndex = 0}) {
|
||||
required int priorityRaw}) {
|
||||
final int size = outputs.length;
|
||||
final List<Pointer<Utf8>> addressesPointers =
|
||||
outputs.map((output) => output.address.toNativeUtf8()).toList();
|
||||
|
@ -142,7 +150,6 @@ PendingTransactionDescription createTransactionMultDestSync(
|
|||
amountsPointerPointer,
|
||||
size,
|
||||
priorityRaw,
|
||||
accountIndex,
|
||||
errorMessagePointer,
|
||||
pendingTransactionRawPointer) !=
|
||||
0;
|
||||
|
@ -193,30 +200,26 @@ PendingTransactionDescription _createTransactionSync(Map args) {
|
|||
final paymentId = args['paymentId'] as String;
|
||||
final amount = args['amount'] as String;
|
||||
final priorityRaw = args['priorityRaw'] as int;
|
||||
final accountIndex = args['accountIndex'] as int;
|
||||
|
||||
return createTransactionSync(
|
||||
address: address,
|
||||
assetType: assetType,
|
||||
paymentId: paymentId,
|
||||
amount: amount,
|
||||
priorityRaw: priorityRaw,
|
||||
accountIndex: accountIndex);
|
||||
priorityRaw: priorityRaw);
|
||||
}
|
||||
|
||||
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 paymentId = args['paymentId'] as String;
|
||||
final priorityRaw = args['priorityRaw'] as int;
|
||||
final accountIndex = args['accountIndex'] as int;
|
||||
|
||||
return createTransactionMultDestSync(
|
||||
outputs: outputs,
|
||||
assetType: assetType,
|
||||
paymentId: paymentId,
|
||||
priorityRaw: priorityRaw,
|
||||
accountIndex: accountIndex);
|
||||
priorityRaw: priorityRaw);
|
||||
}
|
||||
|
||||
Future<PendingTransactionDescription> createTransaction(
|
||||
|
@ -224,27 +227,23 @@ Future<PendingTransactionDescription> createTransaction(
|
|||
required String assetType,
|
||||
required int priorityRaw,
|
||||
String? amount,
|
||||
String paymentId = '',
|
||||
int accountIndex = 0}) =>
|
||||
String paymentId = ''}) =>
|
||||
compute(_createTransactionSync, {
|
||||
'address': address,
|
||||
'assetType': assetType,
|
||||
'paymentId': paymentId,
|
||||
'amount': amount,
|
||||
'priorityRaw': priorityRaw,
|
||||
'accountIndex': accountIndex
|
||||
});
|
||||
|
||||
Future<PendingTransactionDescription> createTransactionMultDest(
|
||||
{required List<MoneroOutput> outputs,
|
||||
{required List<ZanoOutput> outputs,
|
||||
required int priorityRaw,
|
||||
String? assetType,
|
||||
String paymentId = '',
|
||||
int accountIndex = 0}) =>
|
||||
String paymentId = ''}) =>
|
||||
compute(_createTransactionMultDestSync, {
|
||||
'outputs': outputs,
|
||||
'assetType': assetType,
|
||||
'paymentId': paymentId,
|
||||
'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:ffi/ffi.dart';
|
||||
|
||||
typedef CreateWallet = int Function(
|
||||
typedef CreateWallet = Pointer<Utf8> Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>);
|
||||
|
||||
typedef RestoreWalletFromSeed = int Function(
|
||||
|
@ -47,7 +47,7 @@ typedef GetNodeHeight = int Function();
|
|||
typedef IsConnected = int Function();
|
||||
|
||||
typedef SetupNode = int Function(Pointer<Utf8>, Pointer<Utf8>?, Pointer<Utf8>?,
|
||||
int, int, Pointer<Utf8>?, Pointer<Utf8>);
|
||||
int, int, Pointer<Utf8>);
|
||||
|
||||
typedef StartRefresh = void Function();
|
||||
|
||||
|
@ -105,7 +105,6 @@ typedef TransactionCreate = int Function(
|
|||
Pointer<Utf8> paymentId,
|
||||
Pointer<Utf8> amount,
|
||||
int priorityRaw,
|
||||
int subaddrAccount,
|
||||
Pointer<Utf8Box> error,
|
||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||
|
||||
|
@ -116,7 +115,6 @@ typedef TransactionCreateMultDest = int Function(
|
|||
Pointer<Pointer<Utf8>> amounts,
|
||||
int size,
|
||||
int priorityRaw,
|
||||
int subaddrAccount,
|
||||
Pointer<Utf8Box> error,
|
||||
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/types.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:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
@ -16,8 +17,8 @@ final getFileNameNative = zanoApi
|
|||
.lookup<NativeFunction<get_filename>>('get_filename')
|
||||
.asFunction<GetFilename>();
|
||||
|
||||
final getSeedNative =
|
||||
zanoApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
|
||||
/*final getSeedNative =
|
||||
zanoApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();*/
|
||||
|
||||
final getAddressNative = zanoApi
|
||||
.lookup<NativeFunction<get_address>>('get_address')
|
||||
|
@ -31,9 +32,9 @@ final getUnlockedBalanceNative = zanoApi
|
|||
.lookup<NativeFunction<get_unlocked_balanace>>('get_unlocked_balance')
|
||||
.asFunction<GetUnlockedBalance>();
|
||||
|
||||
final getCurrentHeightNative = zanoApi
|
||||
/**final getCurrentHeightNative = zanoApi
|
||||
.lookup<NativeFunction<get_current_height>>('get_current_height')
|
||||
.asFunction<GetCurrentHeight>();
|
||||
.asFunction<GetCurrentHeight>();*/
|
||||
|
||||
final getNodeHeightNative = zanoApi
|
||||
.lookup<NativeFunction<get_node_height>>('get_node_height')
|
||||
|
@ -72,9 +73,9 @@ final setPasswordNative = zanoApi
|
|||
.lookup<NativeFunction<set_password>>('set_password')
|
||||
.asFunction<SetPassword>();
|
||||
|
||||
final setListenerNative = zanoApi
|
||||
/**final setListenerNative = zanoApi
|
||||
.lookup<NativeFunction<set_listener>>('set_listener')
|
||||
.asFunction<SetListener>();
|
||||
.asFunction<SetListener>();*/
|
||||
|
||||
final getSyncingHeightNative = zanoApi
|
||||
.lookup<NativeFunction<get_syncing_height>>('get_syncing_height')
|
||||
|
@ -133,7 +134,7 @@ bool isNewTransactionExist() => isNewTransactionExistNative() != 0;
|
|||
|
||||
String getFilename() => convertUTF8ToString(pointer: getFileNameNative());
|
||||
|
||||
String getSeed() => convertUTF8ToString(pointer: getSeedNative());
|
||||
/**String getSeed() => convertUTF8ToString(pointer: getSeedNative());*/
|
||||
|
||||
String getAddress({int accountIndex = 0, int addressIndex = 0}) =>
|
||||
convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex));
|
||||
|
@ -144,7 +145,11 @@ int getFullBalance({int accountIndex = 0}) =>
|
|||
int getUnlockedBalance({int accountIndex = 0}) =>
|
||||
getUnlockedBalanceNative(accountIndex);
|
||||
|
||||
int getCurrentHeight() => getCurrentHeightNative();
|
||||
int getCurrentHeight(int hWallet) {
|
||||
calls.getWalletStatus(hWallet);
|
||||
return -1;
|
||||
//return getCurrentHeightNative();
|
||||
}
|
||||
|
||||
int getNodeHeightSync() => getNodeHeightNative();
|
||||
|
||||
|
@ -156,7 +161,7 @@ bool setupNodeSync(
|
|||
String? password,
|
||||
bool useSSL = false,
|
||||
bool isLightWallet = false,
|
||||
String? socksProxyAddress}) {
|
||||
/*String? socksProxyAddress*/}) {
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
Pointer<Utf8>? loginPointer;
|
||||
Pointer<Utf8>? socksProxyAddressPointer;
|
||||
|
@ -170,20 +175,23 @@ bool setupNodeSync(
|
|||
passwordPointer = password.toNativeUtf8();
|
||||
}
|
||||
|
||||
if (socksProxyAddress != null) {
|
||||
/*if (socksProxyAddress != null) {
|
||||
socksProxyAddressPointer = socksProxyAddress.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(
|
||||
addressPointer,
|
||||
loginPointer,
|
||||
passwordPointer,
|
||||
_boolToInt(useSSL),
|
||||
_boolToInt(isLightWallet),
|
||||
socksProxyAddressPointer,
|
||||
/*socksProxyAddressPointer,*/
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
debugPrint("setup_node result $isSetupNode");
|
||||
|
||||
calloc.free(addressPointer);
|
||||
|
||||
|
@ -195,10 +203,11 @@ bool setupNodeSync(
|
|||
calloc.free(passwordPointer);
|
||||
}
|
||||
|
||||
if (!isSetupNode) {
|
||||
// TODO: fix it
|
||||
/**if (!isSetupNode) {
|
||||
throw SetupWalletException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
}
|
||||
}*/
|
||||
|
||||
return isSetupNode;
|
||||
}
|
||||
|
@ -213,10 +222,12 @@ void setRefreshFromBlockHeight({required int height}) =>
|
|||
void setRecoveringFromSeed({required bool isRecovery}) =>
|
||||
setRecoveringFromSeedNative(_boolToInt(isRecovery));
|
||||
|
||||
void storeSync() {
|
||||
final pathPointer = ''.toNativeUtf8();
|
||||
void storeSync(int hWallet) {
|
||||
calls.store(hWallet);
|
||||
// TODO: fixit
|
||||
/*final pathPointer = ''.toNativeUtf8();
|
||||
storeNative(pathPointer);
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(pathPointer);*/
|
||||
}
|
||||
|
||||
void setPasswordSync(String password) {
|
||||
|
@ -283,7 +294,8 @@ class SyncListener {
|
|||
var syncHeight = getSyncingHeight();
|
||||
|
||||
if (syncHeight <= 0) {
|
||||
syncHeight = getCurrentHeight();
|
||||
// TODO: fix it
|
||||
syncHeight = getCurrentHeight(-1);
|
||||
}
|
||||
|
||||
if (_initialSyncHeight <= 0) {
|
||||
|
@ -317,13 +329,13 @@ class SyncListener {
|
|||
SyncListener setListeners(void Function(int, int, double) onNewBlock,
|
||||
void Function() onNewTransaction) {
|
||||
final listener = SyncListener(onNewBlock, onNewTransaction);
|
||||
setListenerNative();
|
||||
/**setListenerNative();*/
|
||||
return listener;
|
||||
}
|
||||
|
||||
void onStartup() => onStartupNative();
|
||||
|
||||
void _storeSync(Object _) => storeSync();
|
||||
void _storeSync(int hWallet) => storeSync(hWallet);
|
||||
|
||||
bool _setupNodeSync(Map args) {
|
||||
final address = args['address'] as String;
|
||||
|
@ -331,7 +343,7 @@ bool _setupNodeSync(Map args) {
|
|||
final password = (args['password'] ?? '') as String;
|
||||
final useSSL = args['useSSL'] as bool;
|
||||
final isLightWallet = args['isLightWallet'] as bool;
|
||||
final socksProxyAddress = (args['socksProxyAddress'] ?? '') as String;
|
||||
/*final socksProxyAddress = (args['socksProxyAddress'] ?? '') as String;*/
|
||||
|
||||
return setupNodeSync(
|
||||
address: address,
|
||||
|
@ -339,7 +351,7 @@ bool _setupNodeSync(Map args) {
|
|||
password: password,
|
||||
useSSL: useSSL,
|
||||
isLightWallet: isLightWallet,
|
||||
socksProxyAddress: socksProxyAddress);
|
||||
/*socksProxyAddress: socksProxyAddress*/);
|
||||
}
|
||||
|
||||
bool _isConnected(Object _) => isConnectedSync();
|
||||
|
@ -348,23 +360,23 @@ int _getNodeHeight(Object _) => getNodeHeightSync();
|
|||
|
||||
void startRefresh() => startRefreshSync();
|
||||
|
||||
Future<void> setupNode(
|
||||
Future<bool> setupNode(
|
||||
{required String address,
|
||||
String? login,
|
||||
String? password,
|
||||
bool useSSL = false,
|
||||
String? socksProxyAddress,
|
||||
/*String? socksProxyAddress,*/
|
||||
bool isLightWallet = false}) =>
|
||||
compute<Map<String, Object?>, void>(_setupNodeSync, {
|
||||
compute<Map<String, Object?>, bool>(_setupNodeSync, {
|
||||
'address': address,
|
||||
'login': login,
|
||||
'password': password,
|
||||
'useSSL': useSSL,
|
||||
'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);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ final errorStringNative = zanoApi
|
|||
.lookup<NativeFunction<error_string>>('error_string')
|
||||
.asFunction<ErrorString>();
|
||||
|
||||
void createWalletSync(
|
||||
String createWalletSync(
|
||||
{required String path,
|
||||
required String password,
|
||||
required String language,
|
||||
|
@ -46,20 +46,23 @@ void createWalletSync(
|
|||
final passwordPointer = password.toNativeUtf8();
|
||||
final languagePointer = language.toNativeUtf8();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isWalletCreated = createWalletNative(pathPointer, passwordPointer,
|
||||
languagePointer, nettype, errorMessagePointer) !=
|
||||
0;
|
||||
debugPrint("create_wallet path $path password $password language $language");
|
||||
final result = convertUTF8ToString(pointer: createWalletNative(pathPointer, passwordPointer,
|
||||
languagePointer, nettype, errorMessagePointer));
|
||||
//debugPrint("create_wallet $result");
|
||||
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(languagePointer);
|
||||
|
||||
if (!isWalletCreated) {
|
||||
return result;
|
||||
/*if (hWallet == 0) {
|
||||
throw WalletCreationException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
}
|
||||
|
||||
// setupNodeSync(address: "node.moneroworld.com:18089");
|
||||
return hWallet;
|
||||
// setupNodeSync(address: "node.moneroworld.com:18089");*/
|
||||
}
|
||||
|
||||
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 password = args['password'] 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) {
|
||||
|
@ -206,12 +209,12 @@ void openWallet(
|
|||
Future<void> openWalletAsync(Map<String, String> args) async =>
|
||||
compute(_openWallet, args);
|
||||
|
||||
Future<void> createWallet(
|
||||
Future<String> createWallet(
|
||||
{required String path,
|
||||
required String password,
|
||||
required String language,
|
||||
int nettype = 0}) async =>
|
||||
compute(_createWallet, {
|
||||
compute<Map<String, dynamic>, String>(_createWallet, {
|
||||
'path': path,
|
||||
'password': password,
|
||||
'language': language,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class MoneroOutput {
|
||||
MoneroOutput({required this.address, required this.amount});
|
||||
class ZanoOutput {
|
||||
ZanoOutput({required this.address, required this.amount});
|
||||
|
||||
final String address;
|
||||
final String amount;
|
|
@ -3,11 +3,16 @@ import 'package:cw_core/account.dart';
|
|||
import 'package:cw_core/account_list.dart';
|
||||
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;
|
||||
|
||||
abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
||||
ZanoAccountListBase.simple()
|
||||
: accounts = ObservableList<Account>(),
|
||||
_isRefreshing = false,
|
||||
_isUpdating = false {}
|
||||
|
||||
ZanoAccountListBase()
|
||||
: accounts = ObservableList<Account>(),
|
||||
_isRefreshing = false,
|
||||
|
@ -67,7 +72,7 @@ abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
|||
|
||||
@override
|
||||
void refresh() {
|
||||
if (_isRefreshing) {
|
||||
/**if (_isRefreshing) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -80,5 +85,5 @@ abstract class ZanoAccountListBase extends AccountList<Account> with Store {
|
|||
print(e);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}*/
|
||||
|
|
|
@ -1,16 +1,34 @@
|
|||
import 'package:cw_core/balance.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/monero_balance.dart';
|
||||
import 'package:cw_zano/api/balance_list.dart';
|
||||
import 'package:cw_zano/api/structs/zano_balance_row.dart';
|
||||
|
||||
const inactiveBalances = [
|
||||
CryptoCurrency.xcad,
|
||||
CryptoCurrency.xjpy,
|
||||
CryptoCurrency.xnok,
|
||||
CryptoCurrency.xnzd
|
||||
];
|
||||
class ZanoBalance extends Balance {
|
||||
ZanoBalance(super.available, super.additional);
|
||||
late int unlockedBalance;
|
||||
@override
|
||||
// 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 unlockedBalances = getZanoUnlockedBalance(accountIndex: accountIndex);
|
||||
final zanoBalances = <CryptoCurrency, MoneroBalance>{};
|
||||
|
@ -32,4 +50,4 @@ Map<CryptoCurrency, MoneroBalance> getZanoBalance({required int accountIndex}) {
|
|||
}
|
||||
|
||||
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_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 {
|
||||
ZanoSubaddressListBase()
|
||||
|
@ -85,4 +85,4 @@ abstract class ZanoSubaddressListBase with Store {
|
|||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
|
|
@ -3,11 +3,13 @@ import 'dart:io';
|
|||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/pathForWallet.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_core/monero_amount_format.dart';
|
||||
import 'package:cw_zano/zano_transaction_creation_exception.dart';
|
||||
import 'package:cw_zano/zano_transaction_info.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_zano/api/structs/pending_transaction.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/api/wallet.dart' as zano_wallet;
|
||||
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_core/monero_wallet_keys.dart';
|
||||
import 'package:cw_core/monero_balance.dart';
|
||||
|
@ -37,24 +39,35 @@ const moneroBlockSize = 1000;
|
|||
|
||||
class ZanoWallet = ZanoWalletBase with _$ZanoWallet;
|
||||
|
||||
abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
||||
ZanoTransactionHistory, ZanoTransactionInfo> with Store {
|
||||
abstract class ZanoWalletBase
|
||||
extends WalletBase<ZanoBalance, ZanoTransactionHistory, ZanoTransactionInfo>
|
||||
with Store {
|
||||
ZanoWalletBase.simple({required WalletInfo walletInfo})
|
||||
: balance = ObservableMap(),
|
||||
_isTransactionUpdating = false,
|
||||
_hasSyncAfterStartup = false,
|
||||
walletAddresses = ZanoWalletAddresses(walletInfo),
|
||||
syncStatus = NotConnectedSyncStatus(),
|
||||
super(walletInfo) {
|
||||
transactionHistory = ZanoTransactionHistory();
|
||||
}
|
||||
|
||||
ZanoWalletBase({required WalletInfo walletInfo})
|
||||
: balance = ObservableMap.of(getZanoBalance(accountIndex: 0)),
|
||||
: balance = ObservableMap.of({CryptoCurrency.zano: ZanoBalance(0, 0)}),
|
||||
_isTransactionUpdating = false,
|
||||
_hasSyncAfterStartup = false,
|
||||
walletAddresses = ZanoWalletAddresses(walletInfo),
|
||||
syncStatus = NotConnectedSyncStatus(),
|
||||
super(walletInfo) {
|
||||
transactionHistory = ZanoTransactionHistory();
|
||||
_onAccountChangeReaction =
|
||||
/*_onAccountChangeReaction =
|
||||
reaction((_) => walletAddresses.account, (Account? account) {
|
||||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
balance.addAll(getZanoBalance(accountIndex: account.id));
|
||||
walletAddresses.updateSubaddressList(accountIndex: account.id);
|
||||
});
|
||||
/**walletAddresses.updateSubaddressList(accountIndex: account.id);*/
|
||||
});*/
|
||||
}
|
||||
|
||||
static const int _autoSaveInterval = 30;
|
||||
|
@ -68,12 +81,18 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
|
||||
@override
|
||||
@observable
|
||||
ObservableMap<CryptoCurrency, MoneroBalance> balance;
|
||||
ObservableMap<CryptoCurrency, ZanoBalance> balance;
|
||||
|
||||
@override
|
||||
String get seed => zano_wallet.getSeed();
|
||||
String get seed {
|
||||
// TODO: fix it
|
||||
//return calls.seed(hWallet);
|
||||
return "test";
|
||||
/**zano_wallet.getSeed();*/
|
||||
}
|
||||
|
||||
@override
|
||||
// TODO: ?? why monero
|
||||
MoneroWalletKeys get keys => MoneroWalletKeys(
|
||||
privateSpendKey: zano_wallet.getSecretSpendKey(),
|
||||
privateViewKey: zano_wallet.getSecretViewKey(),
|
||||
|
@ -81,22 +100,30 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
publicViewKey: zano_wallet.getPublicViewKey());
|
||||
|
||||
zano_wallet.SyncListener? _listener;
|
||||
ReactionDisposer? _onAccountChangeReaction;
|
||||
/**ReactionDisposer? _onAccountChangeReaction;*/
|
||||
bool _isTransactionUpdating;
|
||||
bool _hasSyncAfterStartup;
|
||||
Timer? _autoSaveTimer;
|
||||
|
||||
int _hWallet = 0;
|
||||
|
||||
int get hWallet => _hWallet;
|
||||
|
||||
set hWallet(int value) {
|
||||
_hWallet = value;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
await walletAddresses.init();
|
||||
balance
|
||||
.addAll(getZanoBalance(accountIndex: walletAddresses.account?.id ?? 0));
|
||||
.addAll(getZanoBalance(/**accountIndex: walletAddresses.account?.id ?? 0*/));
|
||||
_setListeners();
|
||||
await updateTransactions();
|
||||
|
||||
if (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);
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +138,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
@override
|
||||
void close() {
|
||||
_listener?.stop();
|
||||
_onAccountChangeReaction?.reaction.dispose();
|
||||
/**_onAccountChangeReaction?.reaction.dispose();*/
|
||||
_autoSaveTimer?.cancel();
|
||||
}
|
||||
|
||||
|
@ -120,12 +147,13 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
try {
|
||||
syncStatus = ConnectingSyncStatus();
|
||||
await zano_wallet.setupNode(
|
||||
address: node.uriRaw,
|
||||
login: node.login,
|
||||
password: node.password,
|
||||
useSSL: node.useSSL ?? false,
|
||||
isLightWallet: false, // FIXME: hardcoded value
|
||||
socksProxyAddress: node.socksProxyAddress);
|
||||
address: "195.201.107.230:33336", // node.uriRaw,
|
||||
login: "", // node.login,
|
||||
password: "", // node.password,
|
||||
useSSL: false, // node.useSSL ?? false,
|
||||
isLightWallet: false, // FIXME: hardcoded value
|
||||
/*socksProxyAddress: node.socksProxyAddress*/
|
||||
);
|
||||
|
||||
zano_wallet.setTrustedDaemon(node.trusted);
|
||||
syncStatus = ConnectedSyncStatus();
|
||||
|
@ -160,7 +188,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
final hasMultiDestination = outputs.length > 1;
|
||||
final assetType =
|
||||
CryptoCurrency.fromString(_credentials.assetType.toLowerCase());
|
||||
final balances = getZanoBalance(accountIndex: walletAddresses.account!.id);
|
||||
final balances = getZanoBalance(/*accountIndex: walletAddresses.account!.id*/);
|
||||
final unlockedBalance = balances[assetType]!.unlockedBalance;
|
||||
|
||||
PendingTransactionDescription pendingTransactionDescription;
|
||||
|
@ -184,17 +212,16 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
'You do not have enough coins to send this amount.');
|
||||
}
|
||||
|
||||
final moneroOutputs = outputs
|
||||
.map((output) => MoneroOutput(
|
||||
final zanoOutputs = outputs
|
||||
.map((output) => ZanoOutput(
|
||||
address: output.address,
|
||||
amount: output.cryptoAmount!.replaceAll(',', '.')))
|
||||
.toList();
|
||||
|
||||
pendingTransactionDescription =
|
||||
await transaction_history.createTransactionMultDest(
|
||||
outputs: moneroOutputs,
|
||||
priorityRaw: _credentials.priority.serialize(),
|
||||
accountIndex: walletAddresses.account!.id);
|
||||
outputs: zanoOutputs,
|
||||
priorityRaw: _credentials.priority.serialize());
|
||||
} else {
|
||||
final output = outputs.first;
|
||||
final address = output.isParsedAddress &&
|
||||
|
@ -219,8 +246,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
address: address,
|
||||
assetType: _credentials.assetType,
|
||||
amount: amount,
|
||||
priorityRaw: _credentials.priority.serialize(),
|
||||
accountIndex: walletAddresses.account!.id);
|
||||
priorityRaw: _credentials.priority.serialize());
|
||||
}
|
||||
|
||||
return PendingZanoTransaction(pendingTransactionDescription, assetType);
|
||||
|
@ -252,7 +278,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
Future<void> save() async {
|
||||
await walletAddresses.updateAddressesInBox();
|
||||
await backupWalletFiles(name);
|
||||
await zano_wallet.store();
|
||||
await zano_wallet.store(hWallet);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -301,7 +327,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
zano_wallet.rescanBlockchainAsync();
|
||||
await startSync();
|
||||
_askForUpdateBalance();
|
||||
walletAddresses.accountList.update();
|
||||
/**walletAddresses.accountList.update();*/
|
||||
await _askForUpdateTransactionHistory();
|
||||
await save();
|
||||
await walletInfo.save();
|
||||
|
@ -355,7 +381,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
return;
|
||||
}
|
||||
|
||||
final currentHeight = zano_wallet.getCurrentHeight();
|
||||
final currentHeight = zano_wallet.getCurrentHeight(hWallet);
|
||||
|
||||
if (currentHeight <= 1) {
|
||||
final height = _getHeightByDate(walletInfo.date);
|
||||
|
@ -385,7 +411,7 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
}
|
||||
|
||||
void _askForUpdateBalance() =>
|
||||
balance.addAll(getZanoBalance(accountIndex: walletAddresses.account!.id));
|
||||
balance.addAll(getZanoBalance());
|
||||
|
||||
Future<void> _askForUpdateTransactionHistory() async =>
|
||||
await updateTransactions();
|
||||
|
@ -395,13 +421,13 @@ abstract class ZanoWalletBase extends WalletBase<MoneroBalance,
|
|||
if (walletInfo.isRecovery) {
|
||||
await _askForUpdateTransactionHistory();
|
||||
_askForUpdateBalance();
|
||||
walletAddresses.accountList.update();
|
||||
/*walletAddresses.accountList.update();*/
|
||||
}
|
||||
|
||||
if (blocksLeft < 1000) {
|
||||
await _askForUpdateTransactionHistory();
|
||||
_askForUpdateBalance();
|
||||
walletAddresses.accountList.update();
|
||||
/*walletAddresses.accountList.update();*/
|
||||
syncStatus = SyncedSyncStatus();
|
||||
|
||||
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/account.dart';
|
||||
import 'package:cw_zano/zano_account_list.dart';
|
||||
|
@ -10,12 +10,10 @@ part 'zano_wallet_addresses.g.dart';
|
|||
|
||||
class ZanoWalletAddresses = ZanoWalletAddressesBase with _$ZanoWalletAddresses;
|
||||
|
||||
abstract class ZanoWalletAddressesBase
|
||||
extends WalletAddressesWithAccount<Account> with Store {
|
||||
/**abstract class ZanoWalletAddressesBase extends WalletAddressesWithAccount<Account> with Store {*/
|
||||
abstract class ZanoWalletAddressesBase extends WalletAddresses with Store {
|
||||
ZanoWalletAddressesBase(WalletInfo walletInfo)
|
||||
: accountList = ZanoAccountList(),
|
||||
subaddressList = ZanoSubaddressList(),
|
||||
address = '',
|
||||
: address = '',
|
||||
super(walletInfo);
|
||||
|
||||
@override
|
||||
|
@ -23,65 +21,68 @@ abstract class ZanoWalletAddressesBase
|
|||
String address;
|
||||
|
||||
// @override
|
||||
@observable
|
||||
Account? account;
|
||||
/**@observable
|
||||
Account? account;*/
|
||||
|
||||
@observable
|
||||
Subaddress? subaddress;
|
||||
/**@observable
|
||||
Subaddress? subaddress;*/
|
||||
|
||||
ZanoSubaddressList subaddressList;
|
||||
/**ZanoSubaddressList subaddressList;*/
|
||||
|
||||
ZanoAccountList accountList;
|
||||
/**ZanoAccountList accountList;*/
|
||||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
accountList.update();
|
||||
account = accountList.accounts.first;
|
||||
updateSubaddressList(accountIndex: account?.id ?? 0);
|
||||
/*accountList.update();
|
||||
account = accountList.accounts.first;*/
|
||||
/**updateSubaddressList(accountIndex: account?.id ?? 0);*/
|
||||
address = walletInfo.address;
|
||||
await updateAddressesInBox();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateAddressesInBox() async {
|
||||
try {
|
||||
final _subaddressList = ZanoSubaddressList();
|
||||
/**final _subaddressList = ZanoSubaddressList();*/
|
||||
|
||||
addressesMap.clear();
|
||||
addressesMap[address] = '';
|
||||
await saveAddressesInBox();
|
||||
|
||||
accountList.accounts.forEach((account) {
|
||||
/*accountList.accounts.forEach((account) {
|
||||
_subaddressList.update(accountIndex: account.id);
|
||||
_subaddressList.subaddresses.forEach((subaddress) {
|
||||
addressesMap[subaddress.address] = subaddress.label;
|
||||
});
|
||||
});
|
||||
|
||||
await saveAddressesInBox();
|
||||
await saveAddressesInBox();*/
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
bool validate() {
|
||||
accountList.update();
|
||||
final accountListLength = accountList.accounts.length ?? 0;
|
||||
// bool validate() {
|
||||
// accountList.update();
|
||||
// final accountListLength = accountList.accounts.length ?? 0;
|
||||
|
||||
if (accountListLength <= 0) {
|
||||
return false;
|
||||
}
|
||||
// if (accountListLength <= 0) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
subaddressList.update(accountIndex: accountList.accounts.first.id);
|
||||
final subaddressListLength = subaddressList.subaddresses.length ?? 0;
|
||||
// /**subaddressList.update(accountIndex: accountList.accounts.first.id);
|
||||
// final subaddressListLength = subaddressList.subaddresses.length ?? 0;
|
||||
|
||||
if (subaddressListLength <= 0) {
|
||||
return false;
|
||||
}
|
||||
// if (subaddressListLength <= 0) {
|
||||
// return false;
|
||||
// }*/
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
|
||||
void updateSubaddressList({required int accountIndex}) {
|
||||
/*void updateSubaddressList({required int accountIndex}) {
|
||||
subaddressList.update(accountIndex: accountIndex);
|
||||
subaddress = subaddressList.subaddresses.first;
|
||||
address = subaddress!.address;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import 'dart:io';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:cw_core/node.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/monero_wallet_utils.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
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/calls.dart' as calls;
|
||||
import 'package:cw_zano/api/exceptions/wallet_opening_exception.dart';
|
||||
import 'package:cw_zano/zano_wallet.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';
|
||||
|
||||
class ZanoNewWalletCredentials extends WalletCredentials {
|
||||
ZanoNewWalletCredentials(
|
||||
{required String name, required this.language, String? password})
|
||||
ZanoNewWalletCredentials({required String name, String? password})
|
||||
: super(name: name, password: password);
|
||||
|
||||
final String language;
|
||||
}
|
||||
|
||||
class ZanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
|
@ -65,18 +64,23 @@ class ZanoWalletService extends WalletService<
|
|||
static bool walletFilesExist(String path) =>
|
||||
!File(path).existsSync() && !File('$path.keys').existsSync();
|
||||
|
||||
int hWallet = 0;
|
||||
|
||||
@override
|
||||
WalletType getType() => WalletType.zano;
|
||||
|
||||
@override
|
||||
Future<ZanoWallet> create(ZanoNewWalletCredentials credentials) async {
|
||||
try {
|
||||
final wallet = ZanoWallet.simple(walletInfo: credentials.walletInfo!);
|
||||
wallet.connectToNode(node: Node());
|
||||
final path = await pathForWallet(name: credentials.name, type: getType());
|
||||
await zano_wallet_manager.createWallet(
|
||||
path: path,
|
||||
password: credentials.password!,
|
||||
language: credentials.language);
|
||||
final wallet = ZanoWallet(walletInfo: credentials.walletInfo!);
|
||||
final result = await zano_wallet_manager.createWallet(
|
||||
language: "", path: path, password: credentials.password!);
|
||||
hWallet = -1;
|
||||
wallet.hWallet = hWallet;
|
||||
// TODO: remove it
|
||||
calls.store(hWallet);
|
||||
await wallet.init();
|
||||
return wallet;
|
||||
} catch (e) {
|
||||
|
@ -112,13 +116,13 @@ class ZanoWalletService extends WalletService<
|
|||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||
(info) => info.id == WalletBase.idFor(name, getType()))!;
|
||||
final wallet = ZanoWallet(walletInfo: walletInfo);
|
||||
final isValid = wallet.walletAddresses.validate();
|
||||
/*final isValid = wallet.walletAddresses.validate();
|
||||
|
||||
if (!isValid) {
|
||||
await restoreOrResetWalletFiles(name);
|
||||
wallet.close();
|
||||
return openWallet(name, password);
|
||||
}
|
||||
}*/
|
||||
|
||||
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 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 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);
|
||||
|
||||
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.ethereumIcon = Image.asset('assets/images/eth_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;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
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 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 double tileHeight = 60;
|
||||
Flushbar<void>? _progressBar;
|
||||
|
|
|
@ -48,8 +48,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
|||
case WalletType.ethereum:
|
||||
return ethereum!.createEthereumNewWalletCredentials(name: name);
|
||||
case WalletType.zano:
|
||||
return zano!.createZanoNewWalletCredentials(
|
||||
name: name, language: "en");
|
||||
return zano!.createZanoNewWalletCredentials(name: name);
|
||||
case WalletType.dummy:
|
||||
return dummy!.createDummyNewWalletCredentials(name: name);
|
||||
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';
|
||||
|
||||
class CWZanoAccountList extends ZanoAccountList {
|
||||
/**class CWZanoAccountList extends ZanoAccountList {
|
||||
CWZanoAccountList(this._wallet);
|
||||
|
||||
final Object _wallet;
|
||||
|
@ -49,73 +49,20 @@ class CWZanoAccountList extends ZanoAccountList {
|
|||
await zanoWallet.walletAddresses.accountList
|
||||
.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 {
|
||||
CWZanoWalletDetails(this._wallet);
|
||||
|
||||
final Object _wallet;
|
||||
|
||||
@computed
|
||||
@override
|
||||
Account get account {
|
||||
final zanoWallet = _wallet as ZanoWallet;
|
||||
final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||
return Account(id: acc.id, label: acc.label);
|
||||
}
|
||||
// @computed
|
||||
// @override
|
||||
// Account get account {
|
||||
// final zanoWallet = _wallet as ZanoWallet;
|
||||
// final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||
// return Account(id: acc.id, label: acc.label);
|
||||
// }
|
||||
|
||||
@computed
|
||||
@override
|
||||
|
@ -130,15 +77,10 @@ class CWZanoWalletDetails extends ZanoWalletDetails {
|
|||
}
|
||||
|
||||
class CWZano extends Zano {
|
||||
@override
|
||||
/**@override
|
||||
ZanoAccountList getAccountList(Object wallet) {
|
||||
return CWZanoAccountList(wallet);
|
||||
}
|
||||
|
||||
@override
|
||||
MoneroSubaddressList getSubaddressList(Object wallet) {
|
||||
return CWZanoSubaddressList(wallet);
|
||||
}
|
||||
}*/
|
||||
|
||||
@override
|
||||
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
||||
|
@ -147,7 +89,7 @@ class CWZano extends Zano {
|
|||
}
|
||||
|
||||
@override
|
||||
ZanoWalletDetails getMoneroWalletDetails(Object wallet) {
|
||||
ZanoWalletDetails getZanoWalletDetails(Object wallet) {
|
||||
return CWZanoWalletDetails(wallet);
|
||||
}
|
||||
|
||||
|
@ -231,8 +173,8 @@ class CWZano extends Zano {
|
|||
|
||||
@override
|
||||
WalletCredentials createZanoNewWalletCredentials(
|
||||
{required String name, required String language, String? password}) {
|
||||
return ZanoNewWalletCredentials(name: name, password: password, language: language);
|
||||
{required String name, String? password}) {
|
||||
return ZanoNewWalletCredentials(name: name, password: password);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -283,18 +225,18 @@ class CWZano extends Zano {
|
|||
return moneroParseAmount(amount: amount);
|
||||
}
|
||||
|
||||
@override
|
||||
Account getCurrentAccount(Object wallet) {
|
||||
final zanoWallet = wallet as ZanoWallet;
|
||||
final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||
return Account(id: acc.id, label: acc.label);
|
||||
}
|
||||
// @override
|
||||
// Account getCurrentAccount(Object wallet) {
|
||||
// final zanoWallet = wallet as ZanoWallet;
|
||||
// final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||
// return Account(id: acc.id, label: acc.label);
|
||||
// }
|
||||
|
||||
@override
|
||||
void setCurrentAccount(Object wallet, int id, String label) {
|
||||
final zanoWallet = wallet as ZanoWallet;
|
||||
zanoWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
|
||||
}
|
||||
// @override
|
||||
// void setCurrentAccount(Object wallet, int id, String label) {
|
||||
// final zanoWallet = wallet as ZanoWallet;
|
||||
// zanoWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
|
||||
// }
|
||||
|
||||
@override
|
||||
void onStartup() {
|
||||
|
|
|
@ -37,21 +37,21 @@ part 'cw_zano.dart';
|
|||
|
||||
Zano? zano = CWZano();
|
||||
|
||||
class Account {
|
||||
Account({required this.id, required this.label});
|
||||
final int id;
|
||||
final String label;
|
||||
}
|
||||
// class Account {
|
||||
// Account({required this.id, required this.label});
|
||||
// final int id;
|
||||
// final String label;
|
||||
// }
|
||||
|
||||
class Subaddress {
|
||||
Subaddress({
|
||||
required this.id,
|
||||
required this.label,
|
||||
required this.address});
|
||||
final int id;
|
||||
final String label;
|
||||
final String address;
|
||||
}
|
||||
// class Subaddress {
|
||||
// Subaddress({
|
||||
// required this.id,
|
||||
// required this.label,
|
||||
// required this.address});
|
||||
// final int id;
|
||||
// final String label;
|
||||
// final String address;
|
||||
// }
|
||||
|
||||
class ZanoBalance extends Balance {
|
||||
ZanoBalance({required this.fullBalance, required this.unlockedBalance})
|
||||
|
@ -89,21 +89,19 @@ class AssetRate {
|
|||
|
||||
abstract class ZanoWalletDetails {
|
||||
// FIX-ME: it's abstruct class
|
||||
@observable
|
||||
late Account account;
|
||||
// @observable
|
||||
// late Account account;
|
||||
// FIX-ME: it's abstruct class
|
||||
@observable
|
||||
late ZanoBalance balance;
|
||||
}
|
||||
|
||||
abstract class Zano {
|
||||
ZanoAccountList getAccountList(Object wallet);
|
||||
/**ZanoAccountList getAccountList(Object wallet);*/
|
||||
|
||||
MoneroSubaddressList getSubaddressList(Object wallet);
|
||||
|
||||
TransactionHistoryBase getTransactionHistory(Object wallet);
|
||||
|
||||
ZanoWalletDetails getMoneroWalletDetails(Object wallet);
|
||||
ZanoWalletDetails getZanoWalletDetails(Object wallet);
|
||||
|
||||
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex);
|
||||
|
||||
|
@ -123,14 +121,14 @@ abstract class Zano {
|
|||
required String language,
|
||||
required int height});
|
||||
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);
|
||||
Object createZanoTransactionCreationCredentials({required List<Output> outputs, required TransactionPriority priority, required String assetType});
|
||||
String formatterMoneroAmountToString({required int amount});
|
||||
double formatterMoneroAmountToDouble({required int amount});
|
||||
int formatterMoneroParseAmount({required String amount});
|
||||
Account getCurrentAccount(Object wallet);
|
||||
void setCurrentAccount(Object wallet, int id, String label);
|
||||
// Account getCurrentAccount(Object wallet);
|
||||
// void setCurrentAccount(Object wallet, int id, String label);
|
||||
void onStartup();
|
||||
int getTransactionInfoAccountId(TransactionInfo tx);
|
||||
WalletService createZanoWalletService(Box<WalletInfo> walletInfoSource);
|
||||
|
@ -138,22 +136,22 @@ abstract class Zano {
|
|||
List<AssetRate> getAssetRate();
|
||||
}
|
||||
|
||||
abstract class MoneroSubaddressList {
|
||||
ObservableList<Subaddress> get subaddresses;
|
||||
void update(Object wallet, {required int accountIndex});
|
||||
void refresh(Object wallet, {required int accountIndex});
|
||||
List<Subaddress> getAll(Object wallet);
|
||||
Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label});
|
||||
Future<void> setLabelSubaddress(Object wallet,
|
||||
{required int accountIndex, required int addressIndex, required String label});
|
||||
}
|
||||
// abstract class MoneroSubaddressList {
|
||||
// ObservableList<Subaddress> get subaddresses;
|
||||
// void update(Object wallet, {required int accountIndex});
|
||||
// void refresh(Object wallet, {required int accountIndex});
|
||||
// List<Subaddress> getAll(Object wallet);
|
||||
// Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label});
|
||||
// Future<void> setLabelSubaddress(Object wallet,
|
||||
// {required int accountIndex, required int addressIndex, required String label});
|
||||
// }
|
||||
|
||||
abstract class ZanoAccountList {
|
||||
ObservableList<Account> get accounts;
|
||||
void update(Object wallet);
|
||||
void refresh(Object wallet);
|
||||
List<Account> getAll(Object wallet);
|
||||
Future<void> addAccount(Object wallet, {required String label});
|
||||
Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
|
||||
}
|
||||
// abstract class ZanoAccountList {
|
||||
// ObservableList<Account> get accounts;
|
||||
// void update(Object wallet);
|
||||
// void refresh(Object wallet);
|
||||
// List<Account> getAll(Object wallet);
|
||||
// Future<void> addAccount(Object wallet, {required String label});
|
||||
// Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
|
||||
// }
|
||||
|
Loading…
Reference in a new issue