]> git.codecow.com Git - libnemo.git/commitdiff
Rename RPC schema object and fix unit conversion lookups.
authorChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 19:37:27 +0000 (12:37 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 19:37:27 +0000 (12:37 -0700)
src/lib/account/refresh.ts
src/lib/block/receive.ts
src/lib/block/send.ts
src/lib/ledger/index.ts
src/lib/rpc/index.ts
src/lib/rpc/schema.ts

index 98886740e00a2cbd0fbfd0fa3a32cbb2bb4cc449..ae964f35ef29889d05f3f0372353025918cebeef 100644 (file)
@@ -3,8 +3,7 @@
 
 import { Account } from '.'
 import { Block } from '../block'
-import { SCHEMA } from '../constants'
-import { Rpc } from '../rpc'
+import { Rpc, Schema } from '../rpc'
 
 export async function _refresh (account: Account, rpc: Rpc | string | URL): Promise<void>
 export async function _refresh (account: Account, rpc: unknown): Promise<void> {
@@ -30,7 +29,7 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
                throw new Error('Account not found')
        }
        for (const [k, v] of Object.entries(accountInfo)) {
-               if (SCHEMA.account_info.fields.includes(k) && typeof v === 'string') {
+               if (Schema.account_info.fields.includes(k) && typeof v === 'string') {
                        account[k] = v
                }
        }
@@ -52,7 +51,7 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
        }
        const confirmedFrontierContents: Record<string, string> = {}
        for (const [k, v] of Object.entries(resConfirmedFrontierBlockInfo.contents)) {
-               if (SCHEMA.block_info.contents.fields.includes(k) && typeof v === 'string') {
+               if (Schema.block_info.contents.fields.includes(k) && typeof v === 'string') {
                        confirmedFrontierContents[k] = v
                }
        }
@@ -80,7 +79,7 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
        }
        const frontierContents: Record<string, string> = {}
        for (const [k, v] of Object.entries(resFrontierBlockInfo.contents)) {
-               if (SCHEMA.block_info.contents.fields.includes(k) && typeof v === 'string') {
+               if (Schema.block_info.contents.fields.includes(k) && typeof v === 'string') {
                        frontierContents[k] = v
                }
        }
index bfb5229d21b398b036b95cc13ca39d25dcbd1e80..89044cd72907f3300e2d852a064fdfbabc5ed0e1 100644 (file)
@@ -24,7 +24,7 @@ export function _receive (block: Block, sendBlock: unknown, amount: unknown, uni
                block.subtype = 'receive'
 
                unit ??= 'RAW'
-               if (typeof unit !== 'string' || typeof UNITS[unit] !== 'number') {
+               if (typeof unit !== 'string' || typeof UNITS[unit as keyof typeof UNITS] !== 'number') {
                        throw new TypeError('Invalid unit')
                }
 
index 00552af2a2d329b37217df5ea2a78f6da0714bde..5d42a761da2737f3d42eab0b6543646b832b6e78 100644 (file)
@@ -23,7 +23,7 @@ export function _send (block: Block, account: unknown, amount: unknown, unit: un
                block.subtype = 'send'
 
                unit ??= 'RAW'
-               if (typeof unit !== 'string' || typeof UNITS[unit] !== 'number') {
+               if (typeof unit !== 'string' || typeof UNITS[unit as keyof typeof UNITS] !== 'number') {
                        throw new TypeError('Invalid unit', { cause: unit })
                }
 
index 9c175cfa26e9a76f8cce24b7f42672c60678479a..032af1213438944b41662285d41731c05c6adddc 100644 (file)
@@ -8,8 +8,7 @@ import TransportUSB from '@ledgerhq/hw-transport-webusb'
 import { Block } from '../block'
 import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from '../constants'
 import { dec } from '../convert'
-import { Rpc } from '../rpc'
-import { SCHEMA } from '../rpc/schema'
+import { Rpc, Schema } from '../rpc'
 import { _account } from './account'
 import { _cache } from './cache'
 import { _close } from './close'
@@ -244,7 +243,7 @@ export class Ledger {
                        }
                        const contents = {} as Record<string, string>
                        for (const [k, v] of Object.entries(blockInfo.contents)) {
-                               if (SCHEMA.block_info.fields.includes(k)) {
+                               if (Schema.block_info.fields.includes(k)) {
                                        contents[k] = v
                                }
                        }
index bb1881f86375e89deb42c9a848862a2ecd56fbd7..2d1c1f42d9206c2d6459a548f62dc3f1c94c35f2 100644 (file)
@@ -1,6 +1,8 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
-import { SCHEMA } from './schema'
+import { Schema } from './schema'
+
+export { Schema }
 
 /**
  * Represents a Nano network node. It primarily consists of a URL which will
@@ -91,7 +93,7 @@ export class Rpc {
                if (!/^[A-Za-z]+(_[A-Za-z]+)*$/.test(action)) {
                        throw new TypeError('RPC action contains invalid characters')
                }
-               if (!(action in SCHEMA)) {
+               if (!(action in Schema)) {
                        throw new TypeError('Unknown RPC action')
                }
        }
index 6a7cf51b77b24b8fc6fdbec84f941490054256fa..7af2f2ec716f639565ceea3eaaa48e6a436e6a8c 100644 (file)
@@ -3,7 +3,7 @@
 import { account_info } from './account_info'
 import { block_info } from './block_info'
 
-export const SCHEMA = Object.freeze({
+export const Schema = Object.freeze({
        account_info,
        block_info,
 })