Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/Node: id() on wrapper #1369

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bindings/nodejs/lib/types/block/core/wrapper.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this another scenario where we're going to be importing stuff we don't need if you just want the types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be so yes. :/

return Utils.blockId(this, params);
}

/**
* Checks whether the block is a `BasicBlock`.
* @returns true if it is, otherwise false
Expand Down
5 changes: 4 additions & 1 deletion bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {
Ed25519Signature,
HexEncodedString,
Block,

Check warning on line 4 in bindings/nodejs/lib/types/utils/bridge/utils.ts

View workflow job for this annotation

GitHub Actions / Lint

'Block' is defined but never used
TransactionEssence,
TransactionPayload,
TransactionId,
TokenSchemeType,
Output,
RentStructure,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment there, but 'Block' is defined but never used

BlockWrapper,
ProtocolParameters,
} from '../../';
import { AccountId } from '../../block/id';
import { SlotCommitment } from '../../block/slot';
Expand Down Expand Up @@ -88,7 +90,8 @@
export interface __BlockIdMethod__ {
name: 'blockId';
data: {
block: Block;
wrapper: BlockWrapper;
params: ProtocolParameters;
};
}

Expand Down
12 changes: 8 additions & 4 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {
Address,
HexEncodedString,
Block,

Check warning on line 8 in bindings/nodejs/lib/utils/utils.ts

View workflow job for this annotation

GitHub Actions / Lint

'Block' is defined but never used
Ed25519Signature,
TransactionEssence,
TransactionPayload,
Expand All @@ -15,6 +15,8 @@
RentStructure,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment there, but 'Block' is defined but never used

OutputId,
u64,
BlockWrapper,
ProtocolParameters,
} from '../types';
import {
AccountId,
Expand Down Expand Up @@ -193,16 +195,18 @@
}

/**
* 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,
},
});
}
Expand Down
Loading