From 05cb5cf0695a7035f1ff4f3b9587a44642e75f1b Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 2 Oct 2023 13:17:36 +0200 Subject: [PATCH 1/2] added id() --- bindings/nodejs/lib/types/block/core/wrapper.ts | 14 +++++++++++++- bindings/nodejs/lib/types/utils/bridge/utils.ts | 5 ++++- bindings/nodejs/lib/utils/utils.ts | 12 ++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bindings/nodejs/lib/types/block/core/wrapper.ts b/bindings/nodejs/lib/types/block/core/wrapper.ts index 5445e30041..79b4ed3de8 100644 --- a/bindings/nodejs/lib/types/block/core/wrapper.ts +++ b/bindings/nodejs/lib/types/block/core/wrapper.ts @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { IssuerId } from '../id'; +import { BlockId, IssuerId } from '../id'; import { Signature, SignatureDiscriminator } from '../signature'; import { SlotCommitmentId, SlotIndex } from '../slot'; import { u64 } from '../../utils/type-aliases'; @@ -10,6 +10,8 @@ import { Block, BlockType } from './block'; import { BasicBlock } from './basic'; import { ValidationBlock } from './validation'; import { BlockDiscriminator } from './'; +import { Utils } from '../../../utils'; +import { ProtocolParameters } from '../../models'; /** * Represent the object that nodes gossip around the network. @@ -73,6 +75,16 @@ class BlockWrapper { this.block = block; } + /** + * Compute the block ID (Blake2b256 hash of the block bytes). + * + * @param params The network protocol parameters. + * @returns The corresponding block ID. + */ + id(params: ProtocolParameters): BlockId { + return Utils.blockId(this, params) + } + /** * Checks whether the block is a `BasicBlock`. * @returns true if it is, otherwise false diff --git a/bindings/nodejs/lib/types/utils/bridge/utils.ts b/bindings/nodejs/lib/types/utils/bridge/utils.ts index 451c2f93f5..cc41c58df0 100644 --- a/bindings/nodejs/lib/types/utils/bridge/utils.ts +++ b/bindings/nodejs/lib/types/utils/bridge/utils.ts @@ -8,6 +8,8 @@ import { TokenSchemeType, Output, RentStructure, + BlockWrapper, + ProtocolParameters, } from '../../'; import { AccountId } from '../../block/id'; import { SlotCommitment } from '../../block/slot'; @@ -88,7 +90,8 @@ export interface __ParseBech32AddressMethod__ { export interface __BlockIdMethod__ { name: 'blockId'; data: { - block: Block; + wrapper: BlockWrapper; + params: ProtocolParameters; }; } diff --git a/bindings/nodejs/lib/utils/utils.ts b/bindings/nodejs/lib/utils/utils.ts index 014975a1e2..740a27bb03 100644 --- a/bindings/nodejs/lib/utils/utils.ts +++ b/bindings/nodejs/lib/utils/utils.ts @@ -15,6 +15,8 @@ import { RentStructure, OutputId, u64, + BlockWrapper, + ProtocolParameters, } from '../types'; import { AccountId, @@ -193,16 +195,18 @@ export class Utils { } /** - * Compute the block ID (Blake2b256 hash of the block bytes) of a block. + * Compute the block ID (Blake2b256 hash of the block bytes) of a blockwrapper. * - * @param block A block. + * @param wrapper A blockwrapper. + * @param params The network protocol parameters. * @returns The corresponding block ID. */ - static blockId(block: Block): BlockId { + static blockId(wrapper: BlockWrapper, params: ProtocolParameters): BlockId { return callUtilsMethod({ name: 'blockId', data: { - block, + wrapper, + params, }, }); } From 083b27f3f48d60f1ca7f768e646c7c76983cfbef Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 2 Oct 2023 13:29:47 +0200 Subject: [PATCH 2/2] fmt --- bindings/nodejs/lib/types/block/core/wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/nodejs/lib/types/block/core/wrapper.ts b/bindings/nodejs/lib/types/block/core/wrapper.ts index 79b4ed3de8..23d2b144ea 100644 --- a/bindings/nodejs/lib/types/block/core/wrapper.ts +++ b/bindings/nodejs/lib/types/block/core/wrapper.ts @@ -77,12 +77,12 @@ class BlockWrapper { /** * Compute the block ID (Blake2b256 hash of the block bytes). - * + * * @param params The network protocol parameters. * @returns The corresponding block ID. */ id(params: ProtocolParameters): BlockId { - return Utils.blockId(this, params) + return Utils.blockId(this, params); } /**