]> git.codecow.com Git - libnemo.git/commitdiff
Fix account refresh rep setting and refactor RPC error logging.
authorChris Duncan <chris@codecow.com>
Tue, 4 Aug 2026 18:51:17 +0000 (11:51 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 4 Aug 2026 18:51:17 +0000 (11:51 -0700)
src/lib/rpc/index.ts
src/lib/wallet/refresh.ts

index e05192e7c4760736e4e91914ce20f689e66544cb..90f6e2402b45e30ee8379963f11a848d9ef9e581 100644 (file)
@@ -67,11 +67,17 @@ export class Rpc {
                }, 10000)
                try {
                        const res = await fetch(req)
-                       const { status, statusText } = res
+                       const status = res.status
+                       const statusText = res.statusText ? ` ${res.statusText}` : ''
+                       if (status !== 200) {
+                               throw new Error(`${status} ${statusText}`, { cause: JSON.stringify(res) })
+                       }
                        const resBody = await res.json()
-                       const { error, message } = resBody
-                       if (status !== 200 || error != null) {
-                               throw new Error(`${status} ${statusText}`, { cause: { error, message } })
+                       const code = resBody.code ? `${resBody.code} ` : ''
+                       const error = resBody.error ? `${resBody.error}\n` : ''
+                       const message = resBody.message ?? ''
+                       if (error) {
+                               throw new Error(`${code}${error}${message}`, { cause: JSON.stringify(resBody) })
                        }
                        return resBody
                } catch (err) {
index aaa286f9d1d0106491ebbac6c9dc04248545f0a2..24e4dcfdd30f683e02d8b8a226f26ccfe9fc2b18 100644 (file)
@@ -42,17 +42,14 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to:
                }
                const { balances } = await rpc.post('accounts_balances', data) as { balances?: { [address: string]: { balance: string, receivable: string } } }
                const { frontiers } = await rpc.post('accounts_frontiers', data) as { frontiers: { [address: string]: string } }
-               const { representatives } = await rpc.post('accounts_representatives', data) as { representatives: { [address: string]: string } }
                const { blocks } = await rpc.post('blocks_info', { json_block: true, hashes: Object.values(frontiers) }) as BlockInfo
                for (const account of accounts.values()) {
                        account.balance = balances?.[account.address]?.balance ?? 0
                        account.receivable = balances?.[account.address]?.receivable ?? 0
-                       account.representative = representatives?.[account.address]
                        if (frontiers[account.address] != null) {
-                               const { representative: accountRepresentative } = await rpc.post('account_representative', { account: account.address }) as { representative: string }
-                               account.representative ??= accountRepresentative
                                account.frontier = frontiers[account.address]
                                const { subtype, contents: { balance, link, previous, representative, signature } } = blocks[account.frontier]
+                               account.representative = representative
                                const frontierBlock = new Block(account, balance, previous, representative)
                                if (typeof frontierBlock[subtype] !== 'function') {
                                        throw new TypeError('Unknown frontier block subtype', { cause: subtype })