Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CW-867 Wownero fixes #1881

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cw_monero/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: af5277f96073917185864d3596e82b67bee54e78
resolved-ref: af5277f96073917185864d3596e82b67bee54e78
ref: 1193898122baaff465aa698fc3fab1a86da22395
resolved-ref: 1193898122baaff465aa698fc3fab1a86da22395
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion cw_monero/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: af5277f96073917185864d3596e82b67bee54e78
ref: 1193898122baaff465aa698fc3fab1a86da22395
# ref: 6eb571ea498ed7b854934785f00fabfd0dadf75b # monero_c hash
path: impls/monero.dart
mutex: ^3.1.0
Expand Down
10 changes: 7 additions & 3 deletions cw_wownero/lib/api/transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:cw_wownero/exceptions/wownero_transaction_creation_exception.dar
import 'package:ffi/ffi.dart';
import 'package:monero/wownero.dart' as wownero;
import 'package:monero/src/generated_bindings_wownero.g.dart' as wownero_gen;
import 'package:mutex/mutex.dart';


String getTxKey(String txId) {
Expand All @@ -18,29 +19,32 @@ String getTxKey(String txId) {
return ret;
}

final txHistoryMutex = Mutex();
wownero.TransactionHistory? txhistory;

bool isRefreshingTx = false;
Future<void> refreshTransactions() async {
if (isRefreshingTx == true) return;
isRefreshingTx = true;
txhistory ??= wownero.Wallet_history(wptr!);
final ptr = txhistory!.address;
await txHistoryMutex.acquire();
await Isolate.run(() {
wownero.TransactionHistory_refresh(Pointer.fromAddress(ptr));
});
txHistoryMutex.release();
isRefreshingTx = false;
}

int countOfTransactions() => wownero.TransactionHistory_count(txhistory!);

List<Transaction> getAllTransactions() {
Future<List<Transaction>> getAllTransactions() async {
List<Transaction> dummyTxs = [];

await txHistoryMutex.acquire();
txhistory ??= wownero.Wallet_history(wptr!);
wownero.TransactionHistory_refresh(txhistory!);
int size = countOfTransactions();
final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index)));
txHistoryMutex.release();

final accts = wownero.Wallet_numSubaddressAccounts(wptr!);
for (var i = 0; i < accts; i++) {
Expand Down
1 change: 1 addition & 0 deletions cw_wownero/lib/api/wallet_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void restoreWalletFromSeedSync(
}

wptr = newWptr;
wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);

openedWalletsByPath[path] = wptr!;
}
Expand Down
8 changes: 4 additions & 4 deletions cw_wownero/lib/wownero_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ abstract class WowneroWalletBase
@override
Future<Map<String, WowneroTransactionInfo>> fetchTransactions() async {
transaction_history.refreshTransactions();
return _getAllTransactionsOfAccount(walletAddresses.account?.id)
return (await _getAllTransactionsOfAccount(walletAddresses.account?.id))
.fold<Map<String, WowneroTransactionInfo>>(<String, WowneroTransactionInfo>{},
(Map<String, WowneroTransactionInfo> acc, WowneroTransactionInfo tx) {
acc[tx.id] = tx;
Expand Down Expand Up @@ -586,9 +586,9 @@ abstract class WowneroWalletBase
String getSubaddressLabel(int accountIndex, int addressIndex) =>
wownero_wallet.getSubaddressLabel(accountIndex, addressIndex);

List<WowneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) =>
transaction_history
.getAllTransactions()
Future<List<WowneroTransactionInfo>> _getAllTransactionsOfAccount(int? accountIndex) async =>
(await transaction_history
.getAllTransactions())
.map(
(row) => WowneroTransactionInfo(
row.hash,
Expand Down
4 changes: 2 additions & 2 deletions cw_wownero/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: af5277f96073917185864d3596e82b67bee54e78
resolved-ref: af5277f96073917185864d3596e82b67bee54e78
ref: 1193898122baaff465aa698fc3fab1a86da22395
resolved-ref: 1193898122baaff465aa698fc3fab1a86da22395
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion cw_wownero/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: af5277f96073917185864d3596e82b67bee54e78
ref: 1193898122baaff465aa698fc3fab1a86da22395
# ref: 6eb571ea498ed7b854934785f00fabfd0dadf75b # monero_c hash
path: impls/monero.dart
mutex: ^3.1.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare_moneroc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [[ ! -d "monero_c" ]];
then
git clone https://github.com/mrcyjanek/monero_c --branch master
cd monero_c
git checkout af5277f96073917185864d3596e82b67bee54e78
git checkout 1193898122baaff465aa698fc3fab1a86da22395
git reset --hard
git submodule update --init --force --recursive
./apply_patches.sh monero
Expand Down