mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
initial monero.dart implementation
This commit is contained in:
parent
5f78769338
commit
7bc6967fc9
23 changed files with 573 additions and 839 deletions
120
Makefile
Normal file
120
Makefile
Normal file
|
@ -0,0 +1,120 @@
|
|||
# TODO(mrcyjanek): Cleanup, this is borrowed from unnamed_monero_wallet repo.
|
||||
|
||||
MONERO_C_TAG=v0.18.3.3-RC21
|
||||
LIBCPP_SHARED_SO_TAG=latest-RC1
|
||||
LIBCPP_SHARED_SO_NDKVERSION=r17c
|
||||
|
||||
.PHONY: android
|
||||
android:
|
||||
./build_changelog.sh
|
||||
flutter build apk --split-per-abi --flavor calc --dart-define=libstealth_calculator=true
|
||||
flutter build apk --split-per-abi --flavor clean --dart-define=libstealth_calculator=false
|
||||
|
||||
.PHONY: linux
|
||||
linux:
|
||||
./build_changelog.sh
|
||||
flutter build linux
|
||||
echo https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/${TARGET_TRIPLET}_libwallet2_api_c.so.xz
|
||||
wget https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/${TARGET_TRIPLET}_libwallet2_api_c.so.xz \
|
||||
-O build/linux/${FLUTTER_ARCH}/release/bundle/lib/libwallet2_api_c.so.xz
|
||||
-rm build/linux/${FLUTTER_ARCH}/release/bundle/lib/libwallet2_api_c.so
|
||||
unxz build/linux/${FLUTTER_ARCH}/release/bundle/lib/libwallet2_api_c.so.xz
|
||||
-rm build/linux/${FLUTTER_ARCH}/release/xmruw-linux-${DEBIAN_ARCH}.tar*
|
||||
(cd build/linux/${FLUTTER_ARCH}/release && cp -a bundle xmruw && tar -cvf xmruw-linux-${DEBIAN_ARCH}.tar xmruw && xz -e xmruw-linux-${DEBIAN_ARCH}.tar)
|
||||
|
||||
|
||||
.PHONY: linux_debug_lib
|
||||
linux_debug_lib:
|
||||
wget https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/${shell gcc -dumpmachine}_libwallet2_api_c.so.xz \
|
||||
-O build/linux/${FLUTTER_ARCH}/debug/bundle/lib/libwallet2_api_c.so.xz
|
||||
-rm build/linux/${FLUTTER_ARCH}/debug/bundle/lib/libwallet2_api_c.so
|
||||
unxz build/linux/${FLUTTER_ARCH}/debug/bundle/lib/libwallet2_api_c.so.xz
|
||||
|
||||
deb:
|
||||
dart pub global activate --source git https://github.com/tomekit/flutter_to_debian.git
|
||||
cat debian/debian.yaml.txt | sed 's/x64/${FLUTTER_ARCH}/g' | sed 's/amd64/${DEBIAN_ARCH}/g' > debian/debian.yaml
|
||||
${HOME}/.pub-cache/bin/flutter_to_debian
|
||||
|
||||
.PHONY: dev
|
||||
dev: libs
|
||||
|
||||
dev:
|
||||
lib/const/resource.g.dart:
|
||||
dart pub global activate flutter_asset_generator
|
||||
timeout 15 ${HOME}/.pub-cache/bin/fgen || true
|
||||
mv lib/const/resource.dart lib/const/resource.g.dart
|
||||
.PHONY: lib/const/resource.g.dart
|
||||
|
||||
.PHONY: sailfishos
|
||||
sailfishos:
|
||||
./build_changelog.sh
|
||||
bash ./elinux/sailfish_build.sh
|
||||
|
||||
.PHONY: version
|
||||
version:
|
||||
sed -i "s/^version: .*/version: 1.0.0+$(shell git rev-list --count HEAD)/" "pubspec.yaml"
|
||||
sed -i "s/^ Version: .*/ Version: 1.0.0+$(shell git rev-list --count HEAD)/" "debian/debian.yaml.txt"
|
||||
sed -i "s/^Version=.*/Version=1.0.0+$(shell git rev-list --count HEAD)/" "debian/gui/xmruw.desktop"
|
||||
sed -i "s/^Version=.*/Version=1.0.0+$(shell git rev-list --count HEAD)/" "elinux/unnamed-monero-wallet.desktop"
|
||||
sed -i "s/^Version: .*/Version: 1.0.0+$(shell git rev-list --count HEAD)/" "elinux/sailfishos.spec"
|
||||
sed -i "s/^Release: .*/Release: $(shell git rev-list --count HEAD)/" "elinux/sailfishos.spec"
|
||||
sed -i "s/^Version: .*/Version: 1.0.0+$(shell git rev-list --count HEAD)/" "elinux/sailfishos.spec"
|
||||
sed -i "s/^const xmruwVersion = .*/const xmruwVersion = '$(shell git describe --tags)';/" "lib/helpers/licenses_extra.dart"
|
||||
|
||||
.PHONY: lib/helpers/licenses.g.dart
|
||||
lib/helpers/licenses.g.dart:
|
||||
dart pub run flutter_oss_licenses:generate.dart -o lib/helpers/licenses.g.dart
|
||||
|
||||
libs: android/app/src/main/jniLibs/arm64-v8a/libmonero_libwallet2_api_c.so
|
||||
.PHONY: android/app/src/main/jniLibs/arm64-v8a/libmonero_libwallet2_api_c.so
|
||||
android/app/src/main/jniLibs/arm64-v8a/libmonero_libwallet2_api_c.so:
|
||||
wget -q https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/monero/aarch64-linux-android_libwallet2_api_c.so.xz -O android/app/src/main/jniLibs/arm64-v8a/libmonero_libwallet2_api_c.so.xz
|
||||
unxz android/app/src/main/jniLibs/arm64-v8a/libmonero_libwallet2_api_c.so.xz
|
||||
|
||||
libs: android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so
|
||||
.PHONY: android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so
|
||||
android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so:
|
||||
wget -q https://git.mrcyjanek.net/mrcyjanek/libcpp_shared.so/releases/download/${LIBCPP_SHARED_SO_TAG}/${LIBCPP_SHARED_SO_NDKVERSION}_arm64-v8a_libc++_shared.so -O android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so
|
||||
|
||||
libs: android/app/src/main/jniLibs/armeabi-v7a/libmonero_libwallet2_api_c.so
|
||||
.PHONY: android/app/src/main/jniLibs/armeabi-v7a/libmonero_libwallet2_api_c.so
|
||||
android/app/src/main/jniLibs/armeabi-v7a/libmonero_libwallet2_api_c.so:
|
||||
wget -q https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/monero/arm-linux-androideabi_libwallet2_api_c.so.xz -O android/app/src/main/jniLibs/armeabi-v7a/libmonero_libwallet2_api_c.so.xz
|
||||
unxz android/app/src/main/jniLibs/armeabi-v7a/libmonero_libwallet2_api_c.so.xz
|
||||
|
||||
libs: android/app/src/main/jniLibs/armeabi-v7a/libc++_shared.so
|
||||
.PHONY: android/app/src/main/jniLibs/armeabi-v7a/libc++_shared.so
|
||||
android/app/src/main/jniLibs/armeabi-v7a/libc++_shared.so:
|
||||
wget -q https://git.mrcyjanek.net/mrcyjanek/libcpp_shared.so/releases/download/${LIBCPP_SHARED_SO_TAG}/${LIBCPP_SHARED_SO_NDKVERSION}_armeabi-v7a_libc++_shared.so -O android/app/src/main/jniLibs/armeabi-v7a/libc++_shared.so
|
||||
|
||||
# libs: android/app/src/main/jniLibs/x86/libmonero_libwallet2_api_c.so
|
||||
# .PHONY: android/app/src/main/jniLibs/x86/libmonero_libwallet2_api_c.so
|
||||
# android/app/src/main/jniLibs/x86/libmonero_libwallet2_api_c.so:
|
||||
# wget -q https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/monero/i686-linux-android_libwallet2_api_c.so.xz -O android/app/src/main/jniLibs/x86/libmonero_libwallet2_api_c.so.xz
|
||||
# unxz android/app/src/main/jniLibs/x86/libmonero_libwallet2_api_c.so.xz
|
||||
|
||||
libs: android/app/src/main/jniLibs/x86/libc++_shared.so
|
||||
.PHONY: android/app/src/main/jniLibs/x86/libc++_shared.so
|
||||
android/app/src/main/jniLibs/x86/libc++_shared.so:
|
||||
wget -q https://git.mrcyjanek.net/mrcyjanek/libcpp_shared.so/releases/download/${LIBCPP_SHARED_SO_TAG}/${LIBCPP_SHARED_SO_NDKVERSION}_x86_libc++_shared.so -O android/app/src/main/jniLibs/x86/libc++_shared.so
|
||||
|
||||
libs: android/app/src/main/jniLibs/x86_64/libmonero_libwallet2_api_c.so
|
||||
.PHONY: android/app/src/main/jniLibs/x86_64/libmonero_libwallet2_api_c.so
|
||||
android/app/src/main/jniLibs/x86_64/libmonero_libwallet2_api_c.so:
|
||||
wget -q https://static.mrcyjanek.net/monero_c/${MONERO_C_TAG}/monero/x86_64-linux-android_libwallet2_api_c.so.xz -O android/app/src/main/jniLibs/x86_64/libmonero_libwallet2_api_c.so.xz
|
||||
unxz android/app/src/main/jniLibs/x86_64/libmonero_libwallet2_api_c.so.xz
|
||||
|
||||
libs: android/app/src/main/jniLibs/x86_64/libc++_shared.so
|
||||
.PHONY: android/app/src/main/jniLibs/x86_64/libc++_shared.so
|
||||
android/app/src/main/jniLibs/x86_64/libc++_shared.so:
|
||||
wget -q https://git.mrcyjanek.net/mrcyjanek/libcpp_shared.so/releases/download/${LIBCPP_SHARED_SO_TAG}/${LIBCPP_SHARED_SO_NDKVERSION}_x86_64_libc++_shared.so -O android/app/src/main/jniLibs/x86_64/libc++_shared.so
|
||||
|
||||
clean_libs:
|
||||
-rm android/app/src/main/jniLibs/x86_64/libc++_shared.so*
|
||||
-rm android/app/src/main/jniLibs/x86_64/*_libwallet2_api_c.so*
|
||||
-rm android/app/src/main/jniLibs/armeabi-v7a/libc++_shared.so*
|
||||
-rm android/app/src/main/jniLibs/armeabi-v7a/*_libwallet2_api_c.so*
|
||||
-rm android/app/src/main/jniLibs/x86/libc++_shared.so*
|
||||
-rm android/app/src/main/jniLibs/x86/*_libwallet2_api_c.so*
|
||||
-rm android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so*
|
||||
-rm android/app/src/main/jniLibs/arm64-v8a/*_libwallet2_api_c.so*
|
|
@ -18,7 +18,8 @@
|
|||
android:fullBackupContent="false"
|
||||
android:versionCode="__versionCode__"
|
||||
android:versionName="__versionName__"
|
||||
android:requestLegacyExternalStorage="true">
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:extractNativeLibs="true">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleInstance"
|
||||
|
|
0
android/app/src/main/jniLibs/arm64-v8a/.gitkeep
Normal file
0
android/app/src/main/jniLibs/arm64-v8a/.gitkeep
Normal file
0
android/app/src/main/jniLibs/armeabi-v7a/.gitkeep
Normal file
0
android/app/src/main/jniLibs/armeabi-v7a/.gitkeep
Normal file
0
android/app/src/main/jniLibs/x86/.gitkeep
Normal file
0
android/app/src/main/jniLibs/x86/.gitkeep
Normal file
0
android/app/src/main/jniLibs/x86_64/.gitkeep
Normal file
0
android/app/src/main/jniLibs/x86_64/.gitkeep
Normal file
|
@ -4,7 +4,6 @@ import 'package:cw_haven/api/signatures.dart';
|
|||
import 'package:cw_haven/api/types.dart';
|
||||
import 'package:cw_haven/api/haven_api.dart';
|
||||
import 'package:cw_haven/api/structs/account_row.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cw_haven/api/wallet.dart';
|
||||
|
||||
final accountSizeNative = havenApi
|
||||
|
@ -72,12 +71,11 @@ void _setLabelForAccount(Map<String, dynamic> args) {
|
|||
}
|
||||
|
||||
Future<void> addAccount({required String label}) async {
|
||||
await compute(_addAccount, label);
|
||||
_addAccount(label);
|
||||
await store();
|
||||
}
|
||||
|
||||
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
||||
await compute(
|
||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
||||
_setLabelForAccount({'accountIndex': accountIndex, 'label': label});
|
||||
await store();
|
||||
}
|
|
@ -115,10 +115,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: ffi
|
||||
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
|
||||
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.1.0"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -241,6 +241,15 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.3+1"
|
||||
monero:
|
||||
dependency: transitive
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "08c5a32cbcf1f04dbae5826c83abda8fb0dbdcce"
|
||||
url: "https://git.mrcyjanek.net/mrcyjanek/monero.dart"
|
||||
source: git
|
||||
version: "0.0.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -1,38 +1,16 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:cw_monero/api/signatures.dart';
|
||||
import 'package:cw_monero/api/types.dart';
|
||||
import 'package:cw_monero/api/monero_api.dart';
|
||||
import 'package:cw_monero/api/structs/account_row.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cw_monero/api/wallet.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
final accountSizeNative = moneroApi
|
||||
.lookup<NativeFunction<account_size>>('account_size')
|
||||
.asFunction<SubaddressSize>();
|
||||
|
||||
final accountRefreshNative = moneroApi
|
||||
.lookup<NativeFunction<account_refresh>>('account_refresh')
|
||||
.asFunction<AccountRefresh>();
|
||||
|
||||
final accountGetAllNative = moneroApi
|
||||
.lookup<NativeFunction<account_get_all>>('account_get_all')
|
||||
.asFunction<AccountGetAll>();
|
||||
|
||||
final accountAddNewNative = moneroApi
|
||||
.lookup<NativeFunction<account_add_new>>('account_add_row')
|
||||
.asFunction<AccountAddNew>();
|
||||
|
||||
final accountSetLabelNative = moneroApi
|
||||
.lookup<NativeFunction<account_set_label>>('account_set_label_row')
|
||||
.asFunction<AccountSetLabel>();
|
||||
monero.wallet? wptr = null;
|
||||
monero.SubaddressAccount? account;
|
||||
|
||||
bool isUpdating = false;
|
||||
|
||||
void refreshAccounts() {
|
||||
try {
|
||||
isUpdating = true;
|
||||
accountRefreshNative();
|
||||
account = monero.Wallet_subaddressAccount(wptr!);
|
||||
monero.SubaddressAccount_refresh(account!);
|
||||
isUpdating = false;
|
||||
} catch (e) {
|
||||
isUpdating = false;
|
||||
|
@ -40,26 +18,22 @@ void refreshAccounts() {
|
|||
}
|
||||
}
|
||||
|
||||
List<AccountRow> getAllAccount() {
|
||||
final size = accountSizeNative();
|
||||
final accountAddressesPointer = accountGetAllNative();
|
||||
final accountAddresses = accountAddressesPointer.asTypedList(size);
|
||||
List<monero.SubaddressAccountRow> getAllAccount() {
|
||||
// final size = monero.Wallet_numSubaddressAccounts(wptr!);
|
||||
final size = monero.SubaddressAccount_getAll_size(wptr!);
|
||||
|
||||
return accountAddresses
|
||||
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
|
||||
.toList();
|
||||
return List.generate(size, (index) {
|
||||
return monero.SubaddressAccount_getAll_byIndex(wptr!, index: index);
|
||||
});
|
||||
}
|
||||
|
||||
void addAccountSync({required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
accountAddNewNative(labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
monero.Wallet_addSubaddressAccount(wptr!, label: label);
|
||||
}
|
||||
|
||||
void setLabelForAccountSync({required int accountIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
accountSetLabelNative(accountIndex, labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
// TODO(mrcyjanek): this may be wrong function?
|
||||
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: 0, label: label);
|
||||
}
|
||||
|
||||
void _addAccount(String label) => addAccountSync(label: label);
|
||||
|
@ -72,12 +46,11 @@ void _setLabelForAccount(Map<String, dynamic> args) {
|
|||
}
|
||||
|
||||
Future<void> addAccount({required String label}) async {
|
||||
await compute(_addAccount, label);
|
||||
_addAccount(label);
|
||||
await store();
|
||||
}
|
||||
|
||||
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
||||
await compute(
|
||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
||||
_setLabelForAccount({'accountIndex': accountIndex, 'label': label});
|
||||
await store();
|
||||
}
|
|
@ -1,35 +1,17 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:cw_monero/api/signatures.dart';
|
||||
import 'package:cw_monero/api/structs/coins_info_row.dart';
|
||||
import 'package:cw_monero/api/types.dart';
|
||||
import 'package:cw_monero/api/monero_api.dart';
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
final refreshCoinsNative = moneroApi
|
||||
.lookup<NativeFunction<refresh_coins>>('refresh_coins')
|
||||
.asFunction<RefreshCoins>();
|
||||
monero.Coins? coins = null;
|
||||
|
||||
final coinsCountNative = moneroApi
|
||||
.lookup<NativeFunction<coins_count>>('coins_count')
|
||||
.asFunction<CoinsCount>();
|
||||
void refreshCoins(int accountIndex) {
|
||||
coins = monero.Wallet_coins(wptr!);
|
||||
monero.Coins_refresh(coins!);
|
||||
}
|
||||
|
||||
final coinNative = moneroApi
|
||||
.lookup<NativeFunction<coin>>('coin')
|
||||
.asFunction<GetCoin>();
|
||||
int countOfCoins() => monero.Coins_count(coins!);
|
||||
|
||||
final freezeCoinNative = moneroApi
|
||||
.lookup<NativeFunction<freeze_coin>>('freeze_coin')
|
||||
.asFunction<FreezeCoin>();
|
||||
monero.CoinsInfo getCoin(int index) => monero.Coins_coin(coins!, index);
|
||||
|
||||
final thawCoinNative = moneroApi
|
||||
.lookup<NativeFunction<thaw_coin>>('thaw_coin')
|
||||
.asFunction<ThawCoin>();
|
||||
void freezeCoin(int index) => monero.Coins_setFrozen(coins!, index: index);
|
||||
|
||||
void refreshCoins(int accountIndex) => refreshCoinsNative(accountIndex);
|
||||
|
||||
int countOfCoins() => coinsCountNative();
|
||||
|
||||
CoinsInfoRow getCoin(int index) => coinNative(index).ref;
|
||||
|
||||
void freezeCoin(int index) => freezeCoinNative(index);
|
||||
|
||||
void thawCoin(int index) => thawCoinNative(index);
|
||||
void thawCoin(int index) => monero.Coins_thaw(coins!, index: index);
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
String convertUTF8ToString({required Pointer<Utf8> pointer}) {
|
||||
final str = pointer.toDartString();
|
||||
calloc.free(pointer);
|
||||
return str;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
final DynamicLibrary moneroApi = Platform.isAndroid
|
||||
? DynamicLibrary.open("libcw_monero.so")
|
||||
: DynamicLibrary.open("cw_monero.framework/cw_monero");
|
|
@ -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 create_wallet = Int8 Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>);
|
||||
|
||||
typedef restore_wallet_from_seed = Int8 Function(
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>);
|
||||
|
||||
typedef restore_wallet_from_keys = Int8 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>,
|
||||
Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>);
|
||||
|
||||
typedef restore_wallet_from_spend_key = Int8 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>,
|
||||
Pointer<Utf8>, Pointer<Utf8>, Int32, Int64, Pointer<Utf8>);
|
||||
|
||||
typedef is_wallet_exist = Int8 Function(Pointer<Utf8>);
|
||||
|
||||
typedef load_wallet = Int8 Function(Pointer<Utf8>, Pointer<Utf8>, Int8);
|
||||
|
||||
typedef error_string = Pointer<Utf8> Function();
|
||||
|
||||
typedef get_filename = Pointer<Utf8> Function();
|
||||
|
||||
typedef get_seed = Pointer<Utf8> Function();
|
||||
|
||||
typedef get_address = Pointer<Utf8> Function(Int32, Int32);
|
||||
|
||||
typedef get_full_balanace = Int64 Function(Int32);
|
||||
|
||||
typedef get_unlocked_balanace = Int64 Function(Int32);
|
||||
|
||||
typedef get_current_height = Int64 Function();
|
||||
|
||||
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>);
|
||||
|
||||
typedef start_refresh = Void Function();
|
||||
|
||||
typedef connect_to_node = Int8 Function();
|
||||
|
||||
typedef set_refresh_from_block_height = Void Function(Int64);
|
||||
|
||||
typedef set_recovering_from_seed = Void Function(Int8);
|
||||
|
||||
typedef store_c = Void Function(Pointer<Utf8>);
|
||||
|
||||
typedef set_password = Int8 Function(Pointer<Utf8> password, Pointer<Utf8Box> error);
|
||||
|
||||
typedef set_listener = Void Function();
|
||||
|
||||
typedef get_syncing_height = Int64 Function();
|
||||
|
||||
typedef is_needed_to_refresh = Int8 Function();
|
||||
|
||||
typedef is_new_transaction_exist = Int8 Function();
|
||||
|
||||
typedef subaddrress_size = Int32 Function();
|
||||
|
||||
typedef subaddrress_refresh = Void Function(Int32);
|
||||
|
||||
typedef subaddress_get_all = Pointer<Int64> Function();
|
||||
|
||||
typedef subaddress_add_new = Void Function(Int32 accountIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef subaddress_set_label = Void Function(
|
||||
Int32 accountIndex, Int32 addressIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef account_size = Int32 Function();
|
||||
|
||||
typedef account_refresh = Void Function();
|
||||
|
||||
typedef account_get_all = Pointer<Int64> Function();
|
||||
|
||||
typedef account_add_new = Void Function(Pointer<Utf8> label);
|
||||
|
||||
typedef account_set_label = Void Function(Int32 accountIndex, Pointer<Utf8> label);
|
||||
|
||||
typedef transactions_refresh = Void Function();
|
||||
|
||||
typedef get_transaction = Pointer<TransactionInfoRow> Function(Pointer<Utf8> txId);
|
||||
|
||||
typedef get_tx_key = Pointer<Utf8>? Function(Pointer<Utf8> txId);
|
||||
|
||||
typedef transactions_count = Int64 Function();
|
||||
|
||||
typedef transactions_get_all = Pointer<Int64> Function();
|
||||
|
||||
typedef transaction_create = Int8 Function(
|
||||
Pointer<Utf8> address,
|
||||
Pointer<Utf8> paymentId,
|
||||
Pointer<Utf8> amount,
|
||||
Int8 priorityRaw,
|
||||
Int32 subaddrAccount,
|
||||
Pointer<Pointer<Utf8>> preferredInputs,
|
||||
Int32 preferredInputsSize,
|
||||
Pointer<Utf8Box> error,
|
||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||
|
||||
typedef transaction_create_mult_dest = Int8 Function(
|
||||
Pointer<Pointer<Utf8>> addresses,
|
||||
Pointer<Utf8> paymentId,
|
||||
Pointer<Pointer<Utf8>> amounts,
|
||||
Int32 size,
|
||||
Int8 priorityRaw,
|
||||
Int32 subaddrAccount,
|
||||
Pointer<Pointer<Utf8>> preferredInputs,
|
||||
Int32 preferredInputsSize,
|
||||
Pointer<Utf8Box> error,
|
||||
Pointer<PendingTransactionRaw> pendingTransaction);
|
||||
|
||||
typedef transaction_commit = Int8 Function(Pointer<PendingTransactionRaw>, Pointer<Utf8Box>);
|
||||
|
||||
typedef secret_view_key = Pointer<Utf8> Function();
|
||||
|
||||
typedef public_view_key = Pointer<Utf8> Function();
|
||||
|
||||
typedef secret_spend_key = Pointer<Utf8> Function();
|
||||
|
||||
typedef public_spend_key = Pointer<Utf8> Function();
|
||||
|
||||
typedef close_current_wallet = Void Function();
|
||||
|
||||
typedef on_startup = Void Function();
|
||||
|
||||
typedef rescan_blockchain = Void Function();
|
||||
|
||||
typedef get_subaddress_label = Pointer<Utf8> Function(Int32 accountIndex, Int32 addressIndex);
|
||||
|
||||
typedef set_trusted_daemon = Void Function(Int8 trusted);
|
||||
|
||||
typedef trusted_daemon = Int8 Function();
|
||||
|
||||
typedef refresh_coins = Void Function(Int32 accountIndex);
|
||||
|
||||
typedef coins_count = Int64 Function();
|
||||
|
||||
// typedef coins_from_txid = Pointer<CoinsInfoRow> Function(Pointer<Utf8> txid);
|
||||
|
||||
typedef coin = Pointer<CoinsInfoRow> Function(Int32 index);
|
||||
|
||||
typedef freeze_coin = Void Function(Int32 index);
|
||||
|
||||
typedef thaw_coin = Void Function(Int32 index);
|
||||
|
||||
typedef sign_message = Pointer<Utf8> Function(Pointer<Utf8> message, Pointer<Utf8> address);
|
|
@ -1,38 +1,14 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cw_monero/api/signatures.dart';
|
||||
import 'package:cw_monero/api/types.dart';
|
||||
import 'package:cw_monero/api/monero_api.dart';
|
||||
import 'package:cw_monero/api/structs/subaddress_row.dart';
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:cw_monero/api/wallet.dart';
|
||||
|
||||
final subaddressSizeNative = moneroApi
|
||||
.lookup<NativeFunction<subaddrress_size>>('subaddrress_size')
|
||||
.asFunction<SubaddressSize>();
|
||||
|
||||
final subaddressRefreshNative = moneroApi
|
||||
.lookup<NativeFunction<subaddrress_refresh>>('subaddress_refresh')
|
||||
.asFunction<SubaddressRefresh>();
|
||||
|
||||
final subaddrressGetAllNative = moneroApi
|
||||
.lookup<NativeFunction<subaddress_get_all>>('subaddrress_get_all')
|
||||
.asFunction<SubaddressGetAll>();
|
||||
|
||||
final subaddrressAddNewNative = moneroApi
|
||||
.lookup<NativeFunction<subaddress_add_new>>('subaddress_add_row')
|
||||
.asFunction<SubaddressAddNew>();
|
||||
|
||||
final subaddrressSetLabelNative = moneroApi
|
||||
.lookup<NativeFunction<subaddress_set_label>>('subaddress_set_label')
|
||||
.asFunction<SubaddressSetLabel>();
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
bool isUpdating = false;
|
||||
|
||||
monero.AddressBook? addressbook = null;
|
||||
void refreshSubaddresses({required int accountIndex}) {
|
||||
try {
|
||||
isUpdating = true;
|
||||
subaddressRefreshNative(accountIndex);
|
||||
addressbook = monero.Wallet_subaddressAccount(wptr!);
|
||||
monero.AddressBook_refresh(addressbook!);
|
||||
isUpdating = false;
|
||||
} catch (e) {
|
||||
isUpdating = false;
|
||||
|
@ -40,28 +16,21 @@ void refreshSubaddresses({required int accountIndex}) {
|
|||
}
|
||||
}
|
||||
|
||||
List<SubaddressRow> getAllSubaddresses() {
|
||||
final size = subaddressSizeNative();
|
||||
final subaddressAddressesPointer = subaddrressGetAllNative();
|
||||
final subaddressAddresses = subaddressAddressesPointer.asTypedList(size);
|
||||
List<monero.SubaddressRow> getAllSubaddresses() {
|
||||
final size = monero.AddressBook_getAll_size(addressbook!);
|
||||
|
||||
return subaddressAddresses
|
||||
.map((addr) => Pointer<SubaddressRow>.fromAddress(addr).ref)
|
||||
.toList();
|
||||
return List.generate(size, (index) {
|
||||
return monero.Subaddress_getAll_byIndex(wptr!, index: index);
|
||||
});
|
||||
}
|
||||
|
||||
void addSubaddressSync({required int accountIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
subaddrressAddNewNative(accountIndex, labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex, label: label);
|
||||
}
|
||||
|
||||
void setLabelForSubaddressSync(
|
||||
{required int accountIndex, required int addressIndex, required String label}) {
|
||||
final labelPointer = label.toNativeUtf8();
|
||||
|
||||
subaddrressSetLabelNative(accountIndex, addressIndex, labelPointer);
|
||||
calloc.free(labelPointer);
|
||||
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
||||
}
|
||||
|
||||
void _addSubaddress(Map<String, dynamic> args) {
|
||||
|
@ -81,14 +50,13 @@ void _setLabelForSubaddress(Map<String, dynamic> args) {
|
|||
}
|
||||
|
||||
Future<void> addSubaddress({required int accountIndex, required String label}) async {
|
||||
await compute<Map<String, Object>, void>(
|
||||
_addSubaddress, {'accountIndex': accountIndex, 'label': label});
|
||||
await store();
|
||||
_addSubaddress({'accountIndex': accountIndex, 'label': label});
|
||||
await store();
|
||||
}
|
||||
|
||||
Future<void> setLabelForSubaddress(
|
||||
{required int accountIndex, required int addressIndex, required String label}) async {
|
||||
await compute<Map<String, Object>, void>(_setLabelForSubaddress, {
|
||||
_setLabelForSubaddress({
|
||||
'accountIndex': accountIndex,
|
||||
'addressIndex': addressIndex,
|
||||
'label': label
|
||||
|
|
|
@ -1,78 +1,35 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:cw_monero/api/convert_utf8_to_string.dart';
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart';
|
||||
import 'package:cw_monero/api/monero_api.dart';
|
||||
import 'package:cw_monero/api/monero_output.dart';
|
||||
import 'package:cw_monero/api/signatures.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:cw_monero/api/types.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
final transactionsRefreshNative = moneroApi
|
||||
.lookup<NativeFunction<transactions_refresh>>('transactions_refresh')
|
||||
.asFunction<TransactionsRefresh>();
|
||||
|
||||
final transactionsCountNative = moneroApi
|
||||
.lookup<NativeFunction<transactions_count>>('transactions_count')
|
||||
.asFunction<TransactionsCount>();
|
||||
|
||||
final transactionsGetAllNative = moneroApi
|
||||
.lookup<NativeFunction<transactions_get_all>>('transactions_get_all')
|
||||
.asFunction<TransactionsGetAll>();
|
||||
|
||||
final transactionCreateNative = moneroApi
|
||||
.lookup<NativeFunction<transaction_create>>('transaction_create')
|
||||
.asFunction<TransactionCreate>();
|
||||
|
||||
final transactionCreateMultDestNative = moneroApi
|
||||
.lookup<NativeFunction<transaction_create_mult_dest>>('transaction_create_mult_dest')
|
||||
.asFunction<TransactionCreateMultDest>();
|
||||
|
||||
final transactionCommitNative = moneroApi
|
||||
.lookup<NativeFunction<transaction_commit>>('transaction_commit')
|
||||
.asFunction<TransactionCommit>();
|
||||
|
||||
final getTxKeyNative =
|
||||
moneroApi.lookup<NativeFunction<get_tx_key>>('get_tx_key').asFunction<GetTxKey>();
|
||||
|
||||
final getTransactionNative = moneroApi
|
||||
.lookup<NativeFunction<get_transaction>>('get_transaction')
|
||||
.asFunction<GetTransaction>();
|
||||
|
||||
String getTxKey(String txId) {
|
||||
final txIdPointer = txId.toNativeUtf8();
|
||||
final keyPointer = getTxKeyNative(txIdPointer);
|
||||
|
||||
calloc.free(txIdPointer);
|
||||
|
||||
if (keyPointer != null) {
|
||||
return convertUTF8ToString(pointer: keyPointer);
|
||||
}
|
||||
|
||||
return '';
|
||||
return monero.Wallet_getTxKey(wptr!, txid: txId);
|
||||
}
|
||||
|
||||
void refreshTransactions() => transactionsRefreshNative();
|
||||
monero.TransactionHistory? txhistory;
|
||||
|
||||
int countOfTransactions() => transactionsCountNative();
|
||||
|
||||
List<TransactionInfoRow> getAllTransactions() {
|
||||
final size = transactionsCountNative();
|
||||
final transactionsPointer = transactionsGetAllNative();
|
||||
final transactionsAddresses = transactionsPointer.asTypedList(size);
|
||||
|
||||
return transactionsAddresses
|
||||
.map((addr) => Pointer<TransactionInfoRow>.fromAddress(addr).ref)
|
||||
.toList();
|
||||
void refreshTransactions() {
|
||||
txhistory = monero.Wallet_history(wptr!);
|
||||
monero.TransactionHistory_refresh(txhistory!);
|
||||
}
|
||||
|
||||
TransactionInfoRow getTransaction(String txId) {
|
||||
final txIdPointer = txId.toNativeUtf8();
|
||||
return getTransactionNative(txIdPointer).ref;
|
||||
int countOfTransactions() => monero.TransactionHistory_count(txhistory!);
|
||||
|
||||
List<Transaction> getAllTransactions() {
|
||||
final size = countOfTransactions();
|
||||
|
||||
return List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index)));
|
||||
}
|
||||
|
||||
// TODO(mrcyjanek): ...
|
||||
Transaction getTransaction(String txId) {
|
||||
return Transaction(txInfo: monero.TransactionHistory_transactionById(txhistory!, txid: txId));
|
||||
}
|
||||
|
||||
PendingTransactionDescription createTransactionSync(
|
||||
|
@ -82,8 +39,6 @@ PendingTransactionDescription createTransactionSync(
|
|||
String? amount,
|
||||
int accountIndex = 0,
|
||||
List<String> preferredInputs = const []}) {
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
||||
final amountPointer = amount != null ? amount.toNativeUtf8() : nullptr;
|
||||
|
||||
final int preferredInputsSize = preferredInputs.length;
|
||||
|
@ -95,44 +50,38 @@ PendingTransactionDescription createTransactionSync(
|
|||
preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
||||
}
|
||||
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
||||
final created = transactionCreateNative(
|
||||
addressPointer,
|
||||
paymentIdPointer,
|
||||
amountPointer,
|
||||
priorityRaw,
|
||||
accountIndex,
|
||||
preferredInputsPointerPointer,
|
||||
preferredInputsSize,
|
||||
errorMessagePointer,
|
||||
pendingTransactionRawPointer) !=
|
||||
0;
|
||||
final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount);
|
||||
final pendingTx = monero.Wallet_createTransaction(
|
||||
wptr!,
|
||||
dst_addr: address,
|
||||
payment_id: paymentId,
|
||||
amount: amt,
|
||||
mixin_count: 1,
|
||||
pendingTransactionPriority: priorityRaw,
|
||||
subaddr_account: accountIndex,
|
||||
preferredInputs: preferredInputs,
|
||||
);
|
||||
final String? error = (() {
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status == 0) {
|
||||
return null;
|
||||
}
|
||||
return monero.Wallet_errorString(wptr!);
|
||||
})();
|
||||
|
||||
calloc.free(preferredInputsPointerPointer);
|
||||
|
||||
preferredInputsPointers.forEach((element) => calloc.free(element));
|
||||
|
||||
calloc.free(addressPointer);
|
||||
calloc.free(paymentIdPointer);
|
||||
|
||||
if (amountPointer != nullptr) {
|
||||
calloc.free(amountPointer);
|
||||
}
|
||||
|
||||
if (!created) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
calloc.free(errorMessagePointer);
|
||||
if (error != null) {
|
||||
final message = error;
|
||||
throw CreationTransactionException(message: message);
|
||||
}
|
||||
|
||||
return PendingTransactionDescription(
|
||||
amount: pendingTransactionRawPointer.ref.amount,
|
||||
fee: pendingTransactionRawPointer.ref.fee,
|
||||
hash: pendingTransactionRawPointer.ref.getHash(),
|
||||
hex: pendingTransactionRawPointer.ref.getHex(),
|
||||
txKey: pendingTransactionRawPointer.ref.getKey(),
|
||||
pointerAddress: pendingTransactionRawPointer.address);
|
||||
amount: monero.PendingTransaction_amount(wptr!),
|
||||
fee: monero.PendingTransaction_fee(wptr!),
|
||||
hash: monero.PendingTransaction_txid(wptr!, ''),
|
||||
hex: '',
|
||||
txKey: monero.PendingTransaction_txid(wptr!, ''),
|
||||
pointerAddress: pendingTx.address,
|
||||
);
|
||||
}
|
||||
|
||||
PendingTransactionDescription createTransactionMultDestSync(
|
||||
|
@ -141,80 +90,88 @@ PendingTransactionDescription createTransactionMultDestSync(
|
|||
required int priorityRaw,
|
||||
int accountIndex = 0,
|
||||
List<String> preferredInputs = const []}) {
|
||||
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);
|
||||
// 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];
|
||||
}
|
||||
// for (int i = 0; i < size; i++) {
|
||||
// addressesPointerPointer[i] = addressesPointers[i];
|
||||
// amountsPointerPointer[i] = amountsPointers[i];
|
||||
// }
|
||||
|
||||
final int preferredInputsSize = preferredInputs.length;
|
||||
final List<Pointer<Utf8>> preferredInputsPointers =
|
||||
preferredInputs.map((output) => output.toNativeUtf8()).toList();
|
||||
final Pointer<Pointer<Utf8>> preferredInputsPointerPointer = calloc(preferredInputsSize);
|
||||
// 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];
|
||||
}
|
||||
// for (int i = 0; i < preferredInputsSize; i++) {
|
||||
// preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
||||
// }
|
||||
|
||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
||||
final created = transactionCreateMultDestNative(
|
||||
addressesPointerPointer,
|
||||
paymentIdPointer,
|
||||
amountsPointerPointer,
|
||||
size,
|
||||
priorityRaw,
|
||||
accountIndex,
|
||||
preferredInputsPointerPointer,
|
||||
preferredInputsSize,
|
||||
errorMessagePointer,
|
||||
pendingTransactionRawPointer) !=
|
||||
0;
|
||||
// final paymentIdPointer = paymentId.toNativeUtf8();
|
||||
// final errorMessagePointer = calloc<Utf8Box>();
|
||||
// final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
||||
// final created = transactionCreateMultDestNative(
|
||||
// addressesPointerPointer,
|
||||
// paymentIdPointer,
|
||||
// amountsPointerPointer,
|
||||
// size,
|
||||
// priorityRaw,
|
||||
// accountIndex,
|
||||
// preferredInputsPointerPointer,
|
||||
// preferredInputsSize,
|
||||
// errorMessagePointer,
|
||||
// pendingTransactionRawPointer) !=
|
||||
// 0;
|
||||
|
||||
calloc.free(addressesPointerPointer);
|
||||
calloc.free(amountsPointerPointer);
|
||||
calloc.free(preferredInputsPointerPointer);
|
||||
// calloc.free(addressesPointerPointer);
|
||||
// calloc.free(amountsPointerPointer);
|
||||
// calloc.free(preferredInputsPointerPointer);
|
||||
|
||||
addressesPointers.forEach((element) => calloc.free(element));
|
||||
amountsPointers.forEach((element) => calloc.free(element));
|
||||
preferredInputsPointers.forEach((element) => calloc.free(element));
|
||||
// addressesPointers.forEach((element) => calloc.free(element));
|
||||
// amountsPointers.forEach((element) => calloc.free(element));
|
||||
// preferredInputsPointers.forEach((element) => calloc.free(element));
|
||||
|
||||
calloc.free(paymentIdPointer);
|
||||
// calloc.free(paymentIdPointer);
|
||||
|
||||
if (!created) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
calloc.free(errorMessagePointer);
|
||||
throw CreationTransactionException(message: message);
|
||||
}
|
||||
// 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(),
|
||||
hex: pendingTransactionRawPointer.ref.getHex(),
|
||||
txKey: pendingTransactionRawPointer.ref.getKey(),
|
||||
pointerAddress: pendingTransactionRawPointer.address);
|
||||
// return PendingTransactionDescription(
|
||||
// amount: pendingTransactionRawPointer.ref.amount,
|
||||
// fee: pendingTransactionRawPointer.ref.fee,
|
||||
// hash: pendingTransactionRawPointer.ref.getHash(),
|
||||
// hex: pendingTransactionRawPointer.ref.getHex(),
|
||||
// txKey: pendingTransactionRawPointer.ref.getKey(),
|
||||
// pointerAddress: pendingTransactionRawPointer.address);
|
||||
throw CreationTransactionException(message: "Unimplemented in monero_c");
|
||||
}
|
||||
|
||||
void commitTransactionFromPointerAddress({required int address}) =>
|
||||
commitTransaction(transactionPointer: Pointer<PendingTransactionRaw>.fromAddress(address));
|
||||
commitTransaction(transactionPointer: monero.PendingTransaction.fromAddress(address));
|
||||
|
||||
void commitTransaction({required Pointer<PendingTransactionRaw> transactionPointer}) {
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final isCommited = transactionCommitNative(transactionPointer, errorMessagePointer) != 0;
|
||||
void commitTransaction({required monero.PendingTransaction transactionPointer}) {
|
||||
|
||||
final txCommit = monero.PendingTransaction_commit(transactionPointer, filename: '', overwrite: false);
|
||||
final status = monero.PendingTransaction_status(transactionPointer.cast());
|
||||
|
||||
if (!isCommited) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
calloc.free(errorMessagePointer);
|
||||
throw CreationTransactionException(message: message);
|
||||
final String? error = (() {
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status == 0) {
|
||||
return null;
|
||||
}
|
||||
return monero.Wallet_errorString(wptr!);
|
||||
})();
|
||||
|
||||
if (error != null) {
|
||||
throw CreationTransactionException(message: error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,8 +213,8 @@ Future<PendingTransactionDescription> createTransaction(
|
|||
String? amount,
|
||||
String paymentId = '',
|
||||
int accountIndex = 0,
|
||||
List<String> preferredInputs = const []}) =>
|
||||
compute(_createTransactionSync, {
|
||||
List<String> preferredInputs = const []}) async =>
|
||||
_createTransactionSync({
|
||||
'address': address,
|
||||
'paymentId': paymentId,
|
||||
'amount': amount,
|
||||
|
@ -271,11 +228,75 @@ Future<PendingTransactionDescription> createTransactionMultDest(
|
|||
required int priorityRaw,
|
||||
String paymentId = '',
|
||||
int accountIndex = 0,
|
||||
List<String> preferredInputs = const []}) =>
|
||||
compute(_createTransactionMultDestSync, {
|
||||
List<String> preferredInputs = const []}) async =>
|
||||
_createTransactionMultDestSync({
|
||||
'outputs': outputs,
|
||||
'paymentId': paymentId,
|
||||
'priorityRaw': priorityRaw,
|
||||
'accountIndex': accountIndex,
|
||||
'preferredInputs': preferredInputs
|
||||
});
|
||||
|
||||
|
||||
class Transaction {
|
||||
final String displayLabel;
|
||||
String subaddressLabel = monero.Wallet_getSubaddressLabel(wptr!, accountIndex: 0, addressIndex: 0);
|
||||
late final String address = monero.Wallet_address(
|
||||
wptr!,
|
||||
accountIndex: 0,
|
||||
addressIndex: 0,
|
||||
);
|
||||
final String description;
|
||||
final int fee;
|
||||
final int confirmations;
|
||||
late final bool isPending = confirmations < 10;
|
||||
final int blockheight;
|
||||
final int accountIndex;
|
||||
final String paymentId;
|
||||
final int amount;
|
||||
final bool isSpend;
|
||||
late DateTime timeStamp;
|
||||
late final bool isConfirmed = !isPending;
|
||||
final String hash;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"displayLabel": displayLabel,
|
||||
"subaddressLabel": subaddressLabel,
|
||||
"address": address,
|
||||
"description": description,
|
||||
"fee": fee,
|
||||
"confirmations": confirmations,
|
||||
"isPending": isPending,
|
||||
"blockheight": blockheight,
|
||||
"accountIndex": accountIndex,
|
||||
"paymentId": paymentId,
|
||||
"amount": amount,
|
||||
"isSpend": isSpend,
|
||||
"timeStamp": timeStamp.toIso8601String(),
|
||||
"isConfirmed": isConfirmed,
|
||||
"hash": hash,
|
||||
};
|
||||
}
|
||||
|
||||
// S finalubAddress? subAddress;
|
||||
// List<Transfer> transfers = [];
|
||||
// final int txIndex;
|
||||
final monero.TransactionInfo txInfo;
|
||||
Transaction({
|
||||
required this.txInfo,
|
||||
}) : displayLabel = monero.TransactionInfo_label(txInfo),
|
||||
hash = monero.TransactionInfo_hash(txInfo),
|
||||
timeStamp = DateTime.fromMillisecondsSinceEpoch(
|
||||
monero.TransactionInfo_timestamp(txInfo) * 1000,
|
||||
),
|
||||
isSpend = monero.TransactionInfo_direction(txInfo) ==
|
||||
monero.TransactionInfo_Direction.Out,
|
||||
amount = monero.TransactionInfo_amount(txInfo),
|
||||
paymentId = monero.TransactionInfo_paymentId(txInfo),
|
||||
accountIndex = monero.TransactionInfo_subaddrAccount(txInfo),
|
||||
blockheight = monero.TransactionInfo_blockHeight(txInfo),
|
||||
confirmations = monero.TransactionInfo_confirmations(txInfo),
|
||||
fee = monero.TransactionInfo_fee(txInfo),
|
||||
description = monero.TransactionInfo_description(txInfo);
|
||||
}
|
|
@ -1,160 +1,31 @@
|
|||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:cw_monero/api/structs/ut8_box.dart';
|
||||
import 'package:cw_monero/api/convert_utf8_to_string.dart';
|
||||
import 'package:cw_monero/api/signatures.dart';
|
||||
import 'package:cw_monero/api/types.dart';
|
||||
import 'package:cw_monero/api/monero_api.dart';
|
||||
import 'package:cw_monero/api/account_list.dart';
|
||||
import 'package:cw_monero/api/exceptions/setup_wallet_exception.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
int _boolToInt(bool value) => value ? 1 : 0;
|
||||
|
||||
final getFileNameNative = moneroApi
|
||||
.lookup<NativeFunction<get_filename>>('get_filename')
|
||||
.asFunction<GetFilename>();
|
||||
int getSyncingHeight() => monero.Wallet_blockChainHeight(wptr!);
|
||||
|
||||
final getSeedNative =
|
||||
moneroApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
|
||||
bool isNeededToRefresh() => false; // TODO(mrcyjanek): ?
|
||||
|
||||
final getAddressNative = moneroApi
|
||||
.lookup<NativeFunction<get_address>>('get_address')
|
||||
.asFunction<GetAddress>();
|
||||
bool isNewTransactionExist() => false;
|
||||
|
||||
final getFullBalanceNative = moneroApi
|
||||
.lookup<NativeFunction<get_full_balanace>>('get_full_balance')
|
||||
.asFunction<GetFullBalance>();
|
||||
String getFilename() => monero.Wallet_filename(wptr!);
|
||||
|
||||
final getUnlockedBalanceNative = moneroApi
|
||||
.lookup<NativeFunction<get_unlocked_balanace>>('get_unlocked_balance')
|
||||
.asFunction<GetUnlockedBalance>();
|
||||
String getSeed() => monero.Wallet_seed(wptr!, seedOffset: '');
|
||||
|
||||
final getCurrentHeightNative = moneroApi
|
||||
.lookup<NativeFunction<get_current_height>>('get_current_height')
|
||||
.asFunction<GetCurrentHeight>();
|
||||
String getAddress({int accountIndex = 0, int addressIndex = 0}) => monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex);
|
||||
|
||||
final getNodeHeightNative = moneroApi
|
||||
.lookup<NativeFunction<get_node_height>>('get_node_height')
|
||||
.asFunction<GetNodeHeight>();
|
||||
int getFullBalance({int accountIndex = 0}) => monero.Wallet_balance(wptr!, accountIndex: accountIndex);
|
||||
|
||||
final isConnectedNative = moneroApi
|
||||
.lookup<NativeFunction<is_connected>>('is_connected')
|
||||
.asFunction<IsConnected>();
|
||||
int getUnlockedBalance({int accountIndex = 0}) => monero.Wallet_unlockedBalance(wptr!, accountIndex: accountIndex);
|
||||
|
||||
final setupNodeNative = moneroApi
|
||||
.lookup<NativeFunction<setup_node>>('setup_node')
|
||||
.asFunction<SetupNode>();
|
||||
int getCurrentHeight() => monero.Wallet_blockChainHeight(wptr!);
|
||||
|
||||
final startRefreshNative = moneroApi
|
||||
.lookup<NativeFunction<start_refresh>>('start_refresh')
|
||||
.asFunction<StartRefresh>();
|
||||
int getNodeHeightSync() => monero.Wallet_daemonBlockChainHeight(wptr!);
|
||||
|
||||
final connecToNodeNative = moneroApi
|
||||
.lookup<NativeFunction<connect_to_node>>('connect_to_node')
|
||||
.asFunction<ConnectToNode>();
|
||||
|
||||
final setRefreshFromBlockHeightNative = moneroApi
|
||||
.lookup<NativeFunction<set_refresh_from_block_height>>(
|
||||
'set_refresh_from_block_height')
|
||||
.asFunction<SetRefreshFromBlockHeight>();
|
||||
|
||||
final setRecoveringFromSeedNative = moneroApi
|
||||
.lookup<NativeFunction<set_recovering_from_seed>>(
|
||||
'set_recovering_from_seed')
|
||||
.asFunction<SetRecoveringFromSeed>();
|
||||
|
||||
final storeNative =
|
||||
moneroApi.lookup<NativeFunction<store_c>>('store').asFunction<Store>();
|
||||
|
||||
final setPasswordNative =
|
||||
moneroApi.lookup<NativeFunction<set_password>>('set_password').asFunction<SetPassword>();
|
||||
|
||||
final setListenerNative = moneroApi
|
||||
.lookup<NativeFunction<set_listener>>('set_listener')
|
||||
.asFunction<SetListener>();
|
||||
|
||||
final getSyncingHeightNative = moneroApi
|
||||
.lookup<NativeFunction<get_syncing_height>>('get_syncing_height')
|
||||
.asFunction<GetSyncingHeight>();
|
||||
|
||||
final isNeededToRefreshNative = moneroApi
|
||||
.lookup<NativeFunction<is_needed_to_refresh>>('is_needed_to_refresh')
|
||||
.asFunction<IsNeededToRefresh>();
|
||||
|
||||
final isNewTransactionExistNative = moneroApi
|
||||
.lookup<NativeFunction<is_new_transaction_exist>>(
|
||||
'is_new_transaction_exist')
|
||||
.asFunction<IsNewTransactionExist>();
|
||||
|
||||
final getSecretViewKeyNative = moneroApi
|
||||
.lookup<NativeFunction<secret_view_key>>('secret_view_key')
|
||||
.asFunction<SecretViewKey>();
|
||||
|
||||
final getPublicViewKeyNative = moneroApi
|
||||
.lookup<NativeFunction<public_view_key>>('public_view_key')
|
||||
.asFunction<PublicViewKey>();
|
||||
|
||||
final getSecretSpendKeyNative = moneroApi
|
||||
.lookup<NativeFunction<secret_spend_key>>('secret_spend_key')
|
||||
.asFunction<SecretSpendKey>();
|
||||
|
||||
final getPublicSpendKeyNative = moneroApi
|
||||
.lookup<NativeFunction<secret_view_key>>('public_spend_key')
|
||||
.asFunction<PublicSpendKey>();
|
||||
|
||||
final closeCurrentWalletNative = moneroApi
|
||||
.lookup<NativeFunction<close_current_wallet>>('close_current_wallet')
|
||||
.asFunction<CloseCurrentWallet>();
|
||||
|
||||
final onStartupNative = moneroApi
|
||||
.lookup<NativeFunction<on_startup>>('on_startup')
|
||||
.asFunction<OnStartup>();
|
||||
|
||||
final rescanBlockchainAsyncNative = moneroApi
|
||||
.lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain')
|
||||
.asFunction<RescanBlockchainAsync>();
|
||||
|
||||
final getSubaddressLabelNative = moneroApi
|
||||
.lookup<NativeFunction<get_subaddress_label>>('get_subaddress_label')
|
||||
.asFunction<GetSubaddressLabel>();
|
||||
|
||||
final setTrustedDaemonNative = moneroApi
|
||||
.lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
|
||||
.asFunction<SetTrustedDaemon>();
|
||||
|
||||
final trustedDaemonNative = moneroApi
|
||||
.lookup<NativeFunction<trusted_daemon>>('trusted_daemon')
|
||||
.asFunction<TrustedDaemon>();
|
||||
|
||||
final signMessageNative = moneroApi
|
||||
.lookup<NativeFunction<sign_message>>('sign_message')
|
||||
.asFunction<SignMessage>();
|
||||
|
||||
int getSyncingHeight() => getSyncingHeightNative();
|
||||
|
||||
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
|
||||
|
||||
bool isNewTransactionExist() => isNewTransactionExistNative() != 0;
|
||||
|
||||
String getFilename() => convertUTF8ToString(pointer: getFileNameNative());
|
||||
|
||||
String getSeed() => convertUTF8ToString(pointer: getSeedNative());
|
||||
|
||||
String getAddress({int accountIndex = 0, int addressIndex = 0}) =>
|
||||
convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex));
|
||||
|
||||
int getFullBalance({int accountIndex = 0}) =>
|
||||
getFullBalanceNative(accountIndex);
|
||||
|
||||
int getUnlockedBalance({int accountIndex = 0}) =>
|
||||
getUnlockedBalanceNative(accountIndex);
|
||||
|
||||
int getCurrentHeight() => getCurrentHeightNative();
|
||||
|
||||
int getNodeHeightSync() => getNodeHeightNative();
|
||||
|
||||
bool isConnectedSync() => isConnectedNative() != 0;
|
||||
bool isConnectedSync() => monero.Wallet_connected(wptr!) != 0;
|
||||
|
||||
bool setupNodeSync(
|
||||
{required String address,
|
||||
|
@ -163,96 +34,64 @@ bool setupNodeSync(
|
|||
bool useSSL = false,
|
||||
bool isLightWallet = false,
|
||||
String? socksProxyAddress}) {
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
Pointer<Utf8>? loginPointer;
|
||||
Pointer<Utf8>? socksProxyAddressPointer;
|
||||
Pointer<Utf8>? passwordPointer;
|
||||
|
||||
if (login != null) {
|
||||
loginPointer = login.toNativeUtf8();
|
||||
monero.Wallet_init(
|
||||
wptr!,
|
||||
daemonAddress: address,
|
||||
useSsl: useSSL,
|
||||
proxyAddress: socksProxyAddress ?? '',
|
||||
daemonUsername: login ?? '',
|
||||
daemonPassword: password ?? ''
|
||||
);
|
||||
// monero.Wallet_init3(wptr!, argv0: '', defaultLogBaseName: 'moneroc', console: true);
|
||||
monero.Wallet_startRefresh(wptr!);
|
||||
monero.Wallet_refreshAsync(wptr!);
|
||||
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
|
||||
if (status == 0) {
|
||||
throw SetupWalletException(message: monero.Wallet_errorString(wptr!));
|
||||
}
|
||||
|
||||
if (password != null) {
|
||||
passwordPointer = password.toNativeUtf8();
|
||||
}
|
||||
|
||||
if (socksProxyAddress != null) {
|
||||
socksProxyAddressPointer = socksProxyAddress.toNativeUtf8();
|
||||
}
|
||||
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isSetupNode = setupNodeNative(
|
||||
addressPointer,
|
||||
loginPointer,
|
||||
passwordPointer,
|
||||
_boolToInt(useSSL),
|
||||
_boolToInt(isLightWallet),
|
||||
socksProxyAddressPointer,
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
calloc.free(addressPointer);
|
||||
|
||||
if (loginPointer != null) {
|
||||
calloc.free(loginPointer);
|
||||
}
|
||||
|
||||
if (passwordPointer != null) {
|
||||
calloc.free(passwordPointer);
|
||||
}
|
||||
|
||||
if (!isSetupNode) {
|
||||
throw SetupWalletException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
}
|
||||
|
||||
return isSetupNode;
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
void startRefreshSync() => startRefreshNative();
|
||||
void startRefreshSync() {}
|
||||
|
||||
Future<bool> connectToNode() async => connecToNodeNative() != 0;
|
||||
Future<bool> connectToNode() async {
|
||||
return true;
|
||||
}
|
||||
|
||||
void setRefreshFromBlockHeight({required int height}) =>
|
||||
setRefreshFromBlockHeightNative(height);
|
||||
void setRefreshFromBlockHeight({required int height}) => monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height);
|
||||
|
||||
void setRecoveringFromSeed({required bool isRecovery}) =>
|
||||
setRecoveringFromSeedNative(_boolToInt(isRecovery));
|
||||
void setRecoveringFromSeed({required bool isRecovery}) => monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery);
|
||||
|
||||
void storeSync() {
|
||||
final pathPointer = ''.toNativeUtf8();
|
||||
storeNative(pathPointer);
|
||||
calloc.free(pathPointer);
|
||||
monero.Wallet_store(wptr!);
|
||||
}
|
||||
|
||||
void setPasswordSync(String password) {
|
||||
final passwordPointer = password.toNativeUtf8();
|
||||
final errorMessagePointer = calloc<Utf8Box>();
|
||||
final changed = setPasswordNative(passwordPointer, errorMessagePointer) != 0;
|
||||
calloc.free(passwordPointer);
|
||||
|
||||
if (!changed) {
|
||||
final message = errorMessagePointer.ref.getValue();
|
||||
calloc.free(errorMessagePointer);
|
||||
throw Exception(message);
|
||||
}
|
||||
monero.Wallet_setPassword(wptr!, password: password);
|
||||
|
||||
calloc.free(errorMessagePointer);
|
||||
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status == 0) {
|
||||
throw Exception(monero.Wallet_errorString(wptr!));
|
||||
}
|
||||
}
|
||||
|
||||
void closeCurrentWallet() => closeCurrentWalletNative();
|
||||
void closeCurrentWallet() {
|
||||
monero.Wallet_store(wptr!);
|
||||
monero.Wallet_stop(wptr!);
|
||||
}
|
||||
|
||||
String getSecretViewKey() =>
|
||||
convertUTF8ToString(pointer: getSecretViewKeyNative());
|
||||
String getSecretViewKey() => monero.Wallet_secretViewKey(wptr!);
|
||||
|
||||
String getPublicViewKey() =>
|
||||
convertUTF8ToString(pointer: getPublicViewKeyNative());
|
||||
String getPublicViewKey() => monero.Wallet_publicViewKey(wptr!);
|
||||
|
||||
String getSecretSpendKey() =>
|
||||
convertUTF8ToString(pointer: getSecretSpendKeyNative());
|
||||
String getSecretSpendKey() => monero.Wallet_secretSpendKey(wptr!);
|
||||
|
||||
String getPublicSpendKey() =>
|
||||
convertUTF8ToString(pointer: getPublicSpendKeyNative());
|
||||
String getPublicSpendKey() => monero.Wallet_publicSpendKey(wptr!);
|
||||
|
||||
class SyncListener {
|
||||
SyncListener(this.onNewBlock, this.onNewTransaction)
|
||||
|
@ -324,11 +163,11 @@ class SyncListener {
|
|||
SyncListener setListeners(void Function(int, int, double) onNewBlock,
|
||||
void Function() onNewTransaction) {
|
||||
final listener = SyncListener(onNewBlock, onNewTransaction);
|
||||
setListenerNative();
|
||||
// setListenerNative();
|
||||
return listener;
|
||||
}
|
||||
|
||||
void onStartup() => onStartupNative();
|
||||
void onStartup() {}
|
||||
|
||||
void _storeSync(Object _) => storeSync();
|
||||
|
||||
|
@ -361,8 +200,8 @@ Future<void> setupNode(
|
|||
String? password,
|
||||
bool useSSL = false,
|
||||
String? socksProxyAddress,
|
||||
bool isLightWallet = false}) =>
|
||||
compute<Map<String, Object?>, void>(_setupNodeSync, {
|
||||
bool isLightWallet = false}) async =>
|
||||
_setupNodeSync({
|
||||
'address': address,
|
||||
'login': login ,
|
||||
'password': password,
|
||||
|
@ -371,29 +210,22 @@ Future<void> setupNode(
|
|||
'socksProxyAddress': socksProxyAddress
|
||||
});
|
||||
|
||||
Future<void> store() => compute<int, void>(_storeSync, 0);
|
||||
Future<void> store() async => _storeSync(0);
|
||||
|
||||
Future<bool> isConnected() => compute(_isConnected, 0);
|
||||
Future<bool> isConnected() async => _isConnected(0);
|
||||
|
||||
Future<int> getNodeHeight() => compute(_getNodeHeight, 0);
|
||||
Future<int> getNodeHeight() async => _getNodeHeight(0);
|
||||
|
||||
void rescanBlockchainAsync() => rescanBlockchainAsyncNative();
|
||||
void rescanBlockchainAsync() => monero.Wallet_rescanBlockchainAsync(wptr!);
|
||||
|
||||
String getSubaddressLabel(int accountIndex, int addressIndex) {
|
||||
return convertUTF8ToString(pointer: getSubaddressLabelNative(accountIndex, addressIndex));
|
||||
return monero.Wallet_getSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: addressIndex);
|
||||
}
|
||||
|
||||
Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted));
|
||||
Future setTrustedDaemon(bool trusted) async => monero.Wallet_setTrustedDaemon(wptr!, arg: trusted);
|
||||
|
||||
Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;
|
||||
Future<bool> trustedDaemon() async => monero.Wallet_trustedDaemon(wptr!);
|
||||
|
||||
String signMessage(String message, {String address = ""}) {
|
||||
final messagePointer = message.toNativeUtf8();
|
||||
final addressPointer = address.toNativeUtf8();
|
||||
|
||||
final signature = convertUTF8ToString(pointer: signMessageNative(messagePointer, addressPointer));
|
||||
calloc.free(messagePointer);
|
||||
calloc.free(addressPointer);
|
||||
|
||||
return signature;
|
||||
return monero.Wallet_signMessage(wptr!, message: message, address: address);
|
||||
}
|
||||
|
|
|
@ -1,80 +1,44 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:cw_monero/api/convert_utf8_to_string.dart';
|
||||
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';
|
||||
import 'package:cw_monero/api/exceptions/wallet_restore_from_keys_exception.dart';
|
||||
import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_exception.dart';
|
||||
import 'package:cw_monero/api/monero_api.dart';
|
||||
import 'package:cw_monero/api/signatures.dart';
|
||||
import 'package:cw_monero/api/types.dart';
|
||||
import 'package:cw_monero/api/wallet.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
import 'dart:ffi';
|
||||
|
||||
final createWalletNative = moneroApi
|
||||
.lookup<NativeFunction<create_wallet>>('create_wallet')
|
||||
.asFunction<CreateWallet>();
|
||||
|
||||
final restoreWalletFromSeedNative = moneroApi
|
||||
.lookup<NativeFunction<restore_wallet_from_seed>>(
|
||||
'restore_wallet_from_seed')
|
||||
.asFunction<RestoreWalletFromSeed>();
|
||||
|
||||
final restoreWalletFromKeysNative = moneroApi
|
||||
.lookup<NativeFunction<restore_wallet_from_keys>>(
|
||||
'restore_wallet_from_keys')
|
||||
.asFunction<RestoreWalletFromKeys>();
|
||||
|
||||
final restoreWalletFromSpendKeyNative = moneroApi
|
||||
.lookup<NativeFunction<restore_wallet_from_spend_key>>(
|
||||
'restore_wallet_from_spend_key')
|
||||
.asFunction<RestoreWalletFromSpendKey>();
|
||||
|
||||
final isWalletExistNative = moneroApi
|
||||
.lookup<NativeFunction<is_wallet_exist>>('is_wallet_exist')
|
||||
.asFunction<IsWalletExist>();
|
||||
|
||||
final loadWalletNative = moneroApi
|
||||
.lookup<NativeFunction<load_wallet>>('load_wallet')
|
||||
.asFunction<LoadWallet>();
|
||||
|
||||
final errorStringNative = moneroApi
|
||||
.lookup<NativeFunction<error_string>>('error_string')
|
||||
.asFunction<ErrorString>();
|
||||
monero.WalletManager? _wmPtr;
|
||||
final monero.WalletManager wmPtr = Pointer.fromAddress((() {
|
||||
try {
|
||||
monero.printStarts = true;
|
||||
_wmPtr ??= monero.WalletManagerFactory_getWalletManager();
|
||||
print("ptr: $_wmPtr");
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
return _wmPtr!.address;
|
||||
})());
|
||||
|
||||
void 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();
|
||||
final isWalletCreated = createWalletNative(pathPointer, passwordPointer,
|
||||
languagePointer, nettype, errorMessagePointer) !=
|
||||
0;
|
||||
wptr = monero.WalletManager_createWallet(wmPtr, path: path, password: password, language: language);
|
||||
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(languagePointer);
|
||||
|
||||
if (!isWalletCreated) {
|
||||
throw WalletCreationException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status != 0) {
|
||||
throw WalletCreationException(message: monero.Wallet_errorString(wptr!));
|
||||
}
|
||||
|
||||
// is the line below needed?
|
||||
// setupNodeSync(address: "node.moneroworld.com:18089");
|
||||
}
|
||||
|
||||
bool isWalletExistSync({required String path}) {
|
||||
final pathPointer = path.toNativeUtf8();
|
||||
final isExist = isWalletExistNative(pathPointer) != 0;
|
||||
|
||||
calloc.free(pathPointer);
|
||||
|
||||
return isExist;
|
||||
return monero.WalletManager_walletExists(wmPtr, path);
|
||||
}
|
||||
|
||||
void restoreWalletFromSeedSync(
|
||||
|
@ -87,22 +51,20 @@ void restoreWalletFromSeedSync(
|
|||
final passwordPointer = password.toNativeUtf8();
|
||||
final seedPointer = seed.toNativeUtf8();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isWalletRestored = restoreWalletFromSeedNative(
|
||||
pathPointer,
|
||||
passwordPointer,
|
||||
seedPointer,
|
||||
nettype,
|
||||
restoreHeight,
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(seedPointer);
|
||||
wptr = monero.WalletManager_recoveryWallet(
|
||||
wmPtr,
|
||||
path: path,
|
||||
password: password,
|
||||
mnemonic: seed,
|
||||
restoreHeight: restoreHeight,
|
||||
seedOffset: '',
|
||||
);
|
||||
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
|
||||
if (!isWalletRestored) {
|
||||
throw WalletRestoreFromSeedException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
if (status != 0) {
|
||||
throw WalletRestoreFromSeedException(message: monero.Wallet_errorString(wptr!));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,28 +84,19 @@ void restoreWalletFromKeysSync(
|
|||
final viewKeyPointer = viewKey.toNativeUtf8();
|
||||
final spendKeyPointer = spendKey.toNativeUtf8();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isWalletRestored = restoreWalletFromKeysNative(
|
||||
pathPointer,
|
||||
passwordPointer,
|
||||
languagePointer,
|
||||
addressPointer,
|
||||
viewKeyPointer,
|
||||
spendKeyPointer,
|
||||
nettype,
|
||||
restoreHeight,
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(languagePointer);
|
||||
calloc.free(addressPointer);
|
||||
calloc.free(viewKeyPointer);
|
||||
calloc.free(spendKeyPointer);
|
||||
|
||||
if (!isWalletRestored) {
|
||||
throw WalletRestoreFromKeysException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
wptr = monero.WalletManager_createWalletFromKeys(
|
||||
wmPtr,
|
||||
path: path,
|
||||
password: password,
|
||||
restoreHeight: restoreHeight,
|
||||
addressString: address,
|
||||
viewKeyString: viewKey,
|
||||
spendKeyString: spendKey,
|
||||
);
|
||||
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status != 0) {
|
||||
throw WalletRestoreFromKeysException(message: monero.Wallet_errorString(wptr!));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,43 +114,40 @@ void restoreWalletFromSpendKeySync(
|
|||
final languagePointer = language.toNativeUtf8();
|
||||
final spendKeyPointer = spendKey.toNativeUtf8();
|
||||
final errorMessagePointer = ''.toNativeUtf8();
|
||||
final isWalletRestored = restoreWalletFromSpendKeyNative(
|
||||
pathPointer,
|
||||
passwordPointer,
|
||||
seedPointer,
|
||||
languagePointer,
|
||||
spendKeyPointer,
|
||||
nettype,
|
||||
restoreHeight,
|
||||
errorMessagePointer) !=
|
||||
0;
|
||||
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
calloc.free(languagePointer);
|
||||
calloc.free(spendKeyPointer);
|
||||
wptr = monero.WalletManager_createWalletFromKeys(
|
||||
wmPtr,
|
||||
path: path,
|
||||
password: password,
|
||||
restoreHeight: restoreHeight,
|
||||
addressString: '',
|
||||
spendKeyString: spendKey,
|
||||
viewKeyString: '',
|
||||
);
|
||||
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
|
||||
if (status == 0) {
|
||||
throw WalletRestoreFromKeysException(message: monero.Wallet_errorString(wptr!));
|
||||
}
|
||||
|
||||
storeSync();
|
||||
|
||||
if (!isWalletRestored) {
|
||||
throw WalletRestoreFromKeysException(
|
||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
calloc.free(pathPointer);
|
||||
calloc.free(passwordPointer);
|
||||
|
||||
if (!loaded) {
|
||||
throw WalletOpeningException(
|
||||
message: convertUTF8ToString(pointer: errorStringNative()));
|
||||
try {
|
||||
wptr ??= monero.WalletManager_openWallet(wmPtr, path: path, password: password);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status != 0) {
|
||||
final err = monero.Wallet_errorString(wptr!);
|
||||
print(err);
|
||||
throw WalletOpeningException(message: err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,20 +208,20 @@ void _restoreFromSpendKey(Map<String, dynamic> args) {
|
|||
Future<void> _openWallet(Map<String, String> args) async =>
|
||||
loadWallet(path: args['path'] as String, password: args['password'] as String);
|
||||
|
||||
bool _isWalletExist(String path) => isWalletExistSync(path: path);
|
||||
Future<bool> _isWalletExist(String path) async => isWalletExistSync(path: path);
|
||||
|
||||
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);
|
||||
_openWallet(args);
|
||||
|
||||
Future<void> createWallet(
|
||||
{required String path,
|
||||
required String password,
|
||||
required String language,
|
||||
int nettype = 0}) async =>
|
||||
compute(_createWallet, {
|
||||
_createWallet({
|
||||
'path': path,
|
||||
'password': password,
|
||||
'language': language,
|
||||
|
@ -284,7 +234,7 @@ Future<void> restoreFromSeed(
|
|||
required String seed,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) async =>
|
||||
compute<Map<String, Object>, void>(_restoreFromSeed, {
|
||||
_restoreFromSeed({
|
||||
'path': path,
|
||||
'password': password,
|
||||
'seed': seed,
|
||||
|
@ -301,7 +251,7 @@ Future<void> restoreFromKeys(
|
|||
required String spendKey,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) async =>
|
||||
compute<Map<String, Object>, void>(_restoreFromKeys, {
|
||||
_restoreFromKeys({
|
||||
'path': path,
|
||||
'password': password,
|
||||
'language': language,
|
||||
|
@ -320,7 +270,7 @@ Future<void> restoreFromSpendKey(
|
|||
required String spendKey,
|
||||
int nettype = 0,
|
||||
int restoreHeight = 0}) async =>
|
||||
compute<Map<String, Object>, void>(_restoreFromSpendKey, {
|
||||
_restoreFromSpendKey({
|
||||
'path': path,
|
||||
'password': password,
|
||||
'seed': seed,
|
||||
|
@ -330,4 +280,4 @@ Future<void> restoreFromSpendKey(
|
|||
'restoreHeight': restoreHeight
|
||||
});
|
||||
|
||||
Future<bool> isWalletExist({required String path}) => compute(_isWalletExist, path);
|
||||
Future<bool> isWalletExist({required String path}) => _isWalletExist(path);
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'package:cw_core/monero_amount_format.dart';
|
|||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/account.dart';
|
||||
import 'package:cw_monero/api/account_list.dart' as account_list;
|
||||
import 'package:cw_monero/api/wallet.dart' as monero_wallet;
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
part 'monero_account_list.g.dart';
|
||||
|
||||
|
@ -44,13 +44,12 @@ abstract class MoneroAccountListBase with Store {
|
|||
}
|
||||
|
||||
List<Account> getAll() => account_list.getAllAccount().map((accountRow) {
|
||||
final accountIndex = accountRow.getId();
|
||||
final balance = monero_wallet.getFullBalance(accountIndex: accountIndex);
|
||||
final balance = monero.SubaddressAccountRow_getUnlockedBalance(accountRow);
|
||||
|
||||
return Account(
|
||||
id: accountRow.getId(),
|
||||
label: accountRow.getLabel(),
|
||||
balance: moneroAmountToString(amount: balance),
|
||||
id: monero.SubaddressAccountRow_getRowId(accountRow),
|
||||
label: monero.SubaddressAccountRow_getLabel(accountRow),
|
||||
balance: moneroAmountToString(amount: monero.Wallet_amountFromString(balance)),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:mobx/mobx.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;
|
||||
|
||||
part 'monero_subaddress_list.g.dart';
|
||||
|
||||
|
@ -51,18 +52,21 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
}
|
||||
|
||||
return subaddresses.map((subaddressRow) {
|
||||
final label = monero.SubaddressRow_getLabel(subaddressRow);
|
||||
final id = monero.SubaddressRow_getRowId(subaddressRow);
|
||||
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||
final hasDefaultAddressName =
|
||||
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase() ||
|
||||
subaddressRow.getLabel().toLowerCase() == 'Untitled account'.toLowerCase();
|
||||
final isPrimaryAddress = subaddressRow.getId() == 0 && hasDefaultAddressName;
|
||||
label.toLowerCase() == 'Primary account'.toLowerCase() ||
|
||||
label.toLowerCase() == 'Untitled account'.toLowerCase();
|
||||
final isPrimaryAddress = id == 0 && hasDefaultAddressName;
|
||||
return Subaddress(
|
||||
id: subaddressRow.getId(),
|
||||
address: subaddressRow.getAddress(),
|
||||
id: id,
|
||||
address: address,
|
||||
label: isPrimaryAddress
|
||||
? 'Primary address'
|
||||
: hasDefaultAddressName
|
||||
? ''
|
||||
: subaddressRow.getLabel());
|
||||
: label);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
|
@ -121,8 +125,8 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
Future<List<Subaddress>> _getAllUnusedAddresses(
|
||||
{required int accountIndex, required String label}) async {
|
||||
final allAddresses = subaddress_list.getAllSubaddresses();
|
||||
|
||||
if (allAddresses.isEmpty || _usedAddresses.contains(allAddresses.last.getAddress())) {
|
||||
final lastAddress = monero.SubaddressRow_getAddress(allAddresses.last);
|
||||
if (allAddresses.isEmpty || _usedAddresses.contains(lastAddress)) {
|
||||
final isAddressUnused = await _newSubaddress(accountIndex: accountIndex, label: label);
|
||||
if (!isAddressUnused) {
|
||||
return await _getAllUnusedAddresses(accountIndex: accountIndex, label: label);
|
||||
|
@ -130,13 +134,18 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
}
|
||||
|
||||
return allAddresses
|
||||
.map((subaddressRow) => Subaddress(
|
||||
id: subaddressRow.getId(),
|
||||
address: subaddressRow.getAddress(),
|
||||
label: subaddressRow.getId() == 0 &&
|
||||
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase()
|
||||
.map((subaddressRow) {
|
||||
final id = monero.SubaddressRow_getRowId(subaddressRow);
|
||||
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||
final label = monero.SubaddressRow_getLabel(subaddressRow);
|
||||
return Subaddress(
|
||||
id: id,
|
||||
address: address,
|
||||
label: id == 0 &&
|
||||
label.toLowerCase() == 'Primary account'.toLowerCase()
|
||||
? 'Primary address'
|
||||
: subaddressRow.getLabel()))
|
||||
: label);
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
@ -145,7 +154,10 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
|
||||
return subaddress_list
|
||||
.getAllSubaddresses()
|
||||
.where((subaddressRow) => !_usedAddresses.contains(subaddressRow.getAddress()))
|
||||
.where((subaddressRow) {
|
||||
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||
return !_usedAddresses.contains(address);
|
||||
})
|
||||
.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:cw_core/node.dart';
|
|||
import 'package:cw_core/pathForWallet.dart';
|
||||
import 'package:cw_core/pending_transaction.dart';
|
||||
import 'package:cw_core/sync_status.dart';
|
||||
import 'package:cw_core/transaction_direction.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
|
@ -32,6 +33,7 @@ import 'package:cw_monero/pending_monero_transaction.dart';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
|
||||
part 'monero_wallet.g.dart';
|
||||
|
||||
|
@ -417,10 +419,18 @@ abstract class MoneroWalletBase
|
|||
final coinCount = countOfCoins();
|
||||
for (var i = 0; i < coinCount; i++) {
|
||||
final coin = getCoin(i);
|
||||
if (coin.spent == 0) {
|
||||
final unspent = MoneroUnspent.fromCoinsInfoRow(coin);
|
||||
final coinSpent = monero.CoinsInfo_spent(coin);
|
||||
if (coinSpent == 0) {
|
||||
final unspent = MoneroUnspent(
|
||||
monero.CoinsInfo_address(coin),
|
||||
monero.CoinsInfo_hash(coin),
|
||||
monero.CoinsInfo_keyImage(coin),
|
||||
monero.CoinsInfo_amount(coin),
|
||||
monero.CoinsInfo_frozen(coin),
|
||||
monero.CoinsInfo_unlocked(coin),
|
||||
);
|
||||
if (unspent.hash.isNotEmpty) {
|
||||
unspent.isChange = transaction_history.getTransaction(unspent.hash).direction == 1;
|
||||
unspent.isChange = transaction_history.getTransaction(unspent.hash) == 1;
|
||||
}
|
||||
unspentCoins.add(unspent);
|
||||
}
|
||||
|
@ -541,7 +551,17 @@ abstract class MoneroWalletBase
|
|||
|
||||
List<MoneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) => transaction_history
|
||||
.getAllTransactions()
|
||||
.map((row) => MoneroTransactionInfo.fromRow(row))
|
||||
.map((row) => MoneroTransactionInfo(
|
||||
row.hash,
|
||||
row.blockheight,
|
||||
row.isSpend ? TransactionDirection.outgoing : TransactionDirection.incoming,
|
||||
row.timeStamp,
|
||||
row.isPending,
|
||||
row.amount,
|
||||
row.accountIndex,
|
||||
0,
|
||||
row.fee,
|
||||
row.confirmations))
|
||||
.where((element) => element.accountIndex == (accountIndex ?? 0))
|
||||
.toList();
|
||||
|
||||
|
|
|
@ -204,10 +204,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: ffi
|
||||
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
|
||||
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.1.0"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -410,6 +410,15 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
monero:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "08c5a32cbcf1f04dbae5826c83abda8fb0dbdcce"
|
||||
url: "https://git.mrcyjanek.net/mrcyjanek/monero.dart"
|
||||
source: git
|
||||
version: "0.0.0"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -22,6 +22,10 @@ dependencies:
|
|||
polyseed: ^0.0.2
|
||||
cw_core:
|
||||
path: ../cw_core
|
||||
monero:
|
||||
git:
|
||||
url: https://git.mrcyjanek.net/mrcyjanek/monero.dart
|
||||
ref: master
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -111,7 +111,10 @@ dependencies:
|
|||
git:
|
||||
url: https://github.com/cake-tech/bitcoin_base.git
|
||||
ref: cake-update-v2
|
||||
|
||||
monero:
|
||||
git:
|
||||
url: https://git.mrcyjanek.net/mrcyjanek/monero.dart
|
||||
ref: master
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
|
Loading…
Reference in a new issue