import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:cw_monero/signatures.dart'; import 'package:cw_monero/types.dart'; import 'package:cw_monero/monero_api.dart'; import 'package:cw_monero/structs/account_row.dart'; import 'package:flutter/foundation.dart'; final accountSizeNative = moneroApi .lookup>('account_size') .asFunction(); final accountRefreshNative = moneroApi .lookup>('account_refresh') .asFunction(); final accountGetAllNative = moneroApi .lookup>('account_get_all') .asFunction(); final accountAddNewNative = moneroApi .lookup>('account_add_row') .asFunction(); final accountSetLabelNative = moneroApi .lookup>('account_set_label_row') .asFunction(); refreshAccounts() => accountRefreshNative(); List getAllAccount() { final size = accountSizeNative(); final accountAddressesPointer = accountGetAllNative(); final accountAddresses = accountAddressesPointer.asTypedList(size); return accountAddresses .map((addr) => Pointer.fromAddress(addr).ref) .toList(); } addAccountSync({String label}) { final labelPointer = Utf8.toUtf8(label); accountAddNewNative(labelPointer); free(labelPointer); } setLabelForAccountSync({int accountIndex, String label}) { final labelPointer = Utf8.toUtf8(label); accountSetLabelNative(accountIndex, labelPointer); free(labelPointer); } _addAccount(String label) => addAccountSync(label: label); _setLabelForAccount(Map args) => setLabelForAccountSync( label: args['label'], accountIndex: args['accountIndex']); Future addAccount({String label}) async => compute(_addAccount, label); Future setLabelForAccount({int accountIndex, String label}) async => compute( _setLabelForAccount, {'accountIndex': accountIndex, 'label': label});