import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:flutter/foundation.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/subaddress_row.dart'; final subaddressSizeNative = moneroApi .lookup>('subaddrress_size') .asFunction(); final subaddressRefreshNative = moneroApi .lookup>('subaddress_refresh') .asFunction(); final subaddrressGetAllNative = moneroApi .lookup>('subaddrress_get_all') .asFunction(); final subaddrressAddNewNative = moneroApi .lookup>('subaddress_add_row') .asFunction(); final subaddrressSetLabelNative = moneroApi .lookup>('subaddress_set_label') .asFunction(); void refreshSubaddresses({int accountIndex}) => subaddressRefreshNative(accountIndex); List getAllSubaddresses() { final size = subaddressSizeNative(); final subaddressAddressesPointer = subaddrressGetAllNative(); final subaddressAddresses = subaddressAddressesPointer.asTypedList(size); return subaddressAddresses .map((addr) => Pointer.fromAddress(addr).ref) .toList(); } void addSubaddressSync({int accountIndex, String label}) { final labelPointer = Utf8.toUtf8(label); subaddrressAddNewNative(accountIndex, labelPointer); free(labelPointer); } void setLabelForSubaddressSync( {int accountIndex, int addressIndex, String label}) { final labelPointer = Utf8.toUtf8(label); subaddrressSetLabelNative(accountIndex, addressIndex, labelPointer); free(labelPointer); } void _addSubaddress(Map args) { final label = args['label'] as String; final accountIndex = args['accountIndex'] as int; addSubaddressSync(accountIndex: accountIndex, label: label); } void _setLabelForSubaddress(Map args) { final label = args['label'] as String; final accountIndex = args['accountIndex'] as int; final addressIndex = args['addressIndex'] as int; setLabelForSubaddressSync( accountIndex: accountIndex, addressIndex: addressIndex, label: label); } Future addSubaddress({int accountIndex, String label}) async => compute(_addSubaddress, {'accountIndex': accountIndex, 'label': label}); Future setLabelForSubaddress( {int accountIndex, int addressIndex, String label}) => compute(_setLabelForSubaddress, { 'accountIndex': accountIndex, 'addressIndex': addressIndex, 'label': label });