From 6d5632da4abe16624c247dcbc514f569d8a4d69c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 7 Aug 2026 12:22:34 -0700 Subject: [PATCH] Configure specialized block function for the subtype "open". --- src/lib/block/index.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/block/index.ts b/src/lib/block/index.ts index 8f2b2c7..440b83a 100644 --- a/src/lib/block/index.ts +++ b/src/lib/block/index.ts @@ -67,7 +67,7 @@ export class Block { throw new TypeError('Invalid account') } balance ??= account.balance - previous ??= account.frontier + previous ??= account.frontier ?? '00' representative ??= account.representative if (typeof balance !== 'bigint' && typeof balance !== 'number' && typeof balance !== 'string') { throw new TypeError('Account balance is unknown') @@ -157,6 +157,20 @@ export class Block { return _change(this, representative) } + /** + * Alias for `receive()`. Zeros out `previous` as required for initial recieve + * blocks. + * + * @param {(string|Block)} sendBlock - Corresponding send block or its hash + * @param {(bigint|number|string)} amount - Amount to be received from sender + * @param {string} [unit] - Unit of measure for amount (e.g. 'NANO' = 10³⁰ RAW). Default: "RAW" + * @returns {Block} This block with balance, link, and subtype configured + */ + open (sendBlock: string | Block, amount: bigint | number | string, unit?: string): Block { + this.previous.fill(0) + return _receive(this, sendBlock, amount, unit) + } + /** * Calculates proof-of-work using NanoPow. * -- 2.52.0