Add Monero subaccounts and subaddresses with a QR per address

This commit is contained in:
2026-09-20 00:11:53 +08:00
parent 1a23c730c6
commit caca4321cc
7 changed files with 332 additions and 3 deletions
@@ -224,6 +224,59 @@ static void connectDaemon(monero_wallet_full *w) {
}
resp[@"transactions"] = entries;
}
} else if ([op isEqualToString:@"getAccounts"]) {
NSMutableArray *accounts = [NSMutableArray new];
if (!g_wallet) {
resp[@"accounts"] = accounts;
} else {
for (const auto &account : g_wallet->get_accounts(true, "")) {
NSMutableDictionary *accountDict = [NSMutableDictionary new];
accountDict[@"index"] = @(account.m_index ? *account.m_index : 0);
accountDict[@"address"] = [NSString stringWithUTF8String:(account.m_primary_address ? *account.m_primary_address : "").c_str()];
accountDict[@"balance"] = @((account.m_balance ? *account.m_balance : 0)).stringValue;
accountDict[@"unlocked"] = @((account.m_unlocked_balance ? *account.m_unlocked_balance : 0)).stringValue;
NSMutableArray *subaddresses = [NSMutableArray new];
for (const auto &sub : account.m_subaddresses) {
[subaddresses addObject:@{
@"accountIndex" : @(sub.m_account_index ? *sub.m_account_index : 0),
@"index" : @(sub.m_index ? *sub.m_index : 0),
@"address" : [NSString stringWithUTF8String:(sub.m_address ? *sub.m_address : "").c_str()],
@"label" : [NSString stringWithUTF8String:(sub.m_label ? *sub.m_label : "").c_str()],
@"balance" : @((sub.m_balance ? *sub.m_balance : 0)).stringValue,
@"unlocked" : @((sub.m_unlocked_balance ? *sub.m_unlocked_balance : 0)).stringValue,
@"isUsed" : @((sub.m_is_used ? *sub.m_is_used : false)),
}];
}
accountDict[@"subaddresses"] = subaddresses;
[accounts addObject:accountDict];
}
resp[@"accounts"] = accounts;
}
} else if ([op isEqualToString:@"createAccount"]) {
if (!g_wallet) {
resp[@"error"] = @"No wallet open";
} else {
monero_account account = g_wallet->create_account(std::string([req[@"label"] UTF8String]));
g_wallet->save();
excludeWalletFilesFromBackup(g_walletPath);
resp[@"index"] = @(account.m_index ? *account.m_index : 0);
resp[@"address"] = [NSString stringWithUTF8String:(account.m_primary_address ? *account.m_primary_address : "").c_str()];
resp[@"balance"] = @((account.m_balance ? *account.m_balance : 0)).stringValue;
resp[@"unlocked"] = @((account.m_unlocked_balance ? *account.m_unlocked_balance : 0)).stringValue;
}
} else if ([op isEqualToString:@"createSubaddress"]) {
if (!g_wallet) {
resp[@"error"] = @"No wallet open";
} else {
uint32_t accountIndex = (uint32_t)[req[@"accountIndex"] integerValue];
monero_subaddress sub = g_wallet->create_subaddress(accountIndex, std::string([req[@"label"] UTF8String]));
g_wallet->save();
excludeWalletFilesFromBackup(g_walletPath);
resp[@"accountIndex"] = @(sub.m_account_index ? *sub.m_account_index : 0);
resp[@"index"] = @(sub.m_index ? *sub.m_index : 0);
resp[@"address"] = [NSString stringWithUTF8String:(sub.m_address ? *sub.m_address : "").c_str()];
resp[@"label"] = [NSString stringWithUTF8String:(sub.m_label ? *sub.m_label : "").c_str()];
}
} else if ([op isEqualToString:@"startSync"]) {
if (g_wallet) {
connectDaemon(g_wallet);