create accounts/subaddresses, chunked address style, fix canSend for subaddresses

This commit is contained in:
2026-05-26 13:33:28 +08:00
parent 34602a4bfa
commit 2139d5e6ff
7 changed files with 259 additions and 12 deletions
+2
View File
@@ -17,6 +17,8 @@ export {
getDaemonHeight,
transfer,
sweepAll,
createAccount,
createSubaddress,
isWalletOpen,
isConnected,
listWallets,
+26
View File
@@ -259,6 +259,32 @@ export async function getAddress(
return address
}
export async function createAccount(
state: MoneroWalletState,
label?: string,
): Promise<{ index: number; address: string }> {
if (!state.wallet) throw new Error('Wallet RPC not started')
const result = await rawRpc(state, 'create_account', {
label: label ?? '',
})
console.log(`[monero] created account ${result.account_index}: ${result.address}`)
return { index: result.account_index, address: result.address }
}
export async function createSubaddress(
state: MoneroWalletState,
accountIndex: number,
label?: string,
): Promise<{ index: number; address: string }> {
if (!state.wallet) throw new Error('Wallet RPC not started')
const result = await rawRpc(state, 'create_address', {
account_index: accountIndex,
label: label ?? '',
})
console.log(`[monero] created subaddress ${result.address_index} for account ${accountIndex}: ${result.address}`)
return { index: result.address_index, address: result.address }
}
export async function getAccounts(
state: MoneroWalletState,
): Promise<any[]> {
+26
View File
@@ -18,6 +18,8 @@ import {
getFeeEstimate as walletGetFeeEstimate,
transfer as walletTransfer,
sweepAll as walletSweepAll,
createAccount as walletCreateAccount,
createSubaddress as walletCreateSubaddress,
isWalletOpen,
isConnected,
} from '../../lib/monero'
@@ -256,6 +258,30 @@ export function createMoneroHandlers(state: {
console.log('[rpc] moneroSweepAll complete:', result.txHash)
return result
},
moneroCreateAccount: async ({ label }: { label?: string }) => {
console.log('[rpc] moneroCreateAccount:', { label })
if (!state.manager) throw new Error('Monero wallet RPC not started')
const result = await walletCreateAccount(state.manager, label)
console.log('[rpc] moneroCreateAccount complete:', result)
return result
},
moneroCreateSubaddress: async ({
accountIndex,
label,
}: {
accountIndex: number
label?: string
}) => {
console.log('[rpc] moneroCreateSubaddress:', { accountIndex, label })
if (!state.manager) throw new Error('Monero wallet RPC not started')
const result = await walletCreateSubaddress(
state.manager,
accountIndex,
label,
)
console.log('[rpc] moneroCreateSubaddress complete:', result)
return result
},
moneroGetTransferDetails: async ({ txid }: { txid: string }) => {
console.log('[rpc] moneroGetTransferDetails:', txid)
if (!state.manager)