From 0e5a1256115339cacfc776898aa509c7c67f6157 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 15 Oct 2024 21:41:27 +0200 Subject: [PATCH 1/8] fix coin freezing --- cw_monero/lib/api/coins_info.dart | 12 +++++++ cw_monero/lib/api/transaction_history.dart | 8 +++-- cw_monero/lib/api/wallet.dart | 11 ++++++- cw_monero/lib/monero_unspent.dart | 24 +++++++++++++- cw_monero/lib/monero_wallet.dart | 35 +++++++++++---------- cw_monero/pubspec.lock | 4 +-- cw_monero/pubspec.yaml | 2 +- cw_wownero/lib/api/transaction_history.dart | 4 ++- cw_wownero/pubspec.lock | 4 +-- cw_wownero/pubspec.yaml | 2 +- scripts/android/pubspec_gen.sh | 1 + scripts/prepare_moneroc.sh | 2 +- 12 files changed, 80 insertions(+), 29 deletions(-) diff --git a/cw_monero/lib/api/coins_info.dart b/cw_monero/lib/api/coins_info.dart index c1b634cc6b..ef7d3cfd6c 100644 --- a/cw_monero/lib/api/coins_info.dart +++ b/cw_monero/lib/api/coins_info.dart @@ -12,6 +12,18 @@ int countOfCoins() => monero.Coins_count(coins!); monero.CoinsInfo getCoin(int index) => monero.Coins_coin(coins!, index); +int? getCoinByKeyImage(String keyImage) { + final count = countOfCoins(); + for (int i = 0; i < count; i++) { + final coin = getCoin(i); + final coinAddress = monero.CoinsInfo_keyImage(coin); + if (keyImage == coinAddress) { + return i; + } + } + return null; +} + void freezeCoin(int index) => monero.Coins_setFrozen(coins!, index: index); void thawCoin(int index) => monero.Coins_thaw(coins!, index: index); diff --git a/cw_monero/lib/api/transaction_history.dart b/cw_monero/lib/api/transaction_history.dart index a308b682ed..89bcea800e 100644 --- a/cw_monero/lib/api/transaction_history.dart +++ b/cw_monero/lib/api/transaction_history.dart @@ -13,7 +13,9 @@ import 'package:mutex/mutex.dart'; String getTxKey(String txId) { - return monero.Wallet_getTxKey(wptr!, txid: txId); + final ret = monero.Wallet_getTxKey(wptr!, txid: txId); + monero.Wallet_status(wptr!); + return ret; } final txHistoryMutex = Mutex(); monero.TransactionHistory? txhistory; @@ -87,7 +89,9 @@ Future createTransactionSync( final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount); final address_ = address.toNativeUtf8(); - final paymentId_ = paymentId.toNativeUtf8(); + final paymentId_ = paymentId.toNativeUtf8(); + print("inputs: $preferredInputs"); + final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8(); final waddr = wptr!.address; diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 8e03cff3e3..422acf1268 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -4,6 +4,7 @@ import 'dart:isolate'; 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; import 'package:mutex/mutex.dart'; @@ -119,7 +120,6 @@ Future setupNodeSync( daemonUsername: login ?? '', daemonPassword: password ?? ''); }); - // monero.Wallet_init3(wptr!, argv0: '', defaultLogBaseName: 'moneroc', console: true); final status = monero.Wallet_status(wptr!); @@ -129,6 +129,15 @@ Future setupNodeSync( throw SetupWalletException(message: error); } + if (kDebugMode) { + monero.Wallet_init3( + wptr!, argv0: '', + defaultLogBaseName: 'moneroc', + console: true, + logPath: '', + ); + } + return status == 0; } diff --git a/cw_monero/lib/monero_unspent.dart b/cw_monero/lib/monero_unspent.dart index 87d8f0b392..f45fcddaff 100644 --- a/cw_monero/lib/monero_unspent.dart +++ b/cw_monero/lib/monero_unspent.dart @@ -1,10 +1,32 @@ import 'package:cw_core/unspent_transaction_output.dart'; +import 'package:cw_monero/api/coins_info.dart'; +import 'package:monero/monero.dart' as monero; class MoneroUnspent extends Unspent { MoneroUnspent( String address, String hash, String keyImage, int value, bool isFrozen, this.isUnlocked) : super(address, hash, value, 0, keyImage) { - this.isFrozen = isFrozen; + } + + @override + set isFrozen(bool freeze) { + print("set isFrozen: $freeze ($keyImage): $freeze"); + final coinId = getCoinByKeyImage(keyImage!); + if (coinId == null) throw Exception("Unable to find a coin for address $address"); + if (freeze) { + freezeCoin(coinId); + } else { + thawCoin(coinId); + } + } + + @override + bool get isFrozen { + print("get isFrozen"); + final coinId = getCoinByKeyImage(keyImage!); + if (coinId == null) throw Exception("Unable to find a coin for address $address"); + final coin = getCoin(coinId); + return monero.CoinsInfo_frozen(coin); } final bool isUnlocked; diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 0ae2202ba6..60c536b42a 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -275,9 +275,9 @@ abstract class MoneroWalletBase extends WalletBase Date: Wed, 16 Oct 2024 14:28:44 +0200 Subject: [PATCH 2/8] fix frozen balance --- cw_monero/lib/monero_wallet.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 60c536b42a..3a64715f78 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -696,9 +696,8 @@ abstract class MoneroWalletBase extends WalletBase element.walletId == id && element.accountIndex == walletAddresses.account!.id)) { - if (coin.isFrozen) frozenBalance += coin.value; + if (coin.isFrozen && !coin.isSending) frozenBalance += coin.value; } - return frozenBalance; } From ddf4c2461aaeced6383bc860db5544488a2a58ca Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Wed, 16 Oct 2024 16:42:36 +0200 Subject: [PATCH 3/8] update monero_c hash --- cw_monero/pubspec.lock | 4 ++-- cw_monero/pubspec.yaml | 2 +- cw_wownero/pubspec.lock | 4 ++-- cw_wownero/pubspec.yaml | 2 +- scripts/prepare_moneroc.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cw_monero/pubspec.lock b/cw_monero/pubspec.lock index aedff9c804..27d949a179 100644 --- a/cw_monero/pubspec.lock +++ b/cw_monero/pubspec.lock @@ -463,8 +463,8 @@ packages: dependency: "direct main" description: path: "impls/monero.dart" - ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894" - resolved-ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894" + ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" + resolved-ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" url: "https://github.com/mrcyjanek/monero_c" source: git version: "0.0.0" diff --git a/cw_monero/pubspec.yaml b/cw_monero/pubspec.yaml index ec81f6ee79..7fe305765f 100644 --- a/cw_monero/pubspec.yaml +++ b/cw_monero/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: monero: git: url: https://github.com/mrcyjanek/monero_c - ref: 33f6ef2fa28ebcc799529230bbb026a5f9385894 # monero_c hash + ref: 193b9868f6bcec745a7a716dbb98ffcf26a06a33 # monero_c hash path: impls/monero.dart mutex: ^3.1.0 diff --git a/cw_wownero/pubspec.lock b/cw_wownero/pubspec.lock index 17582720a9..1909c91661 100644 --- a/cw_wownero/pubspec.lock +++ b/cw_wownero/pubspec.lock @@ -463,8 +463,8 @@ packages: dependency: "direct main" description: path: "impls/monero.dart" - ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894" - resolved-ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894" + ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" + resolved-ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" url: "https://github.com/mrcyjanek/monero_c" source: git version: "0.0.0" diff --git a/cw_wownero/pubspec.yaml b/cw_wownero/pubspec.yaml index 41a2d67c92..9feacae75a 100644 --- a/cw_wownero/pubspec.yaml +++ b/cw_wownero/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: monero: git: url: https://github.com/mrcyjanek/monero_c - ref: 33f6ef2fa28ebcc799529230bbb026a5f9385894 # monero_c hash + ref: 193b9868f6bcec745a7a716dbb98ffcf26a06a33 # monero_c hash path: impls/monero.dart mutex: ^3.1.0 diff --git a/scripts/prepare_moneroc.sh b/scripts/prepare_moneroc.sh index 4932411ad6..29947e4fb1 100755 --- a/scripts/prepare_moneroc.sh +++ b/scripts/prepare_moneroc.sh @@ -8,7 +8,7 @@ if [[ ! -d "monero_c" ]]; then git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip cd monero_c - git checkout 33f6ef2fa28ebcc799529230bbb026a5f9385894 + git checkout 193b9868f6bcec745a7a716dbb98ffcf26a06a33 git reset --hard git submodule update --init --force --recursive ./apply_patches.sh monero From bc504bf23812a5d4b4640592b4fd0d779eae2ff4 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Wed, 16 Oct 2024 17:35:16 +0200 Subject: [PATCH 4/8] update monero_c hash (after merge) --- cw_monero/pubspec.lock | 4 ++-- cw_monero/pubspec.yaml | 2 +- cw_wownero/pubspec.lock | 4 ++-- cw_wownero/pubspec.yaml | 2 +- scripts/prepare_moneroc.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cw_monero/pubspec.lock b/cw_monero/pubspec.lock index 27d949a179..53dc1927dc 100644 --- a/cw_monero/pubspec.lock +++ b/cw_monero/pubspec.lock @@ -463,8 +463,8 @@ packages: dependency: "direct main" description: path: "impls/monero.dart" - ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" - resolved-ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" + ref: "939040032f6e22529ccb6b5f54d9c48fc94db3d6" + resolved-ref: "939040032f6e22529ccb6b5f54d9c48fc94db3d6" url: "https://github.com/mrcyjanek/monero_c" source: git version: "0.0.0" diff --git a/cw_monero/pubspec.yaml b/cw_monero/pubspec.yaml index 7fe305765f..21039061ef 100644 --- a/cw_monero/pubspec.yaml +++ b/cw_monero/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: monero: git: url: https://github.com/mrcyjanek/monero_c - ref: 193b9868f6bcec745a7a716dbb98ffcf26a06a33 # monero_c hash + ref: 939040032f6e22529ccb6b5f54d9c48fc94db3d6 # monero_c hash path: impls/monero.dart mutex: ^3.1.0 diff --git a/cw_wownero/pubspec.lock b/cw_wownero/pubspec.lock index 1909c91661..7b7342f8ce 100644 --- a/cw_wownero/pubspec.lock +++ b/cw_wownero/pubspec.lock @@ -463,8 +463,8 @@ packages: dependency: "direct main" description: path: "impls/monero.dart" - ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" - resolved-ref: "193b9868f6bcec745a7a716dbb98ffcf26a06a33" + ref: "939040032f6e22529ccb6b5f54d9c48fc94db3d6" + resolved-ref: "939040032f6e22529ccb6b5f54d9c48fc94db3d6" url: "https://github.com/mrcyjanek/monero_c" source: git version: "0.0.0" diff --git a/cw_wownero/pubspec.yaml b/cw_wownero/pubspec.yaml index 9feacae75a..0dbde724fd 100644 --- a/cw_wownero/pubspec.yaml +++ b/cw_wownero/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: monero: git: url: https://github.com/mrcyjanek/monero_c - ref: 193b9868f6bcec745a7a716dbb98ffcf26a06a33 # monero_c hash + ref: 939040032f6e22529ccb6b5f54d9c48fc94db3d6 # monero_c hash path: impls/monero.dart mutex: ^3.1.0 diff --git a/scripts/prepare_moneroc.sh b/scripts/prepare_moneroc.sh index 29947e4fb1..e57f246713 100755 --- a/scripts/prepare_moneroc.sh +++ b/scripts/prepare_moneroc.sh @@ -8,7 +8,7 @@ if [[ ! -d "monero_c" ]]; then git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip cd monero_c - git checkout 193b9868f6bcec745a7a716dbb98ffcf26a06a33 + git checkout 939040032f6e22529ccb6b5f54d9c48fc94db3d6 git reset --hard git submodule update --init --force --recursive ./apply_patches.sh monero From 0dd75083ad796f1001e273538bd763ce0ac6b3cc Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Thu, 17 Oct 2024 12:22:33 +0200 Subject: [PATCH 5/8] fix test E make it ready --- cw_monero/lib/api/transaction_history.dart | 4 ++++ cw_monero/lib/monero_wallet.dart | 15 +++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cw_monero/lib/api/transaction_history.dart b/cw_monero/lib/api/transaction_history.dart index 89bcea800e..5f94e36555 100644 --- a/cw_monero/lib/api/transaction_history.dart +++ b/cw_monero/lib/api/transaction_history.dart @@ -6,6 +6,7 @@ import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart'; import 'package:cw_monero/api/monero_output.dart'; import 'package:cw_monero/api/structs/pending_transaction.dart'; import 'package:cw_monero/api/wallet.dart'; +import 'package:cw_monero/exceptions/monero_transaction_creation_exception.dart'; import 'package:ffi/ffi.dart'; import 'package:monero/monero.dart' as monero; import 'package:monero/src/generated_bindings_monero.g.dart' as monero_gen; @@ -91,6 +92,9 @@ Future createTransactionSync( final address_ = address.toNativeUtf8(); final paymentId_ = paymentId.toNativeUtf8(); print("inputs: $preferredInputs"); + if (preferredInputs.isEmpty) { + throw MoneroTransactionCreationException("No inputs provided, transaction cannot be constructed"); + } final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8(); diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 3a64715f78..9ae320dcdd 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -275,9 +275,8 @@ abstract class MoneroWalletBase extends WalletBase Date: Thu, 17 Oct 2024 11:06:57 +0000 Subject: [PATCH 6/8] revert local change --- scripts/android/pubspec_gen.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/android/pubspec_gen.sh b/scripts/android/pubspec_gen.sh index 9ff6d48831..468f548f34 100755 --- a/scripts/android/pubspec_gen.sh +++ b/scripts/android/pubspec_gen.sh @@ -19,7 +19,6 @@ case $APP_ANDROID_TYPE in CONFIG_ARGS="--haven" ;; esac -CONFIG_ARGS="--monero --ethereum --polygon --nano --solana --tron --wownero" cd ../.. cp -rf pubspec_description.yaml pubspec.yaml From eb52baff41df42a8f66d52626c69f0f62af64cfa Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Fri, 18 Oct 2024 10:03:37 +0200 Subject: [PATCH 7/8] throw error on wow as well --- cw_monero/lib/api/transaction_history.dart | 1 - cw_wownero/lib/api/transaction_history.dart | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cw_monero/lib/api/transaction_history.dart b/cw_monero/lib/api/transaction_history.dart index 5f94e36555..c47263a0f7 100644 --- a/cw_monero/lib/api/transaction_history.dart +++ b/cw_monero/lib/api/transaction_history.dart @@ -91,7 +91,6 @@ Future createTransactionSync( final address_ = address.toNativeUtf8(); final paymentId_ = paymentId.toNativeUtf8(); - print("inputs: $preferredInputs"); if (preferredInputs.isEmpty) { throw MoneroTransactionCreationException("No inputs provided, transaction cannot be constructed"); } diff --git a/cw_wownero/lib/api/transaction_history.dart b/cw_wownero/lib/api/transaction_history.dart index b0a6bc3d04..ce93df7d18 100644 --- a/cw_wownero/lib/api/transaction_history.dart +++ b/cw_wownero/lib/api/transaction_history.dart @@ -6,6 +6,7 @@ import 'package:cw_wownero/api/exceptions/creation_transaction_exception.dart'; import 'package:cw_wownero/api/wallet.dart'; import 'package:cw_wownero/api/wownero_output.dart'; import 'package:cw_wownero/api/structs/pending_transaction.dart'; +import 'package:cw_wownero/exceptions/wownero_transaction_creation_exception.dart'; import 'package:ffi/ffi.dart'; import 'package:monero/wownero.dart' as wownero; import 'package:monero/src/generated_bindings_wownero.g.dart' as wownero_gen; @@ -88,7 +89,10 @@ Future createTransactionSync( final amt = amount == null ? 0 : wownero.Wallet_amountFromString(amount); final address_ = address.toNativeUtf8(); - final paymentId_ = paymentId.toNativeUtf8(); + final paymentId_ = paymentId.toNativeUtf8(); + if (preferredInputs.isEmpty) { + throw WowneroTransactionCreationException("No inputs provided, transaction cannot be constructed"); + } final preferredInputs_ = preferredInputs.join(wownero.defaultSeparatorStr).toNativeUtf8(); final waddr = wptr!.address; From 8597ab765264dd1818c6ad71fa63a51f8c2464d1 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Sun, 20 Oct 2024 18:58:49 +0200 Subject: [PATCH 8/8] experiment with view model code --- lib/view_model/send/send_view_model.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 0ad8ba376e..3629dc8985 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/priority_for_wallet_type.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; @@ -16,6 +17,7 @@ import 'package:cake_wallet/tron/tron.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; import 'package:cake_wallet/view_model/hardware_wallet/ledger_view_model.dart'; +import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_list_view_model.dart'; import 'package:cake_wallet/wownero/wownero.dart'; import 'package:cw_core/exceptions.dart'; import 'package:cw_core/transaction_info.dart'; @@ -501,6 +503,17 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor throw Exception('Priority is null for wallet type: ${wallet.type}'); } + if (hasCoinControl) { + final vm = getIt.get(param1: coinTypeToSpendFrom); + bool isCoinSelected = false; + for (var coin in vm.items) { + isCoinSelected = isCoinSelected || (coin.isSending && !coin.isFrozen); + } + if (!isCoinSelected) { + throw Exception("No coin selected in coin control, you need to select a coin in order to spend"); + } + } + switch (wallet.type) { case WalletType.bitcoin: case WalletType.litecoin: