From f723ea75eec12e1c028abf078726ec06e08aa1fb Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:13:04 +0100 Subject: [PATCH 1/4] Nodejs: fix NativeTokenFeature (#2182) --- bindings/nodejs/lib/types/block/output/feature.ts | 14 ++++++++------ bindings/nodejs/lib/types/block/output/output.ts | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bindings/nodejs/lib/types/block/output/feature.ts b/bindings/nodejs/lib/types/block/output/feature.ts index 1f1e1ade19..ee5e0465ed 100644 --- a/bindings/nodejs/lib/types/block/output/feature.ts +++ b/bindings/nodejs/lib/types/block/output/feature.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { SlotIndex } from '../slot'; -import { Type } from 'class-transformer'; +import { Transform, Type } from 'class-transformer'; import { Address, AddressDiscriminator } from '../address'; import { BlockIssuerKey, @@ -11,7 +11,7 @@ import { import { u256, u64 } from '../../utils/type-aliases'; import { EpochIndex } from '../../block/slot'; import { NativeToken } from '../../models/native-token'; -import { HexEncodedString } from '../../utils/hex-encoding'; +import { HexEncodedString, hexToBigInt } from '../../utils/hex-encoding'; /** * Printable ASCII characters. @@ -147,16 +147,18 @@ class NativeTokenFeature extends Feature { /** * Amount of native tokens of the given Token ID. */ + @Transform((value) => hexToBigInt(value.value)) readonly amount: u256; /** * Creates a new `NativeTokenFeature`. - * @param nativeToken The native token stored with the feature. + * @param id The identifier of the native token. + * @param amount The native token amount. */ - constructor(nativeToken: NativeToken) { + constructor(id: HexEncodedString, amount: u256) { super(FeatureType.NativeToken); - this.id = nativeToken.id; - this.amount = nativeToken.amount; + this.id = id; + this.amount = amount; } /** diff --git a/bindings/nodejs/lib/types/block/output/output.ts b/bindings/nodejs/lib/types/block/output/output.ts index 0637133718..55cea2b67d 100644 --- a/bindings/nodejs/lib/types/block/output/output.ts +++ b/bindings/nodejs/lib/types/block/output/output.ts @@ -153,6 +153,7 @@ class BasicOutput extends CommonOutput { /** * @param amount The amount of the output. + * @param mana The mana of the output. * @param unlockConditions The unlock conditions for the output. */ constructor(amount: u64, mana: u64, unlockConditions: UnlockCondition[]) { From 89d20d3775a66680449cb0a0b28bf8850a3ee616 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:13:29 +0100 Subject: [PATCH 2/4] Add slots_remaining to InsufficientMana Display (#2178) --- sdk/src/client/api/block_builder/transaction_builder/error.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/error.rs b/sdk/src/client/api/block_builder/transaction_builder/error.rs index 8affd1f350..910501d47b 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/error.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/error.rs @@ -39,7 +39,9 @@ pub enum TransactionBuilderError { required: u64, }, /// Insufficient mana provided. - #[error("insufficient mana: found {found}, required {required}")] + #[error( + "insufficient mana: found {found}, required {required}, slots remaining until enough mana {slots_remaining}" + )] InsufficientMana { /// The amount found. found: u64, From 9c36a7cd7328f2e29359cdad2f9f7b1609ea6232 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:13:56 +0100 Subject: [PATCH 3/4] Update getCommittee epoch query parameter (#2179) * Update getCommittee epoch query parameter * Update client method handler --- bindings/core/src/method/client.rs | 3 +-- bindings/core/src/method_handler/client.rs | 2 +- bindings/nodejs/lib/client/client.ts | 6 +++--- bindings/nodejs/lib/types/client/bridge/client.ts | 2 +- bindings/python/iota_sdk/client/_node_core_api.py | 6 +++--- sdk/src/client/node_api/core/routes.rs | 6 +++--- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/bindings/core/src/method/client.rs b/bindings/core/src/method/client.rs index 12272531d9..dcc7054473 100644 --- a/bindings/core/src/method/client.rs +++ b/bindings/core/src/method/client.rs @@ -187,10 +187,9 @@ pub enum ClientMethod { }, /// Return the information of committee members at the given epoch index. If epoch index is not provided, the /// current committee members are returned. - #[serde(rename_all = "camelCase")] GetCommittee { /// The epoch index to query. - epoch_index: Option, + epoch: Option, }, /// Get issuance GetIssuance, diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index f3159e5d5d..feba7de3ed 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -196,7 +196,7 @@ pub(crate) async fn call_client_method_internal( Response::Validators(client.get_validators(page_size, cursor).await?) } ClientMethod::GetValidator { account_id } => Response::Validator(client.get_validator(&account_id).await?), - ClientMethod::GetCommittee { epoch_index } => Response::Committee(client.get_committee(epoch_index).await?), + ClientMethod::GetCommittee { epoch } => Response::Committee(client.get_committee(epoch).await?), ClientMethod::GetIssuance => Response::Issuance(client.get_issuance().await?), ClientMethod::PostBlockRaw { block_bytes } => Response::BlockId( client diff --git a/bindings/nodejs/lib/client/client.ts b/bindings/nodejs/lib/client/client.ts index f158874354..cd42a7f507 100644 --- a/bindings/nodejs/lib/client/client.ts +++ b/bindings/nodejs/lib/client/client.ts @@ -252,13 +252,13 @@ export class Client { /** * Returns the information of committee members at the given epoch index. If epoch index is not provided, the * current committee members are returned. - * GET /api/core/v3/committee/?epochIndex + * GET /api/core/v3/committee/?epoch */ - async getCommittee(epochIndex?: EpochIndex): Promise { + async getCommittee(epoch?: EpochIndex): Promise { const response = await this.methodHandler.callMethod({ name: 'getCommittee', data: { - epochIndex, + epoch, }, }); diff --git a/bindings/nodejs/lib/types/client/bridge/client.ts b/bindings/nodejs/lib/types/client/bridge/client.ts index 3805397cbe..8e59066702 100644 --- a/bindings/nodejs/lib/types/client/bridge/client.ts +++ b/bindings/nodejs/lib/types/client/bridge/client.ts @@ -104,7 +104,7 @@ export interface __GetValidatorMethod__ { export interface __GetCommitteeMethod__ { name: 'getCommittee'; data: { - epochIndex?: EpochIndex; + epoch?: EpochIndex; }; } diff --git a/bindings/python/iota_sdk/client/_node_core_api.py b/bindings/python/iota_sdk/client/_node_core_api.py index f62b32525d..a83d076717 100644 --- a/bindings/python/iota_sdk/client/_node_core_api.py +++ b/bindings/python/iota_sdk/client/_node_core_api.py @@ -144,13 +144,13 @@ def get_validator(self, account_id: HexStr) -> ValidatorResponse: # Committee routes. def get_committee( - self, epoch_index: Optional[EpochIndex] = None) -> CommitteeResponse: + self, epoch: Optional[EpochIndex] = None) -> CommitteeResponse: """Returns the information of committee members at the given epoch index. If epoch index is not provided, the current committee members are returned. - GET /api/core/v3/committee/?epochIndex + GET /api/core/v3/committee/?epoch """ return CommitteeResponse.from_dict(self._call_method('getCommittee', { - 'epochIndex': epoch_index + 'epoch': epoch })) # Block routes. diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index c7b09ce4da..cd7694841e 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -167,13 +167,13 @@ impl Client { /// Returns the information of committee members at the given epoch index. If epoch index is not provided, the /// current committee members are returned. - /// GET /api/core/v3/committee/?epochIndex + /// GET /api/core/v3/committee/?epoch pub async fn get_committee( &self, - epoch_index: impl Into> + Send, + epoch: impl Into> + Send, ) -> Result { const PATH: &str = "api/core/v3/committee"; - let query = query_tuples_to_query_string([epoch_index.into().map(|i| ("epochIndex", i.to_string()))]); + let query = query_tuples_to_query_string([epoch.into().map(|i| ("epoch", i.to_string()))]); self.get_request(PATH, query.as_deref(), false).await } From 05cf6819f12bb172f3beb4f2e406b75de14bfbcb Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:14:35 +0100 Subject: [PATCH 4/4] Improve wait_for_transaction_acceptance (#2177) * Don't error with NotFound for the first attempts in wait_for_transaction_acceptance as the node may not have fully processed the tx at this point * Don't error on NotFound as nodes may haven't processed/got the tx yet --- sdk/src/client/api/wait_for_tx_acceptance.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sdk/src/client/api/wait_for_tx_acceptance.rs b/sdk/src/client/api/wait_for_tx_acceptance.rs index fa2e0d668a..778a6a2f38 100644 --- a/sdk/src/client/api/wait_for_tx_acceptance.rs +++ b/sdk/src/client/api/wait_for_tx_acceptance.rs @@ -26,14 +26,20 @@ impl Client { .unwrap_or(DEFAULT_WAIT_FOR_TX_ACCEPTANCE_INTERVAL); for _ in 0..max_attempts.unwrap_or(DEFAULT_WAIT_FOR_TX_ACCEPTANCE_MAX_ATTEMPTS) { - let transaction_metadata = self.get_transaction_metadata(transaction_id).await?; - - match transaction_metadata.transaction_state { - TransactionState::Accepted | TransactionState::Committed | TransactionState::Finalized => { - return Ok(()); + match self.get_transaction_metadata(transaction_id).await { + Ok(transaction_metadata) => { + match transaction_metadata.transaction_state { + TransactionState::Accepted | TransactionState::Committed | TransactionState::Finalized => { + return Ok(()); + } + TransactionState::Failed => { + return Err(ClientError::TransactionAcceptance(transaction_id.to_string())); + } + TransactionState::Pending => {} // Just need to wait longer + }; } - TransactionState::Failed => return Err(ClientError::TransactionAcceptance(transaction_id.to_string())), - TransactionState::Pending => {} // Just need to wait longer + Err(ClientError::Node(crate::client::node_api::error::Error::NotFound(_))) => {} + Err(e) => return Err(e), }; #[cfg(target_family = "wasm")]