]> git.codecow.com Git - libnemo.git/commitdiff
Configure specialized block function for the subtype "open".
authorChris Duncan <chris@codecow.com>
Fri, 7 Aug 2026 19:22:34 +0000 (12:22 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 7 Aug 2026 19:22:34 +0000 (12:22 -0700)
src/lib/block/index.ts

index 8f2b2c771b3faec75cd90e1b97cca70717fbd001..440b83a4041271c681eb1bdccdc94e565fdfb0c6 100644 (file)
@@ -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.
         *