From 0972dc85f73df4012cc4a2e9846fd392b148e392 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 6 Aug 2025 12:46:14 -0700 Subject: [PATCH] Representative may be unknown when creating block intended for change request. --- src/lib/block.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 6aca69f..db27d45 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -66,7 +66,7 @@ export class Block { account: Account balance: bigint previous: string - representative: Account + representative?: Account link?: Uint8Array signature?: string work?: string @@ -92,13 +92,12 @@ export class Block { 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 (representative instanceof Account) { + this.representative = representative + } if (typeof signature === 'string') { this.signature = signature } @@ -118,7 +117,10 @@ export class Block { get hash (): Uint8Array { try { if (this.link == null) { - throw new Error('Block link is required') + throw new Error('Link is required') + } + if (this.representative == null) { + throw new Error('Representative is required') } const data = [ PREAMBLE, @@ -145,7 +147,10 @@ export class Block { toJSON (): { [key: string]: string } { try { if (this.link == null) { - throw new Error('Block link is required') + throw new Error('Link is required') + } + if (this.representative == null) { + throw new Error('Representative is required') } return { "type": "state", -- 2.47.3