]> git.codecow.com Git - libnemo.git/commitdiff
Generate PoW automatically during networking processing if work value is not present...
authorChris Duncan <chris@zoso.dev>
Mon, 13 Apr 2026 06:09:55 +0000 (23:09 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 13 Apr 2026 06:09:55 +0000 (23:09 -0700)
src/lib/block.ts

index 17f5bc362d88ca6abfbc410be80863a922575cbb..54024469b154c5a2ed27465f1ab2523d7863acbd 100644 (file)
@@ -251,7 +251,8 @@ export class Block {
        * Sends the block to a node for processing on the network.
        *
        * The block must already be signed (see `sign()` for more information).
-       * The block must also have a `work` value.
+       *
+       * If the block has no `work` value, `pow()` will be called automatically.
        *
        * @param {Rpc} rpc - RPC node information required to call `process`
        * @returns {Promise<string>} Hash of the processed block
@@ -262,9 +263,7 @@ export class Block {
                if (this.signature == null) {
                        throw new Error('Block is missing signature. Use sign() and try again.')
                }
-               if (this.work == null) {
-                       throw new Error('Block is missing proof-of-work. Use pow() and try again.')
-               }
+               if (this.work == null) await this.pow()
                const data = {
                        subtype: this.subtype,
                        json_block: true,