From: Chris Duncan Date: Sun, 9 Aug 2026 16:40:48 +0000 (-0700) Subject: Call other subtype Block methods explicitly. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=03e2e1788d048e383549eae912f963ce7614cc3a;p=libnemo.git Call other subtype Block methods explicitly. --- diff --git a/src/lib/account/refresh.ts b/src/lib/account/refresh.ts index 9172309..10c14ce 100644 --- a/src/lib/account/refresh.ts +++ b/src/lib/account/refresh.ts @@ -40,8 +40,6 @@ export async function _refresh (account: Account, rpc: unknown): Promise { throw new Error('Confirmed frontier block info subtype not found') } const confirmedFrontierSubtype = resConfirmedFrontierBlockInfo.subtype - if (!['change', 'epoch', 'open', 'receive', 'send'].includes(confirmedFrontierSubtype)) { - throw new RangeError('Invalid subtype for confirmed frontier block', { cause: confirmedFrontierSubtype }) } if (!('contents' in resConfirmedFrontierBlockInfo) || resConfirmedFrontierBlockInfo.contents == null || typeof resConfirmedFrontierBlockInfo.contents !== 'object') { throw new Error('Confirmed frontier block info contents not found') @@ -51,15 +49,14 @@ export async function _refresh (account: Account, rpc: unknown): Promise { confirmedFrontierContents[k] = v } const confirmedFrontierBlock = new Block(confirmedFrontierContents.account, confirmedFrontierContents.balance, confirmedFrontierContents.previous, confirmedFrontierContents.representative) - if (typeof confirmedFrontierBlock[confirmedFrontierSubtype] !== 'function') { - throw new TypeError('Unknown subtype of confirmed frontier block', { cause: confirmedFrontierSubtype }) - } if (confirmedFrontierSubtype === 'epoch') { confirmedFrontierBlock.epoch(accountInfo.account_version) } else if (confirmedFrontierSubtype === 'change') { confirmedFrontierBlock.change(confirmedFrontierContents.representative) - } else { + } else if (confirmedFrontierSubtype === 'open' || confirmedFrontierSubtype === 'receive' || confirmedFrontierSubtype === 'send'{ confirmedFrontierBlock[confirmedFrontierSubtype](confirmedFrontierContents.link, 0) + } else { + throw new TypeError('Invalid confirmed frontier block subtype', { cause: confirmedFrontierSubtype }) } confirmedFrontierBlock.signature = confirmedFrontierContents.signature account.confirmed_frontier_block = confirmedFrontierBlock @@ -88,15 +85,14 @@ export async function _refresh (account: Account, rpc: unknown): Promise { frontierContents[k] = v } const frontierBlock = new Block(frontierContents.account, frontierContents.balance, frontierContents.previous, frontierContents.representative) - if (typeof frontierBlock[frontierSubtype] !== 'function') { - throw new TypeError('Unknown subtype of frontier block', { cause: frontierSubtype }) - } if (frontierSubtype === 'epoch') { frontierBlock.epoch(accountInfo.account_version) } else if (frontierSubtype === 'change') { frontierBlock.change(frontierContents.representative) - } else { + } else if (frontierSubtype === 'open' || frontierSubtype === 'receive' || frontierSubtype === 'send') { frontierBlock[frontierSubtype](frontierContents.link, 0) + } else { + throw new TypeError('Invalid frontier block subtype', { cause: frontierSubtype }) } frontierBlock.signature = frontierContents.signature account.frontier_block = frontierBlock diff --git a/src/lib/wallet/refresh.ts b/src/lib/wallet/refresh.ts index 89b8ae7..43a6667 100644 --- a/src/lib/wallet/refresh.ts +++ b/src/lib/wallet/refresh.ts @@ -67,9 +67,11 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to: frontierBlock.epoch(account_version) } else if (subtype === 'change') { frontierBlock.change(representative) - } else { + } else if (subtype === 'open' || subtype === 'receive' || subtype === 'send') { frontierBlock[subtype](link, 0) - } + } else { + throw new TypeError('Invalid frontier block subtype', { cause: subtype }) + } frontierBlock.signature = signature account.frontier_block = frontierBlock }