mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-11 05:14:46 +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:fullBackupContent="false"
|
||||||
android:versionCode="__versionCode__"
|
android:versionCode="__versionCode__"
|
||||||
android:versionName="__versionName__"
|
android:versionName="__versionName__"
|
||||||
android:requestLegacyExternalStorage="true">
|
android:requestLegacyExternalStorage="true"
|
||||||
|
android:extractNativeLibs="true">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:launchMode="singleInstance"
|
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/types.dart';
|
||||||
import 'package:cw_haven/api/haven_api.dart';
|
import 'package:cw_haven/api/haven_api.dart';
|
||||||
import 'package:cw_haven/api/structs/account_row.dart';
|
import 'package:cw_haven/api/structs/account_row.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:cw_haven/api/wallet.dart';
|
import 'package:cw_haven/api/wallet.dart';
|
||||||
|
|
||||||
final accountSizeNative = havenApi
|
final accountSizeNative = havenApi
|
||||||
|
@ -72,12 +71,11 @@ void _setLabelForAccount(Map<String, dynamic> args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addAccount({required String label}) async {
|
Future<void> addAccount({required String label}) async {
|
||||||
await compute(_addAccount, label);
|
_addAccount(label);
|
||||||
await store();
|
await store();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
||||||
await compute(
|
_setLabelForAccount({'accountIndex': accountIndex, 'label': label});
|
||||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
|
||||||
await store();
|
await store();
|
||||||
}
|
}
|
|
@ -115,10 +115,10 @@ packages:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: ffi
|
name: ffi
|
||||||
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
|
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.1.0"
|
||||||
file:
|
file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -241,6 +241,15 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3+1"
|
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:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
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:cw_monero/api/wallet.dart';
|
||||||
|
import 'package:monero/monero.dart' as monero;
|
||||||
|
|
||||||
final accountSizeNative = moneroApi
|
monero.wallet? wptr = null;
|
||||||
.lookup<NativeFunction<account_size>>('account_size')
|
monero.SubaddressAccount? account;
|
||||||
.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>();
|
|
||||||
|
|
||||||
bool isUpdating = false;
|
bool isUpdating = false;
|
||||||
|
|
||||||
void refreshAccounts() {
|
void refreshAccounts() {
|
||||||
try {
|
try {
|
||||||
isUpdating = true;
|
isUpdating = true;
|
||||||
accountRefreshNative();
|
account = monero.Wallet_subaddressAccount(wptr!);
|
||||||
|
monero.SubaddressAccount_refresh(account!);
|
||||||
isUpdating = false;
|
isUpdating = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isUpdating = false;
|
isUpdating = false;
|
||||||
|
@ -40,26 +18,22 @@ void refreshAccounts() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AccountRow> getAllAccount() {
|
List<monero.SubaddressAccountRow> getAllAccount() {
|
||||||
final size = accountSizeNative();
|
// final size = monero.Wallet_numSubaddressAccounts(wptr!);
|
||||||
final accountAddressesPointer = accountGetAllNative();
|
final size = monero.SubaddressAccount_getAll_size(wptr!);
|
||||||
final accountAddresses = accountAddressesPointer.asTypedList(size);
|
|
||||||
|
|
||||||
return accountAddresses
|
return List.generate(size, (index) {
|
||||||
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
|
return monero.SubaddressAccount_getAll_byIndex(wptr!, index: index);
|
||||||
.toList();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void addAccountSync({required String label}) {
|
void addAccountSync({required String label}) {
|
||||||
final labelPointer = label.toNativeUtf8();
|
monero.Wallet_addSubaddressAccount(wptr!, label: label);
|
||||||
accountAddNewNative(labelPointer);
|
|
||||||
calloc.free(labelPointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLabelForAccountSync({required int accountIndex, required String label}) {
|
void setLabelForAccountSync({required int accountIndex, required String label}) {
|
||||||
final labelPointer = label.toNativeUtf8();
|
// TODO(mrcyjanek): this may be wrong function?
|
||||||
accountSetLabelNative(accountIndex, labelPointer);
|
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: 0, label: label);
|
||||||
calloc.free(labelPointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addAccount(String label) => addAccountSync(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 {
|
Future<void> addAccount({required String label}) async {
|
||||||
await compute(_addAccount, label);
|
_addAccount(label);
|
||||||
await store();
|
await store();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
Future<void> setLabelForAccount({required int accountIndex, required String label}) async {
|
||||||
await compute(
|
_setLabelForAccount({'accountIndex': accountIndex, 'label': label});
|
||||||
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
|
||||||
await store();
|
await store();
|
||||||
}
|
}
|
|
@ -1,35 +1,17 @@
|
||||||
import 'dart:ffi';
|
import 'package:cw_monero/api/account_list.dart';
|
||||||
import 'package:cw_monero/api/signatures.dart';
|
import 'package:monero/monero.dart' as monero;
|
||||||
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';
|
|
||||||
|
|
||||||
final refreshCoinsNative = moneroApi
|
monero.Coins? coins = null;
|
||||||
.lookup<NativeFunction<refresh_coins>>('refresh_coins')
|
|
||||||
.asFunction<RefreshCoins>();
|
|
||||||
|
|
||||||
final coinsCountNative = moneroApi
|
void refreshCoins(int accountIndex) {
|
||||||
.lookup<NativeFunction<coins_count>>('coins_count')
|
coins = monero.Wallet_coins(wptr!);
|
||||||
.asFunction<CoinsCount>();
|
monero.Coins_refresh(coins!);
|
||||||
|
}
|
||||||
|
|
||||||
final coinNative = moneroApi
|
int countOfCoins() => monero.Coins_count(coins!);
|
||||||
.lookup<NativeFunction<coin>>('coin')
|
|
||||||
.asFunction<GetCoin>();
|
|
||||||
|
|
||||||
final freezeCoinNative = moneroApi
|
monero.CoinsInfo getCoin(int index) => monero.Coins_coin(coins!, index);
|
||||||
.lookup<NativeFunction<freeze_coin>>('freeze_coin')
|
|
||||||
.asFunction<FreezeCoin>();
|
|
||||||
|
|
||||||
final thawCoinNative = moneroApi
|
void freezeCoin(int index) => monero.Coins_setFrozen(coins!, index: index);
|
||||||
.lookup<NativeFunction<thaw_coin>>('thaw_coin')
|
|
||||||
.asFunction<ThawCoin>();
|
|
||||||
|
|
||||||
void refreshCoins(int accountIndex) => refreshCoinsNative(accountIndex);
|
void thawCoin(int index) => monero.Coins_thaw(coins!, index: index);
|
||||||
|
|
||||||
int countOfCoins() => coinsCountNative();
|
|
||||||
|
|
||||||
CoinsInfoRow getCoin(int index) => coinNative(index).ref;
|
|
||||||
|
|
||||||
void freezeCoin(int index) => freezeCoinNative(index);
|
|
||||||
|
|
||||||
void thawCoin(int index) => thawCoinNative(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:cw_monero/api/account_list.dart';
|
||||||
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/wallet.dart';
|
import 'package:cw_monero/api/wallet.dart';
|
||||||
|
import 'package:monero/monero.dart' as monero;
|
||||||
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>();
|
|
||||||
|
|
||||||
bool isUpdating = false;
|
bool isUpdating = false;
|
||||||
|
monero.AddressBook? addressbook = null;
|
||||||
void refreshSubaddresses({required int accountIndex}) {
|
void refreshSubaddresses({required int accountIndex}) {
|
||||||
try {
|
try {
|
||||||
isUpdating = true;
|
isUpdating = true;
|
||||||
subaddressRefreshNative(accountIndex);
|
addressbook = monero.Wallet_subaddressAccount(wptr!);
|
||||||
|
monero.AddressBook_refresh(addressbook!);
|
||||||
isUpdating = false;
|
isUpdating = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isUpdating = false;
|
isUpdating = false;
|
||||||
|
@ -40,28 +16,21 @@ void refreshSubaddresses({required int accountIndex}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SubaddressRow> getAllSubaddresses() {
|
List<monero.SubaddressRow> getAllSubaddresses() {
|
||||||
final size = subaddressSizeNative();
|
final size = monero.AddressBook_getAll_size(addressbook!);
|
||||||
final subaddressAddressesPointer = subaddrressGetAllNative();
|
|
||||||
final subaddressAddresses = subaddressAddressesPointer.asTypedList(size);
|
|
||||||
|
|
||||||
return subaddressAddresses
|
return List.generate(size, (index) {
|
||||||
.map((addr) => Pointer<SubaddressRow>.fromAddress(addr).ref)
|
return monero.Subaddress_getAll_byIndex(wptr!, index: index);
|
||||||
.toList();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSubaddressSync({required int accountIndex, required String label}) {
|
void addSubaddressSync({required int accountIndex, required String label}) {
|
||||||
final labelPointer = label.toNativeUtf8();
|
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex, label: label);
|
||||||
subaddrressAddNewNative(accountIndex, labelPointer);
|
|
||||||
calloc.free(labelPointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLabelForSubaddressSync(
|
void setLabelForSubaddressSync(
|
||||||
{required int accountIndex, required int addressIndex, required String label}) {
|
{required int accountIndex, required int addressIndex, required String label}) {
|
||||||
final labelPointer = label.toNativeUtf8();
|
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
||||||
|
|
||||||
subaddrressSetLabelNative(accountIndex, addressIndex, labelPointer);
|
|
||||||
calloc.free(labelPointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addSubaddress(Map<String, dynamic> args) {
|
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 {
|
Future<void> addSubaddress({required int accountIndex, required String label}) async {
|
||||||
await compute<Map<String, Object>, void>(
|
_addSubaddress({'accountIndex': accountIndex, 'label': label});
|
||||||
_addSubaddress, {'accountIndex': accountIndex, 'label': label});
|
await store();
|
||||||
await store();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setLabelForSubaddress(
|
Future<void> setLabelForSubaddress(
|
||||||
{required int accountIndex, required int addressIndex, required String label}) async {
|
{required int accountIndex, required int addressIndex, required String label}) async {
|
||||||
await compute<Map<String, Object>, void>(_setLabelForSubaddress, {
|
_setLabelForSubaddress({
|
||||||
'accountIndex': accountIndex,
|
'accountIndex': accountIndex,
|
||||||
'addressIndex': addressIndex,
|
'addressIndex': addressIndex,
|
||||||
'label': label
|
'label': label
|
||||||
|
|
|
@ -1,78 +1,35 @@
|
||||||
import 'dart:ffi';
|
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/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/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/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: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) {
|
String getTxKey(String txId) {
|
||||||
final txIdPointer = txId.toNativeUtf8();
|
return monero.Wallet_getTxKey(wptr!, txid: txId);
|
||||||
final keyPointer = getTxKeyNative(txIdPointer);
|
|
||||||
|
|
||||||
calloc.free(txIdPointer);
|
|
||||||
|
|
||||||
if (keyPointer != null) {
|
|
||||||
return convertUTF8ToString(pointer: keyPointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshTransactions() => transactionsRefreshNative();
|
monero.TransactionHistory? txhistory;
|
||||||
|
|
||||||
int countOfTransactions() => transactionsCountNative();
|
void refreshTransactions() {
|
||||||
|
txhistory = monero.Wallet_history(wptr!);
|
||||||
List<TransactionInfoRow> getAllTransactions() {
|
monero.TransactionHistory_refresh(txhistory!);
|
||||||
final size = transactionsCountNative();
|
|
||||||
final transactionsPointer = transactionsGetAllNative();
|
|
||||||
final transactionsAddresses = transactionsPointer.asTypedList(size);
|
|
||||||
|
|
||||||
return transactionsAddresses
|
|
||||||
.map((addr) => Pointer<TransactionInfoRow>.fromAddress(addr).ref)
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionInfoRow getTransaction(String txId) {
|
int countOfTransactions() => monero.TransactionHistory_count(txhistory!);
|
||||||
final txIdPointer = txId.toNativeUtf8();
|
|
||||||
return getTransactionNative(txIdPointer).ref;
|
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(
|
PendingTransactionDescription createTransactionSync(
|
||||||
|
@ -82,8 +39,6 @@ PendingTransactionDescription createTransactionSync(
|
||||||
String? amount,
|
String? amount,
|
||||||
int accountIndex = 0,
|
int accountIndex = 0,
|
||||||
List<String> preferredInputs = const []}) {
|
List<String> preferredInputs = const []}) {
|
||||||
final addressPointer = address.toNativeUtf8();
|
|
||||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
|
||||||
final amountPointer = amount != null ? amount.toNativeUtf8() : nullptr;
|
final amountPointer = amount != null ? amount.toNativeUtf8() : nullptr;
|
||||||
|
|
||||||
final int preferredInputsSize = preferredInputs.length;
|
final int preferredInputsSize = preferredInputs.length;
|
||||||
|
@ -95,44 +50,38 @@ PendingTransactionDescription createTransactionSync(
|
||||||
preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
final errorMessagePointer = calloc<Utf8Box>();
|
final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount);
|
||||||
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
final pendingTx = monero.Wallet_createTransaction(
|
||||||
final created = transactionCreateNative(
|
wptr!,
|
||||||
addressPointer,
|
dst_addr: address,
|
||||||
paymentIdPointer,
|
payment_id: paymentId,
|
||||||
amountPointer,
|
amount: amt,
|
||||||
priorityRaw,
|
mixin_count: 1,
|
||||||
accountIndex,
|
pendingTransactionPriority: priorityRaw,
|
||||||
preferredInputsPointerPointer,
|
subaddr_account: accountIndex,
|
||||||
preferredInputsSize,
|
preferredInputs: preferredInputs,
|
||||||
errorMessagePointer,
|
);
|
||||||
pendingTransactionRawPointer) !=
|
final String? error = (() {
|
||||||
0;
|
final status = monero.Wallet_status(wptr!);
|
||||||
|
if (status == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return monero.Wallet_errorString(wptr!);
|
||||||
|
})();
|
||||||
|
|
||||||
calloc.free(preferredInputsPointerPointer);
|
if (error != null) {
|
||||||
|
final message = error;
|
||||||
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);
|
|
||||||
throw CreationTransactionException(message: message);
|
throw CreationTransactionException(message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PendingTransactionDescription(
|
return PendingTransactionDescription(
|
||||||
amount: pendingTransactionRawPointer.ref.amount,
|
amount: monero.PendingTransaction_amount(wptr!),
|
||||||
fee: pendingTransactionRawPointer.ref.fee,
|
fee: monero.PendingTransaction_fee(wptr!),
|
||||||
hash: pendingTransactionRawPointer.ref.getHash(),
|
hash: monero.PendingTransaction_txid(wptr!, ''),
|
||||||
hex: pendingTransactionRawPointer.ref.getHex(),
|
hex: '',
|
||||||
txKey: pendingTransactionRawPointer.ref.getKey(),
|
txKey: monero.PendingTransaction_txid(wptr!, ''),
|
||||||
pointerAddress: pendingTransactionRawPointer.address);
|
pointerAddress: pendingTx.address,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingTransactionDescription createTransactionMultDestSync(
|
PendingTransactionDescription createTransactionMultDestSync(
|
||||||
|
@ -141,80 +90,88 @@ PendingTransactionDescription createTransactionMultDestSync(
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
int accountIndex = 0,
|
int accountIndex = 0,
|
||||||
List<String> preferredInputs = const []}) {
|
List<String> preferredInputs = const []}) {
|
||||||
final int size = outputs.length;
|
// final int size = outputs.length;
|
||||||
final List<Pointer<Utf8>> addressesPointers =
|
// final List<Pointer<Utf8>> addressesPointers =
|
||||||
outputs.map((output) => output.address.toNativeUtf8()).toList();
|
// outputs.map((output) => output.address.toNativeUtf8()).toList();
|
||||||
final Pointer<Pointer<Utf8>> addressesPointerPointer = calloc(size);
|
// final Pointer<Pointer<Utf8>> addressesPointerPointer = calloc(size);
|
||||||
final List<Pointer<Utf8>> amountsPointers =
|
// final List<Pointer<Utf8>> amountsPointers =
|
||||||
outputs.map((output) => output.amount.toNativeUtf8()).toList();
|
// outputs.map((output) => output.amount.toNativeUtf8()).toList();
|
||||||
final Pointer<Pointer<Utf8>> amountsPointerPointer = calloc(size);
|
// final Pointer<Pointer<Utf8>> amountsPointerPointer = calloc(size);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
// for (int i = 0; i < size; i++) {
|
||||||
addressesPointerPointer[i] = addressesPointers[i];
|
// addressesPointerPointer[i] = addressesPointers[i];
|
||||||
amountsPointerPointer[i] = amountsPointers[i];
|
// amountsPointerPointer[i] = amountsPointers[i];
|
||||||
}
|
// }
|
||||||
|
|
||||||
final int preferredInputsSize = preferredInputs.length;
|
// final int preferredInputsSize = preferredInputs.length;
|
||||||
final List<Pointer<Utf8>> preferredInputsPointers =
|
// final List<Pointer<Utf8>> preferredInputsPointers =
|
||||||
preferredInputs.map((output) => output.toNativeUtf8()).toList();
|
// preferredInputs.map((output) => output.toNativeUtf8()).toList();
|
||||||
final Pointer<Pointer<Utf8>> preferredInputsPointerPointer = calloc(preferredInputsSize);
|
// final Pointer<Pointer<Utf8>> preferredInputsPointerPointer = calloc(preferredInputsSize);
|
||||||
|
|
||||||
for (int i = 0; i < preferredInputsSize; i++) {
|
// for (int i = 0; i < preferredInputsSize; i++) {
|
||||||
preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
// preferredInputsPointerPointer[i] = preferredInputsPointers[i];
|
||||||
}
|
// }
|
||||||
|
|
||||||
final paymentIdPointer = paymentId.toNativeUtf8();
|
// final paymentIdPointer = paymentId.toNativeUtf8();
|
||||||
final errorMessagePointer = calloc<Utf8Box>();
|
// final errorMessagePointer = calloc<Utf8Box>();
|
||||||
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
// final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
||||||
final created = transactionCreateMultDestNative(
|
// final created = transactionCreateMultDestNative(
|
||||||
addressesPointerPointer,
|
// addressesPointerPointer,
|
||||||
paymentIdPointer,
|
// paymentIdPointer,
|
||||||
amountsPointerPointer,
|
// amountsPointerPointer,
|
||||||
size,
|
// size,
|
||||||
priorityRaw,
|
// priorityRaw,
|
||||||
accountIndex,
|
// accountIndex,
|
||||||
preferredInputsPointerPointer,
|
// preferredInputsPointerPointer,
|
||||||
preferredInputsSize,
|
// preferredInputsSize,
|
||||||
errorMessagePointer,
|
// errorMessagePointer,
|
||||||
pendingTransactionRawPointer) !=
|
// pendingTransactionRawPointer) !=
|
||||||
0;
|
// 0;
|
||||||
|
|
||||||
calloc.free(addressesPointerPointer);
|
// calloc.free(addressesPointerPointer);
|
||||||
calloc.free(amountsPointerPointer);
|
// calloc.free(amountsPointerPointer);
|
||||||
calloc.free(preferredInputsPointerPointer);
|
// calloc.free(preferredInputsPointerPointer);
|
||||||
|
|
||||||
addressesPointers.forEach((element) => calloc.free(element));
|
// addressesPointers.forEach((element) => calloc.free(element));
|
||||||
amountsPointers.forEach((element) => calloc.free(element));
|
// amountsPointers.forEach((element) => calloc.free(element));
|
||||||
preferredInputsPointers.forEach((element) => calloc.free(element));
|
// preferredInputsPointers.forEach((element) => calloc.free(element));
|
||||||
|
|
||||||
calloc.free(paymentIdPointer);
|
// calloc.free(paymentIdPointer);
|
||||||
|
|
||||||
if (!created) {
|
// if (!created) {
|
||||||
final message = errorMessagePointer.ref.getValue();
|
// final message = errorMessagePointer.ref.getValue();
|
||||||
calloc.free(errorMessagePointer);
|
// calloc.free(errorMessagePointer);
|
||||||
throw CreationTransactionException(message: message);
|
// throw CreationTransactionException(message: message);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return PendingTransactionDescription(
|
// return PendingTransactionDescription(
|
||||||
amount: pendingTransactionRawPointer.ref.amount,
|
// amount: pendingTransactionRawPointer.ref.amount,
|
||||||
fee: pendingTransactionRawPointer.ref.fee,
|
// fee: pendingTransactionRawPointer.ref.fee,
|
||||||
hash: pendingTransactionRawPointer.ref.getHash(),
|
// hash: pendingTransactionRawPointer.ref.getHash(),
|
||||||
hex: pendingTransactionRawPointer.ref.getHex(),
|
// hex: pendingTransactionRawPointer.ref.getHex(),
|
||||||
txKey: pendingTransactionRawPointer.ref.getKey(),
|
// txKey: pendingTransactionRawPointer.ref.getKey(),
|
||||||
pointerAddress: pendingTransactionRawPointer.address);
|
// pointerAddress: pendingTransactionRawPointer.address);
|
||||||
|
throw CreationTransactionException(message: "Unimplemented in monero_c");
|
||||||
}
|
}
|
||||||
|
|
||||||
void commitTransactionFromPointerAddress({required int address}) =>
|
void commitTransactionFromPointerAddress({required int address}) =>
|
||||||
commitTransaction(transactionPointer: Pointer<PendingTransactionRaw>.fromAddress(address));
|
commitTransaction(transactionPointer: monero.PendingTransaction.fromAddress(address));
|
||||||
|
|
||||||
void commitTransaction({required Pointer<PendingTransactionRaw> transactionPointer}) {
|
void commitTransaction({required monero.PendingTransaction transactionPointer}) {
|
||||||
final errorMessagePointer = calloc<Utf8Box>();
|
|
||||||
final isCommited = transactionCommitNative(transactionPointer, errorMessagePointer) != 0;
|
final txCommit = monero.PendingTransaction_commit(transactionPointer, filename: '', overwrite: false);
|
||||||
|
final status = monero.PendingTransaction_status(transactionPointer.cast());
|
||||||
|
|
||||||
if (!isCommited) {
|
final String? error = (() {
|
||||||
final message = errorMessagePointer.ref.getValue();
|
final status = monero.Wallet_status(wptr!);
|
||||||
calloc.free(errorMessagePointer);
|
if (status == 0) {
|
||||||
throw CreationTransactionException(message: message);
|
return null;
|
||||||
|
}
|
||||||
|
return monero.Wallet_errorString(wptr!);
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (error != null) {
|
||||||
|
throw CreationTransactionException(message: error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +213,8 @@ Future<PendingTransactionDescription> createTransaction(
|
||||||
String? amount,
|
String? amount,
|
||||||
String paymentId = '',
|
String paymentId = '',
|
||||||
int accountIndex = 0,
|
int accountIndex = 0,
|
||||||
List<String> preferredInputs = const []}) =>
|
List<String> preferredInputs = const []}) async =>
|
||||||
compute(_createTransactionSync, {
|
_createTransactionSync({
|
||||||
'address': address,
|
'address': address,
|
||||||
'paymentId': paymentId,
|
'paymentId': paymentId,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
|
@ -271,11 +228,75 @@ Future<PendingTransactionDescription> createTransactionMultDest(
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
String paymentId = '',
|
String paymentId = '',
|
||||||
int accountIndex = 0,
|
int accountIndex = 0,
|
||||||
List<String> preferredInputs = const []}) =>
|
List<String> preferredInputs = const []}) async =>
|
||||||
compute(_createTransactionMultDestSync, {
|
_createTransactionMultDestSync({
|
||||||
'outputs': outputs,
|
'outputs': outputs,
|
||||||
'paymentId': paymentId,
|
'paymentId': paymentId,
|
||||||
'priorityRaw': priorityRaw,
|
'priorityRaw': priorityRaw,
|
||||||
'accountIndex': accountIndex,
|
'accountIndex': accountIndex,
|
||||||
'preferredInputs': preferredInputs
|
'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:async';
|
||||||
import 'dart:ffi';
|
import 'package:cw_monero/api/account_list.dart';
|
||||||
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/exceptions/setup_wallet_exception.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;
|
int _boolToInt(bool value) => value ? 1 : 0;
|
||||||
|
|
||||||
final getFileNameNative = moneroApi
|
int getSyncingHeight() => monero.Wallet_blockChainHeight(wptr!);
|
||||||
.lookup<NativeFunction<get_filename>>('get_filename')
|
|
||||||
.asFunction<GetFilename>();
|
|
||||||
|
|
||||||
final getSeedNative =
|
bool isNeededToRefresh() => false; // TODO(mrcyjanek): ?
|
||||||
moneroApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
|
|
||||||
|
|
||||||
final getAddressNative = moneroApi
|
bool isNewTransactionExist() => false;
|
||||||
.lookup<NativeFunction<get_address>>('get_address')
|
|
||||||
.asFunction<GetAddress>();
|
|
||||||
|
|
||||||
final getFullBalanceNative = moneroApi
|
String getFilename() => monero.Wallet_filename(wptr!);
|
||||||
.lookup<NativeFunction<get_full_balanace>>('get_full_balance')
|
|
||||||
.asFunction<GetFullBalance>();
|
|
||||||
|
|
||||||
final getUnlockedBalanceNative = moneroApi
|
String getSeed() => monero.Wallet_seed(wptr!, seedOffset: '');
|
||||||
.lookup<NativeFunction<get_unlocked_balanace>>('get_unlocked_balance')
|
|
||||||
.asFunction<GetUnlockedBalance>();
|
|
||||||
|
|
||||||
final getCurrentHeightNative = moneroApi
|
String getAddress({int accountIndex = 0, int addressIndex = 0}) => monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex);
|
||||||
.lookup<NativeFunction<get_current_height>>('get_current_height')
|
|
||||||
.asFunction<GetCurrentHeight>();
|
|
||||||
|
|
||||||
final getNodeHeightNative = moneroApi
|
int getFullBalance({int accountIndex = 0}) => monero.Wallet_balance(wptr!, accountIndex: accountIndex);
|
||||||
.lookup<NativeFunction<get_node_height>>('get_node_height')
|
|
||||||
.asFunction<GetNodeHeight>();
|
|
||||||
|
|
||||||
final isConnectedNative = moneroApi
|
int getUnlockedBalance({int accountIndex = 0}) => monero.Wallet_unlockedBalance(wptr!, accountIndex: accountIndex);
|
||||||
.lookup<NativeFunction<is_connected>>('is_connected')
|
|
||||||
.asFunction<IsConnected>();
|
|
||||||
|
|
||||||
final setupNodeNative = moneroApi
|
int getCurrentHeight() => monero.Wallet_blockChainHeight(wptr!);
|
||||||
.lookup<NativeFunction<setup_node>>('setup_node')
|
|
||||||
.asFunction<SetupNode>();
|
|
||||||
|
|
||||||
final startRefreshNative = moneroApi
|
int getNodeHeightSync() => monero.Wallet_daemonBlockChainHeight(wptr!);
|
||||||
.lookup<NativeFunction<start_refresh>>('start_refresh')
|
|
||||||
.asFunction<StartRefresh>();
|
|
||||||
|
|
||||||
final connecToNodeNative = moneroApi
|
bool isConnectedSync() => monero.Wallet_connected(wptr!) != 0;
|
||||||
.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 setupNodeSync(
|
bool setupNodeSync(
|
||||||
{required String address,
|
{required String address,
|
||||||
|
@ -163,96 +34,64 @@ bool setupNodeSync(
|
||||||
bool useSSL = false,
|
bool useSSL = false,
|
||||||
bool isLightWallet = false,
|
bool isLightWallet = false,
|
||||||
String? socksProxyAddress}) {
|
String? socksProxyAddress}) {
|
||||||
final addressPointer = address.toNativeUtf8();
|
|
||||||
Pointer<Utf8>? loginPointer;
|
|
||||||
Pointer<Utf8>? socksProxyAddressPointer;
|
|
||||||
Pointer<Utf8>? passwordPointer;
|
|
||||||
|
|
||||||
if (login != null) {
|
monero.Wallet_init(
|
||||||
loginPointer = login.toNativeUtf8();
|
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) {
|
return status == 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void startRefreshSync() => startRefreshNative();
|
void startRefreshSync() {}
|
||||||
|
|
||||||
Future<bool> connectToNode() async => connecToNodeNative() != 0;
|
Future<bool> connectToNode() async {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void setRefreshFromBlockHeight({required int height}) =>
|
void setRefreshFromBlockHeight({required int height}) => monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height);
|
||||||
setRefreshFromBlockHeightNative(height);
|
|
||||||
|
|
||||||
void setRecoveringFromSeed({required bool isRecovery}) =>
|
void setRecoveringFromSeed({required bool isRecovery}) => monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery);
|
||||||
setRecoveringFromSeedNative(_boolToInt(isRecovery));
|
|
||||||
|
|
||||||
void storeSync() {
|
void storeSync() {
|
||||||
final pathPointer = ''.toNativeUtf8();
|
monero.Wallet_store(wptr!);
|
||||||
storeNative(pathPointer);
|
|
||||||
calloc.free(pathPointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPasswordSync(String password) {
|
void setPasswordSync(String password) {
|
||||||
final passwordPointer = password.toNativeUtf8();
|
monero.Wallet_setPassword(wptr!, password: password);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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() =>
|
String getSecretViewKey() => monero.Wallet_secretViewKey(wptr!);
|
||||||
convertUTF8ToString(pointer: getSecretViewKeyNative());
|
|
||||||
|
|
||||||
String getPublicViewKey() =>
|
String getPublicViewKey() => monero.Wallet_publicViewKey(wptr!);
|
||||||
convertUTF8ToString(pointer: getPublicViewKeyNative());
|
|
||||||
|
|
||||||
String getSecretSpendKey() =>
|
String getSecretSpendKey() => monero.Wallet_secretSpendKey(wptr!);
|
||||||
convertUTF8ToString(pointer: getSecretSpendKeyNative());
|
|
||||||
|
|
||||||
String getPublicSpendKey() =>
|
String getPublicSpendKey() => monero.Wallet_publicSpendKey(wptr!);
|
||||||
convertUTF8ToString(pointer: getPublicSpendKeyNative());
|
|
||||||
|
|
||||||
class SyncListener {
|
class SyncListener {
|
||||||
SyncListener(this.onNewBlock, this.onNewTransaction)
|
SyncListener(this.onNewBlock, this.onNewTransaction)
|
||||||
|
@ -324,11 +163,11 @@ class SyncListener {
|
||||||
SyncListener setListeners(void Function(int, int, double) onNewBlock,
|
SyncListener setListeners(void Function(int, int, double) onNewBlock,
|
||||||
void Function() onNewTransaction) {
|
void Function() onNewTransaction) {
|
||||||
final listener = SyncListener(onNewBlock, onNewTransaction);
|
final listener = SyncListener(onNewBlock, onNewTransaction);
|
||||||
setListenerNative();
|
// setListenerNative();
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStartup() => onStartupNative();
|
void onStartup() {}
|
||||||
|
|
||||||
void _storeSync(Object _) => storeSync();
|
void _storeSync(Object _) => storeSync();
|
||||||
|
|
||||||
|
@ -361,8 +200,8 @@ Future<void> setupNode(
|
||||||
String? password,
|
String? password,
|
||||||
bool useSSL = false,
|
bool useSSL = false,
|
||||||
String? socksProxyAddress,
|
String? socksProxyAddress,
|
||||||
bool isLightWallet = false}) =>
|
bool isLightWallet = false}) async =>
|
||||||
compute<Map<String, Object?>, void>(_setupNodeSync, {
|
_setupNodeSync({
|
||||||
'address': address,
|
'address': address,
|
||||||
'login': login ,
|
'login': login ,
|
||||||
'password': password,
|
'password': password,
|
||||||
|
@ -371,29 +210,22 @@ Future<void> setupNode(
|
||||||
'socksProxyAddress': socksProxyAddress
|
'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) {
|
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 = ""}) {
|
String signMessage(String message, {String address = ""}) {
|
||||||
final messagePointer = message.toNativeUtf8();
|
return monero.Wallet_signMessage(wptr!, message: message, address: address);
|
||||||
final addressPointer = address.toNativeUtf8();
|
|
||||||
|
|
||||||
final signature = convertUTF8ToString(pointer: signMessageNative(messagePointer, addressPointer));
|
|
||||||
calloc.free(messagePointer);
|
|
||||||
calloc.free(addressPointer);
|
|
||||||
|
|
||||||
return signature;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_creation_exception.dart';
|
||||||
import 'package:cw_monero/api/exceptions/wallet_opening_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_keys_exception.dart';
|
||||||
import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_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:cw_monero/api/wallet.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:monero/monero.dart' as monero;
|
||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
final createWalletNative = moneroApi
|
monero.WalletManager? _wmPtr;
|
||||||
.lookup<NativeFunction<create_wallet>>('create_wallet')
|
final monero.WalletManager wmPtr = Pointer.fromAddress((() {
|
||||||
.asFunction<CreateWallet>();
|
try {
|
||||||
|
monero.printStarts = true;
|
||||||
final restoreWalletFromSeedNative = moneroApi
|
_wmPtr ??= monero.WalletManagerFactory_getWalletManager();
|
||||||
.lookup<NativeFunction<restore_wallet_from_seed>>(
|
print("ptr: $_wmPtr");
|
||||||
'restore_wallet_from_seed')
|
} catch (e) {
|
||||||
.asFunction<RestoreWalletFromSeed>();
|
print(e);
|
||||||
|
}
|
||||||
final restoreWalletFromKeysNative = moneroApi
|
return _wmPtr!.address;
|
||||||
.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>();
|
|
||||||
|
|
||||||
void createWalletSync(
|
void createWalletSync(
|
||||||
{required String path,
|
{required String path,
|
||||||
required String password,
|
required String password,
|
||||||
required String language,
|
required String language,
|
||||||
int nettype = 0}) {
|
int nettype = 0}) {
|
||||||
final pathPointer = path.toNativeUtf8();
|
wptr = monero.WalletManager_createWallet(wmPtr, path: path, password: password, language: language);
|
||||||
final passwordPointer = password.toNativeUtf8();
|
|
||||||
final languagePointer = language.toNativeUtf8();
|
|
||||||
final errorMessagePointer = ''.toNativeUtf8();
|
|
||||||
final isWalletCreated = createWalletNative(pathPointer, passwordPointer,
|
|
||||||
languagePointer, nettype, errorMessagePointer) !=
|
|
||||||
0;
|
|
||||||
|
|
||||||
calloc.free(pathPointer);
|
final status = monero.Wallet_status(wptr!);
|
||||||
calloc.free(passwordPointer);
|
if (status != 0) {
|
||||||
calloc.free(languagePointer);
|
throw WalletCreationException(message: monero.Wallet_errorString(wptr!));
|
||||||
|
|
||||||
if (!isWalletCreated) {
|
|
||||||
throw WalletCreationException(
|
|
||||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is the line below needed?
|
||||||
// setupNodeSync(address: "node.moneroworld.com:18089");
|
// setupNodeSync(address: "node.moneroworld.com:18089");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWalletExistSync({required String path}) {
|
bool isWalletExistSync({required String path}) {
|
||||||
final pathPointer = path.toNativeUtf8();
|
return monero.WalletManager_walletExists(wmPtr, path);
|
||||||
final isExist = isWalletExistNative(pathPointer) != 0;
|
|
||||||
|
|
||||||
calloc.free(pathPointer);
|
|
||||||
|
|
||||||
return isExist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreWalletFromSeedSync(
|
void restoreWalletFromSeedSync(
|
||||||
|
@ -87,22 +51,20 @@ void restoreWalletFromSeedSync(
|
||||||
final passwordPointer = password.toNativeUtf8();
|
final passwordPointer = password.toNativeUtf8();
|
||||||
final seedPointer = seed.toNativeUtf8();
|
final seedPointer = seed.toNativeUtf8();
|
||||||
final errorMessagePointer = ''.toNativeUtf8();
|
final errorMessagePointer = ''.toNativeUtf8();
|
||||||
final isWalletRestored = restoreWalletFromSeedNative(
|
|
||||||
pathPointer,
|
|
||||||
passwordPointer,
|
|
||||||
seedPointer,
|
|
||||||
nettype,
|
|
||||||
restoreHeight,
|
|
||||||
errorMessagePointer) !=
|
|
||||||
0;
|
|
||||||
|
|
||||||
calloc.free(pathPointer);
|
wptr = monero.WalletManager_recoveryWallet(
|
||||||
calloc.free(passwordPointer);
|
wmPtr,
|
||||||
calloc.free(seedPointer);
|
path: path,
|
||||||
|
password: password,
|
||||||
|
mnemonic: seed,
|
||||||
|
restoreHeight: restoreHeight,
|
||||||
|
seedOffset: '',
|
||||||
|
);
|
||||||
|
|
||||||
|
final status = monero.Wallet_status(wptr!);
|
||||||
|
|
||||||
if (!isWalletRestored) {
|
if (status != 0) {
|
||||||
throw WalletRestoreFromSeedException(
|
throw WalletRestoreFromSeedException(message: monero.Wallet_errorString(wptr!));
|
||||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,28 +84,19 @@ void restoreWalletFromKeysSync(
|
||||||
final viewKeyPointer = viewKey.toNativeUtf8();
|
final viewKeyPointer = viewKey.toNativeUtf8();
|
||||||
final spendKeyPointer = spendKey.toNativeUtf8();
|
final spendKeyPointer = spendKey.toNativeUtf8();
|
||||||
final errorMessagePointer = ''.toNativeUtf8();
|
final errorMessagePointer = ''.toNativeUtf8();
|
||||||
final isWalletRestored = restoreWalletFromKeysNative(
|
wptr = monero.WalletManager_createWalletFromKeys(
|
||||||
pathPointer,
|
wmPtr,
|
||||||
passwordPointer,
|
path: path,
|
||||||
languagePointer,
|
password: password,
|
||||||
addressPointer,
|
restoreHeight: restoreHeight,
|
||||||
viewKeyPointer,
|
addressString: address,
|
||||||
spendKeyPointer,
|
viewKeyString: viewKey,
|
||||||
nettype,
|
spendKeyString: spendKey,
|
||||||
restoreHeight,
|
);
|
||||||
errorMessagePointer) !=
|
|
||||||
0;
|
final status = monero.Wallet_status(wptr!);
|
||||||
|
if (status != 0) {
|
||||||
calloc.free(pathPointer);
|
throw WalletRestoreFromKeysException(message: monero.Wallet_errorString(wptr!));
|
||||||
calloc.free(passwordPointer);
|
|
||||||
calloc.free(languagePointer);
|
|
||||||
calloc.free(addressPointer);
|
|
||||||
calloc.free(viewKeyPointer);
|
|
||||||
calloc.free(spendKeyPointer);
|
|
||||||
|
|
||||||
if (!isWalletRestored) {
|
|
||||||
throw WalletRestoreFromKeysException(
|
|
||||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,43 +114,40 @@ void restoreWalletFromSpendKeySync(
|
||||||
final languagePointer = language.toNativeUtf8();
|
final languagePointer = language.toNativeUtf8();
|
||||||
final spendKeyPointer = spendKey.toNativeUtf8();
|
final spendKeyPointer = spendKey.toNativeUtf8();
|
||||||
final errorMessagePointer = ''.toNativeUtf8();
|
final errorMessagePointer = ''.toNativeUtf8();
|
||||||
final isWalletRestored = restoreWalletFromSpendKeyNative(
|
|
||||||
pathPointer,
|
|
||||||
passwordPointer,
|
|
||||||
seedPointer,
|
|
||||||
languagePointer,
|
|
||||||
spendKeyPointer,
|
|
||||||
nettype,
|
|
||||||
restoreHeight,
|
|
||||||
errorMessagePointer) !=
|
|
||||||
0;
|
|
||||||
|
|
||||||
calloc.free(pathPointer);
|
wptr = monero.WalletManager_createWalletFromKeys(
|
||||||
calloc.free(passwordPointer);
|
wmPtr,
|
||||||
calloc.free(languagePointer);
|
path: path,
|
||||||
calloc.free(spendKeyPointer);
|
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();
|
storeSync();
|
||||||
|
|
||||||
if (!isWalletRestored) {
|
|
||||||
throw WalletRestoreFromKeysException(
|
|
||||||
message: convertUTF8ToString(pointer: errorMessagePointer));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadWallet({
|
void loadWallet({
|
||||||
required String path,
|
required String path,
|
||||||
required String password,
|
required String password,
|
||||||
int nettype = 0}) {
|
int nettype = 0}) {
|
||||||
final pathPointer = path.toNativeUtf8();
|
try {
|
||||||
final passwordPointer = password.toNativeUtf8();
|
wptr ??= monero.WalletManager_openWallet(wmPtr, path: path, password: password);
|
||||||
final loaded = loadWalletNative(pathPointer, passwordPointer, nettype) != 0;
|
} catch (e) {
|
||||||
calloc.free(pathPointer);
|
print(e);
|
||||||
calloc.free(passwordPointer);
|
}
|
||||||
|
final status = monero.Wallet_status(wptr!);
|
||||||
if (!loaded) {
|
if (status != 0) {
|
||||||
throw WalletOpeningException(
|
final err = monero.Wallet_errorString(wptr!);
|
||||||
message: convertUTF8ToString(pointer: errorStringNative()));
|
print(err);
|
||||||
|
throw WalletOpeningException(message: err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,20 +208,20 @@ void _restoreFromSpendKey(Map<String, dynamic> args) {
|
||||||
Future<void> _openWallet(Map<String, String> args) async =>
|
Future<void> _openWallet(Map<String, String> args) async =>
|
||||||
loadWallet(path: args['path'] as String, password: args['password'] as String);
|
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 =>
|
void openWallet({required String path, required String password, int nettype = 0}) async =>
|
||||||
loadWallet(path: path, password: password, nettype: nettype);
|
loadWallet(path: path, password: password, nettype: nettype);
|
||||||
|
|
||||||
Future<void> openWalletAsync(Map<String, String> args) async =>
|
Future<void> openWalletAsync(Map<String, String> args) async =>
|
||||||
compute(_openWallet, args);
|
_openWallet(args);
|
||||||
|
|
||||||
Future<void> createWallet(
|
Future<void> createWallet(
|
||||||
{required String path,
|
{required String path,
|
||||||
required String password,
|
required String password,
|
||||||
required String language,
|
required String language,
|
||||||
int nettype = 0}) async =>
|
int nettype = 0}) async =>
|
||||||
compute(_createWallet, {
|
_createWallet({
|
||||||
'path': path,
|
'path': path,
|
||||||
'password': password,
|
'password': password,
|
||||||
'language': language,
|
'language': language,
|
||||||
|
@ -284,7 +234,7 @@ Future<void> restoreFromSeed(
|
||||||
required String seed,
|
required String seed,
|
||||||
int nettype = 0,
|
int nettype = 0,
|
||||||
int restoreHeight = 0}) async =>
|
int restoreHeight = 0}) async =>
|
||||||
compute<Map<String, Object>, void>(_restoreFromSeed, {
|
_restoreFromSeed({
|
||||||
'path': path,
|
'path': path,
|
||||||
'password': password,
|
'password': password,
|
||||||
'seed': seed,
|
'seed': seed,
|
||||||
|
@ -301,7 +251,7 @@ Future<void> restoreFromKeys(
|
||||||
required String spendKey,
|
required String spendKey,
|
||||||
int nettype = 0,
|
int nettype = 0,
|
||||||
int restoreHeight = 0}) async =>
|
int restoreHeight = 0}) async =>
|
||||||
compute<Map<String, Object>, void>(_restoreFromKeys, {
|
_restoreFromKeys({
|
||||||
'path': path,
|
'path': path,
|
||||||
'password': password,
|
'password': password,
|
||||||
'language': language,
|
'language': language,
|
||||||
|
@ -320,7 +270,7 @@ Future<void> restoreFromSpendKey(
|
||||||
required String spendKey,
|
required String spendKey,
|
||||||
int nettype = 0,
|
int nettype = 0,
|
||||||
int restoreHeight = 0}) async =>
|
int restoreHeight = 0}) async =>
|
||||||
compute<Map<String, Object>, void>(_restoreFromSpendKey, {
|
_restoreFromSpendKey({
|
||||||
'path': path,
|
'path': path,
|
||||||
'password': password,
|
'password': password,
|
||||||
'seed': seed,
|
'seed': seed,
|
||||||
|
@ -330,4 +280,4 @@ Future<void> restoreFromSpendKey(
|
||||||
'restoreHeight': restoreHeight
|
'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:mobx/mobx.dart';
|
||||||
import 'package:cw_core/account.dart';
|
import 'package:cw_core/account.dart';
|
||||||
import 'package:cw_monero/api/account_list.dart' as account_list;
|
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';
|
part 'monero_account_list.g.dart';
|
||||||
|
|
||||||
|
@ -44,13 +44,12 @@ abstract class MoneroAccountListBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Account> getAll() => account_list.getAllAccount().map((accountRow) {
|
List<Account> getAll() => account_list.getAllAccount().map((accountRow) {
|
||||||
final accountIndex = accountRow.getId();
|
final balance = monero.SubaddressAccountRow_getUnlockedBalance(accountRow);
|
||||||
final balance = monero_wallet.getFullBalance(accountIndex: accountIndex);
|
|
||||||
|
|
||||||
return Account(
|
return Account(
|
||||||
id: accountRow.getId(),
|
id: monero.SubaddressAccountRow_getRowId(accountRow),
|
||||||
label: accountRow.getLabel(),
|
label: monero.SubaddressAccountRow_getLabel(accountRow),
|
||||||
balance: moneroAmountToString(amount: balance),
|
balance: moneroAmountToString(amount: monero.Wallet_amountFromString(balance)),
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'package:mobx/mobx.dart';
|
||||||
import 'package:cw_monero/api/coins_info.dart';
|
import 'package:cw_monero/api/coins_info.dart';
|
||||||
import 'package:cw_monero/api/subaddress_list.dart' as subaddress_list;
|
import 'package:cw_monero/api/subaddress_list.dart' as subaddress_list;
|
||||||
import 'package:cw_core/subaddress.dart';
|
import 'package:cw_core/subaddress.dart';
|
||||||
|
import 'package:monero/monero.dart' as monero;
|
||||||
|
|
||||||
part 'monero_subaddress_list.g.dart';
|
part 'monero_subaddress_list.g.dart';
|
||||||
|
|
||||||
|
@ -51,18 +52,21 @@ abstract class MoneroSubaddressListBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
return subaddresses.map((subaddressRow) {
|
return subaddresses.map((subaddressRow) {
|
||||||
|
final label = monero.SubaddressRow_getLabel(subaddressRow);
|
||||||
|
final id = monero.SubaddressRow_getRowId(subaddressRow);
|
||||||
|
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||||
final hasDefaultAddressName =
|
final hasDefaultAddressName =
|
||||||
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase() ||
|
label.toLowerCase() == 'Primary account'.toLowerCase() ||
|
||||||
subaddressRow.getLabel().toLowerCase() == 'Untitled account'.toLowerCase();
|
label.toLowerCase() == 'Untitled account'.toLowerCase();
|
||||||
final isPrimaryAddress = subaddressRow.getId() == 0 && hasDefaultAddressName;
|
final isPrimaryAddress = id == 0 && hasDefaultAddressName;
|
||||||
return Subaddress(
|
return Subaddress(
|
||||||
id: subaddressRow.getId(),
|
id: id,
|
||||||
address: subaddressRow.getAddress(),
|
address: address,
|
||||||
label: isPrimaryAddress
|
label: isPrimaryAddress
|
||||||
? 'Primary address'
|
? 'Primary address'
|
||||||
: hasDefaultAddressName
|
: hasDefaultAddressName
|
||||||
? ''
|
? ''
|
||||||
: subaddressRow.getLabel());
|
: label);
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +125,8 @@ abstract class MoneroSubaddressListBase with Store {
|
||||||
Future<List<Subaddress>> _getAllUnusedAddresses(
|
Future<List<Subaddress>> _getAllUnusedAddresses(
|
||||||
{required int accountIndex, required String label}) async {
|
{required int accountIndex, required String label}) async {
|
||||||
final allAddresses = subaddress_list.getAllSubaddresses();
|
final allAddresses = subaddress_list.getAllSubaddresses();
|
||||||
|
final lastAddress = monero.SubaddressRow_getAddress(allAddresses.last);
|
||||||
if (allAddresses.isEmpty || _usedAddresses.contains(allAddresses.last.getAddress())) {
|
if (allAddresses.isEmpty || _usedAddresses.contains(lastAddress)) {
|
||||||
final isAddressUnused = await _newSubaddress(accountIndex: accountIndex, label: label);
|
final isAddressUnused = await _newSubaddress(accountIndex: accountIndex, label: label);
|
||||||
if (!isAddressUnused) {
|
if (!isAddressUnused) {
|
||||||
return await _getAllUnusedAddresses(accountIndex: accountIndex, label: label);
|
return await _getAllUnusedAddresses(accountIndex: accountIndex, label: label);
|
||||||
|
@ -130,13 +134,18 @@ abstract class MoneroSubaddressListBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
return allAddresses
|
return allAddresses
|
||||||
.map((subaddressRow) => Subaddress(
|
.map((subaddressRow) {
|
||||||
id: subaddressRow.getId(),
|
final id = monero.SubaddressRow_getRowId(subaddressRow);
|
||||||
address: subaddressRow.getAddress(),
|
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||||
label: subaddressRow.getId() == 0 &&
|
final label = monero.SubaddressRow_getLabel(subaddressRow);
|
||||||
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase()
|
return Subaddress(
|
||||||
|
id: id,
|
||||||
|
address: address,
|
||||||
|
label: id == 0 &&
|
||||||
|
label.toLowerCase() == 'Primary account'.toLowerCase()
|
||||||
? 'Primary address'
|
? 'Primary address'
|
||||||
: subaddressRow.getLabel()))
|
: label);
|
||||||
|
})
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +154,10 @@ abstract class MoneroSubaddressListBase with Store {
|
||||||
|
|
||||||
return subaddress_list
|
return subaddress_list
|
||||||
.getAllSubaddresses()
|
.getAllSubaddresses()
|
||||||
.where((subaddressRow) => !_usedAddresses.contains(subaddressRow.getAddress()))
|
.where((subaddressRow) {
|
||||||
|
final address = monero.SubaddressRow_getAddress(subaddressRow);
|
||||||
|
return !_usedAddresses.contains(address);
|
||||||
|
})
|
||||||
.isNotEmpty;
|
.isNotEmpty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import 'package:cw_core/node.dart';
|
||||||
import 'package:cw_core/pathForWallet.dart';
|
import 'package:cw_core/pathForWallet.dart';
|
||||||
import 'package:cw_core/pending_transaction.dart';
|
import 'package:cw_core/pending_transaction.dart';
|
||||||
import 'package:cw_core/sync_status.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/transaction_priority.dart';
|
||||||
import 'package:cw_core/unspent_coins_info.dart';
|
import 'package:cw_core/unspent_coins_info.dart';
|
||||||
import 'package:cw_core/wallet_base.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:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
import 'package:monero/monero.dart' as monero;
|
||||||
|
|
||||||
part 'monero_wallet.g.dart';
|
part 'monero_wallet.g.dart';
|
||||||
|
|
||||||
|
@ -417,10 +419,18 @@ abstract class MoneroWalletBase
|
||||||
final coinCount = countOfCoins();
|
final coinCount = countOfCoins();
|
||||||
for (var i = 0; i < coinCount; i++) {
|
for (var i = 0; i < coinCount; i++) {
|
||||||
final coin = getCoin(i);
|
final coin = getCoin(i);
|
||||||
if (coin.spent == 0) {
|
final coinSpent = monero.CoinsInfo_spent(coin);
|
||||||
final unspent = MoneroUnspent.fromCoinsInfoRow(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) {
|
if (unspent.hash.isNotEmpty) {
|
||||||
unspent.isChange = transaction_history.getTransaction(unspent.hash).direction == 1;
|
unspent.isChange = transaction_history.getTransaction(unspent.hash) == 1;
|
||||||
}
|
}
|
||||||
unspentCoins.add(unspent);
|
unspentCoins.add(unspent);
|
||||||
}
|
}
|
||||||
|
@ -541,7 +551,17 @@ abstract class MoneroWalletBase
|
||||||
|
|
||||||
List<MoneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) => transaction_history
|
List<MoneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) => transaction_history
|
||||||
.getAllTransactions()
|
.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))
|
.where((element) => element.accountIndex == (accountIndex ?? 0))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|
|
@ -204,10 +204,10 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: ffi
|
name: ffi
|
||||||
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
|
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.1.0"
|
||||||
file:
|
file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -410,6 +410,15 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
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:
|
package_config:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -22,6 +22,10 @@ dependencies:
|
||||||
polyseed: ^0.0.2
|
polyseed: ^0.0.2
|
||||||
cw_core:
|
cw_core:
|
||||||
path: ../cw_core
|
path: ../cw_core
|
||||||
|
monero:
|
||||||
|
git:
|
||||||
|
url: https://git.mrcyjanek.net/mrcyjanek/monero.dart
|
||||||
|
ref: master
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
@ -111,7 +111,10 @@ dependencies:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cake-tech/bitcoin_base.git
|
url: https://github.com/cake-tech/bitcoin_base.git
|
||||||
ref: cake-update-v2
|
ref: cake-update-v2
|
||||||
|
monero:
|
||||||
|
git:
|
||||||
|
url: https://git.mrcyjanek.net/mrcyjanek/monero.dart
|
||||||
|
ref: master
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
Loading…
Reference in a new issue