cake_wallet/cw_monero/lib/api/subaddress_list.dart

72 lines
2.2 KiB
Dart
Raw Normal View History

2024-04-10 12:27:10 +00:00
import 'package:cw_monero/api/account_list.dart';
import 'package:cw_monero/api/wallet.dart';
2024-04-10 12:27:10 +00:00
import 'package:monero/monero.dart' as monero;
bool isUpdating = false;
2024-04-12 12:54:24 +00:00
monero.Subaddress? subaddressPtr = null;
2022-10-12 17:09:57 +00:00
void refreshSubaddresses({required int accountIndex}) {
try {
isUpdating = true;
2024-04-12 12:54:24 +00:00
subaddressPtr = monero.Wallet_subaddress(wptr!);
monero.Subaddress_refresh(subaddressPtr!,accountIndex: accountIndex, label: '');
isUpdating = false;
} catch (e) {
isUpdating = false;
rethrow;
}
}
2024-04-10 12:27:10 +00:00
List<monero.SubaddressRow> getAllSubaddresses() {
2024-04-12 12:54:24 +00:00
monero.Subaddress_refresh(subaddressPtr!,
accountIndex: 0,
label: '' // BUG: by me (mrcyjanek), it isn't used, will remove.
);
final size = monero.Subaddress_getAll_size(subaddressPtr!);
2024-04-10 12:27:10 +00:00
return List.generate(size, (index) {
2024-04-12 12:54:24 +00:00
return monero.Subaddress_getAll_byIndex(subaddressAccount!, index: index);
2024-04-10 12:27:10 +00:00
});
}
2022-10-12 17:09:57 +00:00
void addSubaddressSync({required int accountIndex, required String label}) {
2024-04-10 12:27:10 +00:00
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex, label: label);
2024-04-12 12:54:24 +00:00
refreshSubaddresses(accountIndex: accountIndex);
}
void setLabelForSubaddressSync(
2022-10-12 17:09:57 +00:00
{required int accountIndex, required int addressIndex, required String label}) {
2024-04-10 12:27:10 +00:00
monero.Wallet_setSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: addressIndex, label: label);
}
void _addSubaddress(Map<String, dynamic> args) {
final label = args['label'] as String;
final accountIndex = args['accountIndex'] as int;
addSubaddressSync(accountIndex: accountIndex, label: label);
}
void _setLabelForSubaddress(Map<String, dynamic> 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);
}
2022-10-12 17:09:57 +00:00
Future<void> addSubaddress({required int accountIndex, required String label}) async {
2024-04-10 12:27:10 +00:00
_addSubaddress({'accountIndex': accountIndex, 'label': label});
await store();
}
2022-10-12 17:09:57 +00:00
Future<void> setLabelForSubaddress(
{required int accountIndex, required int addressIndex, required String label}) async {
2024-04-10 12:27:10 +00:00
_setLabelForSubaddress({
'accountIndex': accountIndex,
'addressIndex': addressIndex,
'label': label
});
await store();
}