]> git.codecow.com Git - libnemo.git/commitdiff
Representative may be unknown when creating block intended for change request.
authorChris Duncan <chris@zoso.dev>
Wed, 6 Aug 2025 19:46:14 +0000 (12:46 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 6 Aug 2025 19:46:14 +0000 (12:46 -0700)
src/lib/block.ts

index 6aca69f44acd4765a028f40ce3adb693b4a6c788..db27d454cc6d5fbd12fb2dd8dd5b5848648a92e9 100644 (file)
@@ -66,7 +66,7 @@ export class Block {
        account: Account
        balance: bigint
        previous: string
-       representative: Account
+       representative?: Account
        link?: Uint8Array<ArrayBuffer>
        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<ArrayBuffer> {
                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",