diff --git a/cw_monero/lib/api/coins_info.dart b/cw_monero/lib/api/coins_info.dart index c1b634cc6..ef7d3cfd6 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 a308b682e..89bcea800 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 8e03cff3e..422acf126 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 87d8f0b39..f45fcddaf 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 0ae2202ba..60c536b42 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -275,9 +275,9 @@ abstract class MoneroWalletBase extends WalletBase