From 0a85afe7210d7e143a5abd9bcbe03a26abd379af Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 6 Aug 2025 10:52:40 -0700 Subject: [PATCH] Expand options for block constructor arguments, using block account as fallback. --- src/lib/block.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 7258ef1..bce9e19 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -73,24 +73,33 @@ class Block { signature?: string work?: string - constructor (account: Account) - constructor (account: unknown) { + 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') } - if (account.balance == null) { + balance ??= account.balance + previous ??= account.frontier + representative ??= account.representative + if (typeof balance !== 'bigint' && typeof balance !== 'string') { throw new TypeError('Account balance is unknown') } - if (account.frontier == null) { + if (typeof previous !== 'string') { throw new TypeError('Account frontier is unknown') } - if (account.representative == null) { + if (!(representative instanceof Account)) { throw new TypeError('Account representative is unknown') } this.account = account - this.balance = account.balance - this.previous = account.frontier - this.representative = account.representative + this.balance = BigInt(balance) + this.previous = previous + this.representative = representative } /** -- 2.47.3