fix coin freezing

This commit is contained in:
Czarek Nakamoto 2024-10-15 21:41:27 +02:00
parent c3019b91cd
commit 0e5a125611
12 changed files with 80 additions and 29 deletions

View file

@ -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);

View file

@ -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<PendingTransactionDescription> 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;

View file

@ -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<bool> 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<bool> setupNodeSync(
throw SetupWalletException(message: error);
}
if (kDebugMode) {
monero.Wallet_init3(
wptr!, argv0: '',
defaultLogBaseName: 'moneroc',
console: true,
logPath: '',
);
}
return status == 0;
}

View file

@ -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;

View file

@ -275,9 +275,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
'You do not have enough XMR to send this amount.');
}
if (!spendAllCoins && (allInputsAmount < totalAmount + estimatedFee)) {
throw MoneroTransactionNoInputsException(inputs.length);
}
// if (!spendAllCoins && (allInputsAmount < totalAmount + estimatedFee)) {
// throw MoneroTransactionNoInputsException(inputs.length);
// }
final moneroOutputs = outputs.map((output) {
final outputAddress =
@ -303,23 +303,22 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
final formattedAmount =
output.sendAll ? null : output.formattedCryptoAmount;
if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
(formattedAmount == null && unlockedBalance <= 0)) {
final formattedBalance = moneroAmountToString(amount: unlockedBalance);
throw MoneroTransactionCreationException(
'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
}
// if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
// (formattedAmount == null && unlockedBalance <= 0)) {
// final formattedBalance = moneroAmountToString(amount: unlockedBalance);
//
// throw MoneroTransactionCreationException(
// 'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
// }
final estimatedFee =
calculateEstimatedFee(_credentials.priority, formattedAmount);
if (!spendAllCoins &&
((formattedAmount != null &&
allInputsAmount < (formattedAmount + estimatedFee)) ||
formattedAmount == null)) {
throw MoneroTransactionNoInputsException(inputs.length);
}
// if (!spendAllCoins &&
// ((formattedAmount != null &&
// allInputsAmount < (formattedAmount + estimatedFee)) ||
// formattedAmount == null)) {
// throw MoneroTransactionNoInputsException(inputs.length);
// }
pendingTransactionDescription =
await transaction_history.createTransaction(
address: address!,
@ -329,6 +328,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
preferredInputs: inputs);
}
// final status = monero.PendingTransaction_status(pendingTransactionDescription);
return PendingMoneroTransaction(pendingTransactionDescription);
}

View file

@ -463,8 +463,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
resolved-ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
resolved-ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"

View file

@ -25,7 +25,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: 6eb571ea498ed7b854934785f00fabfd0dadf75b # monero_c hash
ref: 33f6ef2fa28ebcc799529230bbb026a5f9385894 # monero_c hash
path: impls/monero.dart
mutex: ^3.1.0

View file

@ -12,7 +12,9 @@ import 'package:monero/src/generated_bindings_wownero.g.dart' as wownero_gen;
String getTxKey(String txId) {
return wownero.Wallet_getTxKey(wptr!, txid: txId);
final ret = wownero.Wallet_getTxKey(wptr!, txid: txId);
wownero.Wallet_status(wptr!);
return ret;
}
wownero.TransactionHistory? txhistory;

View file

@ -463,8 +463,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
resolved-ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
resolved-ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"

View file

@ -25,7 +25,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: 6eb571ea498ed7b854934785f00fabfd0dadf75b # monero_c hash
ref: 33f6ef2fa28ebcc799529230bbb026a5f9385894 # monero_c hash
path: impls/monero.dart
mutex: ^3.1.0

View file

@ -19,6 +19,7 @@ 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

View file

@ -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 6eb571ea498ed7b854934785f00fabfd0dadf75b
git checkout 33f6ef2fa28ebcc799529230bbb026a5f9385894
git reset --hard
git submodule update --init --force --recursive
./apply_patches.sh monero