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
+47
View File
@@ -196,6 +196,53 @@ final class MoneroService {
}
}
// MARK: - Accounts
func accounts() async throws -> [MoneroAccount] {
let response = try await invoke(["op": "getAccounts"])
let entries = response["accounts"] as? [[String: Any]] ?? []
return entries.map { entry in
let subEntries = entry["subaddresses"] as? [[String: Any]] ?? []
return MoneroAccount(
index: (entry["index"] as? NSNumber)?.intValue ?? 0,
address: entry["address"] as? String ?? "",
balance: MoneroAmount.xmr(fromAtomic: entry["balance"] as? String ?? "0"),
unlocked: MoneroAmount.xmr(fromAtomic: entry["unlocked"] as? String ?? "0"),
subaddresses: subEntries.map { sub in
MoneroSubaddress(
accountIndex: (sub["accountIndex"] as? NSNumber)?.intValue ?? 0,
index: (sub["index"] as? NSNumber)?.intValue ?? 0,
address: sub["address"] as? String ?? "",
label: sub["label"] as? String ?? "",
balance: MoneroAmount.xmr(fromAtomic: sub["balance"] as? String ?? "0"),
unlocked: MoneroAmount.xmr(fromAtomic: sub["unlocked"] as? String ?? "0"),
isUsed: (sub["isUsed"] as? Bool) ?? false)
})
}
}
func createAccount(label: String) async throws -> MoneroAccount {
let response = try await invoke(["op": "createAccount", "label": label])
return MoneroAccount(index: (response["index"] as? NSNumber)?.intValue ?? 0,
address: response["address"] as? String ?? "",
balance: MoneroAmount.xmr(fromAtomic: response["balance"] as? String ?? "0"),
unlocked: MoneroAmount.xmr(fromAtomic: response["unlocked"] as? String ?? "0"),
subaddresses: [])
}
func createSubaddress(accountIndex: Int, label: String) async throws -> MoneroSubaddress {
let response = try await invoke(["op": "createSubaddress",
"accountIndex": accountIndex,
"label": label])
return MoneroSubaddress(accountIndex: (response["accountIndex"] as? NSNumber)?.intValue ?? accountIndex,
index: (response["index"] as? NSNumber)?.intValue ?? 0,
address: response["address"] as? String ?? "",
label: response["label"] as? String ?? label,
balance: "0",
unlocked: "0",
isUsed: false)
}
// MARK: - Sync
func startSync() async throws -> Bool {