From b12c5b29239802036d8dfacdb1d1a4a98b6ad270 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 8 Aug 2025 05:44:26 -0700 Subject: [PATCH] Fix block unit conversion. --- src/lib/block.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 5912593..6a05014 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -286,7 +286,7 @@ export class Block { * * @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. Default: "NANO" (10³⁰ RAW) + * @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 */ receive (sendBlock: string | Block, amount: bigint | number | string, unit?: string): Block @@ -306,7 +306,7 @@ export class Block { if (typeof amount !== 'bigint' && typeof amount !== 'number' && typeof amount !== 'string') { throw new TypeError('Invalid amount') } - this.balance += BigInt(amount) * (1n << BigInt(UNITS[unit.toUpperCase()])) + this.balance += BigInt(amount) * (10n ** BigInt(UNITS[unit.toUpperCase()])) if (typeof sendBlock !== 'string' && !(sendBlock instanceof Block)) { throw new TypeError('Invalid send block') @@ -329,7 +329,7 @@ export class Block { * * @param {(string|Account)} account - Account to target or its address or public key * @param {(bigint|number|string)} amount - Amount to send to recipient - * @param {string} [unit] - Unit of measure for amount. Default: "NANO" (10³⁰ RAW) + * @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 */ send (account: string | Account, amount: bigint | number | string, unit?: string): Block @@ -349,7 +349,7 @@ export class Block { if (typeof amount !== 'bigint' && typeof amount !== 'number' && typeof amount !== 'string') { throw new TypeError('Invalid amount') } - this.balance -= BigInt(amount) * (1n << BigInt(UNITS[unit.toUpperCase()])) + this.balance -= BigInt(amount) * (10n ** BigInt(UNITS[unit.toUpperCase()])) if (this.balance < 0) { throw new RangeError('Insufficient funds', { cause: this.balance }) -- 2.47.3