From 74fc49cd4521f02362904d476343d03432edb96d Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 7 Aug 2026 12:33:40 -0700 Subject: [PATCH] Narrow block processing acceptable subtypes since epoch blocks should not be constructible and open blocks are just special receives. --- src/lib/block/index.ts | 17 ++++++++++++----- src/lib/rpc/process.ts | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/block/index.ts b/src/lib/block/index.ts index 440b83a..de8984b 100644 --- a/src/lib/block/index.ts +++ b/src/lib/block/index.ts @@ -157,6 +157,16 @@ export class Block { return _change(this, representative) } + /** + * Specialized block only used for setting account `frontier` when refreshing + * from the network. Epoch blocks are created by Nano Foundation developers. + * + * @returns {Block} This block unchanged + */ + epoch (): Block { + return this + } + /** * Alias for `receive()`. Zeros out `previous` as required for initial recieve * blocks. @@ -232,12 +242,9 @@ export class Block { } try { const res = await rpc.post('process', data) - if (res == null || typeof res !== 'object' || !('hash' in res) || typeof res.hash !== 'string') { - throw new Error('RPC process request received incomplete response', { cause: res }) - } return res.hash - } catch (err) { - throw new Error('Block could not be processed', { cause: err }) + } catch (err: any) { + throw new Error('Block could not be processed', { cause: err.message }) } } diff --git a/src/lib/rpc/process.ts b/src/lib/rpc/process.ts index 8c69b30..cd6fa4f 100644 --- a/src/lib/rpc/process.ts +++ b/src/lib/rpc/process.ts @@ -10,7 +10,7 @@ export type ProcessRequest = { block: BlockInfoContents force: false json_block: true - subtype: 'change' | 'epoch' | 'open' | 'receive' | 'send' + subtype: 'change' | 'receive' | 'send' } export type ProcessResponse = { -- 2.52.0