mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 02:34:59 +00:00
send + receive qr code
This commit is contained in:
parent
df984ca515
commit
e4c775bffe
13 changed files with 90 additions and 57 deletions
|
@ -131,6 +131,23 @@ bool isWalletExist({required String path}) {
|
|||
return isExist;
|
||||
}
|
||||
|
||||
// char* get_address_info(char* address)
|
||||
final _getAddressInfoNative = zanoApi
|
||||
.lookup<NativeFunction<_get_address_info>>('get_address_info')
|
||||
.asFunction<_GetAddressInfo>();
|
||||
typedef _get_address_info = Pointer<Utf8> Function(Pointer<Utf8> password);
|
||||
typedef _GetAddressInfo = Pointer<Utf8> Function(Pointer<Utf8> address);
|
||||
|
||||
String getAddressInfo(String address) {
|
||||
debugPrint('get address info $address');
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
final result =
|
||||
convertUTF8ToString(pointer: _getAddressInfoNative(addressPointer));
|
||||
debugPrint('get address info result $result');
|
||||
calloc.free(addressPointer);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool setupNode({
|
||||
required String address,
|
||||
String? login,
|
||||
|
|
7
cw_zano/lib/api/exceptions/create_wallet_exception.dart
Normal file
7
cw_zano/lib/api/exceptions/create_wallet_exception.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
class CreateWalletException implements Exception {
|
||||
final String message;
|
||||
|
||||
CreateWalletException(this.message): super();
|
||||
@override
|
||||
String toString() => '${this.runtimeType}(message: $message)';
|
||||
}
|
16
cw_zano/lib/api/model/get_address_info_result.dart
Normal file
16
cw_zano/lib/api/model/get_address_info_result.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
class GetAddressInfoResult {
|
||||
final bool valid;
|
||||
final bool auditable;
|
||||
final bool paymentId;
|
||||
final bool wrap;
|
||||
|
||||
GetAddressInfoResult(
|
||||
{required this.valid, required this.auditable, required this.paymentId, required this.wrap});
|
||||
|
||||
factory GetAddressInfoResult.fromJson(Map<String, dynamic> json) => GetAddressInfoResult(
|
||||
valid: json['valid'] as bool,
|
||||
auditable: json['auditable'] as bool,
|
||||
paymentId: json['payment_id'] as bool,
|
||||
wrap: json['wrap'] as bool,
|
||||
);
|
||||
}
|
|
@ -23,13 +23,4 @@ class GetWalletStatusResult {
|
|||
progress: json['progress'] as int,
|
||||
walletState: json['wallet_state'] as int,
|
||||
);
|
||||
/*
|
||||
"current_daemon_height": 238049,
|
||||
"current_wallet_height": 238038,
|
||||
"is_daemon_connected": true,
|
||||
"is_in_long_refresh": true,
|
||||
"progress": 0,
|
||||
"wallet_state": 1
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
17
cw_zano/lib/zano_utils.dart
Normal file
17
cw_zano/lib/zano_utils.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:cw_zano/api/calls.dart' as calls;
|
||||
import 'package:cw_zano/api/model/get_address_info_result.dart';
|
||||
|
||||
class ZanoUtils {
|
||||
static bool validateAddress(String address) {
|
||||
try {
|
||||
final result = GetAddressInfoResult.fromJson(
|
||||
jsonDecode(calls.getAddressInfo(address)) as Map<String, dynamic>,
|
||||
);
|
||||
return result.valid;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -97,8 +97,9 @@ abstract class ZanoWalletBase
|
|||
_hWallet = value;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
Future<void> init(String address) async {
|
||||
await walletAddresses.init();
|
||||
await walletAddresses.updateAddress(address);
|
||||
///balance.addAll(getZanoBalance(/**accountIndex: walletAddresses.account?.id ?? 0*/));
|
||||
_setListeners();
|
||||
await updateTransactions();
|
||||
|
|
|
@ -32,7 +32,12 @@ abstract class ZanoWalletAddressesBase extends WalletAddresses with Store {
|
|||
/*accountList.update();
|
||||
account = accountList.accounts.first;*/
|
||||
/**updateSubaddressList(accountIndex: account?.id ?? 0);*/
|
||||
address = walletInfo.address;
|
||||
//address = walletInfo.address;
|
||||
//await updateAddressesInBox();
|
||||
}
|
||||
|
||||
Future<void> updateAddress(String address) async {
|
||||
this.address = address;
|
||||
await updateAddressesInBox();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:cw_core/wallet_type.dart';
|
|||
import 'package:cw_zano/api/calls.dart' as calls;
|
||||
import 'package:cw_zano/api/consts.dart';
|
||||
import 'package:cw_zano/api/exceptions/already_exists_exception.dart';
|
||||
import 'package:cw_zano/api/exceptions/create_wallet_exception.dart';
|
||||
import 'package:cw_zano/api/exceptions/restore_from_seed_exception.dart';
|
||||
import 'package:cw_zano/api/exceptions/wrong_seed_exception.dart';
|
||||
import 'package:cw_zano/api/model/create_wallet_result.dart';
|
||||
|
@ -65,38 +66,19 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials,
|
|||
@override
|
||||
WalletType getType() => WalletType.zano;
|
||||
|
||||
// @override
|
||||
// Future<ZanoWallet> create(WalletCredentials credentials) async {
|
||||
// try {
|
||||
// final wallet = ZanoWallet(credentials.walletInfo!);
|
||||
// wallet.connectToNode(node: Node()); // TODO: Node() ???
|
||||
// //wallet.setupNode(address: "195.201.107.230:33336", login: "", password: "");
|
||||
// final path = await pathForWallet(name: credentials.name, type: getType());
|
||||
// wallet.createWallet(path: path, password: credentials.password!);
|
||||
// return wallet;
|
||||
// } catch (e) {
|
||||
// print("ZanoWalletService.create error $e");
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
@override
|
||||
Future<ZanoWallet> create(WalletCredentials credentials) async {
|
||||
try {
|
||||
final wallet = ZanoWallet(credentials.walletInfo!);
|
||||
await wallet.connectToNode(node: Node());
|
||||
final path = await pathForWallet(name: credentials.name, type: getType());
|
||||
final result = calls.createWallet(
|
||||
language: "", path: path, password: credentials.password!);
|
||||
final result = calls.createWallet(language: "", path: path, password: credentials.password!);
|
||||
final map = json.decode(result) as Map<String, dynamic>;
|
||||
if (map['result'] != null) {
|
||||
final createWalletResult =
|
||||
CreateWalletResult.fromJson(map['result'] as Map<String, dynamic>);
|
||||
_parseCreateWalletResult(createWalletResult, wallet);
|
||||
}
|
||||
// TODO: remove it TODO why?
|
||||
if (map['result'] == null) throw CreateWalletException('');
|
||||
final createWalletResult = CreateWalletResult.fromJson(map['result'] as Map<String, dynamic>);
|
||||
_parseCreateWalletResult(createWalletResult, wallet);
|
||||
await calls.store(hWallet);
|
||||
await wallet.init();
|
||||
await wallet.init(createWalletResult.wi.address);
|
||||
return wallet;
|
||||
} catch (e) {
|
||||
// TODO: Implement Exception for wallet list service.
|
||||
|
@ -133,13 +115,11 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials,
|
|||
final result = wallet.loadWallet(path, password);
|
||||
print("load wallet result $result");
|
||||
final map = json.decode(result) as Map<String, dynamic>;
|
||||
if (map['result'] != null) {
|
||||
final createWalletResult =
|
||||
CreateWalletResult.fromJson(map['result'] as Map<String, dynamic>);
|
||||
_parseCreateWalletResult(createWalletResult, wallet);
|
||||
}
|
||||
if (map['result'] == null) throw CreateWalletException('');
|
||||
final createWalletResult = CreateWalletResult.fromJson(map['result'] as Map<String, dynamic>);
|
||||
_parseCreateWalletResult(createWalletResult, wallet);
|
||||
await calls.store(hWallet);
|
||||
await wallet.init();
|
||||
await wallet.init(createWalletResult.wi.address);
|
||||
return wallet;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
|
@ -206,6 +186,9 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials,
|
|||
final createWalletResult =
|
||||
CreateWalletResult.fromJson(map['result'] as Map<String, dynamic>);
|
||||
_parseCreateWalletResult(createWalletResult, wallet);
|
||||
await calls.store(hWallet);
|
||||
await wallet.init(createWalletResult.wi.address);
|
||||
return wallet;
|
||||
} else if (map['error'] != null) {
|
||||
final code = map['error']['code'] as String;
|
||||
final message = map['error']['message'] as String;
|
||||
|
@ -216,9 +199,7 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials,
|
|||
}
|
||||
throw RestoreFromSeedException(code, message);
|
||||
}
|
||||
await calls.store(hWallet);
|
||||
await wallet.init();
|
||||
return wallet;
|
||||
throw RestoreFromSeedException('', '');
|
||||
} catch (e) {
|
||||
// TODO: Implement Exception for wallet list service.
|
||||
print('ZanoWalletsManager Error: $e');
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:cake_wallet/generated/i18n.dart';
|
|||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/erc20_token.dart';
|
||||
import 'package:cw_zano/zano_utils.dart';
|
||||
|
||||
class AddressValidator extends TextValidator {
|
||||
AddressValidator({required CryptoCurrency type})
|
||||
|
@ -10,7 +11,9 @@ class AddressValidator extends TextValidator {
|
|||
errorMessage: S.current.error_text_address,
|
||||
useAdditionalValidation: type == CryptoCurrency.btc
|
||||
? bitcoin.Address.validateAddress
|
||||
: null,
|
||||
: type == CryptoCurrency.zano
|
||||
? ZanoUtils.validateAddress
|
||||
: null,
|
||||
pattern: getPattern(type),
|
||||
length: getLength(type));
|
||||
|
||||
|
@ -240,7 +243,7 @@ class AddressValidator extends TextValidator {
|
|||
case CryptoCurrency.btcln:
|
||||
return null;
|
||||
case CryptoCurrency.zano:
|
||||
return [97];
|
||||
return null;//[97];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class TextValidator extends Validator<String> {
|
|||
|
||||
final valueMatched = match(value);
|
||||
final valueValidated = useAdditionalValidation != null
|
||||
? useAdditionalValidation!(value) || valueMatched
|
||||
? useAdditionalValidation!(value) && valueMatched
|
||||
: valueMatched;
|
||||
|
||||
return valueValidated;
|
||||
|
|
|
@ -695,10 +695,9 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
receiveCurrency = CryptoCurrency.xmr;
|
||||
break;
|
||||
case WalletType.zano:
|
||||
// TODO: !!!
|
||||
// depositCurrency = CryptoCurrency.zano;
|
||||
// receiveCurrency = ???
|
||||
throw UnimplementedError();
|
||||
depositCurrency = CryptoCurrency.zano;
|
||||
receiveCurrency = CryptoCurrency.btc;
|
||||
break;
|
||||
case WalletType.dummy:
|
||||
// TODO: !!!
|
||||
// depositCurrency = CryptoCurrency.dummy;
|
||||
|
|
|
@ -11,7 +11,6 @@ import 'package:cw_zano/api/calls.dart' as calls;
|
|||
import 'package:cw_zano/api/model/balance.dart';
|
||||
import 'package:cw_zano/api/model/create_wallet_result.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/zano_wallet_service.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -85,7 +84,7 @@ const walletName = 'walletName';
|
|||
|
||||
Future<void> init() async {
|
||||
version = calls.getVersion();
|
||||
final setupNode = await zano_wallet.setupNode(
|
||||
final setupNode = await calls.setupNode(
|
||||
address: '195.201.107.230:33336',
|
||||
login: '',
|
||||
password: '',
|
||||
|
|
|
@ -69,10 +69,7 @@ class CWZanoWalletDetails extends ZanoWalletDetails {
|
|||
ZanoBalance get balance {
|
||||
final zanoWallet = _wallet as ZanoWallet;
|
||||
final balance = zanoWallet.balance;
|
||||
throw Exception('Unimplemented');
|
||||
//return ZanoBalance(
|
||||
// fullBalance: balance.fullBalance,
|
||||
// unlockedBalance: balance.unlockedBalance);
|
||||
return ZanoBalance(fullBalance: balance[CryptoCurrency.zano]!.total, unlockedBalance: balance[CryptoCurrency.zano]!.unlocked);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue