diff --git a/bindings/core/src/method/client.rs b/bindings/core/src/method/client.rs index 9fd4892db9..7ce48daf54 100644 --- a/bindings/core/src/method/client.rs +++ b/bindings/core/src/method/client.rs @@ -156,15 +156,18 @@ pub enum ClientMethod { /// The Account ID of the account. account_id: AccountId, }, - /// Returns the totally available Mana rewards of an account or delegation output decayed up to endEpoch index - /// provided in the response. + /// Returns all the available Mana rewards of an account or delegation output in the returned range of epochs. #[serde(rename_all = "camelCase")] GetRewards { /// Output ID of an account or delegation output. output_id: OutputId, /// A client can specify a slot index explicitly, which should be equal to the slot it uses as the commitment - /// input for the claiming transaction. This parameter is only recommended to be provided when requesting - /// rewards for a Delegation Output in delegating state (i.e. when Delegation ID is zeroed). + /// input for the claiming transaction to ensure the node calculates the rewards identically as during + /// transaction execution. Rewards are decayed up to the epoch corresponding to the given slotIndex + + /// MinCommittableAge. For a Delegation Output in delegating state (i.e. when Delegation ID is zeroed), that + /// epoch - 1 is also used as the last epoch for which rewards are fetched. Callers that do not build + /// transactions with the returned values may omit this value in which case it defaults to the latest committed + /// slot, which is good enough to, e.g. display estimated rewards to users. slot_index: Option, }, /// Returns information of all registered validators and if they are active, ordered by their holding stake. @@ -282,17 +285,17 @@ pub enum ClientMethod { /// Look up a commitment by a given commitment index. GetCommitmentByIndex { /// Index of the commitment to look up. - index: SlotIndex, + slot: SlotIndex, }, /// Get all UTXO changes of a given slot by commitment index. GetUtxoChangesByIndex { /// Index of the commitment to look up. - index: SlotIndex, + slot: SlotIndex, }, /// Get all full UTXO changes of a given slot by commitment index. GetUtxoChangesFullByIndex { /// Index of the commitment to look up. - index: SlotIndex, + slot: SlotIndex, }, ////////////////////////////////////////////////////////////////////// diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index ca809129f5..629ec5251b 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -251,14 +251,14 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM .get_utxo_changes_full_by_slot_commitment_id(&commitment_id) .await?, ), - ClientMethod::GetCommitmentByIndex { index } => { - Response::SlotCommitment(client.get_slot_commitment_by_slot(index).await?) + ClientMethod::GetCommitmentByIndex { slot } => { + Response::SlotCommitment(client.get_slot_commitment_by_slot(slot).await?) } - ClientMethod::GetUtxoChangesByIndex { index } => { - Response::UtxoChanges(client.get_utxo_changes_by_slot(index).await?) + ClientMethod::GetUtxoChangesByIndex { slot } => { + Response::UtxoChanges(client.get_utxo_changes_by_slot(slot).await?) } - ClientMethod::GetUtxoChangesFullByIndex { index } => { - Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(index).await?) + ClientMethod::GetUtxoChangesFullByIndex { slot } => { + Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(slot).await?) } ClientMethod::OutputIds { query_parameters } => { Response::OutputIdsResponse(client.output_ids(query_parameters).await?) diff --git a/bindings/nodejs/lib/client/client.ts b/bindings/nodejs/lib/client/client.ts index e67935cf7d..082c52bbfa 100644 --- a/bindings/nodejs/lib/client/client.ts +++ b/bindings/nodejs/lib/client/client.ts @@ -44,12 +44,14 @@ import { DelegationId, UnsignedBlock, parseUnsignedBlock, + SlotIndex, + SlotCommitmentId, + SlotCommitment, } from '../types/block'; import { HexEncodedString } from '../utils'; import { IBlockMetadata, INodeInfo, - IPeer, UTXOInput, Response, OutputId, @@ -58,10 +60,19 @@ import { TransactionId, Bech32Address, IBlockWithMetadata, + TransactionMetadata, } from '../types'; -import { OutputResponse, IOutputsResponse } from '../types/models/api'; +import { + OutputResponse, + IOutputsResponse, + CongestionResponse, + UtxoChangesResponse, + UtxoChangesFullResponse, +} from '../types/models/api'; import { plainToInstance } from 'class-transformer'; +import { ManaRewardsResponse } from '../types/models/api/mana-rewards-response'; +import { ValidatorsResponse } from '../types/models/api/validators-response'; /** The Client to interact with nodes. */ export class Client { @@ -106,6 +117,74 @@ export class Client { return JSON.parse(response).payload; } + /** + * Check the readiness of the node to issue a new block, the reference mana cost based on the rate setter and + * current network congestion, and the block issuance credits of the requested account. + */ + async getAccountCongestion( + accountId: AccountId, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getAccountCongestion', + data: { + accountId, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Returns the totally available Mana rewards of an account or delegation output decayed up to endEpoch index + * provided in the response. + */ + async getRewards( + outputId: OutputId, + slotIndex?: SlotIndex, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getRewards', + data: { + outputId, + slotIndex, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Returns information of all registered validators and if they are active, ordered by their holding stake. + */ + async getValidators( + pageSize?: number, + cursor?: string, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getValidators', + data: { + pageSize, + cursor, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Return information about a validator. + */ + async getValidator(accountId: AccountId): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getValidator', + data: { + accountId, + }, + }); + + return JSON.parse(response).payload; + } + /** * Get output from a given output ID. */ @@ -393,17 +472,6 @@ export class Client { return JSON.parse(response).payload; } - /** - * Get the peers of the node. - */ - async getPeers(): Promise { - const response = await this.methodHandler.callMethod({ - name: 'getPeers', - }); - - return JSON.parse(response).payload; - } - /** * Post block as raw bytes, returns the block ID. * @@ -463,15 +531,136 @@ export class Client { */ async getIncludedBlockMetadata( transactionId: TransactionId, - ): Promise { + ): Promise { const response = await this.methodHandler.callMethod({ name: 'getIncludedBlockMetadata', data: { transactionId, }, }); - const parsed = JSON.parse(response) as Response; - return parseBlock(parsed.payload); + return JSON.parse(response).payload; + } + + /** + * Find the metadata of a transaction. + * + * @param transactionId The ID of the transaction. + * @returns The transaction metadata. + */ + async getTransactionMetadata( + transactionId: TransactionId, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getTransactionMetadata', + data: { + transactionId, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Look up a commitment by a given commitment ID. + * + * @param commitmentId Commitment ID of the commitment to look up. + * @returns The commitment. + */ + async getCommitment( + commitmentId: SlotCommitmentId, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getCommitment', + data: { + commitmentId, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Get all UTXO changes of a given slot by Commitment ID. + * + * @param commitmentId Commitment ID of the commitment to look up. + * @returns The UTXO changes. + */ + async getUtxoChanges( + commitmentId: SlotCommitmentId, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getUtxoChanges', + data: { + commitmentId, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Get all full UTXO changes of a given slot by Commitment ID. + * + * @param commitmentId Commitment ID of the commitment to look up. + * @returns The UTXO changes. + */ + async getUtxoChangesFull( + commitmentId: SlotCommitmentId, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getUtxoChangesFull', + data: { + commitmentId, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Look up a commitment by a given commitment index. + * + * @param slot Index of the commitment to look up. + * @returns The commitment. + */ + async getCommitmentByIndex(slot: SlotIndex): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getCommitmentByIndex', + data: { + slot, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Get all UTXO changes of a given slot by commitment index. + * + * @param slot Index of the commitment to look up. + * @returns The UTXO changes. + */ + async getUtxoChangesByIndex(slot: SlotIndex): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getUtxoChangesByIndex', + data: { + slot, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Get all full UTXO changes of a given slot by commitment index. + * + * @param slot Index of the commitment to look up. + * @returns The UTXO changes. + */ + async getUtxoChangesFullByIndex( + slot: SlotIndex, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'getUtxoChangesFullByIndex', + data: { + slot, + }, + }); + return JSON.parse(response).payload; } /** diff --git a/bindings/nodejs/lib/types/client/bridge/client.ts b/bindings/nodejs/lib/types/client/bridge/client.ts index 93bc8f9aec..2919d75f52 100644 --- a/bindings/nodejs/lib/types/client/bridge/client.ts +++ b/bindings/nodejs/lib/types/client/bridge/client.ts @@ -16,6 +16,7 @@ import type { Output, OutputId, Payload, + SlotIndex, } from '../../block'; import type { PreparedTransactionData } from '../prepared-transaction-data'; import type { @@ -68,6 +69,36 @@ export interface __GetNetworkInfoMethod__ { name: 'getNetworkInfo'; } +export interface __GetAccountCongestionMethod__ { + name: 'getAccountCongestion'; + data: { + accountId: AccountId; + }; +} + +export interface __GetRewardsMethod__ { + name: 'getRewards'; + data: { + outputId: OutputId; + slotIndex?: SlotIndex; + }; +} + +export interface __GetValidatorsMethod__ { + name: 'getValidators'; + data: { + pageSize?: number; + cursor?: string; + }; +} + +export interface __GetValidatorMethod__ { + name: 'getValidator'; + data: { + accountId: AccountId; + }; +} + export interface __GetBlockMethod__ { name: 'getBlock'; data: { @@ -153,10 +184,6 @@ export interface __GetNodeInfoMethod__ { }; } -export interface __GetPeersMethod__ { - name: 'getPeers'; -} - export interface __PostBlockRawMethod__ { name: 'postBlockRaw'; data: { @@ -185,6 +212,55 @@ export interface __GetIncludedBlockMetadataMethod__ { }; } +export interface __GetTransactionMetadataMethod__ { + name: 'getTransactionMetadata'; + data: { + transactionId: TransactionId; + }; +} + +export interface __GetCommitmentMethod__ { + name: 'getCommitment'; + data: { + commitmentId: HexEncodedString; + }; +} + +export interface __GetUtxoChangesMethod__ { + name: 'getUtxoChanges'; + data: { + commitmentId: HexEncodedString; + }; +} + +export interface __GetUtxoChangesFullMethod__ { + name: 'getUtxoChangesFull'; + data: { + commitmentId: HexEncodedString; + }; +} + +export interface __GetCommitmentByIndexMethod__ { + name: 'getCommitmentByIndex'; + data: { + slot: SlotIndex; + }; +} + +export interface __GetUtxoChangesByIndexMethod__ { + name: 'getUtxoChangesByIndex'; + data: { + slot: SlotIndex; + }; +} + +export interface __GetUtxoChangesFullByIndexMethod__ { + name: 'getUtxoChangesFullByIndex'; + data: { + slot: SlotIndex; + }; +} + export interface __HexToBech32Method__ { name: 'hexToBech32'; data: { diff --git a/bindings/nodejs/lib/types/client/bridge/index.ts b/bindings/nodejs/lib/types/client/bridge/index.ts index 20de332b70..743c428eda 100644 --- a/bindings/nodejs/lib/types/client/bridge/index.ts +++ b/bindings/nodejs/lib/types/client/bridge/index.ts @@ -10,6 +10,10 @@ import type { __PostBlockMethod__, __GetTipsMethod__, __GetNetworkInfoMethod__, + __GetAccountCongestionMethod__, + __GetRewardsMethod__, + __GetValidatorsMethod__, + __GetValidatorMethod__, __GetBlockMethod__, __GetBlockMetadataMethod__, __GetBlockWithMetadataMethod__, @@ -22,11 +26,17 @@ import type { __GetProtocolParametersMethod__, __GetHealthMethod__, __GetNodeInfoMethod__, - __GetPeersMethod__, __PostBlockRawMethod__, __GetBlockRawMethod__, __GetIncludedBlockMethod__, __GetIncludedBlockMetadataMethod__, + __GetTransactionMetadataMethod__, + __GetCommitmentMethod__, + __GetUtxoChangesMethod__, + __GetUtxoChangesFullMethod__, + __GetCommitmentByIndexMethod__, + __GetUtxoChangesByIndexMethod__, + __GetUtxoChangesFullByIndexMethod__, __HexToBech32Method__, __AccountIdToBech32Method__, __NftIdToBech32Method__, @@ -65,6 +75,10 @@ export type __ClientMethods__ = | __PostBlockMethod__ | __GetTipsMethod__ | __GetNetworkInfoMethod__ + | __GetAccountCongestionMethod__ + | __GetRewardsMethod__ + | __GetValidatorsMethod__ + | __GetValidatorMethod__ | __GetBlockMethod__ | __GetBlockMetadataMethod__ | __GetBlockWithMetadataMethod__ @@ -78,11 +92,17 @@ export type __ClientMethods__ = | __GetProtocolParametersMethod__ | __GetHealthMethod__ | __GetNodeInfoMethod__ - | __GetPeersMethod__ | __PostBlockRawMethod__ | __GetBlockRawMethod__ | __GetIncludedBlockMethod__ | __GetIncludedBlockMetadataMethod__ + | __GetTransactionMetadataMethod__ + | __GetCommitmentMethod__ + | __GetUtxoChangesMethod__ + | __GetUtxoChangesFullMethod__ + | __GetCommitmentByIndexMethod__ + | __GetUtxoChangesByIndexMethod__ + | __GetUtxoChangesFullByIndexMethod__ | __HexToBech32Method__ | __AccountIdToBech32Method__ | __NftIdToBech32Method__ diff --git a/bindings/nodejs/lib/types/models/api/congestion-response.ts b/bindings/nodejs/lib/types/models/api/congestion-response.ts new file mode 100644 index 0000000000..cf40d8effd --- /dev/null +++ b/bindings/nodejs/lib/types/models/api/congestion-response.ts @@ -0,0 +1,27 @@ +// Copyright 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { SlotIndex } from '../../block/slot'; +import { u64 } from '../../utils'; + +/** + * Provides the cost and readiness to issue estimates. + */ +export class CongestionResponse { + /** + * The slot index for which the congestion estimate is provided. + */ + slot!: SlotIndex; + /** + * Indicates if a node is ready to issue a block in a current congestion or should wait. + */ + ready!: boolean; + /** + * The cost in mana for issuing a block in a current congestion estimated based on RMC and slot index. + */ + referenceManaCost!: u64; + /** + * The Block Issuance Credits of the requested account. + */ + blockIssuanceCredits!: u64; +} diff --git a/bindings/nodejs/lib/types/models/api/index.ts b/bindings/nodejs/lib/types/models/api/index.ts index bf835a1377..703fe9a5b0 100644 --- a/bindings/nodejs/lib/types/models/api/index.ts +++ b/bindings/nodejs/lib/types/models/api/index.ts @@ -4,7 +4,11 @@ export * from './plugins'; export * from './block-id-response'; +export * from './congestion-response'; +export * from './mana-rewards-response'; export * from './output-metadata-response'; export * from './output-response'; export * from './response'; export * from './tips-response'; +export * from './validators-response'; +export * from './utxo-changes-response'; diff --git a/bindings/nodejs/lib/types/models/api/mana-rewards-response.ts b/bindings/nodejs/lib/types/models/api/mana-rewards-response.ts new file mode 100644 index 0000000000..0a5f93d196 --- /dev/null +++ b/bindings/nodejs/lib/types/models/api/mana-rewards-response.ts @@ -0,0 +1,31 @@ +// Copyright 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { EpochIndex } from '../../block/slot'; +import { u64 } from '../../utils'; + +/** + * The mana rewards of an account or delegation output. + */ +export class ManaRewardsResponse { + /** + * The starting epoch index for which the mana rewards are returned. + */ + startEpoch!: EpochIndex; + /** + * The ending epoch index for which the mana rewards are returned, the decay is applied up to this point + * included. + */ + endEpoch!: EpochIndex; + /** + * The amount of totally available rewards the requested output may claim. + */ + rewards!: u64; + /** + * The rewards of the latest committed epoch of the staking pool to which this validator or delegator belongs. + * The ratio of this value and the maximally possible rewards for the latest committed epoch can be used to + * determine how well the validator of this staking pool performed in that epoch. Note that if the pool was not + * part of the committee in the latest committed epoch, this value is 0. + */ + latestCommittedEpochPoolRewards!: u64; +} diff --git a/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts b/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts new file mode 100644 index 0000000000..6db602b7d8 --- /dev/null +++ b/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts @@ -0,0 +1,60 @@ +// Copyright 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { OutputId } from '../../block/output'; +import { SlotCommitmentId } from '../../block'; +import { Output, OutputDiscriminator } from '../../block/output'; +import { Type } from 'class-transformer'; + +/** + * All UTXO changes that happened at a specific slot. + */ +export class UtxoChangesResponse { + /** + * The commitment ID of the requested slot that contains the changes. + */ + commitmentId!: SlotCommitmentId; + /** + * The created outputs of the given slot. + */ + createdOutputs!: OutputId[]; + /** + * The consumed outputs of the given slot. + */ + consumedOutputs!: OutputId[]; +} + +/** + * An output with its id. + */ +export class OutputWithId { + /** + * The output id. + */ + outputId!: OutputId; + /** + * The output. + */ + @Type(() => Output, { + discriminator: OutputDiscriminator, + }) + output!: Output; +} + +/** + * All full UTXO changes that happened at a specific slot. + */ +export class UtxoChangesFullResponse { + /** + * The commitment ID of the requested slot that contains the changes. + */ + commitmentId!: SlotCommitmentId; + /** + * The created outputs of the given slot. + */ + createdOutputs!: OutputWithId[]; + /** + * The consumed outputs of the given slot. + */ + consumedOutputs!: OutputWithId[]; +} diff --git a/bindings/nodejs/lib/types/models/api/validators-response.ts b/bindings/nodejs/lib/types/models/api/validators-response.ts new file mode 100644 index 0000000000..ccb518fc9d --- /dev/null +++ b/bindings/nodejs/lib/types/models/api/validators-response.ts @@ -0,0 +1,64 @@ +// Copyright 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Bech32Address, EpochIndex } from '../../block'; +import { u64 } from '../../utils'; +import type { HexEncodedString } from '../../utils/hex-encoding'; + +/** + * Information of a validator. + */ +export interface ValidatorResponse { + /** + * Account address of the validator. + */ + address: Bech32Address; + /** + * The epoch index until which the validator registered to stake. + */ + stakingEndEpoch: EpochIndex; + /** + * The total stake of the pool, including delegators. + */ + poolStake: u64; + /** + * The stake of a validator. + */ + validatorStake: u64; + /** + * The fixed cost of the validator, which it receives as part of its Mana rewards. + */ + fixedCost: u64; + /** + * Shows whether the validator was active recently. + */ + active: boolean; + /** + * The latest protocol version the validator supported. + */ + latestSupportedProtocolVersion: number; + /** + * The latest protocol version the validator supported. + */ + latestSupportedProtocolHash: HexEncodedString; +} + +/** + * A paginated list of all registered validators ready for the next epoch and indicates if they were active recently + * (are eligible for committee selection). + */ +export interface ValidatorsResponse { + /** + * List of registered validators ready for the next epoch. + */ + validators: ValidatorResponse[]; + /** + * The number of validators returned per one API request with pagination. + */ + pageSize: number; + /** + * The cursor that needs to be provided as cursor query parameter to request the next page. If empty, this was the + * last page. + */ + cursor?: string; +} diff --git a/bindings/nodejs/lib/types/models/block-metadata.ts b/bindings/nodejs/lib/types/models/block-metadata.ts index 70043f2a60..ba7cee6f57 100644 --- a/bindings/nodejs/lib/types/models/block-metadata.ts +++ b/bindings/nodejs/lib/types/models/block-metadata.ts @@ -1,11 +1,12 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import type { TransactionFailureReason } from './transaction-failure-reason'; import type { HexEncodedString } from '../utils/hex-encoding'; import { BlockState, TransactionState } from './state'; import { BlockFailureReason } from './block-failure-reason'; import { Block } from '../block'; +import { TransactionId } from '../wallet'; +import { TransactionFailureReason } from './transaction-failure-reason'; /** * Response from the metadata endpoint. @@ -19,18 +20,14 @@ export interface IBlockMetadata { * The block state. */ blockState: BlockState; - /** - * The transaction state. - */ - transactionState?: TransactionState; /** * The block failure reason. */ blockFailureReason?: BlockFailureReason; /** - * The transaction failure reason. + * The metadata of the transaction in the block. */ - transactionFailureReason?: TransactionFailureReason; + transactionMetadata?: TransactionMetadata; } /** @@ -46,3 +43,21 @@ export interface IBlockWithMetadata { */ metadata: IBlockMetadata; } + +/** + * Metadata of a transaction. + */ +export interface TransactionMetadata { + /** + * The transaction id. + */ + transactionId: TransactionId; + /** + * The transaction state. + */ + transactionState: TransactionState; + /** + * The transaction failure reason. + */ + transactionFailureReason?: TransactionFailureReason; +} diff --git a/bindings/nodejs/lib/types/models/gossip-heartbeat.ts b/bindings/nodejs/lib/types/models/gossip-heartbeat.ts deleted file mode 100644 index 8ed9204451..0000000000 --- a/bindings/nodejs/lib/types/models/gossip-heartbeat.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - * Gossip heartbeat. - */ -export interface IGossipHeartbeat { - /** - * Solid milestone index. - */ - solidMilestoneIndex: number; - /** - * Pruned milestone index. - */ - prunedMilestoneIndex: number; - /** - * Latest milestone index. - */ - latestMilestoneIndex: number; - /** - * Connected peers. - */ - connectedPeers: number; - /** - * Synced peers. - */ - syncedPeers: number; -} diff --git a/bindings/nodejs/lib/types/models/gossip-metrics.ts b/bindings/nodejs/lib/types/models/gossip-metrics.ts deleted file mode 100644 index 9ce4f6119b..0000000000 --- a/bindings/nodejs/lib/types/models/gossip-metrics.ts +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - * Gossip metrics. - */ -export interface IGossipMetrics { - /** - * The number of new blocks. - */ - newBlocks: number; - /** - * The number of known blocks. - */ - knownBlocks: number; - /** - * The number of received blocks. - */ - receivedBlocks: number; - /** - * The number of received block requests. - */ - receivedBlockRequests: number; - /** - * The number of received milestone requests. - */ - receivedMilestoneRequests: number; - /** - * The number of received heartbeats. - */ - receivedHeartbeats: number; - /** - * The number of sent blocks. - */ - sentBlocks: number; - /** - * The number of sent block requests. - */ - sentBlockRequests: number; - /** - * The number of sent miletsone requests. - */ - sentMilestoneRequests: number; - /** - * The number of sent heartbeats. - */ - sentHeartbeats: number; - /** - * The number of dropped sent packets. - */ - droppedPackets: number; -} diff --git a/bindings/nodejs/lib/types/models/index.ts b/bindings/nodejs/lib/types/models/index.ts index 8789189173..a4290a39a3 100644 --- a/bindings/nodejs/lib/types/models/index.ts +++ b/bindings/nodejs/lib/types/models/index.ts @@ -6,9 +6,6 @@ export * from './info'; export * from './transaction-failure-reason'; export * from './block-metadata'; -export * from './gossip-metrics'; -export * from './gossip-heartbeat'; export * from './native-token'; -export * from './peer'; export * from './storage-score'; export * from './state'; diff --git a/bindings/nodejs/lib/types/models/info/node-info-protocol.ts b/bindings/nodejs/lib/types/models/info/node-info-protocol.ts index 84f70cd5e4..e7a31d3251 100644 --- a/bindings/nodejs/lib/types/models/info/node-info-protocol.ts +++ b/bindings/nodejs/lib/types/models/info/node-info-protocol.ts @@ -119,6 +119,11 @@ export interface ProtocolParameters { * Target Committee Size defines the target size of the committee. If there's fewer candidates the actual committee size could be smaller in a given epoch. */ targetCommitteeSize: number; + /** + * Defines the number of heavier slots that a chain needs to be ahead of the current chain to be considered for + * switching. + */ + chainSwitchingThreshold: number; } /** diff --git a/bindings/nodejs/lib/types/models/peer.ts b/bindings/nodejs/lib/types/models/peer.ts deleted file mode 100644 index aa7094bce1..0000000000 --- a/bindings/nodejs/lib/types/models/peer.ts +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import type { IGossipHeartbeat } from './gossip-heartbeat'; -import type { IGossipMetrics } from './gossip-metrics'; -/** - * Peer details. - */ -export interface IPeer { - /** - * The id of the peer. - */ - id: string; - /** - * The addresses of the peer. - */ - multiAddresses: string[]; - /** - * The alias of the peer. - */ - alias?: string; - /** - * The relation of the peer. - */ - relation: string; - /** - * Is it connected. - */ - connected: boolean; - /** - * Gossip metrics for the peer. - */ - gossip?: { - /** - * The peer heartbeat. - */ - heartbeat: IGossipHeartbeat; - /** - * The peer metrics. - */ - metrics: IGossipMetrics; - }; -} diff --git a/bindings/nodejs/lib/types/models/state.ts b/bindings/nodejs/lib/types/models/state.ts index 37b6d8b70b..a996330949 100644 --- a/bindings/nodejs/lib/types/models/state.ts +++ b/bindings/nodejs/lib/types/models/state.ts @@ -13,9 +13,15 @@ export declare type BlockState = /** * The different states of a transaction. + * If 'pending', the transaction is not included yet. + * If 'accepted', the transaction is included. + * If 'confirmed', the transaction is included and its included block is confirmed. + * If 'finalized', the transaction is included, its included block is finalized and cannot be reverted anymore. + * If 'failed', the transaction is not successfully issued due to failure reason. */ export declare type TransactionState = | 'pending' + | 'accepted' | 'confirmed' | 'finalized' | 'failed'; diff --git a/bindings/nodejs/tests/client/infoMethods.spec.ts b/bindings/nodejs/tests/client/infoMethods.spec.ts index afeeb165de..5ec63bba74 100644 --- a/bindings/nodejs/tests/client/infoMethods.spec.ts +++ b/bindings/nodejs/tests/client/infoMethods.spec.ts @@ -59,13 +59,6 @@ describe.skip('Client info methods', () => { expect(tips.length).toBeGreaterThan(0); }); - it('gets peers', async () => { - const client = await makeClient(); - await expect(client.getPeers()).rejects.toMatch( - 'missing or malformed jwt', - ); - }); - it('gets networkInfo', async () => { const client = await makeClient(); const networkInfo = await client.getNetworkInfo(); diff --git a/bindings/python/iota_sdk/types/block/metadata.py b/bindings/python/iota_sdk/types/block/metadata.py index 19a45386e2..06d12ebb6f 100644 --- a/bindings/python/iota_sdk/types/block/metadata.py +++ b/bindings/python/iota_sdk/types/block/metadata.py @@ -49,15 +49,17 @@ class TransactionState(Enum): """Describes the state of a transaction. Attributes: - Pending: Stored but not confirmed. - Confirmed: Confirmed with the first level of knowledge. - Finalized: Included and can no longer be reverted. - Failed: The block is not successfully issued due to failure reason. + Pending: Not included yet. + Accepted: Included. + Confirmed: Included and its included block is confirmed. + Finalized: Included, its included block is finalized and cannot be reverted anymore. + Failed: Not successfully issued due to failure reason. """ Pending = 0 - Confirmed = 1 - Finalized = 2 - Failed = 3 + Accepted = 1 + Confirmed = 2 + Finalized = 3 + Failed = 4 class BlockFailureReason(IntEnum): diff --git a/sdk/src/types/api/core.rs b/sdk/src/types/api/core.rs index 804f5f7ca7..bfe36ef4f1 100644 --- a/sdk/src/types/api/core.rs +++ b/sdk/src/types/api/core.rs @@ -25,7 +25,7 @@ use crate::{ }; /// Response of GET /api/core/v3/info. -/// Returns general information about the node. +/// General information about the node. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct InfoResponse { @@ -206,8 +206,8 @@ pub struct ValidatorResponse { #[serde(rename_all = "camelCase")] pub struct ValidatorsResponse { /// List of registered validators ready for the next epoch. - validators: Vec, - /// The number of validators returned per one API request with pagination. + stakers: Vec, + /// The number of validators returned per one API request with pagination. page_size: u32, /// The cursor that needs to be provided as cursor query parameter to request the next page. If empty, this was the /// last page. @@ -216,7 +216,7 @@ pub struct ValidatorsResponse { } /// Response of GET /api/core/v3/rewards/{outputId}. -/// Returns the mana rewards of an account or delegation output. +/// The mana rewards of an account or delegation output. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ManaRewardsResponse { @@ -254,7 +254,7 @@ pub struct CommitteeResponse { pub epoch: EpochIndex, } -/// Returns information of a committee member. +/// Information of a committee member. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CommitteeMember { @@ -356,11 +356,13 @@ pub enum BlockState { #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum TransactionState { - // Stored but not confirmed. + // Not included yet. Pending, - // Confirmed with the first level of knowledge. + // Included. + Accepted, + // Included and its included block is confirmed. Confirmed, - // Included and can no longer be reverted. + // Included, its included block is finalized and cannot be reverted anymore. Finalized, // The block is not successfully issued due to failure reason. Failed, @@ -411,7 +413,7 @@ pub struct TransactionMetadataResponse { } /// Response of GET /api/core/v3/blocks/{blockId}/metadata. -/// Returns the metadata of a block. +/// The metadata of a block. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct BlockMetadataResponse { @@ -424,7 +426,7 @@ pub struct BlockMetadataResponse { } /// Response of GET /api/core/v3/blocks/{blockId}/full. -/// Returns a block and its metadata. +/// A block and its metadata. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct BlockWithMetadataResponse { pub block: BlockDto, @@ -432,7 +434,7 @@ pub struct BlockWithMetadataResponse { } /// Response of GET /api/core/v3/outputs/{output_id}. -/// Returns an output and its metadata. +/// An output and its metadata. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct OutputWithMetadataResponse { @@ -456,7 +458,7 @@ impl From for OutputWithMetadataResponse { } /// Response of GET /api/routes. -/// Returns the available API route groups of the node. +/// The available API route groups of the node. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RoutesResponse { @@ -466,7 +468,7 @@ pub struct RoutesResponse { /// Response of /// - GET /api/core/v3/commitments/{commitmentId}/utxo-changes /// - GET /api/core/v3/commitments/by-slot/{slot}/utxo-changes -/// Returns all UTXO changes that happened at a specific slot. +/// All UTXO changes that happened at a specific slot. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct UtxoChangesResponse { @@ -478,7 +480,7 @@ pub struct UtxoChangesResponse { /// Response of /// - GET /api/core/v3/commitments/{commitmentId}/utxo-changes/full /// - GET /api/core/v3/commitments/by-slot/{slot}/utxo-changes/full -/// Returns all full UTXO changes that happened at a specific slot. +/// All full UTXO changes that happened at a specific slot. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct UtxoChangesFullResponse { diff --git a/sdk/src/wallet/operations/syncing/transactions.rs b/sdk/src/wallet/operations/syncing/transactions.rs index 609dff8c62..57e4662179 100644 --- a/sdk/src/wallet/operations/syncing/transactions.rs +++ b/sdk/src/wallet/operations/syncing/transactions.rs @@ -103,8 +103,10 @@ where Ok(metadata) => { if let Some(tx_state) = metadata.transaction_metadata.map(|m| m.transaction_state) { match tx_state { - // TODO: Separate TransactionState::Finalized? - TransactionState::Finalized | TransactionState::Confirmed => { + // TODO: Separate TransactionState::Finalized, TransactionState::Accepted? https://github.com/iotaledger/iota-sdk/issues/1814 + TransactionState::Accepted + | TransactionState::Confirmed + | TransactionState::Finalized => { log::debug!( "[SYNC] confirmed transaction {transaction_id} in block {}", metadata.block_id