added pending transfer, some cleanup of unused

This commit is contained in:
leo 2023-12-16 08:49:23 +00:00
parent 8d3dd6f202
commit 3eaec03b6c
57 changed files with 314 additions and 16189 deletions

View file

@ -1,85 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.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/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 accountRefreshNative = zanoApi
// .lookup<NativeFunction<account_refresh>>('account_refresh')
// .asFunction<AccountRefresh>();
// 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 accountSetLabelNative = zanoApi
// .lookup<NativeFunction<account_set_label>>('account_set_label_row')
// .asFunction<AccountSetLabel>();
bool isUpdating = false;
/**void refreshAccounts() {
try {
isUpdating = true;
accountRefreshNative();
isUpdating = false;
} catch (e) {
isUpdating = false;
rethrow;
}
}*/
/**List<AccountRow> getAllAccount() {
final size = accountSizeNative();
final accountAddressesPointer = accountGetAllNative();
final accountAddresses = accountAddressesPointer.asTypedList(size);
return accountAddresses
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
.toList();
}*/
/**void addAccountSync({required String label}) {
final labelPointer = label.toNativeUtf8();
accountAddNewNative(labelPointer);
calloc.free(labelPointer);
}*/
/**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 _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 {
await compute(_addAccount, label);
await store();
}*/
/**Future<void> setLabelForAccount(
{required int accountIndex, required String label}) async {
await compute(
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
await store();
}*/

View file

@ -1,23 +0,0 @@
import 'dart:ffi';
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:ffi/ffi.dart';
final assetTypesSizeNative = zanoApi
.lookup<NativeFunction<account_size>>('asset_types_size')
.asFunction<SubaddressSize>();
final getAssetTypesNative = zanoApi
.lookup<NativeFunction<asset_types>>('asset_types')
.asFunction<AssetTypes>();
List<String> getAssetTypes() {
List<String> assetTypes = [];
Pointer<Pointer<Utf8>> assetTypePointers = getAssetTypesNative();
Pointer<Utf8> assetpointer = assetTypePointers.elementAt(0)[0];
String asset = convertUTF8ToString(pointer: assetpointer);
return assetTypes;
}

View file

@ -1,55 +0,0 @@
import 'dart:ffi';
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/structs/zano_balance_row.dart';
import 'package:cw_zano/api/structs/zano_rate.dart';
import 'asset_types.dart';
List<ZanoBalanceRow> getZanoFullBalance({int accountIndex = 0}) {
final size = assetTypesSizeNative();
final balanceAddressesPointer = getZanoFullBalanceNative(accountIndex);
final balanceAddresses = balanceAddressesPointer.asTypedList(size);
return balanceAddresses
.map((addr) => Pointer<ZanoBalanceRow>.fromAddress(addr).ref)
.toList();
}
List<ZanoBalanceRow> getZanoUnlockedBalance({int accountIndex = 0}) {
final size = assetTypesSizeNative();
final balanceAddressesPointer = getZanoUnlockedBalanceNative(accountIndex);
final balanceAddresses = balanceAddressesPointer.asTypedList(size);
return balanceAddresses
.map((addr) => Pointer<ZanoBalanceRow>.fromAddress(addr).ref)
.toList();
}
List<ZanoRate> getRate() {
updateRateNative();
final size = sizeOfRateNative();
final ratePointer = getRateNative();
final rate = ratePointer.asTypedList(size);
return rate.map((addr) => Pointer<ZanoRate>.fromAddress(addr).ref).toList();
}
final getZanoFullBalanceNative = zanoApi
.lookup<NativeFunction<get_full_balance>>('get_full_balance')
.asFunction<GetZanoFullBalance>();
final getZanoUnlockedBalanceNative = zanoApi
.lookup<NativeFunction<get_unlocked_balance>>('get_unlocked_balance')
.asFunction<GetZanoUnlockedBalance>();
final getRateNative =
zanoApi.lookup<NativeFunction<get_rate>>('get_rate').asFunction<GetRate>();
final sizeOfRateNative = zanoApi
.lookup<NativeFunction<size_of_rate>>('size_of_rate')
.asFunction<SizeOfRate>();
final updateRateNative = zanoApi
.lookup<NativeFunction<update_rate>>('update_rate')
.asFunction<UpdateRate>();

View file

@ -2,18 +2,24 @@ import 'dart:ffi';
import 'dart:convert'; import 'dart:convert';
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/model.dart';
import 'package:cw_zano/api/model/get_recent_txs_and_info_params.dart'; import 'package:cw_zano/api/model/get_recent_txs_and_info_params.dart';
import 'package:cw_zano/api/model/transfer_params.dart'; import 'package:cw_zano/api/model/transfer_params.dart';
import 'package:cw_zano/api/zano_api.dart'; import 'package:cw_zano/api/zano_api.dart';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
final _asyncCallNative = zanoApi // create_wallet
.lookup<NativeFunction<_async_call>>('async_call') final _createWalletNative =
.asFunction<_AsyncCall>(); zanoApi.lookup<NativeFunction<_create_wallet>>('create_wallet').asFunction<_CreateWallet>();
typedef _async_call = Pointer<Utf8> Function( typedef _create_wallet = Pointer<Utf8> Function(
Pointer<Utf8>, Int64, Pointer<Utf8>); Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>);
typedef _CreateWallet = Pointer<Utf8> Function(
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>);
// async_call
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( typedef _AsyncCall = Pointer<Utf8> Function(
Pointer<Utf8> methodName, int hWallet, Pointer<Utf8> params); Pointer<Utf8> methodName, int hWallet, Pointer<Utf8> params);
@ -39,18 +45,15 @@ typedef _get_connectivity_status = Pointer<Utf8> Function();
typedef _GetConnectivityStatus = Pointer<Utf8> Function(); typedef _GetConnectivityStatus = Pointer<Utf8> Function();
// get_version // get_version
final _getVersionNative = zanoApi final _getVersionNative =
.lookup<NativeFunction<_get_version>>('get_version') zanoApi.lookup<NativeFunction<_get_version>>('get_version').asFunction<_GetVersion>();
.asFunction<_GetVersion>();
typedef _get_version = Pointer<Utf8> Function(); typedef _get_version = Pointer<Utf8> Function();
typedef _GetVersion = Pointer<Utf8> Function(); typedef _GetVersion = Pointer<Utf8> Function();
// load_wallet // load_wallet
final _loadWalletNative = zanoApi final _loadWalletNative =
.lookup<NativeFunction<_load_wallet>>('load_wallet') zanoApi.lookup<NativeFunction<_load_wallet>>('load_wallet').asFunction<_LoadWallet>();
.asFunction<_LoadWallet>(); typedef _load_wallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, Int8);
typedef _load_wallet = Pointer<Utf8> Function(
Pointer<Utf8>, Pointer<Utf8>, Int8);
typedef _LoadWallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int); typedef _LoadWallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int);
// try_pull_result // try_pull_result
@ -61,9 +64,8 @@ typedef _try_pull_result = Pointer<Utf8> Function(Int64);
typedef _TryPullResult = Pointer<Utf8> Function(int hWallet); typedef _TryPullResult = Pointer<Utf8> Function(int hWallet);
// close_wallet // close_wallet
final _closeWalletNative = zanoApi final _closeWalletNative =
.lookup<NativeFunction<_close_wallet>>('close_wallet') zanoApi.lookup<NativeFunction<_close_wallet>>('close_wallet').asFunction<_closeWalletStatus>();
.asFunction<_closeWalletStatus>();
typedef _close_wallet = Void Function(Int64); typedef _close_wallet = Void Function(Int64);
typedef _closeWalletStatus = void Function(int hWallet); typedef _closeWalletStatus = void Function(int hWallet);
@ -75,25 +77,20 @@ typedef _get_current_tx_fee = Int64 Function(Int64);
typedef _getCurrentTxFee = int Function(int priority); typedef _getCurrentTxFee = int Function(int priority);
final _restoreWalletFromSeedNative = zanoApi final _restoreWalletFromSeedNative = zanoApi
.lookup<NativeFunction<_restore_wallet_from_seed>>( .lookup<NativeFunction<_restore_wallet_from_seed>>('restore_wallet_from_seed')
'restore_wallet_from_seed')
.asFunction<_RestoreWalletFromSeed>(); .asFunction<_RestoreWalletFromSeed>();
typedef _restore_wallet_from_seed = Pointer<Utf8> Function( typedef _restore_wallet_from_seed = Pointer<Utf8> Function(
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>); Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>);
typedef _RestoreWalletFromSeed = Pointer<Utf8> Function( typedef _RestoreWalletFromSeed = Pointer<Utf8> Function(
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Utf8>); Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Utf8>);
String doAsyncCall( String doAsyncCall({required String methodName, required int hWallet, required String params}) {
{required String methodName,
required int hWallet,
required String params}) {
final methodNamePointer = methodName.toNativeUtf8(); final methodNamePointer = methodName.toNativeUtf8();
final paramsPointer = params.toNativeUtf8(); final paramsPointer = params.toNativeUtf8();
debugPrint( debugPrint('async_call method_name $methodName hWallet $hWallet params $params');
'async_call method_name $methodName hWallet $hWallet params $params'); final result =
final result = convertUTF8ToString( convertUTF8ToString(pointer: _asyncCallNative(methodNamePointer, hWallet, paramsPointer));
pointer: _asyncCallNative(methodNamePointer, hWallet, paramsPointer));
calloc.free(methodNamePointer); calloc.free(methodNamePointer);
calloc.free(paramsPointer); calloc.free(paramsPointer);
@ -101,8 +98,25 @@ String doAsyncCall(
return result; return result;
} }
Future<String> invokeMethod( String createWallet(
int hWallet, String methodName, String params) async { {required String path, required String password, required String language, int nettype = 0}) {
final pathPointer = path.toNativeUtf8();
final passwordPointer = password.toNativeUtf8();
final languagePointer = language.toNativeUtf8();
final errorMessagePointer = ''.toNativeUtf8();
debugPrint('create_wallet path $path password $password language $language');
final result = convertUTF8ToString(
pointer: _createWalletNative(
pathPointer, passwordPointer, languagePointer, nettype, errorMessagePointer));
debugPrint('create_wallet result $result');
calloc.free(pathPointer);
calloc.free(passwordPointer);
calloc.free(languagePointer);
return result;
}
Future<String> invokeMethod(int hWallet, String methodName, String params) async {
debugPrint('invoke method $methodName params $params'); debugPrint('invoke method $methodName params $params');
final invokeResult = doAsyncCall( final invokeResult = doAsyncCall(
methodName: 'invoke', methodName: 'invoke',
@ -134,6 +148,7 @@ Future<String> transfer(int hWallet, TransferParams params) async {
debugPrint('invoke result $invokeResult'); debugPrint('invoke result $invokeResult');
var map = json.decode(invokeResult); var map = json.decode(invokeResult);
if (map['job_id'] != null) { if (map['job_id'] != null) {
// TODO: fixit
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
final result = tryPullResult(map['job_id'] as int); final result = tryPullResult(map['job_id'] as int);
return result; return result;
@ -151,9 +166,7 @@ Future<String> getRecentTxsAndInfo(
'get_recent_txs_and_info', 'get_recent_txs_and_info',
json.encode( json.encode(
GetRecentTxsAndInfoParams( GetRecentTxsAndInfoParams(
offset: offset, offset: offset, count: count, updateProvisionInfo: updateProvisionInfo),
count: count,
updateProvisionInfo: updateProvisionInfo),
), ),
); );
} }
@ -202,8 +215,9 @@ String restoreWalletFromSeed(String path, String password, String seed) {
final passwordPointer = password.toNativeUtf8(); final passwordPointer = password.toNativeUtf8();
final seedPointer = seed.toNativeUtf8(); final seedPointer = seed.toNativeUtf8();
final errorMessagePointer = ''.toNativeUtf8(); final errorMessagePointer = ''.toNativeUtf8();
final result = convertUTF8ToString(pointer: _restoreWalletFromSeedNative(pathPointer, final result = convertUTF8ToString(
passwordPointer, seedPointer, 0, 0, errorMessagePointer)); pointer: _restoreWalletFromSeedNative(
pathPointer, passwordPointer, seedPointer, 0, 0, errorMessagePointer));
return result; return result;
} }

View file

@ -1,5 +0,0 @@
class ConnectionToNodeException implements Exception {
ConnectionToNodeException({required this.message});
final String message;
}

View file

@ -1,8 +0,0 @@
class CreationTransactionException implements Exception {
CreationTransactionException({required this.message});
final String message;
@override
String toString() => message;
}

View file

@ -1,5 +0,0 @@
class SetupWalletException implements Exception {
SetupWalletException({required this.message});
final String message;
}

View file

@ -1,8 +0,0 @@
class WalletCreationException implements Exception {
WalletCreationException({required this.message});
final String message;
@override
String toString() => message;
}

View file

@ -1,8 +0,0 @@
class WalletOpeningException implements Exception {
WalletOpeningException({required this.message});
final String message;
@override
String toString() => message;
}

View file

@ -1,5 +0,0 @@
class WalletRestoreFromSeedException implements Exception {
WalletRestoreFromSeedException({required this.message});
final String message;
}

View file

@ -1,49 +0,0 @@
// 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,
// };
// }

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:cw_zano/api/model/asset_info.dart'; import 'package:cw_zano/api/model/asset_info.dart';
class Balance { class Balance {

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:cw_zano/api/model/recent_history.dart'; import 'package:cw_zano/api/model/recent_history.dart';
import 'package:cw_zano/api/model/wi.dart'; import 'package:cw_zano/api/model/wi.dart';

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:cw_zano/api/model/receive.dart'; import 'package:cw_zano/api/model/receive.dart';
class EmployedEntries { class EmployedEntries {

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:cw_zano/api/model/employed_entries.dart'; import 'package:cw_zano/api/model/employed_entries.dart';
import 'package:cw_zano/api/model/subtransfer.dart'; import 'package:cw_zano/api/model/subtransfer.dart';

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:cw_zano/api/model/history.dart'; import 'package:cw_zano/api/model/history.dart';
class RecentHistory { class RecentHistory {

View file

@ -0,0 +1,13 @@
class TransferResult {
final String txHash;
final int txSize;
final String txUnsignedHex;
TransferResult({required this.txHash, required this.txSize, required this.txUnsignedHex});
factory TransferResult.fromJson(Map<String, dynamic> json) => TransferResult(
txHash: json['tx_hash'] as String,
txSize: json['tx_size'] as int,
txUnsignedHex: json['tx_unsigned_hex'] as String,
);
}

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:cw_zano/api/model/balance.dart'; import 'package:cw_zano/api/model/balance.dart';
class Wi { class Wi {

View file

@ -1,10 +1,9 @@
import 'dart:ffi'; import 'dart:ffi';
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 = Pointer<Utf8> 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(
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>); Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>);
@ -22,7 +21,7 @@ typedef restore_wallet_from_keys = Int8 Function(
typedef is_wallet_exist = Int8 Function(Pointer<Utf8>); typedef is_wallet_exist = Int8 Function(Pointer<Utf8>);
typedef load_wallet = Int8 Function(Pointer<Utf8>, Pointer<Utf8>, Int8); //typedef load_wallet = Int8 Function(Pointer<Utf8>, Pointer<Utf8>, Int8);
typedef error_string = Pointer<Utf8> Function(); typedef error_string = Pointer<Utf8> Function();
@ -68,60 +67,60 @@ typedef get_syncing_height = Int64 Function();
typedef is_needed_to_refresh = Int8 Function(); typedef is_needed_to_refresh = Int8 Function();
typedef is_new_transaction_exist = Int8 Function(); // typedef is_new_transaction_exist = Int8 Function();
typedef subaddrress_size = Int32 Function(); // typedef subaddrress_size = Int32 Function();
typedef subaddrress_refresh = Void Function(Int32); // typedef subaddrress_refresh = Void Function(Int32);
typedef subaddress_get_all = Pointer<Int64> Function(); // typedef subaddress_get_all = Pointer<Int64> Function();
typedef subaddress_add_new = Void Function( // typedef subaddress_add_new = Void Function(
Int32 accountIndex, Pointer<Utf8> label); // Int32 accountIndex, Pointer<Utf8> label);
typedef subaddress_set_label = Void Function( // typedef subaddress_set_label = Void Function(
Int32 accountIndex, Int32 addressIndex, Pointer<Utf8> label); // Int32 accountIndex, Int32 addressIndex, Pointer<Utf8> label);
typedef account_size = Int32 Function(); // typedef account_size = Int32 Function();
typedef account_refresh = Void Function(); // typedef account_refresh = Void Function();
typedef account_get_all = Pointer<Int64> Function(); // typedef account_get_all = Pointer<Int64> Function();
typedef account_add_new = Void Function(Pointer<Utf8> label); // typedef account_add_new = Void Function(Pointer<Utf8> label);
typedef account_set_label = Void Function( // typedef account_set_label = Void Function(
Int32 accountIndex, Pointer<Utf8> label); // Int32 accountIndex, Pointer<Utf8> label);
typedef transactions_refresh = Void Function(); //typedef transactions_refresh = Void Function();
typedef get_tx_key = Pointer<Utf8>? Function(Pointer<Utf8> txId); //typedef get_tx_key = Pointer<Utf8>? Function(Pointer<Utf8> txId);
typedef transactions_count = Int64 Function(); //typedef transactions_count = Int64 Function();
typedef transactions_get_all = Pointer<Int64> Function(); //typedef transactions_get_all = Pointer<Int64> Function();
typedef transaction_create = Int8 Function( // typedef transaction_create = Int8 Function(
Pointer<Utf8> address, // Pointer<Utf8> address,
Pointer<Utf8> assetType, // Pointer<Utf8> assetType,
Pointer<Utf8> paymentId, // Pointer<Utf8> paymentId,
Pointer<Utf8> amount, // Pointer<Utf8> amount,
Int8 priorityRaw, // Int8 priorityRaw,
Pointer<Utf8Box> error, // Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction); // Pointer<PendingTransactionRaw> pendingTransaction);
typedef transaction_create_mult_dest = Int8 Function( // typedef transaction_create_mult_dest = Int8 Function(
Pointer<Pointer<Utf8>> addresses, // Pointer<Pointer<Utf8>> addresses,
Pointer<Utf8> assetType, // Pointer<Utf8> assetType,
Pointer<Utf8> paymentId, // Pointer<Utf8> paymentId,
Pointer<Pointer<Utf8>> amounts, // Pointer<Pointer<Utf8>> amounts,
Int32 size, // Int32 size,
Int8 priorityRaw, // Int8 priorityRaw,
Pointer<Utf8Box> error, // Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction); // Pointer<PendingTransactionRaw> pendingTransaction);
typedef transaction_commit = Int8 Function( // typedef transaction_commit = Int8 Function(
Pointer<PendingTransactionRaw>, Pointer<Utf8Box>); // Pointer<PendingTransactionRaw>, Pointer<Utf8Box>);
typedef secret_view_key = Pointer<Utf8> Function(); typedef secret_view_key = Pointer<Utf8> Function();

View file

@ -1,12 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
class AccountRow extends Struct {
@Int64()
external int id;
external Pointer<Utf8> label;
String getLabel() => label.toDartString();
int getId() => id;
}

View file

@ -1,27 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
class PendingTransactionRaw extends Struct {
@Int64()
external int amount;
@Int64()
external int fee;
external Pointer<Utf8> hash;
String getHash() => hash.toDartString();
}
class PendingTransactionDescription {
PendingTransactionDescription({
required this.amount,
required this.fee,
required this.hash,
required this.pointerAddress});
final int amount;
final int fee;
final String hash;
final int pointerAddress;
}

View file

@ -1,15 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
class SubaddressRow extends Struct {
@Int64()
external int id;
external Pointer<Utf8> address;
external Pointer<Utf8> label;
String getLabel() => label.toDartString();
String getAddress() => address.toDartString();
int getId() => id;
}

View file

@ -1,44 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
class TransactionInfoRow extends Struct {
@Uint64()
external int amount;
@Uint64()
external int fee;
@Uint64()
external int blockHeight;
@Uint64()
external int confirmations;
@Uint32()
external int subaddrAccount;
@Int8()
external int direction;
@Int8()
external int isPending;
@Uint32()
external int subaddrIndex;
external Pointer<Utf8> hash;
external Pointer<Utf8> paymentId;
external Pointer<Utf8> assetType;
@Int64()
external int datetime;
int getDatetime() => datetime;
int getAmount() => amount >= 0 ? amount : amount * -1;
bool getIsPending() => isPending != 0;
String getHash() => hash.toDartString();
String getPaymentId() => paymentId.toDartString();
String getAssetType() => assetType.toDartString();
}

View file

@ -1,12 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
class ZanoBalanceRow extends Struct {
@Int64()
external int amount;
external Pointer<Utf8> assetType;
int getAmount() => amount;
String getAssetType() => assetType.toDartString();
}

View file

@ -1,12 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
class ZanoRate extends Struct {
@Int64()
external int rate;
external Pointer<Utf8> assetType;
int getRate() => rate;
String getAssetType() => assetType.toDartString();
}

View file

@ -1,103 +0,0 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.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/structs/subaddress_row.dart';
import 'package:cw_zano/api/wallet.dart';
/**
final subaddressSizeNative = zanoApi
.lookup<NativeFunction<subaddrress_size>>('subaddrress_size')
.asFunction<SubaddressSize>();
final subaddressRefreshNative = zanoApi
.lookup<NativeFunction<subaddrress_refresh>>('subaddress_refresh')
.asFunction<SubaddressRefresh>();
final subaddrressGetAllNative = zanoApi
.lookup<NativeFunction<subaddress_get_all>>('subaddrress_get_all')
.asFunction<SubaddressGetAll>();
final subaddrressAddNewNative = zanoApi
.lookup<NativeFunction<subaddress_add_new>>('subaddress_add_row')
.asFunction<SubaddressAddNew>();
final subaddrressSetLabelNative = zanoApi
.lookup<NativeFunction<subaddress_set_label>>('subaddress_set_label')
.asFunction<SubaddressSetLabel>();
bool isUpdating = false;
void refreshSubaddresses({required int accountIndex}) {
try {
isUpdating = true;
subaddressRefreshNative(accountIndex);
isUpdating = false;
} catch (e) {
isUpdating = false;
rethrow;
}
}
List<SubaddressRow> getAllSubaddresses() {
final size = subaddressSizeNative();
final subaddressAddressesPointer = subaddrressGetAllNative();
final subaddressAddresses = subaddressAddressesPointer.asTypedList(size);
return subaddressAddresses
.map((addr) => Pointer<SubaddressRow>.fromAddress(addr).ref)
.toList();
}
void addSubaddressSync({required int accountIndex, required String label}) {
final labelPointer = label.toNativeUtf8();
subaddrressAddNewNative(accountIndex, labelPointer);
calloc.free(labelPointer);
}
void setLabelForSubaddressSync(
{required int accountIndex,
required int addressIndex,
required String label}) {
final labelPointer = label.toNativeUtf8();
subaddrressSetLabelNative(accountIndex, addressIndex, labelPointer);
calloc.free(labelPointer);
}
void _addSubaddress(Map<String, dynamic> args) {
final label = args['label'] as String;
final accountIndex = args['accountIndex'] as int;
addSubaddressSync(accountIndex: accountIndex, label: label);
}
void _setLabelForSubaddress(Map<String, dynamic> args) {
final label = args['label'] as String;
final accountIndex = args['accountIndex'] as int;
final addressIndex = args['addressIndex'] as int;
setLabelForSubaddressSync(
accountIndex: accountIndex, addressIndex: addressIndex, label: label);
}
Future addSubaddress({required int accountIndex, required String label}) async {
await compute<Map<String, Object>, void>(
_addSubaddress, {'accountIndex': accountIndex, 'label': label});
await store();
}
Future setLabelForSubaddress(
{required int accountIndex,
required int addressIndex,
required String label}) async {
await compute<Map<String, Object>, void>(_setLabelForSubaddress, {
'accountIndex': accountIndex,
'addressIndex': addressIndex,
'label': label
});
await store();
}
*/

View file

@ -1,250 +0,0 @@
import 'dart:ffi';
import 'package:cw_zano/api/convert_utf8_to_string.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';
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/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
.lookup<NativeFunction<transactions_refresh>>('transactions_refresh')
.asFunction<TransactionsRefresh>();*/
/**final transactionsCountNative = zanoApi
.lookup<NativeFunction<transactions_count>>('transactions_count')
.asFunction<TransactionsCount>();*/
final transactionsGetAllNative = zanoApi
.lookup<NativeFunction<transactions_get_all>>('transactions_get_all')
.asFunction<TransactionsGetAll>();
final transactionCreateNative = zanoApi
.lookup<NativeFunction<transaction_create>>('transaction_create')
.asFunction<TransactionCreate>();
final transactionCreateMultDestNative = zanoApi
.lookup<NativeFunction<transaction_create_mult_dest>>(
'transaction_create_mult_dest')
.asFunction<TransactionCreateMultDest>();
// final transactionCommitNative = zanoApi
// .lookup<NativeFunction<transaction_commit>>('transaction_commit')
// .asFunction<TransactionCommit>();
final getTxKeyNative = zanoApi
.lookup<NativeFunction<get_tx_key>>('get_tx_key')
.asFunction<GetTxKey>();
String getTxKey(String txId) {
final txIdPointer = txId.toNativeUtf8();
final keyPointer = getTxKeyNative(txIdPointer);
calloc.free(txIdPointer);
if (keyPointer != null) {
return convertUTF8ToString(pointer: keyPointer);
}
return '';
}
// void refreshTransactions() {
// // TODO: fix it
// //transactionsRefreshNative();
// debugPrint("refreshing transactions");
// }
int countOfTransactions() {
//return transactionsCountNative();
// TODO: fix it
debugPrint("count of transactions");
return 0;
}
List<TransactionInfoRow> getAllTransations() {
// 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();*/
}
PendingTransactionDescription createTransactionSync(
{required String address,
required String assetType,
required String paymentId,
required int priorityRaw,
String? amount}) {
final addressPointer = address.toNativeUtf8();
final assetTypePointer = assetType.toNativeUtf8();
final paymentIdPointer = paymentId.toNativeUtf8();
final amountPointer = amount != null ? amount.toNativeUtf8() : nullptr;
final errorMessagePointer = calloc<Utf8Box>();
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
final created = transactionCreateNative(
addressPointer,
assetTypePointer,
paymentIdPointer,
amountPointer,
priorityRaw,
errorMessagePointer,
pendingTransactionRawPointer) !=
0;
calloc.free(addressPointer);
calloc.free(assetTypePointer);
calloc.free(paymentIdPointer);
if (amountPointer != nullptr) {
calloc.free(amountPointer);
}
if (!created) {
final message = errorMessagePointer.ref.getValue();
calloc.free(errorMessagePointer);
throw CreationTransactionException(message: message);
}
return PendingTransactionDescription(
amount: pendingTransactionRawPointer.ref.amount,
fee: pendingTransactionRawPointer.ref.fee,
hash: pendingTransactionRawPointer.ref.getHash(),
pointerAddress: pendingTransactionRawPointer.address);
}
PendingTransactionDescription createTransactionMultDestSync(
{required List<ZanoOutput> outputs,
required String assetType,
required String paymentId,
required int priorityRaw}) {
final int size = outputs.length;
final List<Pointer<Utf8>> addressesPointers =
outputs.map((output) => output.address.toNativeUtf8()).toList();
final Pointer<Pointer<Utf8>> addressesPointerPointer = calloc(size);
final List<Pointer<Utf8>> amountsPointers =
outputs.map((output) => output.amount.toNativeUtf8()).toList();
final Pointer<Pointer<Utf8>> amountsPointerPointer = calloc(size);
for (int i = 0; i < size; i++) {
addressesPointerPointer[i] = addressesPointers[i];
amountsPointerPointer[i] = amountsPointers[i];
}
final assetTypePointer = assetType.toNativeUtf8();
final paymentIdPointer = paymentId.toNativeUtf8();
final errorMessagePointer = calloc<Utf8Box>();
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
final created = transactionCreateMultDestNative(
addressesPointerPointer,
assetTypePointer,
paymentIdPointer,
amountsPointerPointer,
size,
priorityRaw,
errorMessagePointer,
pendingTransactionRawPointer) !=
0;
calloc.free(addressesPointerPointer);
calloc.free(assetTypePointer);
calloc.free(amountsPointerPointer);
addressesPointers.forEach((element) => calloc.free(element));
amountsPointers.forEach((element) => calloc.free(element));
calloc.free(paymentIdPointer);
if (!created) {
final message = errorMessagePointer.ref.getValue();
calloc.free(errorMessagePointer);
throw CreationTransactionException(message: message);
}
return PendingTransactionDescription(
amount: pendingTransactionRawPointer.ref.amount,
fee: pendingTransactionRawPointer.ref.fee,
hash: pendingTransactionRawPointer.ref.getHash(),
pointerAddress: pendingTransactionRawPointer.address);
}
void commitTransactionFromPointerAddress({required int address}) =>
commitTransaction(
transactionPointer:
Pointer<PendingTransactionRaw>.fromAddress(address));
void commitTransaction(
{required Pointer<PendingTransactionRaw> transactionPointer}) {
final errorMessagePointer = calloc<Utf8Box>();
print("commit transaction");
final isCommited = true;
//transactionCommitNative(transactionPointer, errorMessagePointer) != 0;
if (!isCommited) {
final message = errorMessagePointer.ref.getValue();
calloc.free(errorMessagePointer);
throw CreationTransactionException(message: message);
}
}
PendingTransactionDescription _createTransactionSync(Map args) {
final address = args['address'] as String;
final assetType = args['assetType'] as String;
final paymentId = args['paymentId'] as String;
final amount = args['amount'] as String;
final priorityRaw = args['priorityRaw'] as int;
return createTransactionSync(
address: address,
assetType: assetType,
paymentId: paymentId,
amount: amount,
priorityRaw: priorityRaw);
}
PendingTransactionDescription _createTransactionMultDestSync(Map args) {
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;
return createTransactionMultDestSync(
outputs: outputs,
assetType: assetType,
paymentId: paymentId,
priorityRaw: priorityRaw);
}
Future<PendingTransactionDescription> createTransaction(
{required String address,
required String assetType,
required int priorityRaw,
String? amount,
String paymentId = ''}) =>
compute(_createTransactionSync, {
'address': address,
'assetType': assetType,
'paymentId': paymentId,
'amount': amount,
'priorityRaw': priorityRaw,
});
Future<PendingTransactionDescription> createTransactionMultDest(
{required List<ZanoOutput> outputs,
required int priorityRaw,
String? assetType,
String paymentId = ''}) =>
compute(_createTransactionMultDestSync, {
'outputs': outputs,
'assetType': assetType,
'paymentId': paymentId,
'priorityRaw': priorityRaw,
});

View file

@ -1,5 +1,4 @@
import 'dart:ffi'; import 'dart:ffi';
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';
@ -22,7 +21,7 @@ typedef RestoreWalletFromKeys = int Function(
typedef IsWalletExist = int Function(Pointer<Utf8>); typedef IsWalletExist = int Function(Pointer<Utf8>);
typedef LoadWallet = int Function(Pointer<Utf8>, Pointer<Utf8>, int); //typedef LoadWallet = int Function(Pointer<Utf8>, Pointer<Utf8>, int);
typedef ErrorString = Pointer<Utf8> Function(); typedef ErrorString = Pointer<Utf8> Function();
@ -99,27 +98,27 @@ typedef TransactionsCount = int Function();
typedef TransactionsGetAll = Pointer<Int64> Function(); typedef TransactionsGetAll = Pointer<Int64> Function();
typedef TransactionCreate = int Function( // typedef TransactionCreate = int Function(
Pointer<Utf8> address, // Pointer<Utf8> address,
Pointer<Utf8> assetType, // Pointer<Utf8> assetType,
Pointer<Utf8> paymentId, // Pointer<Utf8> paymentId,
Pointer<Utf8> amount, // Pointer<Utf8> amount,
int priorityRaw, // int priorityRaw,
Pointer<Utf8Box> error, // Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction); // Pointer<PendingTransactionRaw> pendingTransaction);
typedef TransactionCreateMultDest = int Function( // typedef TransactionCreateMultDest = int Function(
Pointer<Pointer<Utf8>> addresses, // Pointer<Pointer<Utf8>> addresses,
Pointer<Utf8> assetType, // Pointer<Utf8> assetType,
Pointer<Utf8> paymentId, // Pointer<Utf8> paymentId,
Pointer<Pointer<Utf8>> amounts, // Pointer<Pointer<Utf8>> amounts,
int size, // int size,
int priorityRaw, // int priorityRaw,
Pointer<Utf8Box> error, // Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction); // Pointer<PendingTransactionRaw> pendingTransaction);
typedef TransactionCommit = int Function( // typedef TransactionCommit = int Function(
Pointer<PendingTransactionRaw>, Pointer<Utf8Box>); // Pointer<PendingTransactionRaw>, Pointer<Utf8Box>);
typedef SecretViewKey = Pointer<Utf8> Function(); typedef SecretViewKey = Pointer<Utf8> Function();

View file

@ -14,7 +14,6 @@ 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/calls.dart' as calls;
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';
import 'package:mobx/mobx.dart' as mobx; import 'package:mobx/mobx.dart' as mobx;
@ -163,9 +162,9 @@ int getNodeHeightSync(int hWallet) {
// return 0; // return 0;
// } // }
int getTxFee(int priority) { // int getTxFee(int priority) {
return calls.getCurrentTxFee(priority); // return calls.getCurrentTxFee(priority);
} // }
bool isConnectedSync() => isConnectedNative() != 0; bool isConnectedSync() => isConnectedNative() != 0;
@ -325,7 +324,7 @@ class SyncListener {
wallet.balance = mobx.ObservableMap.of( wallet.balance = mobx.ObservableMap.of(
{CryptoCurrency.zano: ZanoBalance(total: balance.total, unlocked: balance.unlocked)}); {CryptoCurrency.zano: ZanoBalance(total: balance.total, unlocked: balance.unlocked)});
getTxFee(hWallet); ///getTxFee(hWallet);
if (_initialSyncHeight <= 0) { if (_initialSyncHeight <= 0) {
_initialSyncHeight = syncHeight; _initialSyncHeight = syncHeight;

View file

@ -5,15 +5,11 @@ 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/wallet.dart';
import 'package:cw_zano/api/exceptions/wallet_opening_exception.dart';
import 'package:cw_zano/api/exceptions/wallet_creation_exception.dart';
import 'package:cw_zano/api/exceptions/wallet_restore_from_keys_exception.dart'; import 'package:cw_zano/api/exceptions/wallet_restore_from_keys_exception.dart';
import 'package:cw_zano/api/exceptions/wallet_restore_from_seed_exception.dart';
final createWalletNative = zanoApi // final createWalletNative = zanoApi
.lookup<NativeFunction<create_wallet>>('create_wallet') // .lookup<NativeFunction<create_wallet>>('create_wallet')
.asFunction<CreateWallet>(); // .asFunction<CreateWallet>();
final restoreWalletFromSeedNative = zanoApi final restoreWalletFromSeedNative = zanoApi
.lookup<NativeFunction<restore_wallet_from_seed>>( .lookup<NativeFunction<restore_wallet_from_seed>>(
@ -29,15 +25,15 @@ final isWalletExistNative = zanoApi
.lookup<NativeFunction<is_wallet_exist>>('is_wallet_exist') .lookup<NativeFunction<is_wallet_exist>>('is_wallet_exist')
.asFunction<IsWalletExist>(); .asFunction<IsWalletExist>();
final loadWalletNative = zanoApi // final loadWalletNative = zanoApi
.lookup<NativeFunction<load_wallet>>('load_wallet') // .lookup<NativeFunction<load_wallet>>('load_wallet')
.asFunction<LoadWallet>(); // .asFunction<LoadWallet>();
final errorStringNative = zanoApi final errorStringNative = zanoApi
.lookup<NativeFunction<error_string>>('error_string') .lookup<NativeFunction<error_string>>('error_string')
.asFunction<ErrorString>(); .asFunction<ErrorString>();
String createWalletSync( /*String createWalletSync(
{required String path, {required String path,
required String password, required String password,
required String language, required String language,
@ -63,7 +59,7 @@ String createWalletSync(
return hWallet; return hWallet;
// setupNodeSync(address: "node.moneroworld.com:18089");*/ // setupNodeSync(address: "node.moneroworld.com:18089");*/
} }*/
bool isWalletExistSync({required String path}) { bool isWalletExistSync({required String path}) {
final pathPointer = path.toNativeUtf8(); final pathPointer = path.toNativeUtf8();
@ -74,34 +70,34 @@ bool isWalletExistSync({required String path}) {
return isExist; return isExist;
} }
void restoreWalletFromSeedSync( // void restoreWalletFromSeedSync(
{required String path, // {required String path,
required String password, // required String password,
required String seed, // required String seed,
int nettype = 0, // int nettype = 0,
int restoreHeight = 0}) { // int restoreHeight = 0}) {
final pathPointer = path.toNativeUtf8(); // final pathPointer = path.toNativeUtf8();
final passwordPointer = password.toNativeUtf8(); // final passwordPointer = password.toNativeUtf8();
final seedPointer = seed.toNativeUtf8(); // final seedPointer = seed.toNativeUtf8();
final errorMessagePointer = ''.toNativeUtf8(); // final errorMessagePointer = ''.toNativeUtf8();
final isWalletRestored = restoreWalletFromSeedNative( // final isWalletRestored = restoreWalletFromSeedNative(
pathPointer, // pathPointer,
passwordPointer, // passwordPointer,
seedPointer, // seedPointer,
nettype, // nettype,
restoreHeight, // restoreHeight,
errorMessagePointer) != // errorMessagePointer) !=
0; // 0;
calloc.free(pathPointer); // calloc.free(pathPointer);
calloc.free(passwordPointer); // calloc.free(passwordPointer);
calloc.free(seedPointer); // calloc.free(seedPointer);
if (!isWalletRestored) { // if (!isWalletRestored) {
throw WalletRestoreFromSeedException( // throw WalletRestoreFromSeedException(
message: convertUTF8ToString(pointer: errorMessagePointer)); // message: convertUTF8ToString(pointer: errorMessagePointer));
} // }
} // }
void restoreWalletFromKeysSync( void restoreWalletFromKeysSync(
{required String path, {required String path,
@ -144,37 +140,37 @@ void restoreWalletFromKeysSync(
} }
} }
void loadWallet( // void loadWallet(
{required String path, required String password, int nettype = 0}) { // {required String path, required String password, int nettype = 0}) {
final pathPointer = path.toNativeUtf8(); // final pathPointer = path.toNativeUtf8();
final passwordPointer = password.toNativeUtf8(); // final passwordPointer = password.toNativeUtf8();
final loaded = loadWalletNative(pathPointer, passwordPointer, nettype) != 0; // final loaded = loadWalletNative(pathPointer, passwordPointer, nettype) != 0;
calloc.free(pathPointer); // calloc.free(pathPointer);
calloc.free(passwordPointer); // calloc.free(passwordPointer);
if (!loaded) { // if (!loaded) {
throw WalletOpeningException( // throw WalletOpeningException(
message: convertUTF8ToString(pointer: errorStringNative())); // message: convertUTF8ToString(pointer: errorStringNative()));
} // }
} // }
String _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;
return 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) {
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 seed = args['seed'] as String; // final seed = args['seed'] as String;
final restoreHeight = args['restoreHeight'] as int; // final restoreHeight = args['restoreHeight'] as int;
restoreWalletFromSeedSync( // restoreWalletFromSeedSync(
path: path, password: password, seed: seed, restoreHeight: restoreHeight); // path: path, password: password, seed: seed, restoreHeight: restoreHeight);
} // }
void _restoreFromKeys(Map<String, dynamic> args) { void _restoreFromKeys(Map<String, dynamic> args) {
final path = args['path'] as String; final path = args['path'] as String;
@ -195,8 +191,8 @@ void _restoreFromKeys(Map<String, dynamic> args) {
spendKey: spendKey); spendKey: spendKey);
} }
Future<void> _openWallet(Map<String, String> args) async => loadWallet( // Future<void> _openWallet(Map<String, String> args) async => loadWallet(
path: args['path'] as String, password: args['password'] as String); // path: args['path'] as String, password: args['password'] as String);
bool _isWalletExist(String path) => isWalletExistSync(path: path); bool _isWalletExist(String path) => isWalletExistSync(path: path);
@ -206,34 +202,34 @@ bool _isWalletExist(String path) => isWalletExistSync(path: path);
// int nettype = 0}) async => // int nettype = 0}) async =>
// loadWallet(path: path, password: password, nettype: nettype); // loadWallet(path: path, password: password, nettype: nettype);
Future<void> openWalletAsync(Map<String, String> args) async => // Future<void> openWalletAsync(Map<String, String> args) async =>
compute(_openWallet, args); // compute(_openWallet, args);
Future<String> 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<Map<String, dynamic>, String>(_createWallet, { // compute<Map<String, dynamic>, String>(_createWallet, {
'path': path, // 'path': path,
'password': password, // 'password': password,
'language': language, // 'language': language,
'nettype': nettype // 'nettype': nettype
}); // });
Future<void> restoreFromSeed( // Future<void> restoreFromSeed(
{required String path, // {required String path,
required String password, // required String password,
required String seed, // required String seed,
int nettype = 0, // int nettype = 0,
int restoreHeight = 0}) async => // int restoreHeight = 0}) async =>
compute<Map<String, Object>, void>(_restoreFromSeed, { // compute<Map<String, Object>, void>(_restoreFromSeed, {
'path': path, // 'path': path,
'password': password, // 'password': password,
'seed': seed, // 'seed': seed,
'nettype': nettype, // 'nettype': nettype,
'restoreHeight': restoreHeight // 'restoreHeight': restoreHeight
}); // });
Future<void> restoreFromKeys( Future<void> restoreFromKeys(
{required String path, {required String path,

View file

@ -1,8 +0,0 @@
import 'package:flutter/foundation.dart';
class ZanoOutput {
ZanoOutput({required this.address, required this.amount});
final String address;
final String amount;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,19 +0,0 @@
import 'package:cw_core/wallet_addresses.dart';
class NewZanoWalletAddresses extends WalletAddresses {
@override
String address;
NewZanoWalletAddresses(super.walletInfo): address = "";
@override
Future<void> init() async {
print("NewZanoWalletAddresses init");
}
@override
Future<void> updateAddressesInBox() async {
print("NewZanoWalletAddresses updateAddressesInBox");
}
}

View file

@ -1,239 +0,0 @@
import 'dart:async';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_zano/api/model/balance.dart';
import 'package:cw_zano/api/model/create_wallet_result.dart';
import 'package:cw_zano/api/zano_api.dart';
import 'package:cw_zano/zano_balance.dart';
import 'package:cw_zano/zano_transaction_history.dart';
import 'package:cw_zano/zano_transaction_info.dart';
import 'package:mobx/src/api/observable_collections.dart';
import 'package:cw_zano/api/wallet.dart' as zano_wallet;
import 'dart:convert';
import 'dart:ffi';
import 'package:cw_zano/api/signatures.dart';
import 'package:cw_zano/api/types.dart';
import 'package:ffi/ffi.dart';
import 'api/model/zano_wallet_keys.dart';
import 'new_zano_addresses_base.dart';
typedef _load_wallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, Int8);
typedef _LoadWallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int);
class NewZanoWallet extends WalletBase<ZanoBalance, ZanoTransactionHistory, ZanoTransactionInfo> {
@override
SyncStatus syncStatus;
Timer? _autoSaveTimer;
static const int _autoSaveInterval = 30;
NewZanoWallet(super.walletInfo)
: balance = ObservableMap.of({CryptoCurrency.zano: ZanoBalance(total: 0, unlocked: 0)}),
walletAddresses = NewZanoWalletAddresses(walletInfo),
syncStatus = NotConnectedSyncStatus() {
transactionHistory = ZanoTransactionHistory();
}
Future<void> init() async {
print("NewZanoWallet init");
if (walletInfo.isRecovery) {
print("is recovery");
}
_autoSaveTimer =
Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save());
}
String getTransactionAddress(int accountIndex, int addressIndex) {
print("NewZanoWallet getTransactionAddress");
return "";
}
@override
ObservableMap<CryptoCurrency, ZanoBalance> balance;
@override
int calculateEstimatedFee(TransactionPriority priority, int? amount) {
// TODO: implement calculateEstimatedFee
throw UnimplementedError();
}
@override
Future<void> changePassword(String password) {
// TODO: implement changePassword
throw UnimplementedError();
}
@override
void close() {
// TODO: implement close
}
@override
Future<void> connectToNode({required Node node}) async {
print("NewZanoWallet connecttoNode");
try {
syncStatus = ConnectingSyncStatus();
_setupNode(address: "195.201.107.230:33336", login: "", password: "");
syncStatus = ConnectedSyncStatus();
} catch (e) {
syncStatus = FailedSyncStatus();
print("connectToNode error $e");
}
}
@override
Future<PendingTransaction> createTransaction(Object credentials) {
// TODO: implement createTransaction
throw UnimplementedError();
}
@override
Future<Map<String, ZanoTransactionInfo>> fetchTransactions() {
// TODO: implement fetchTransactions
throw UnimplementedError();
}
@override
ZanoWalletKeys get keys => ZanoWalletKeys(
privateSpendKey: "", privateViewKey: "", publicSpendKey: "", publicViewKey: "");
@override
Future<void> renameWalletFiles(String newWalletName) {
// TODO: implement renameWalletFiles
throw UnimplementedError();
}
@override
Future<void> rescan({required int height}) {
// TODO: implement rescan
throw UnimplementedError();
}
@override
Future<void> save() async {
await walletAddresses.updateAddressesInBox();
if (hWallet != null) await zano_wallet.store(hWallet!);
}
@override
// TODO: implement seed
String? seed = "Тут пока пусто";
@override
Future<void> startSync() {
// TODO: implement startSync
throw UnimplementedError();
}
@override
Future<void>? updateBalance() {
// TODO: implement updateBalance
throw UnimplementedError();
}
@override
NewZanoWalletAddresses walletAddresses;
CreateWalletResult? createWalletResult;
List<Balance>? balances;
int? hWallet;
final assetIds = <String, String>{};
final _setupNodeNative =
zanoApi.lookup<NativeFunction<setup_node>>('setup_node').asFunction<SetupNode>();
final _createWalletNative =
zanoApi.lookup<NativeFunction<create_wallet>>('create_wallet').asFunction<CreateWallet>();
final _loadWalletNative =
zanoApi.lookup<NativeFunction<_load_wallet>>('load_wallet').asFunction<_LoadWallet>();
bool _setupNode(
{required String address,
required String login,
required String password,
bool useSSL = false,
bool isLightWallet = false}) {
final addressPointer = address.toNativeUtf8();
final loginPointer = login.toNativeUtf8();
final passwordPointer = password.toNativeUtf8();
final errorMessagePointer = ''.toNativeUtf8();
print(
"setup_node address $address login $login password $password useSSL $useSSL isLightWallet $isLightWallet");
final result = _intToBool(_setupNodeNative(addressPointer, loginPointer, passwordPointer,
_boolToInt(useSSL), _boolToInt(isLightWallet), errorMessagePointer));
print("setup_node result $result");
calloc.free(addressPointer);
calloc.free(loginPointer);
calloc.free(passwordPointer);
return result;
}
String _createWalletSync(
{required String path, required String password, required String language, int nettype = 0}) {
final pathPointer = path.toNativeUtf8();
final passwordPointer = password.toNativeUtf8();
final languagePointer = language.toNativeUtf8();
final errorMessagePointer = ''.toNativeUtf8();
print("create_wallet path $path password $password language $language");
final result = _convertUTF8ToString(
pointer: _createWalletNative(
pathPointer, passwordPointer, languagePointer, nettype, errorMessagePointer));
print("create_wallet $result");
calloc.free(pathPointer);
calloc.free(passwordPointer);
calloc.free(languagePointer);
return result;
}
void createWallet({required String path, required String password}) {
final createResult = _createWalletSync(path: path, password: password, language: "");
final address = _parseResult(createResult)!;
walletAddresses.address = address;
}
String loadWallet(String path, String password) {
print('load_wallet path $path password $password');
final pathPointer = path.toNativeUtf8();
final passwordPointer = password.toNativeUtf8();
final result = _convertUTF8ToString(
pointer: _loadWalletNative(pathPointer, passwordPointer, 0),
);
print('load_wallet result $result');
return result;
}
int _boolToInt(bool value) => value ? 1 : 0;
bool _intToBool(int value) => value != 0;
String _convertUTF8ToString({required Pointer<Utf8> pointer}) {
final str = pointer.toDartString();
calloc.free(pointer);
return str;
}
// TODO: kind of stupid thing, in one method parsing json and then setting properties of a class
String? _parseResult(String result) {
final map = json.decode(result) as Map<String, dynamic>;
if (map['result'] != null) {
createWalletResult =
CreateWalletResult.fromJson(map['result'] as Map<String, dynamic>);
balances = createWalletResult!.wi.balances;
hWallet = createWalletResult!.walletId;
assetIds.clear();
for (final balance in createWalletResult!.wi.balances) {
assetIds[balance.assetInfo.assetId] = balance.assetInfo.ticker;
}
return createWalletResult!.wi.address;
}
return null;
}
}

View file

@ -1,54 +1,87 @@
import 'package:cw_zano/api/structs/pending_transaction.dart'; import 'dart:convert';
import 'package:cw_zano/api/transaction_history.dart'
as zano_transaction_history; import 'package:cw_zano/api/model/destination.dart';
import 'package:cw_zano/api/model/transfer_params.dart';
import 'package:cw_zano/api/model/transfer_result.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/amount_converter.dart'; import 'package:cw_core/amount_converter.dart';
import 'package:cw_core/pending_transaction.dart'; import 'package:cw_core/pending_transaction.dart';
import 'package:cw_zano/api/calls.dart' as calls;
class DoubleSpendException implements Exception { import 'package:cw_zano/zano_wallet.dart';
DoubleSpendException();
@override
String toString() =>
'This transaction cannot be committed. This can be due to many reasons including the wallet not being synced, there is not enough XMR in your available balance, or previous transactions are not yet fully processed.';
}
class PendingZanoTransaction with PendingTransaction { class PendingZanoTransaction with PendingTransaction {
PendingZanoTransaction( PendingZanoTransaction(
this.pendingTransactionDescription, this.cryptoCurrency); {required this.fee,
required this.intAmount,
//required this.stringAmount,
required this.hWallet,
required this.address,
required this.assetId,
required this.comment});
final PendingTransactionDescription pendingTransactionDescription; final int hWallet;
final CryptoCurrency cryptoCurrency; final int intAmount;
//final String stringAmount;
final int fee;
final String address;
final String assetId;
final String comment;
final CryptoCurrency cryptoCurrency = CryptoCurrency.zano;
@override @override
String get id => pendingTransactionDescription.hash; String get id => transferResult != null ? transferResult!.txHash : '';
@override @override
String get hex => ''; String get hex => '';
@override @override
String get amountFormatted { String get amountFormatted {
return AmountConverter.amountIntToString( return AmountConverter.amountIntToString(cryptoCurrency, intAmount);
cryptoCurrency, pendingTransactionDescription.amount);
} }
@override @override
String get feeFormatted => AmountConverter.amountIntToString( String get feeFormatted => AmountConverter.amountIntToString(cryptoCurrency, fee);
cryptoCurrency, pendingTransactionDescription.fee);
TransferResult? transferResult;
@override @override
Future<void> commit() async { Future<void> commit() async {
try { final result = await calls.transfer(
zano_transaction_history.commitTransactionFromPointerAddress( hWallet,
address: pendingTransactionDescription.pointerAddress); TransferParams(
} catch (e) { destinations: [
final message = e.toString(); Destination(
amount: intAmount.toString(), //stringAmount,
if (message.contains('Reason: double spend')) { address: address,
throw DoubleSpendException(); assetId: assetId,
)
],
fee: fee,
mixin: zanoMixin,
paymentId: '',
comment: comment,
pushPayer: false,
hideReceiver: false,
));
print('transfer result $result');
final map = jsonDecode(result);
if (map["result"] != null && map["result"]["result"] != null ) {
transferResult = TransferResult.fromJson(
map["result"]["result"] as Map<String, dynamic>,
);
} }
// try {
// zano_transaction_history.commitTransactionFromPointerAddress(
// address: pendingTransactionDescription.pointerAddress);
// } catch (e) {
// final message = e.toString();
rethrow; // if (message.contains('Reason: double spend')) {
} // throw DoubleSpendException();
// }
// rethrow;
// }
} }
} }

View file

@ -1,15 +0,0 @@
//import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/monero_amount_format.dart';
import 'package:cw_zano/api/balance_list.dart';
//Future<void> updateZanoRate(FiatConversionStore fiatConversionStore) async {
// final rate = getRate();
// final base = rate.firstWhere((row) => row.getAssetType() == 'XUSD', orElse: () => null);
// rate.forEach((row) {
// final cur = CryptoCurrency.fromString(row.getAssetType());
// final baseRate = moneroAmountToDouble(amount: base.getRate());
// final rowRate = moneroAmountToDouble(amount: row.getRate());
// fiatConversionStore.prices[cur] = baseRate * rowRate;
// });
//}

View file

@ -1,89 +0,0 @@
import 'package:mobx/mobx.dart';
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';
/*
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,
_isUpdating = false {
refresh();
}
@override
@observable
ObservableList<Account> accounts;
bool _isRefreshing;
bool _isUpdating;
@override
void update() async {
if (_isUpdating) {
return;
}
try {
_isUpdating = true;
refresh();
final accounts = getAll();
if (accounts.isNotEmpty) {
this.accounts.clear();
this.accounts.addAll(accounts);
}
_isUpdating = false;
} catch (e) {
_isUpdating = false;
rethrow;
}
}
@override
List<Account> getAll() => account_list
.getAllAccount()
.map((accountRow) =>
Account(id: accountRow.getId(), label: accountRow.getLabel()))
.toList();
@override
Future<void> addAccount({required String label}) async {
await account_list.addAccount(label: label);
update();
}
@override
Future<void> setLabelAccount(
{required int accountIndex, required String label}) async {
await account_list.setLabelForAccount(
accountIndex: accountIndex, label: label);
update();
}
@override
void refresh() {
/**if (_isRefreshing) {
return;
}
try {
_isRefreshing = true;
account_list.refreshAccounts();
_isRefreshing = false;
} catch (e) {
_isRefreshing = false;
print(e);
rethrow;
}
}*/
}*/

View file

@ -1,23 +1,18 @@
import 'package:cw_core/balance.dart'; import 'package:cw_core/balance.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/monero_amount_format.dart'; import 'package:cw_core/monero_amount_format.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';
class ZanoBalance extends Balance { class ZanoBalance extends Balance {
final int total; final int total;
final int unlocked; final int unlocked;
ZanoBalance({required this.total, required this.unlocked}): super(unlocked, 0); ZanoBalance({required this.total, required this.unlocked}): super(unlocked, total-unlocked);
@override @override
String get formattedAdditionalBalance => moneroAmountToString(amount: additional); String get formattedAdditionalBalance => moneroAmountToString(amount: total-unlocked);
@override @override
String get formattedAvailableBalance => moneroAmountToString(amount: unlocked); String get formattedAvailableBalance => moneroAmountToString(amount: unlocked);
@override @override
String get formattedFrozenBalance => total == unlocked ? '' : moneroAmountToString(amount: total - unlocked); String get formattedFrozenBalance => '';
} }

View file

@ -1,88 +0,0 @@
import 'package:cw_zano/api/structs/subaddress_row.dart';
import 'package:flutter/services.dart';
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';
/*class ZanoSubaddressList = ZanoSubaddressListBase with _$ZanoSubaddressList;
abstract class ZanoSubaddressListBase with Store {
ZanoSubaddressListBase()
: _isRefreshing = false,
_isUpdating = false,
subaddresses = ObservableList<Subaddress>();
@observable
ObservableList<Subaddress> subaddresses;
bool _isRefreshing;
bool _isUpdating;
void update({required int accountIndex}) {
if (_isUpdating) {
return;
}
try {
_isUpdating = true;
refresh(accountIndex: accountIndex);
subaddresses.clear();
subaddresses.addAll(getAll());
_isUpdating = false;
} catch (e) {
_isUpdating = false;
rethrow;
}
}
List<Subaddress> getAll() {
var subaddresses = subaddress_list.getAllSubaddresses();
if (subaddresses.length > 2) {
final primary = subaddresses.first;
final rest = subaddresses.sublist(1).reversed;
subaddresses = [primary] + rest.toList();
}
return subaddresses
.map((subaddressRow) => Subaddress(
id: subaddressRow.getId(),
address: subaddressRow.getAddress(),
label: subaddressRow.getLabel()))
.toList();
}
Future<void> addSubaddress(
{required int accountIndex, required String label}) async {
await subaddress_list.addSubaddress(
accountIndex: accountIndex, label: label);
update(accountIndex: accountIndex);
}
Future<void> setLabelSubaddress(
{required int accountIndex,
required int addressIndex,
required String label}) async {
await subaddress_list.setLabelForSubaddress(
accountIndex: accountIndex, addressIndex: addressIndex, label: label);
update(accountIndex: accountIndex);
}
void refresh({required int accountIndex}) {
if (_isRefreshing) {
return;
}
try {
_isRefreshing = true;
subaddress_list.refreshSubaddresses(accountIndex: accountIndex);
_isRefreshing = false;
} on PlatformException catch (e) {
_isRefreshing = false;
print(e);
rethrow;
}
}
}*/

View file

@ -1,8 +0,0 @@
class ZanoTransactionCreationException implements Exception {
ZanoTransactionCreationException(this.message);
final String message;
@override
String toString() => message;
}

View file

@ -1,11 +1,8 @@
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/monero_amount_format.dart';
import 'package:cw_zano/api/model/history.dart';
import 'package:cw_zano/api/structs/transaction_info_row.dart';
import 'package:cw_core/parseBoolFromString.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/format_amount.dart'; import 'package:cw_core/format_amount.dart';
import 'package:cw_zano/api/transaction_history.dart'; import 'package:cw_core/monero_amount_format.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_zano/api/model/history.dart';
class ZanoTransactionInfo extends TransactionInfo { class ZanoTransactionInfo extends TransactionInfo {
ZanoTransactionInfo( ZanoTransactionInfo(

View file

@ -14,12 +14,8 @@ import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_info.dart';
import 'package:cw_zano/api/calls.dart' as calls; import 'package:cw_zano/api/calls.dart' as calls;
import 'package:cw_zano/api/model/destination.dart';
import 'package:cw_zano/api/model/history.dart'; import 'package:cw_zano/api/model/history.dart';
import 'package:cw_zano/api/model/transfer_params.dart';
import 'package:cw_zano/api/model/zano_wallet_keys.dart'; import 'package:cw_zano/api/model/zano_wallet_keys.dart';
import 'package:cw_zano/api/structs/pending_transaction.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/zano_api.dart'; import 'package:cw_zano/api/zano_api.dart';
import 'package:cw_zano/pending_zano_transaction.dart'; import 'package:cw_zano/pending_zano_transaction.dart';
@ -175,8 +171,8 @@ abstract class ZanoWalletBase
final address = output.isParsedAddress && (output.extractedAddress?.isNotEmpty ?? false) final address = output.isParsedAddress && (output.extractedAddress?.isNotEmpty ?? false)
? output.extractedAddress! ? output.extractedAddress!
: output.address; : output.address;
final amount = output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.'); final stringAmount = output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
final int? formattedAmount = output.sendAll ? null : output.formattedCryptoAmount; //final int? formattedAmount = output.sendAll ? null : output.formattedCryptoAmount;
final fee = calculateEstimatedFee(creds.priority); final fee = calculateEstimatedFee(creds.priority);
// final result = await calls.transfer( // final result = await calls.transfer(
// hWallet, // hWallet,
@ -195,10 +191,12 @@ abstract class ZanoWalletBase
// pushPayer: false, // pushPayer: false,
// hideReceiver: false, // hideReceiver: false,
// )); // ));
int iAmount = (double.parse(amount!) * pow(10, 12)).toInt(); final intAmount = (double.parse(stringAmount!) * pow(10, 12)).toInt();
final description = PendingTransactionDescription( // final description = PendingTransactionDescription(
amount: iAmount, fee: fee, hash: 'fade', pointerAddress: 0); // amount: iAmount, fee: fee, hash: '', pointerAddress: 0);
final transaction = PendingZanoTransaction(description, CryptoCurrency.zano); final transaction = PendingZanoTransaction(fee: fee, intAmount: intAmount,
hWallet: hWallet, address: address, assetId: assetId,
comment: output.note ?? '');
return transaction; return transaction;
/*final _credentials = credentials as ZanoTransactionCreationCredentials; /*final _credentials = credentials as ZanoTransactionCreationCredentials;

View file

@ -1,9 +1,5 @@
import 'package:cw_core/wallet_addresses.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_zano/zano_account_list.dart';
import 'package:cw_zano/zano_subaddress_list.dart';
import 'package:cw_core/subaddress.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
part 'zano_wallet_addresses.g.dart'; part 'zano_wallet_addresses.g.dart';

View file

@ -1,24 +1,21 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/node.dart'; import 'package:cw_core/node.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/monero_wallet_utils.dart';
import 'package:cw_zano/api/model/create_wallet_result.dart';
import 'package:cw_zano/new_zano_wallet.dart';
import 'package:cw_zano/zano_balance.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';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/pathForWallet.dart'; import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:cw_zano/api/calls.dart' as calls;
import 'package:cw_zano/api/model/create_wallet_result.dart';
import 'package:cw_zano/api/wallet_manager.dart' as zano_wallet_manager;
import 'package:cw_zano/zano_balance.dart';
import 'package:cw_zano/zano_wallet.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
class ZanoNewWalletCredentials extends WalletCredentials { class ZanoNewWalletCredentials extends WalletCredentials {
@ -34,11 +31,6 @@ class ZanoRestoreWalletFromSeedCredentials extends WalletCredentials {
final String mnemonic; final String mnemonic;
} }
class ZanoWalletLoadingException implements Exception {
@override
String toString() => 'Failure to load the wallet.';
}
class ZanoRestoreWalletFromKeysCredentials extends WalletCredentials { class ZanoRestoreWalletFromKeysCredentials extends WalletCredentials {
ZanoRestoreWalletFromKeysCredentials( ZanoRestoreWalletFromKeysCredentials(
{required String name, {required String name,
@ -91,9 +83,8 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials,
final wallet = ZanoWallet(credentials.walletInfo!); final wallet = ZanoWallet(credentials.walletInfo!);
await wallet.connectToNode(node: Node()); await wallet.connectToNode(node: Node());
final path = await pathForWallet(name: credentials.name, type: getType()); final path = await pathForWallet(name: credentials.name, type: getType());
final result = await zano_wallet_manager.createWallet( final result = calls.createWallet(
language: "", path: path, password: credentials.password!); language: "", path: path, password: credentials.password!);
print("create wallet result $result");
final map = json.decode(result) as Map<String, dynamic>; final map = json.decode(result) as Map<String, dynamic>;
if (map['result'] != null) { if (map['result'] != null) {
final createWalletResult = final createWalletResult =

View file

@ -30,7 +30,7 @@ class SeedValidator extends Validator<MnemonicItem> {
case WalletType.haven: case WalletType.haven:
return haven!.getMoneroWordList(language); return haven!.getMoneroWordList(language);
case WalletType.zano: case WalletType.zano:
return zano!.getMoneroWordList(language); return zano!.getWordList(language);
case WalletType.ethereum: case WalletType.ethereum:
return ethereum!.getEthereumWordList(language); return ethereum!.getEthereumWordList(language);
case WalletType.dummy: case WalletType.dummy:

View file

@ -123,7 +123,7 @@ abstract class TransactionDetailsViewModelBase with Store {
case WalletType.ethereum: case WalletType.ethereum:
return 'https://etherscan.io/tx/${txId}'; return 'https://etherscan.io/tx/${txId}';
case WalletType.zano: case WalletType.zano:
return 'https://example.com/${txId}'; return 'https://testnet-explorer.zano.org/transaction/${txId}';
case WalletType.dummy: case WalletType.dummy:
return 'https://example.com/${txId}'; return 'https://example.com/${txId}';
default: default:

View file

@ -106,7 +106,7 @@ Future<String?> create(String name) async {
credentials.password = password; credentials.password = password;
await keyService.saveWalletPassword(password: password, walletName: credentials.name); await keyService.saveWalletPassword(password: password, walletName: credentials.name);
debugPrint('path $path password $password'); debugPrint('path $path password $password');
final result = zano_wallet_manager.createWalletSync(path: path, password: password, language: ''); final result = calls.createWallet(path: path, password: password, language: '');
debugPrint('create result $result'); debugPrint('create result $result');
return _parseResult(result); return _parseResult(result);
} }

View file

@ -115,31 +115,9 @@ class CWZano extends Zano {
} }
@override @override
List<String> getMoneroWordList(String language) { List<String> getWordList(String language) {
switch (language.toLowerCase()) { assert(language.toLowerCase() == LanguageList.english.toLowerCase());
case 'english':
return EnglishMnemonics.words; return EnglishMnemonics.words;
case 'chinese (simplified)':
return ChineseSimplifiedMnemonics.words;
case 'dutch':
return DutchMnemonics.words;
case 'german':
return GermanMnemonics.words;
case 'japanese':
return JapaneseMnemonics.words;
case 'portuguese':
return PortugueseMnemonics.words;
case 'russian':
return RussianMnemonics.words;
case 'spanish':
return SpanishMnemonics.words;
case 'french':
return FrenchMnemonics.words;
case 'italian':
return ItalianMnemonics.words;
default:
return EnglishMnemonics.words;
}
} }
@override @override
@ -267,7 +245,7 @@ class CWZano extends Zano {
return asset; return asset;
} }
@override // @override
List<AssetRate> getAssetRate() => // List<AssetRate> getAssetRate() =>
getRate().map((rate) => AssetRate(rate.getAssetType(), rate.getRate())).toList(); // getRate().map((rate) => AssetRate(rate.getAssetType(), rate.getRate())).toList();
} }

View file

@ -1,4 +1,4 @@
import 'package:cw_zano/new_zano_wallet.dart'; import 'package:cake_wallet/utils/language_list.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_credentials.dart';
@ -22,15 +22,6 @@ import 'package:cw_zano/zano_transaction_history.dart';
import 'package:cw_core/account.dart' as monero_account; import 'package:cw_core/account.dart' as monero_account;
import 'package:cw_zano/api/wallet.dart' as monero_wallet_api; import 'package:cw_zano/api/wallet.dart' as monero_wallet_api;
import 'package:cw_zano/mnemonics/english.dart'; import 'package:cw_zano/mnemonics/english.dart';
import 'package:cw_zano/mnemonics/chinese_simplified.dart';
import 'package:cw_zano/mnemonics/dutch.dart';
import 'package:cw_zano/mnemonics/german.dart';
import 'package:cw_zano/mnemonics/japanese.dart';
import 'package:cw_zano/mnemonics/russian.dart';
import 'package:cw_zano/mnemonics/spanish.dart';
import 'package:cw_zano/mnemonics/portuguese.dart';
import 'package:cw_zano/mnemonics/french.dart';
import 'package:cw_zano/mnemonics/italian.dart';
import 'package:cw_zano/zano_transaction_creation_credentials.dart'; import 'package:cw_zano/zano_transaction_creation_credentials.dart';
import 'package:cw_zano/api/balance_list.dart'; import 'package:cw_zano/api/balance_list.dart';
@ -111,7 +102,7 @@ abstract class Zano {
TransactionPriority getDefaultTransactionPriority(); TransactionPriority getDefaultTransactionPriority();
TransactionPriority deserializeMoneroTransactionPriority({required int raw}); TransactionPriority deserializeMoneroTransactionPriority({required int raw});
List<TransactionPriority> getTransactionPriorities(); List<TransactionPriority> getTransactionPriorities();
List<String> getMoneroWordList(String language); List<String> getWordList(String language);
WalletCredentials createZanoRestoreWalletFromKeysCredentials({ WalletCredentials createZanoRestoreWalletFromKeysCredentials({
required String name, required String name,
@ -134,7 +125,7 @@ abstract class Zano {
int getTransactionInfoAccountId(TransactionInfo tx); int getTransactionInfoAccountId(TransactionInfo tx);
WalletService createZanoWalletService(Box<WalletInfo> walletInfoSource); WalletService createZanoWalletService(Box<WalletInfo> walletInfoSource);
CryptoCurrency assetOfTransaction(TransactionInfo tx); CryptoCurrency assetOfTransaction(TransactionInfo tx);
List<AssetRate> getAssetRate(); // List<AssetRate> getAssetRate();
} }
// abstract class MoneroSubaddressList { // abstract class MoneroSubaddressList {