mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-03 12:24:19 +01:00
Flutter upgrade
This commit is contained in:
@@ -50,16 +50,16 @@ List<AccountRow> getAllAccount() {
|
||||
.toList();
|
||||
}
|
||||
|
||||
void addAccountSync({String label}) {
|
||||
final labelPointer = Utf8.toUtf8(label);
|
||||
void addAccountSync({required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
accountAddNewNative(labelPointer);
|
||||
free(labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
}
|
||||
|
||||
void setLabelForAccountSync({int accountIndex, String label}) {
|
||||
final labelPointer = Utf8.toUtf8(label);
|
||||
void setLabelForAccountSync({required int accountIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
accountSetLabelNative(accountIndex, labelPointer);
|
||||
free(labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
}
|
||||
|
||||
void _addAccount(String label) => addAccountSync(label: label);
|
||||
@@ -71,12 +71,12 @@ void _setLabelForAccount(Map<String, dynamic> args) {
|
||||
setLabelForAccountSync(label: label, accountIndex: accountIndex);
|
||||
}
|
||||
|
||||
Future<void> addAccount({String label}) async {
|
||||
Future<void> addAccount({required String label}) async {
|
||||
await compute(_addAccount, label);
|
||||
await store();
|
||||
}
|
||||
|
||||
Future<void> setLabelForAccount({int accountIndex, String label}) async {
|
||||
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
||||
await compute(
|
||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
||||
await store();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
String convertUTF8ToString({Pointer<Utf8> pointer}) {
|
||||
final str = Utf8.fromUtf8(pointer);
|
||||
free(pointer);
|
||||
String convertUTF8ToString({required Pointer<Utf8> pointer}) {
|
||||
final str = pointer.toDartString();
|
||||
calloc.free(pointer);
|
||||
return str;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class CwHaven {
|
||||
const MethodChannel('cw_haven');
|
||||
|
||||
static Future<String> get platformVersion async {
|
||||
final String version = await _channel.invokeMethod('getPlatformVersion');
|
||||
final String version = await _channel.invokeMethod<String>('getPlatformVersion') ?? '';
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class ConnectionToNodeException implements Exception {
|
||||
ConnectionToNodeException({this.message});
|
||||
ConnectionToNodeException({required this.message});
|
||||
|
||||
final String message;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
class CreationTransactionException implements Exception {
|
||||
CreationTransactionException({this.message});
|
||||
CreationTransactionException({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class SetupWalletException implements Exception {
|
||||
SetupWalletException({this.message});
|
||||
SetupWalletException({required this.message});
|
||||
|
||||
final String message;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
class WalletCreationException implements Exception {
|
||||
WalletCreationException({this.message});
|
||||
WalletCreationException({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class WalletOpeningException implements Exception {
|
||||
WalletOpeningException({this.message});
|
||||
WalletOpeningException({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class WalletRestoreFromKeysException implements Exception {
|
||||
WalletRestoreFromKeysException({this.message});
|
||||
WalletRestoreFromKeysException({required this.message});
|
||||
|
||||
final String message;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
class WalletRestoreFromSeedException implements Exception {
|
||||
WalletRestoreFromSeedException({this.message});
|
||||
WalletRestoreFromSeedException({required this.message});
|
||||
|
||||
final String message;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class MoneroOutput {
|
||||
MoneroOutput({@required this.address, @required this.amount});
|
||||
MoneroOutput({required this.address, required this.amount});
|
||||
|
||||
final String address;
|
||||
final String amount;
|
||||
|
||||
@@ -39,7 +39,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>?, Pointer<Utf8>?, Int8, Int8, Pointer<Utf8>);
|
||||
|
||||
typedef start_refresh = Void Function();
|
||||
|
||||
@@ -86,7 +86,7 @@ typedef account_set_label = 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();
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
class AccountRow extends Struct {
|
||||
@Int64()
|
||||
int id;
|
||||
Pointer<Utf8> label;
|
||||
external int id;
|
||||
|
||||
external Pointer<Utf8> label;
|
||||
|
||||
String getLabel() => Utf8.fromUtf8(label);
|
||||
String getLabel() => label.toDartString();
|
||||
int getId() => id;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
class HavenBalanceRow extends Struct {
|
||||
@Int64()
|
||||
int amount;
|
||||
Pointer<Utf8> assetType;
|
||||
external int amount;
|
||||
|
||||
external Pointer<Utf8> assetType;
|
||||
|
||||
int getAmount() => amount;
|
||||
String getAssetType() => Utf8.fromUtf8(assetType);
|
||||
String getAssetType() => assetType.toDartString();
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
class HavenRate extends Struct {
|
||||
@Int64()
|
||||
int rate;
|
||||
Pointer<Utf8> assetType;
|
||||
external int rate;
|
||||
|
||||
external Pointer<Utf8> assetType;
|
||||
|
||||
int getRate() => rate;
|
||||
String getAssetType() => Utf8.fromUtf8(assetType);
|
||||
String getAssetType() => assetType.toDartString();
|
||||
}
|
||||
|
||||
@@ -3,18 +3,22 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
class PendingTransactionRaw extends Struct {
|
||||
@Int64()
|
||||
int amount;
|
||||
external int amount;
|
||||
|
||||
@Int64()
|
||||
int fee;
|
||||
external int fee;
|
||||
|
||||
Pointer<Utf8> hash;
|
||||
external Pointer<Utf8> hash;
|
||||
|
||||
String getHash() => Utf8.fromUtf8(hash);
|
||||
String getHash() => hash.toDartString();
|
||||
}
|
||||
|
||||
class PendingTransactionDescription {
|
||||
PendingTransactionDescription({this.amount, this.fee, this.hash, this.pointerAddress});
|
||||
PendingTransactionDescription({
|
||||
required this.amount,
|
||||
required this.fee,
|
||||
required this.hash,
|
||||
required this.pointerAddress});
|
||||
|
||||
final int amount;
|
||||
final int fee;
|
||||
|
||||
@@ -3,11 +3,13 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
class SubaddressRow extends Struct {
|
||||
@Int64()
|
||||
int id;
|
||||
Pointer<Utf8> address;
|
||||
Pointer<Utf8> label;
|
||||
external int id;
|
||||
|
||||
external Pointer<Utf8> address;
|
||||
|
||||
external Pointer<Utf8> label;
|
||||
|
||||
String getLabel() => Utf8.fromUtf8(label);
|
||||
String getAddress() => Utf8.fromUtf8(address);
|
||||
String getLabel() => label.toDartString();
|
||||
String getAddress() => address.toDartString();
|
||||
int getId() => id;
|
||||
}
|
||||
@@ -3,42 +3,42 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
class TransactionInfoRow extends Struct {
|
||||
@Uint64()
|
||||
int amount;
|
||||
external int amount;
|
||||
|
||||
@Uint64()
|
||||
int fee;
|
||||
external int fee;
|
||||
|
||||
@Uint64()
|
||||
int blockHeight;
|
||||
external int blockHeight;
|
||||
|
||||
@Uint64()
|
||||
int confirmations;
|
||||
external int confirmations;
|
||||
|
||||
@Uint32()
|
||||
int subaddrAccount;
|
||||
external int subaddrAccount;
|
||||
|
||||
@Int8()
|
||||
int direction;
|
||||
external int direction;
|
||||
|
||||
@Int8()
|
||||
int isPending;
|
||||
external int isPending;
|
||||
|
||||
@Uint32()
|
||||
int subaddrIndex;
|
||||
external int subaddrIndex;
|
||||
|
||||
Pointer<Utf8> hash;
|
||||
external Pointer<Utf8> hash;
|
||||
|
||||
Pointer<Utf8> paymentId;
|
||||
external Pointer<Utf8> paymentId;
|
||||
|
||||
Pointer<Utf8> assetType;
|
||||
external Pointer<Utf8> assetType;
|
||||
|
||||
@Int64()
|
||||
int datetime;
|
||||
external int datetime;
|
||||
|
||||
int getDatetime() => datetime;
|
||||
int getAmount() => amount >= 0 ? amount : amount * -1;
|
||||
bool getIsPending() => isPending != 0;
|
||||
String getHash() => Utf8.fromUtf8(hash);
|
||||
String getPaymentId() => Utf8.fromUtf8(paymentId);
|
||||
String getAssetType() => Utf8.fromUtf8(assetType);
|
||||
String getHash() => hash.toDartString();
|
||||
String getPaymentId() => paymentId.toDartString();
|
||||
String getAssetType() => assetType.toDartString();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
class Utf8Box extends Struct {
|
||||
Pointer<Utf8> value;
|
||||
external Pointer<Utf8> value;
|
||||
|
||||
String getValue() => Utf8.fromUtf8(value);
|
||||
String getValue() => value.toDartString();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ final subaddrressSetLabelNative = havenApi
|
||||
|
||||
bool isUpdating = false;
|
||||
|
||||
void refreshSubaddresses({@required int accountIndex}) {
|
||||
void refreshSubaddresses({required int accountIndex}) {
|
||||
try {
|
||||
isUpdating = true;
|
||||
subaddressRefreshNative(accountIndex);
|
||||
@@ -50,18 +50,18 @@ List<SubaddressRow> getAllSubaddresses() {
|
||||
.toList();
|
||||
}
|
||||
|
||||
void addSubaddressSync({int accountIndex, String label}) {
|
||||
final labelPointer = Utf8.toUtf8(label);
|
||||
void addSubaddressSync({required int accountIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
subaddrressAddNewNative(accountIndex, labelPointer);
|
||||
free(labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
}
|
||||
|
||||
void setLabelForSubaddressSync(
|
||||
{int accountIndex, int addressIndex, String label}) {
|
||||
final labelPointer = Utf8.toUtf8(label);
|
||||
{required int accountIndex, required int addressIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
|
||||
subaddrressSetLabelNative(accountIndex, addressIndex, labelPointer);
|
||||
free(labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
}
|
||||
|
||||
void _addSubaddress(Map<String, dynamic> args) {
|
||||
@@ -80,14 +80,14 @@ void _setLabelForSubaddress(Map<String, dynamic> args) {
|
||||
accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
||||
}
|
||||
|
||||
Future addSubaddress({int accountIndex, String label}) async {
|
||||
Future addSubaddress({required int accountIndex, required String label}) async {
|
||||
await compute<Map<String, Object>, void>(
|
||||
_addSubaddress, {'accountIndex': accountIndex, 'label': label});
|
||||
await store();
|
||||
}
|
||||
|
||||
Future setLabelForSubaddress(
|
||||
{int accountIndex, int addressIndex, String label}) async {
|
||||
{required int accountIndex, required int addressIndex, required String label}) async {
|
||||
await compute<Map<String, Object>, void>(_setLabelForSubaddress, {
|
||||
'accountIndex': accountIndex,
|
||||
'addressIndex': addressIndex,
|
||||
|
||||
@@ -40,16 +40,16 @@ final getTxKeyNative = havenApi
|
||||
.asFunction<GetTxKey>();
|
||||
|
||||
String getTxKey(String txId) {
|
||||
final txIdPointer = Utf8.toUtf8(txId);
|
||||
final txIdPointer = txId.toNativeUtf8();
|
||||
final keyPointer = getTxKeyNative(txIdPointer);
|
||||
|
||||
free(txIdPointer);
|
||||
calloc.free(txIdPointer);
|
||||
|
||||
if (keyPointer != null) {
|
||||
return convertUTF8ToString(pointer: keyPointer);
|
||||
}
|
||||
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
void refreshTransactions() => transactionsRefreshNative();
|
||||
@@ -67,18 +67,18 @@ List<TransactionInfoRow> getAllTransations() {
|
||||
}
|
||||
|
||||
PendingTransactionDescription createTransactionSync(
|
||||
{String address,
|
||||
String assetType,
|
||||
String paymentId,
|
||||
String amount,
|
||||
int priorityRaw,
|
||||
{required String address,
|
||||
required String assetType,
|
||||
required String paymentId,
|
||||
required int priorityRaw,
|
||||
String? amount,
|
||||
int accountIndex = 0}) {
|
||||
final addressPointer = Utf8.toUtf8(address);
|
||||
final assetTypePointer = Utf8.toUtf8(assetType);
|
||||
final paymentIdPointer = Utf8.toUtf8(paymentId);
|
||||
final amountPointer = amount != null ? Utf8.toUtf8(amount) : nullptr;
|
||||
final errorMessagePointer = allocate<Utf8Box>();
|
||||
final pendingTransactionRawPointer = allocate<PendingTransactionRaw>();
|
||||
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,
|
||||
@@ -90,17 +90,17 @@ PendingTransactionDescription createTransactionSync(
|
||||
pendingTransactionRawPointer) !=
|
||||
0;
|
||||
|
||||
free(addressPointer);
|
||||
free(assetTypePointer);
|
||||
free(paymentIdPointer);
|
||||
calloc.free(addressPointer);
|
||||
calloc.free(assetTypePointer);
|
||||
calloc.free(paymentIdPointer);
|
||||
|
||||
if (amountPointer != nullptr) {
|
||||
free(amountPointer);
|
||||
calloc.free(amountPointer);
|
||||
}
|
||||
|
||||
if (!created) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
free(errorMessagePointer);
|
||||
calloc.free(errorMessagePointer);
|
||||
throw CreationTransactionException(message: message);
|
||||
}
|
||||
|
||||
@@ -112,28 +112,28 @@ PendingTransactionDescription createTransactionSync(
|
||||
}
|
||||
|
||||
PendingTransactionDescription createTransactionMultDestSync(
|
||||
{List<MoneroOutput> outputs,
|
||||
String assetType,
|
||||
String paymentId,
|
||||
int priorityRaw,
|
||||
{required List<MoneroOutput> outputs,
|
||||
required String assetType,
|
||||
required String paymentId,
|
||||
required int priorityRaw,
|
||||
int accountIndex = 0}) {
|
||||
final int size = outputs.length;
|
||||
final List<Pointer<Utf8>> addressesPointers = outputs.map((output) =>
|
||||
Utf8.toUtf8(output.address)).toList();
|
||||
final Pointer<Pointer<Utf8>> addressesPointerPointer = allocate(count: size);
|
||||
output.address.toNativeUtf8()).toList();
|
||||
final Pointer<Pointer<Utf8>> addressesPointerPointer = calloc(size);
|
||||
final List<Pointer<Utf8>> amountsPointers = outputs.map((output) =>
|
||||
Utf8.toUtf8(output.amount)).toList();
|
||||
final Pointer<Pointer<Utf8>> amountsPointerPointer = allocate(count: size);
|
||||
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 = Utf8.toUtf8(assetType);
|
||||
final paymentIdPointer = Utf8.toUtf8(paymentId);
|
||||
final errorMessagePointer = allocate<Utf8Box>();
|
||||
final pendingTransactionRawPointer = allocate<PendingTransactionRaw>();
|
||||
final assetTypePointer = assetType.toNativeUtf8();
|
||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
||||
final created = transactionCreateMultDestNative(
|
||||
addressesPointerPointer,
|
||||
assetTypePointer,
|
||||
@@ -146,18 +146,18 @@ PendingTransactionDescription createTransactionMultDestSync(
|
||||
pendingTransactionRawPointer) !=
|
||||
0;
|
||||
|
||||
free(addressesPointerPointer);
|
||||
free(assetTypePointer);
|
||||
free(amountsPointerPointer);
|
||||
calloc.free(addressesPointerPointer);
|
||||
calloc.free(assetTypePointer);
|
||||
calloc.free(amountsPointerPointer);
|
||||
|
||||
addressesPointers.forEach((element) => free(element));
|
||||
amountsPointers.forEach((element) => free(element));
|
||||
addressesPointers.forEach((element) => calloc.free(element));
|
||||
amountsPointers.forEach((element) => calloc.free(element));
|
||||
|
||||
free(paymentIdPointer);
|
||||
calloc.free(paymentIdPointer);
|
||||
|
||||
if (!created) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
free(errorMessagePointer);
|
||||
calloc.free(errorMessagePointer);
|
||||
throw CreationTransactionException(message: message);
|
||||
}
|
||||
|
||||
@@ -168,17 +168,17 @@ PendingTransactionDescription createTransactionMultDestSync(
|
||||
pointerAddress: pendingTransactionRawPointer.address);
|
||||
}
|
||||
|
||||
void commitTransactionFromPointerAddress({int address}) => commitTransaction(
|
||||
void commitTransactionFromPointerAddress({required int address}) => commitTransaction(
|
||||
transactionPointer: Pointer<PendingTransactionRaw>.fromAddress(address));
|
||||
|
||||
void commitTransaction({Pointer<PendingTransactionRaw> transactionPointer}) {
|
||||
final errorMessagePointer = allocate<Utf8Box>();
|
||||
void commitTransaction({required Pointer<PendingTransactionRaw> transactionPointer}) {
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final isCommited =
|
||||
transactionCommitNative(transactionPointer, errorMessagePointer) != 0;
|
||||
|
||||
if (!isCommited) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
free(errorMessagePointer);
|
||||
calloc.free(errorMessagePointer);
|
||||
throw CreationTransactionException(message: message);
|
||||
}
|
||||
}
|
||||
@@ -216,11 +216,11 @@ PendingTransactionDescription _createTransactionMultDestSync(Map args) {
|
||||
}
|
||||
|
||||
Future<PendingTransactionDescription> createTransaction(
|
||||
{String address,
|
||||
String assetType,
|
||||
{required String address,
|
||||
required String assetType,
|
||||
required int priorityRaw,
|
||||
String? amount,
|
||||
String paymentId = '',
|
||||
String amount,
|
||||
int priorityRaw,
|
||||
int accountIndex = 0}) =>
|
||||
compute(_createTransactionSync, {
|
||||
'address': address,
|
||||
@@ -232,10 +232,10 @@ Future<PendingTransactionDescription> createTransaction(
|
||||
});
|
||||
|
||||
Future<PendingTransactionDescription> createTransactionMultDest(
|
||||
{List<MoneroOutput> outputs,
|
||||
String assetType,
|
||||
{required List<MoneroOutput> outputs,
|
||||
required int priorityRaw,
|
||||
String? assetType,
|
||||
String paymentId = '',
|
||||
int priorityRaw,
|
||||
int accountIndex = 0}) =>
|
||||
compute(_createTransactionMultDestSync, {
|
||||
'outputs': outputs,
|
||||
|
||||
@@ -39,7 +39,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>, Pointer<Utf8>?, Pointer<Utf8>?, int, int, Pointer<Utf8>);
|
||||
|
||||
typedef StartRefresh = void Function();
|
||||
|
||||
@@ -84,7 +84,7 @@ typedef AccountSetLabel = void Function(int accountIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef TransactionsRefresh = void Function();
|
||||
|
||||
typedef GetTxKey = Pointer<Utf8> Function(Pointer<Utf8> txId);
|
||||
typedef GetTxKey = Pointer<Utf8>? Function(Pointer<Utf8> txId);
|
||||
|
||||
typedef TransactionsCount = int Function();
|
||||
|
||||
|
||||
@@ -142,24 +142,24 @@ int getNodeHeightSync() => getNodeHeightNative();
|
||||
bool isConnectedSync() => isConnectedNative() != 0;
|
||||
|
||||
bool setupNodeSync(
|
||||
{String address,
|
||||
String login,
|
||||
String password,
|
||||
{required String address,
|
||||
String? login,
|
||||
String? password,
|
||||
bool useSSL = false,
|
||||
bool isLightWallet = false}) {
|
||||
final addressPointer = Utf8.toUtf8(address);
|
||||
Pointer<Utf8> loginPointer;
|
||||
Pointer<Utf8> passwordPointer;
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
Pointer<Utf8>? loginPointer;
|
||||
Pointer<Utf8>? passwordPointer;
|
||||
|
||||
if (login != null) {
|
||||
loginPointer = Utf8.toUtf8(login);
|
||||
loginPointer = login.toNativeUtf8();
|
||||
}
|
||||
|
||||
if (password != null) {
|
||||
passwordPointer = Utf8.toUtf8(password);
|
||||
passwordPointer = password.toNativeUtf8();
|
||||
}
|
||||
|
||||
final errorMessagePointer = allocate<Utf8>();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isSetupNode = setupNodeNative(
|
||||
addressPointer,
|
||||
loginPointer,
|
||||
@@ -169,9 +169,15 @@ bool setupNodeSync(
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
free(addressPointer);
|
||||
free(loginPointer);
|
||||
free(passwordPointer);
|
||||
calloc.free(addressPointer);
|
||||
|
||||
if (loginPointer != null) {
|
||||
calloc.free(loginPointer);
|
||||
}
|
||||
|
||||
if (passwordPointer != null) {
|
||||
calloc.free(passwordPointer);
|
||||
}
|
||||
|
||||
if (!isSetupNode) {
|
||||
throw SetupWalletException(
|
||||
@@ -185,31 +191,31 @@ void startRefreshSync() => startRefreshNative();
|
||||
|
||||
Future<bool> connectToNode() async => connecToNodeNative() != 0;
|
||||
|
||||
void setRefreshFromBlockHeight({int height}) =>
|
||||
void setRefreshFromBlockHeight({required int height}) =>
|
||||
setRefreshFromBlockHeightNative(height);
|
||||
|
||||
void setRecoveringFromSeed({bool isRecovery}) =>
|
||||
void setRecoveringFromSeed({required bool isRecovery}) =>
|
||||
setRecoveringFromSeedNative(_boolToInt(isRecovery));
|
||||
|
||||
void storeSync() {
|
||||
final pathPointer = Utf8.toUtf8('');
|
||||
final pathPointer = ''.toNativeUtf8();
|
||||
storeNative(pathPointer);
|
||||
free(pathPointer);
|
||||
calloc.free(pathPointer);
|
||||
}
|
||||
|
||||
void setPasswordSync(String password) {
|
||||
final passwordPointer = Utf8.toUtf8(password);
|
||||
final errorMessagePointer = allocate<Utf8Box>();
|
||||
final passwordPointer = password.toNativeUtf8();
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final changed = setPasswordNative(passwordPointer, errorMessagePointer) != 0;
|
||||
free(passwordPointer);
|
||||
calloc.free(passwordPointer);
|
||||
|
||||
if (!changed) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
free(errorMessagePointer);
|
||||
calloc.free(errorMessagePointer);
|
||||
throw Exception(message);
|
||||
}
|
||||
|
||||
free(errorMessagePointer);
|
||||
calloc.free(errorMessagePointer);
|
||||
}
|
||||
|
||||
void closeCurrentWallet() => closeCurrentWalletNative();
|
||||
@@ -227,16 +233,15 @@ String getPublicSpendKey() =>
|
||||
convertUTF8ToString(pointer: getPublicSpendKeyNative());
|
||||
|
||||
class SyncListener {
|
||||
SyncListener(this.onNewBlock, this.onNewTransaction) {
|
||||
_cachedBlockchainHeight = 0;
|
||||
_lastKnownBlockHeight = 0;
|
||||
_initialSyncHeight = 0;
|
||||
}
|
||||
SyncListener(this.onNewBlock, this.onNewTransaction)
|
||||
: _cachedBlockchainHeight = 0,
|
||||
_lastKnownBlockHeight = 0,
|
||||
_initialSyncHeight = 0;
|
||||
|
||||
void Function(int, int, double) onNewBlock;
|
||||
void Function() onNewTransaction;
|
||||
|
||||
Timer _updateSyncInfoTimer;
|
||||
Timer? _updateSyncInfoTimer;
|
||||
int _cachedBlockchainHeight;
|
||||
int _lastKnownBlockHeight;
|
||||
int _initialSyncHeight;
|
||||
@@ -325,13 +330,13 @@ int _getNodeHeight(Object _) => getNodeHeightSync();
|
||||
|
||||
void startRefresh() => startRefreshSync();
|
||||
|
||||
Future setupNode(
|
||||
{String address,
|
||||
String login,
|
||||
String password,
|
||||
Future<void> setupNode(
|
||||
{required String address,
|
||||
String? login,
|
||||
String? password,
|
||||
bool useSSL = false,
|
||||
bool isLightWallet = false}) =>
|
||||
compute<Map<String, Object>, void>(_setupNodeSync, {
|
||||
compute<Map<String, Object?>, void>(_setupNodeSync, {
|
||||
'address': address,
|
||||
'login': login,
|
||||
'password': password,
|
||||
@@ -339,7 +344,7 @@ Future setupNode(
|
||||
'isLightWallet': isLightWallet
|
||||
});
|
||||
|
||||
Future store() => compute<int, void>(_storeSync, 0);
|
||||
Future<void> store() => compute<int, void>(_storeSync, 0);
|
||||
|
||||
Future<bool> isConnected() => compute(_isConnected, 0);
|
||||
|
||||
|
||||
@@ -38,18 +38,18 @@ final errorStringNative = havenApi
|
||||
.asFunction<ErrorString>();
|
||||
|
||||
void createWalletSync(
|
||||
{String path, String password, String language, int nettype = 0}) {
|
||||
final pathPointer = Utf8.toUtf8(path);
|
||||
final passwordPointer = Utf8.toUtf8(password);
|
||||
final languagePointer = Utf8.toUtf8(language);
|
||||
final errorMessagePointer = allocate<Utf8>();
|
||||
{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();
|
||||
final isWalletCreated = createWalletNative(pathPointer, passwordPointer,
|
||||
languagePointer, nettype, errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
free(pathPointer);
|
||||
free(passwordPointer);
|
||||
free(languagePointer);
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(languagePointer);
|
||||
|
||||
if (!isWalletCreated) {
|
||||
throw WalletCreationException(
|
||||
@@ -59,25 +59,25 @@ void createWalletSync(
|
||||
// setupNodeSync(address: "node.moneroworld.com:18089");
|
||||
}
|
||||
|
||||
bool isWalletExistSync({String path}) {
|
||||
final pathPointer = Utf8.toUtf8(path);
|
||||
bool isWalletExistSync({required String path}) {
|
||||
final pathPointer = path.toNativeUtf8();
|
||||
final isExist = isWalletExistNative(pathPointer) != 0;
|
||||
|
||||
free(pathPointer);
|
||||
calloc.free(pathPointer);
|
||||
|
||||
return isExist;
|
||||
}
|
||||
|
||||
void restoreWalletFromSeedSync(
|
||||
{String path,
|
||||
String password,
|
||||
String seed,
|
||||
{required String path,
|
||||
required String password,
|
||||
required String seed,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) {
|
||||
final pathPointer = Utf8.toUtf8(path);
|
||||
final passwordPointer = Utf8.toUtf8(password);
|
||||
final seedPointer = Utf8.toUtf8(seed);
|
||||
final errorMessagePointer = allocate<Utf8>();
|
||||
final pathPointer = path.toNativeUtf8();
|
||||
final passwordPointer = password.toNativeUtf8();
|
||||
final seedPointer = seed.toNativeUtf8();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isWalletRestored = restoreWalletFromSeedNative(
|
||||
pathPointer,
|
||||
passwordPointer,
|
||||
@@ -87,9 +87,9 @@ void restoreWalletFromSeedSync(
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
free(pathPointer);
|
||||
free(passwordPointer);
|
||||
free(seedPointer);
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(seedPointer);
|
||||
|
||||
if (!isWalletRestored) {
|
||||
throw WalletRestoreFromSeedException(
|
||||
@@ -98,21 +98,21 @@ void restoreWalletFromSeedSync(
|
||||
}
|
||||
|
||||
void restoreWalletFromKeysSync(
|
||||
{String path,
|
||||
String password,
|
||||
String language,
|
||||
String address,
|
||||
String viewKey,
|
||||
String spendKey,
|
||||
{required String path,
|
||||
required String password,
|
||||
required String language,
|
||||
required String address,
|
||||
required String viewKey,
|
||||
required String spendKey,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) {
|
||||
final pathPointer = Utf8.toUtf8(path);
|
||||
final passwordPointer = Utf8.toUtf8(password);
|
||||
final languagePointer = Utf8.toUtf8(language);
|
||||
final addressPointer = Utf8.toUtf8(address);
|
||||
final viewKeyPointer = Utf8.toUtf8(viewKey);
|
||||
final spendKeyPointer = Utf8.toUtf8(spendKey);
|
||||
final errorMessagePointer = allocate<Utf8>();
|
||||
final pathPointer = path.toNativeUtf8();
|
||||
final passwordPointer = password.toNativeUtf8();
|
||||
final languagePointer = language.toNativeUtf8();
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
final viewKeyPointer = viewKey.toNativeUtf8();
|
||||
final spendKeyPointer = spendKey.toNativeUtf8();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isWalletRestored = restoreWalletFromKeysNative(
|
||||
pathPointer,
|
||||
passwordPointer,
|
||||
@@ -125,12 +125,12 @@ void restoreWalletFromKeysSync(
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
free(pathPointer);
|
||||
free(passwordPointer);
|
||||
free(languagePointer);
|
||||
free(addressPointer);
|
||||
free(viewKeyPointer);
|
||||
free(spendKeyPointer);
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(languagePointer);
|
||||
calloc.free(addressPointer);
|
||||
calloc.free(viewKeyPointer);
|
||||
calloc.free(spendKeyPointer);
|
||||
|
||||
if (!isWalletRestored) {
|
||||
throw WalletRestoreFromKeysException(
|
||||
@@ -138,12 +138,12 @@ void restoreWalletFromKeysSync(
|
||||
}
|
||||
}
|
||||
|
||||
void loadWallet({String path, String password, int nettype = 0}) {
|
||||
final pathPointer = Utf8.toUtf8(path);
|
||||
final passwordPointer = Utf8.toUtf8(password);
|
||||
void loadWallet({required String path, required String password, int nettype = 0}) {
|
||||
final pathPointer = path.toNativeUtf8();
|
||||
final passwordPointer = password.toNativeUtf8();
|
||||
final loaded = loadWalletNative(pathPointer, passwordPointer, nettype) != 0;
|
||||
free(pathPointer);
|
||||
free(passwordPointer);
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
|
||||
if (!loaded) {
|
||||
throw WalletOpeningException(
|
||||
@@ -189,20 +189,20 @@ void _restoreFromKeys(Map<String, dynamic> args) {
|
||||
}
|
||||
|
||||
Future<void> _openWallet(Map<String, String> args) async =>
|
||||
loadWallet(path: args['path'], password: args['password']);
|
||||
loadWallet(path: args['path'] as String, password: args['password'] as String);
|
||||
|
||||
bool _isWalletExist(String path) => isWalletExistSync(path: path);
|
||||
|
||||
void openWallet({String path, String password, int nettype = 0}) async =>
|
||||
void openWallet({required String path, required String password, int nettype = 0}) async =>
|
||||
loadWallet(path: path, password: password, nettype: nettype);
|
||||
|
||||
Future<void> openWalletAsync(Map<String, String> args) async =>
|
||||
compute(_openWallet, args);
|
||||
|
||||
Future<void> createWallet(
|
||||
{String path,
|
||||
String password,
|
||||
String language,
|
||||
{required String path,
|
||||
required String password,
|
||||
required String language,
|
||||
int nettype = 0}) async =>
|
||||
compute(_createWallet, {
|
||||
'path': path,
|
||||
@@ -211,10 +211,10 @@ Future<void> createWallet(
|
||||
'nettype': nettype
|
||||
});
|
||||
|
||||
Future restoreFromSeed(
|
||||
{String path,
|
||||
String password,
|
||||
String seed,
|
||||
Future<void> restoreFromSeed(
|
||||
{required String path,
|
||||
required String password,
|
||||
required String seed,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) async =>
|
||||
compute<Map<String, Object>, void>(_restoreFromSeed, {
|
||||
@@ -225,13 +225,13 @@ Future restoreFromSeed(
|
||||
'restoreHeight': restoreHeight
|
||||
});
|
||||
|
||||
Future restoreFromKeys(
|
||||
{String path,
|
||||
String password,
|
||||
String language,
|
||||
String address,
|
||||
String viewKey,
|
||||
String spendKey,
|
||||
Future<void> restoreFromKeys(
|
||||
{required String path,
|
||||
required String password,
|
||||
required String language,
|
||||
required String address,
|
||||
required String viewKey,
|
||||
required String spendKey,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) async =>
|
||||
compute<Map<String, Object>, void>(_restoreFromKeys, {
|
||||
@@ -245,4 +245,4 @@ Future restoreFromKeys(
|
||||
'restoreHeight': restoreHeight
|
||||
});
|
||||
|
||||
Future<bool> isWalletExist({String path}) => compute(_isWalletExist, path);
|
||||
Future<bool> isWalletExist({required String path}) => compute(_isWalletExist, path);
|
||||
|
||||
Reference in New Issue
Block a user