mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-25 12:06:05 +00:00
fix coin freezing
This commit is contained in:
parent
c3019b91cd
commit
0e5a125611
12 changed files with 80 additions and 29 deletions
|
@ -12,6 +12,18 @@ int countOfCoins() => monero.Coins_count(coins!);
|
||||||
|
|
||||||
monero.CoinsInfo getCoin(int index) => monero.Coins_coin(coins!, index);
|
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 freezeCoin(int index) => monero.Coins_setFrozen(coins!, index: index);
|
||||||
|
|
||||||
void thawCoin(int index) => monero.Coins_thaw(coins!, index: index);
|
void thawCoin(int index) => monero.Coins_thaw(coins!, index: index);
|
||||||
|
|
|
@ -13,7 +13,9 @@ import 'package:mutex/mutex.dart';
|
||||||
|
|
||||||
|
|
||||||
String getTxKey(String txId) {
|
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();
|
final txHistoryMutex = Mutex();
|
||||||
monero.TransactionHistory? txhistory;
|
monero.TransactionHistory? txhistory;
|
||||||
|
@ -88,6 +90,8 @@ Future<PendingTransactionDescription> createTransactionSync(
|
||||||
|
|
||||||
final address_ = address.toNativeUtf8();
|
final address_ = address.toNativeUtf8();
|
||||||
final paymentId_ = paymentId.toNativeUtf8();
|
final paymentId_ = paymentId.toNativeUtf8();
|
||||||
|
print("inputs: $preferredInputs");
|
||||||
|
|
||||||
final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8();
|
final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8();
|
||||||
|
|
||||||
final waddr = wptr!.address;
|
final waddr = wptr!.address;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:cw_monero/api/account_list.dart';
|
import 'package:cw_monero/api/account_list.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;
|
import 'package:monero/monero.dart' as monero;
|
||||||
import 'package:mutex/mutex.dart';
|
import 'package:mutex/mutex.dart';
|
||||||
|
|
||||||
|
@ -119,7 +120,6 @@ Future<bool> setupNodeSync(
|
||||||
daemonUsername: login ?? '',
|
daemonUsername: login ?? '',
|
||||||
daemonPassword: password ?? '');
|
daemonPassword: password ?? '');
|
||||||
});
|
});
|
||||||
// monero.Wallet_init3(wptr!, argv0: '', defaultLogBaseName: 'moneroc', console: true);
|
|
||||||
|
|
||||||
final status = monero.Wallet_status(wptr!);
|
final status = monero.Wallet_status(wptr!);
|
||||||
|
|
||||||
|
@ -129,6 +129,15 @@ Future<bool> setupNodeSync(
|
||||||
throw SetupWalletException(message: error);
|
throw SetupWalletException(message: error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kDebugMode) {
|
||||||
|
monero.Wallet_init3(
|
||||||
|
wptr!, argv0: '',
|
||||||
|
defaultLogBaseName: 'moneroc',
|
||||||
|
console: true,
|
||||||
|
logPath: '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return status == 0;
|
return status == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,32 @@
|
||||||
import 'package:cw_core/unspent_transaction_output.dart';
|
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 {
|
class MoneroUnspent extends Unspent {
|
||||||
MoneroUnspent(
|
MoneroUnspent(
|
||||||
String address, String hash, String keyImage, int value, bool isFrozen, this.isUnlocked)
|
String address, String hash, String keyImage, int value, bool isFrozen, this.isUnlocked)
|
||||||
: super(address, hash, value, 0, keyImage) {
|
: 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;
|
final bool isUnlocked;
|
||||||
|
|
|
@ -275,9 +275,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
'You do not have enough XMR to send this amount.');
|
'You do not have enough XMR to send this amount.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spendAllCoins && (allInputsAmount < totalAmount + estimatedFee)) {
|
// if (!spendAllCoins && (allInputsAmount < totalAmount + estimatedFee)) {
|
||||||
throw MoneroTransactionNoInputsException(inputs.length);
|
// throw MoneroTransactionNoInputsException(inputs.length);
|
||||||
}
|
// }
|
||||||
|
|
||||||
final moneroOutputs = outputs.map((output) {
|
final moneroOutputs = outputs.map((output) {
|
||||||
final outputAddress =
|
final outputAddress =
|
||||||
|
@ -303,23 +303,22 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
final formattedAmount =
|
final formattedAmount =
|
||||||
output.sendAll ? null : output.formattedCryptoAmount;
|
output.sendAll ? null : output.formattedCryptoAmount;
|
||||||
|
|
||||||
if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
|
// if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
|
||||||
(formattedAmount == null && unlockedBalance <= 0)) {
|
// (formattedAmount == null && unlockedBalance <= 0)) {
|
||||||
final formattedBalance = moneroAmountToString(amount: unlockedBalance);
|
// final formattedBalance = moneroAmountToString(amount: unlockedBalance);
|
||||||
|
//
|
||||||
throw MoneroTransactionCreationException(
|
// throw MoneroTransactionCreationException(
|
||||||
'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
|
// 'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
|
||||||
}
|
// }
|
||||||
|
|
||||||
final estimatedFee =
|
final estimatedFee =
|
||||||
calculateEstimatedFee(_credentials.priority, formattedAmount);
|
calculateEstimatedFee(_credentials.priority, formattedAmount);
|
||||||
if (!spendAllCoins &&
|
// if (!spendAllCoins &&
|
||||||
((formattedAmount != null &&
|
// ((formattedAmount != null &&
|
||||||
allInputsAmount < (formattedAmount + estimatedFee)) ||
|
// allInputsAmount < (formattedAmount + estimatedFee)) ||
|
||||||
formattedAmount == null)) {
|
// formattedAmount == null)) {
|
||||||
throw MoneroTransactionNoInputsException(inputs.length);
|
// throw MoneroTransactionNoInputsException(inputs.length);
|
||||||
}
|
// }
|
||||||
|
|
||||||
pendingTransactionDescription =
|
pendingTransactionDescription =
|
||||||
await transaction_history.createTransaction(
|
await transaction_history.createTransaction(
|
||||||
address: address!,
|
address: address!,
|
||||||
|
@ -329,6 +328,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
preferredInputs: inputs);
|
preferredInputs: inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// final status = monero.PendingTransaction_status(pendingTransactionDescription);
|
||||||
|
|
||||||
return PendingMoneroTransaction(pendingTransactionDescription);
|
return PendingMoneroTransaction(pendingTransactionDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -463,8 +463,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "impls/monero.dart"
|
path: "impls/monero.dart"
|
||||||
ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
|
ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
|
||||||
resolved-ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
|
resolved-ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
|
||||||
url: "https://github.com/mrcyjanek/monero_c"
|
url: "https://github.com/mrcyjanek/monero_c"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
|
|
@ -25,7 +25,7 @@ dependencies:
|
||||||
monero:
|
monero:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/mrcyjanek/monero_c
|
url: https://github.com/mrcyjanek/monero_c
|
||||||
ref: 6eb571ea498ed7b854934785f00fabfd0dadf75b # monero_c hash
|
ref: 33f6ef2fa28ebcc799529230bbb026a5f9385894 # monero_c hash
|
||||||
path: impls/monero.dart
|
path: impls/monero.dart
|
||||||
mutex: ^3.1.0
|
mutex: ^3.1.0
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ import 'package:monero/src/generated_bindings_wownero.g.dart' as wownero_gen;
|
||||||
|
|
||||||
|
|
||||||
String getTxKey(String txId) {
|
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;
|
wownero.TransactionHistory? txhistory;
|
||||||
|
|
|
@ -463,8 +463,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "impls/monero.dart"
|
path: "impls/monero.dart"
|
||||||
ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
|
ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
|
||||||
resolved-ref: "6eb571ea498ed7b854934785f00fabfd0dadf75b"
|
resolved-ref: "33f6ef2fa28ebcc799529230bbb026a5f9385894"
|
||||||
url: "https://github.com/mrcyjanek/monero_c"
|
url: "https://github.com/mrcyjanek/monero_c"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
|
|
@ -25,7 +25,7 @@ dependencies:
|
||||||
monero:
|
monero:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/mrcyjanek/monero_c
|
url: https://github.com/mrcyjanek/monero_c
|
||||||
ref: 6eb571ea498ed7b854934785f00fabfd0dadf75b # monero_c hash
|
ref: 33f6ef2fa28ebcc799529230bbb026a5f9385894 # monero_c hash
|
||||||
path: impls/monero.dart
|
path: impls/monero.dart
|
||||||
mutex: ^3.1.0
|
mutex: ^3.1.0
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ case $APP_ANDROID_TYPE in
|
||||||
CONFIG_ARGS="--haven"
|
CONFIG_ARGS="--haven"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
CONFIG_ARGS="--monero --ethereum --polygon --nano --solana --tron --wownero"
|
||||||
|
|
||||||
cd ../..
|
cd ../..
|
||||||
cp -rf pubspec_description.yaml pubspec.yaml
|
cp -rf pubspec_description.yaml pubspec.yaml
|
||||||
|
|
|
@ -8,7 +8,7 @@ if [[ ! -d "monero_c" ]];
|
||||||
then
|
then
|
||||||
git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip
|
git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip
|
||||||
cd monero_c
|
cd monero_c
|
||||||
git checkout 6eb571ea498ed7b854934785f00fabfd0dadf75b
|
git checkout 33f6ef2fa28ebcc799529230bbb026a5f9385894
|
||||||
git reset --hard
|
git reset --hard
|
||||||
git submodule update --init --force --recursive
|
git submodule update --init --force --recursive
|
||||||
./apply_patches.sh monero
|
./apply_patches.sh monero
|
||||||
|
|
Loading…
Reference in a new issue