From: Chris Duncan Date: Wed, 6 Aug 2025 17:55:15 +0000 (-0700) Subject: Reenable signature and work as block constructor args. Adjust error handling. X-Git-Tag: v0.10.5~43^2~69 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=b92bf0a8f9a4373aaef17f571a41761242d375b7;p=libnemo.git Reenable signature and work as block constructor args. Adjust error handling. --- diff --git a/src/lib/block.ts b/src/lib/block.ts index bce9e19..19dde64 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -73,33 +73,43 @@ class Block { signature?: string work?: string - constructor (account: string | Account, balance?: bigint | string, previous?: string, representative?: string | Account) - constructor (account: unknown, balance: unknown, previous: unknown, representative: unknown) { - if (typeof account === 'string') { - account = Account.import(account) - } - if (typeof representative === 'string') { - representative = Account.import(representative) - } - if (!(account instanceof Account)) { - throw new TypeError('Invalid account') - } - balance ??= account.balance - previous ??= account.frontier - representative ??= account.representative - if (typeof balance !== 'bigint' && typeof balance !== 'string') { - throw new TypeError('Account balance is unknown') - } - if (typeof previous !== 'string') { - throw new TypeError('Account frontier is unknown') - } - if (!(representative instanceof Account)) { - throw new TypeError('Account representative is unknown') + constructor (account: string | Account, balance?: bigint | string, previous?: string, representative?: string | Account, signature?: string, work?: string) + constructor (account: unknown, balance: unknown, previous: unknown, representative: unknown, signature: unknown, work: unknown) { + try { + if (typeof account === 'string') { + account = Account.import(account) + } + if (typeof representative === 'string') { + representative = Account.import(representative) + } + if (!(account instanceof Account)) { + throw new TypeError('Invalid account') + } + balance ??= account.balance + previous ??= account.frontier + representative ??= account.representative + if (typeof balance !== 'bigint' && typeof balance !== 'string') { + throw new TypeError('Account balance is unknown') + } + if (typeof previous !== 'string') { + throw new TypeError('Account frontier is unknown') + } + if (!(representative instanceof Account)) { + throw new TypeError('Account representative is unknown') + } + this.account = account + this.balance = BigInt(balance) + this.previous = previous + this.representative = representative + if (typeof signature === 'string') { + this.signature = signature + } + if (typeof work === 'string') { + this.work = work + } + } catch (err) { + throw new Error('Failed to initialize Block', { cause: err }) } - this.account = account - this.balance = BigInt(balance) - this.previous = previous - this.representative = representative } /**