mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-12 05:44:56 +00:00
multiple wallets
new lib minor fixes
This commit is contained in:
parent
176150cc55
commit
dcf6140444
12 changed files with 97 additions and 231 deletions
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
|||
# TODO(mrcyjanek): Cleanup, this is borrowed from unnamed_monero_wallet repo.
|
||||
|
||||
MONERO_C_TAG=v0.18.3.3-RC21
|
||||
MONERO_C_TAG=v0.18.3.3-RC27
|
||||
LIBCPP_SHARED_SO_TAG=latest-RC1
|
||||
LIBCPP_SHARED_SO_NDKVERSION=r17c
|
||||
|
||||
|
|
|
@ -245,8 +245,8 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "08c5a32cbcf1f04dbae5826c83abda8fb0dbdcce"
|
||||
ref: ada81417cb53d8b0e34022df1dd3d9dc1fe62ab5
|
||||
resolved-ref: ada81417cb53d8b0e34022df1dd3d9dc1fe62ab5
|
||||
url: "https://git.mrcyjanek.net/mrcyjanek/monero.dart"
|
||||
source: git
|
||||
version: "0.0.0"
|
||||
|
|
|
@ -2,6 +2,18 @@ import 'package:cw_monero/api/wallet.dart';
|
|||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
monero.wallet? wptr = null;
|
||||
|
||||
int _wlptrForW = 0;
|
||||
monero.WalletListener? _wlptr = null;
|
||||
|
||||
monero.WalletListener getWlptr() {
|
||||
if (wptr!.address == _wlptrForW) return _wlptr!;
|
||||
_wlptrForW = wptr!.address;
|
||||
_wlptr = monero.MONERO_cw_getWalletListener(wptr!);
|
||||
return _wlptr!;
|
||||
}
|
||||
|
||||
|
||||
monero.SubaddressAccount? subaddressAccount;
|
||||
|
||||
bool isUpdating = false;
|
||||
|
|
|
@ -1,25 +1,3 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
class PendingTransactionRaw extends Struct {
|
||||
@Int64()
|
||||
external int amount;
|
||||
|
||||
@Int64()
|
||||
external int fee;
|
||||
|
||||
external Pointer<Utf8> hash;
|
||||
|
||||
external Pointer<Utf8> hex;
|
||||
|
||||
external Pointer<Utf8> txKey;
|
||||
|
||||
String getHash() => hash.toDartString();
|
||||
|
||||
String getHex() => hex.toDartString();
|
||||
|
||||
String getKey() => txKey.toDartString();
|
||||
}
|
||||
|
||||
class PendingTransactionDescription {
|
||||
PendingTransactionDescription({
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:cw_monero/api/wallet.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
bool isUpdating = false;
|
||||
monero.Subaddress? subaddressPtr = null;
|
||||
|
||||
class SubaddressInfoMetadata {
|
||||
SubaddressInfoMetadata({
|
||||
required this.accountIndex,
|
||||
});
|
||||
int accountIndex;
|
||||
}
|
||||
|
||||
SubaddressInfoMetadata? subaddress = null;
|
||||
|
||||
void refreshSubaddresses({required int accountIndex}) {
|
||||
try {
|
||||
isUpdating = true;
|
||||
subaddressPtr = monero.Wallet_subaddress(wptr!);
|
||||
monero.Subaddress_refresh(subaddressPtr!,accountIndex: accountIndex, label: '');
|
||||
subaddress = SubaddressInfoMetadata(accountIndex: accountIndex);
|
||||
isUpdating = false;
|
||||
} catch (e) {
|
||||
isUpdating = false;
|
||||
|
@ -16,17 +25,29 @@ void refreshSubaddresses({required int accountIndex}) {
|
|||
}
|
||||
}
|
||||
|
||||
List<monero.SubaddressRow> getAllSubaddresses() {
|
||||
monero.Subaddress_refresh(subaddressPtr!,
|
||||
accountIndex: 0,
|
||||
label: '' // BUG: by me (mrcyjanek), it isn't used, will remove.
|
||||
);
|
||||
final size = monero.Subaddress_getAll_size(subaddressPtr!);
|
||||
|
||||
|
||||
return List.generate(size, (index) {
|
||||
return monero.Subaddress_getAll_byIndex(subaddressAccount!, index: index);
|
||||
class Subaddress {
|
||||
Subaddress({
|
||||
required this.addressIndex,
|
||||
required this.accountIndex,
|
||||
});
|
||||
String get address => monero.Wallet_address(
|
||||
wptr!,
|
||||
accountIndex: accountIndex,
|
||||
addressIndex: addressIndex,
|
||||
);
|
||||
final int addressIndex;
|
||||
final int accountIndex;
|
||||
String get label => monero.Wallet_getSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: addressIndex);
|
||||
}
|
||||
|
||||
List<Subaddress> getAllSubaddresses() {
|
||||
final size = monero.Wallet_numSubaddresses(wptr!, accountIndex: subaddress!.accountIndex);
|
||||
return List.generate(size, (index) {
|
||||
return Subaddress(
|
||||
accountIndex: subaddress!.accountIndex,
|
||||
addressIndex: index,
|
||||
);
|
||||
}).reversed.toList();
|
||||
}
|
||||
|
||||
void addSubaddressSync({required int accountIndex, required String label}) {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart';
|
||||
import 'package:cw_monero/api/monero_output.dart';
|
||||
import 'package:cw_monero/api/structs/pending_transaction.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
|
||||
|
@ -39,16 +37,6 @@ PendingTransactionDescription createTransactionSync(
|
|||
String? amount,
|
||||
int accountIndex = 0,
|
||||
List<String> preferredInputs = const []}) {
|
||||
final amountPointer = amount != null ? amount.toNativeUtf8() : nullptr;
|
||||
|
||||
final int preferredInputsSize = preferredInputs.length;
|
||||
final List<Pointer<Utf8>> preferredInputsPointers =
|
||||
preferredInputs.map((output) => output.toNativeUtf8()).toList();
|
||||
final Pointer<Pointer<Utf8>> preferredInputsPointerPointer = calloc(preferredInputsSize);
|
||||
|
||||
for (int i = 0; i < preferredInputsSize; i++) {
|
||||
preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
||||
}
|
||||
|
||||
final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount);
|
||||
final pendingTx = monero.Wallet_createTransaction(
|
||||
|
@ -74,12 +62,17 @@ PendingTransactionDescription createTransactionSync(
|
|||
throw CreationTransactionException(message: message);
|
||||
}
|
||||
|
||||
final rAmt = monero.PendingTransaction_amount(pendingTx);
|
||||
final rFee = monero.PendingTransaction_fee(pendingTx);
|
||||
final rHash = monero.PendingTransaction_txid(pendingTx, '');
|
||||
final rTxKey = rHash;
|
||||
|
||||
return PendingTransactionDescription(
|
||||
amount: monero.PendingTransaction_amount(wptr!),
|
||||
fee: monero.PendingTransaction_fee(wptr!),
|
||||
hash: monero.PendingTransaction_txid(wptr!, ''),
|
||||
amount: rAmt,
|
||||
fee: rFee,
|
||||
hash: rHash,
|
||||
hex: '',
|
||||
txKey: monero.PendingTransaction_txid(wptr!, ''),
|
||||
txKey: rTxKey,
|
||||
pointerAddress: pendingTx.address,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:cw_monero/api/structs/coins_info_row.dart';
|
||||
import 'package:cw_monero/api/structs/pending_transaction.dart';
|
||||
import 'package:cw_monero/api/structs/transaction_info_row.dart';
|
||||
import 'package:cw_monero/api/structs/ut8_box.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
typedef CreateWallet = int Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>);
|
||||
|
||||
typedef RestoreWalletFromSeed = int Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Utf8>);
|
||||
|
||||
typedef RestoreWalletFromKeys = int Function(Pointer<Utf8>, Pointer<Utf8>,
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Utf8>);
|
||||
|
||||
typedef RestoreWalletFromSpendKey = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>,
|
||||
Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Utf8>);
|
||||
|
||||
typedef IsWalletExist = int Function(Pointer<Utf8>);
|
||||
|
||||
typedef LoadWallet = int Function(Pointer<Utf8>, Pointer<Utf8>, int);
|
||||
|
||||
typedef ErrorString = Pointer<Utf8> Function();
|
||||
|
||||
typedef GetFilename = Pointer<Utf8> Function();
|
||||
|
||||
typedef GetSeed = Pointer<Utf8> Function();
|
||||
|
||||
typedef GetAddress = Pointer<Utf8> Function(int, int);
|
||||
|
||||
typedef GetFullBalance = int Function(int);
|
||||
|
||||
typedef GetUnlockedBalance = int Function(int);
|
||||
|
||||
typedef GetCurrentHeight = int Function();
|
||||
|
||||
typedef GetNodeHeight = int Function();
|
||||
|
||||
typedef IsConnected = int Function();
|
||||
|
||||
typedef SetupNode = int Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>?, Pointer<Utf8>?, int, int, Pointer<Utf8>?, Pointer<Utf8>);
|
||||
|
||||
typedef StartRefresh = void Function();
|
||||
|
||||
typedef ConnectToNode = int Function();
|
||||
|
||||
typedef SetRefreshFromBlockHeight = void Function(int);
|
||||
|
||||
typedef SetRecoveringFromSeed = void Function(int);
|
||||
|
||||
typedef Store = void Function(Pointer<Utf8>);
|
||||
|
||||
typedef SetPassword = int Function(Pointer<Utf8> password, Pointer<Utf8Box> error);
|
||||
|
||||
typedef SetListener = void Function();
|
||||
|
||||
typedef GetSyncingHeight = int Function();
|
||||
|
||||
typedef IsNeededToRefresh = int Function();
|
||||
|
||||
typedef IsNewTransactionExist = int Function();
|
||||
|
||||
typedef SubaddressSize = int Function();
|
||||
|
||||
typedef SubaddressRefresh = void Function(int);
|
||||
|
||||
typedef SubaddressGetAll = Pointer<Int64> Function();
|
||||
|
||||
typedef SubaddressAddNew = void Function(int accountIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef SubaddressSetLabel = void Function(
|
||||
int accountIndex, int addressIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef AccountSize = int Function();
|
||||
|
||||
typedef AccountRefresh = void Function();
|
||||
|
||||
typedef AccountGetAll = Pointer<Int64> Function();
|
||||
|
||||
typedef AccountAddNew = void Function(Pointer<Utf8> label);
|
||||
|
||||
typedef AccountSetLabel = void Function(int accountIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef TransactionsRefresh = void Function();
|
||||
|
||||
typedef GetTransaction = Pointer<TransactionInfoRow> Function(Pointer<Utf8> txId);
|
||||
|
||||
typedef GetTxKey = Pointer<Utf8>? Function(Pointer<Utf8> txId);
|
||||
|
||||
typedef TransactionsCount = int Function();
|
||||
|
||||
typedef TransactionsGetAll = Pointer<Int64> Function();
|
||||
|
||||
typedef TransactionCreate = int Function(
|
||||
Pointer<Utf8> address,
|
||||
Pointer<Utf8> paymentId,
|
||||
Pointer<Utf8> amount,
|
||||
int priorityRaw,
|
||||
int subaddrAccount,
|
||||
Pointer<Pointer<Utf8>> preferredInputs,
|
||||
int preferredInputsSize,
|
||||
Pointer<Utf8Box> error,
|
||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||
|
||||
typedef TransactionCreateMultDest = int Function(
|
||||
Pointer<Pointer<Utf8>> addresses,
|
||||
Pointer<Utf8> paymentId,
|
||||
Pointer<Pointer<Utf8>> amounts,
|
||||
int size,
|
||||
int priorityRaw,
|
||||
int subaddrAccount,
|
||||
Pointer<Pointer<Utf8>> preferredInputs,
|
||||
int preferredInputsSize,
|
||||
Pointer<Utf8Box> error,
|
||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||
|
||||
typedef TransactionCommit = int Function(Pointer<PendingTransactionRaw>, Pointer<Utf8Box>);
|
||||
|
||||
typedef SecretViewKey = Pointer<Utf8> Function();
|
||||
|
||||
typedef PublicViewKey = Pointer<Utf8> Function();
|
||||
|
||||
typedef SecretSpendKey = Pointer<Utf8> Function();
|
||||
|
||||
typedef PublicSpendKey = Pointer<Utf8> Function();
|
||||
|
||||
typedef CloseCurrentWallet = void Function();
|
||||
|
||||
typedef OnStartup = void Function();
|
||||
|
||||
typedef RescanBlockchainAsync = void Function();
|
||||
|
||||
typedef GetSubaddressLabel = Pointer<Utf8> Function(
|
||||
int accountIndex,
|
||||
int addressIndex);
|
||||
|
||||
typedef SetTrustedDaemon = void Function(int);
|
||||
|
||||
typedef TrustedDaemon = int Function();
|
||||
|
||||
typedef RefreshCoins = void Function(int);
|
||||
|
||||
typedef CoinsCount = int Function();
|
||||
|
||||
typedef GetCoin = Pointer<CoinsInfoRow> Function(int);
|
||||
|
||||
typedef FreezeCoin = void Function(int);
|
||||
|
||||
typedef ThawCoin = void Function(int);
|
||||
|
||||
typedef SignMessage = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>);
|
|
@ -6,12 +6,19 @@ import 'package:monero/monero.dart' as monero;
|
|||
|
||||
int _boolToInt(bool value) => value ? 1 : 0;
|
||||
|
||||
int getSyncingHeight() => monero.Wallet_blockChainHeight(wptr!);
|
||||
int getSyncingHeight() => monero.MONERO_cw_WalletListener_height(getWlptr());
|
||||
|
||||
bool isNeededToRefresh() => false; // TODO(mrcyjanek): ?
|
||||
|
||||
bool isNewTransactionExist() => false;
|
||||
bool isNeededToRefresh() {
|
||||
final ret = monero.MONERO_cw_WalletListener_isNeedToRefresh(getWlptr());
|
||||
monero.MONERO_cw_WalletListener_resetNeedToRefresh(getWlptr());
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool isNewTransactionExist() {
|
||||
final ret = monero.MONERO_cw_WalletListener_isNewTransactionExist(getWlptr());
|
||||
monero.MONERO_cw_WalletListener_resetIsNewTransactionExist(getWlptr());
|
||||
return ret;
|
||||
}
|
||||
String getFilename() => monero.Wallet_filename(wptr!);
|
||||
|
||||
// TODO(mrcyjanek): Cake polyseed support
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:cw_monero/api/exceptions/wallet_creation_exception.dart';
|
||||
import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart';
|
||||
|
@ -7,7 +9,6 @@ import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_exception.dart
|
|||
import 'package:cw_monero/api/wallet.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
import 'dart:ffi';
|
||||
|
||||
monero.WalletManager? _wmPtr;
|
||||
final monero.WalletManager wmPtr = Pointer.fromAddress((() {
|
||||
|
@ -135,12 +136,20 @@ void restoreWalletFromSpendKeySync(
|
|||
storeSync();
|
||||
}
|
||||
|
||||
String _lastOpenedWallet = "";
|
||||
|
||||
void loadWallet({
|
||||
required String path,
|
||||
required String password,
|
||||
int nettype = 0}) {
|
||||
try {
|
||||
wptr ??= monero.WalletManager_openWallet(wmPtr, path: path, password: password);
|
||||
if (wptr == null || path != _lastOpenedWallet) {
|
||||
if (wptr != null) {
|
||||
monero.Wallet_store(wptr!);
|
||||
}
|
||||
wptr = monero.WalletManager_openWallet(wmPtr, path: path, password: password);
|
||||
_lastOpenedWallet = path;
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/subaddress.dart';
|
||||
import 'package:cw_monero/api/coins_info.dart';
|
||||
import 'package:cw_monero/api/subaddress_list.dart' as subaddress_list;
|
||||
import 'package:cw_core/subaddress.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'monero_subaddress_list.g.dart';
|
||||
|
||||
|
@ -51,10 +50,10 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
subaddresses = [primary] + rest.toList();
|
||||
}
|
||||
|
||||
return subaddresses.map((subaddressRow) {
|
||||
final label = monero.SubaddressRow_getLabel(subaddressRow);
|
||||
final id = monero.SubaddressRow_getRowId(subaddressRow);
|
||||
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||
return subaddresses.map((s) {
|
||||
final address = s.address;
|
||||
final label = s.label;
|
||||
final id = s.addressIndex;
|
||||
final hasDefaultAddressName =
|
||||
label.toLowerCase() == 'Primary account'.toLowerCase() ||
|
||||
label.toLowerCase() == 'Untitled account'.toLowerCase();
|
||||
|
@ -125,7 +124,7 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
Future<List<Subaddress>> _getAllUnusedAddresses(
|
||||
{required int accountIndex, required String label}) async {
|
||||
final allAddresses = subaddress_list.getAllSubaddresses();
|
||||
final lastAddress = monero.SubaddressRow_getAddress(allAddresses.last);
|
||||
final lastAddress = allAddresses.last.address;
|
||||
if (allAddresses.isEmpty || _usedAddresses.contains(lastAddress)) {
|
||||
final isAddressUnused = await _newSubaddress(accountIndex: accountIndex, label: label);
|
||||
if (!isAddressUnused) {
|
||||
|
@ -134,10 +133,10 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
}
|
||||
|
||||
return allAddresses
|
||||
.map((subaddressRow) {
|
||||
final id = monero.SubaddressRow_getRowId(subaddressRow);
|
||||
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||
final label = monero.SubaddressRow_getLabel(subaddressRow);
|
||||
.map((s) {
|
||||
final id = s.addressIndex;
|
||||
final address = s.address;
|
||||
final label = s.label;
|
||||
return Subaddress(
|
||||
id: id,
|
||||
address: address,
|
||||
|
@ -154,8 +153,8 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
|
||||
return subaddress_list
|
||||
.getAllSubaddresses()
|
||||
.where((subaddressRow) {
|
||||
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||
.where((s) {
|
||||
final address = s.address;
|
||||
return !_usedAddresses.contains(address);
|
||||
})
|
||||
.isNotEmpty;
|
||||
|
|
|
@ -414,8 +414,8 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "08c5a32cbcf1f04dbae5826c83abda8fb0dbdcce"
|
||||
ref: ada81417cb53d8b0e34022df1dd3d9dc1fe62ab5
|
||||
resolved-ref: ada81417cb53d8b0e34022df1dd3d9dc1fe62ab5
|
||||
url: "https://git.mrcyjanek.net/mrcyjanek/monero.dart"
|
||||
source: git
|
||||
version: "0.0.0"
|
||||
|
|
|
@ -25,7 +25,7 @@ dependencies:
|
|||
monero:
|
||||
git:
|
||||
url: https://git.mrcyjanek.net/mrcyjanek/monero.dart
|
||||
ref: master
|
||||
ref: ada81417cb53d8b0e34022df1dd3d9dc1fe62ab5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue