Skip to content

Commit

Permalink
Merge branch '2.0' into implicit-account-semantic
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jan 12, 2024
2 parents 9d36f4f + 019d348 commit af58d0e
Show file tree
Hide file tree
Showing 226 changed files with 24,547 additions and 23,597 deletions.
516 changes: 297 additions & 219 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ resolver = "2"
members = [
"bindings/core",
"bindings/nodejs",
# TODO: issue #1423
#"bindings/python",
"bindings/python",
"bindings/wasm",
"cli",
"sdk",
Expand Down
10 changes: 5 additions & 5 deletions bindings/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ iota-sdk = { path = "../../sdk", default-features = false, features = [
backtrace = { version = "0.3.69", default-features = false, features = ["std"] }
derivative = { version = "2.2.0", default-features = false }
fern-logger = { version = "0.5.0", default-features = false }
futures = { version = "0.3.29", default-features = false }
futures = { version = "0.3.30", default-features = false }
iota-crypto = { version = "0.23.0", default-features = false, features = [
"slip10",
"bip44",
Expand All @@ -26,10 +26,10 @@ log = { version = "0.4.20", default-features = false }
packable = { version = "0.10.0", default-features = false }
prefix-hex = { version = "0.7.1", default-features = false }
primitive-types = { version = "0.12.2", default-features = false }
serde = { version = "1.0.193", default-features = false }
serde_json = { version = "1.0.108", default-features = false }
thiserror = { version = "1.0.50", default-features = false }
tokio = { version = "1.34.0", default-features = false }
serde = { version = "1.0.195", default-features = false }
serde_json = { version = "1.0.111", default-features = false }
thiserror = { version = "1.0.56", default-features = false }
tokio = { version = "1.35.1", default-features = false }
url = { version = "2.4.1", default-features = false, features = ["serde"] }
zeroize = { version = "1.7.0", default-features = false }

Expand Down
26 changes: 20 additions & 6 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SlotIndex>,
},
/// Returns information of all registered validators and if they are active, ordered by their holding stake.
Expand Down Expand Up @@ -273,15 +276,26 @@ pub enum ClientMethod {
/// Commitment ID of the commitment to look up.
commitment_id: SlotCommitmentId,
},
/// Get all full UTXO changes of a given slot by Commitment ID.
#[serde(rename_all = "camelCase")]
GetUtxoChangesFull {
/// Commitment ID of the commitment to look up.
commitment_id: SlotCommitmentId,
},
/// 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.
slot: SlotIndex,
},

//////////////////////////////////////////////////////////////////////
Expand Down
21 changes: 21 additions & 0 deletions bindings/core/src/method/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ pub enum SecretManagerMethod {
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
mnemonic: String,
},
/// Set the stronghold password.
/// Expected response: [`Ok`](crate::Response::Ok)
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
SetStrongholdPassword {
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
password: String,
},
/// Change the stronghold password.
/// Expected response: [`Ok`](crate::Response::Ok)
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
ChangeStrongholdPassword {
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
password: String,
},
/// Clear the stronghold password.
/// Expected response: [`Ok`](crate::Response::Ok)
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
ClearStrongholdPassword,
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub enum UtilsMethod {
ComputeNftId { output_id: OutputId },
/// Computes the output ID from transaction id and output index
ComputeOutputId { id: TransactionId, index: u16 },
/// Computes a tokenId from the aliasId, serial number and token scheme type.
/// Computes a tokenId from the accountId, serial number and token scheme type.
#[serde(rename_all = "camelCase")]
ComputeTokenId {
account_id: AccountId,
Expand Down
130 changes: 74 additions & 56 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iota_sdk::{
api::core::OutputWithMetadataResponse,
block::{
output::{
AccountOutput, BasicOutput, FoundryOutput, MinimumOutputAmount, NftOutput, Output, OutputBuilderAmount,
AccountOutputBuilder, BasicOutputBuilder, FoundryOutputBuilder, MinimumOutputAmount, NftOutputBuilder,
},
payload::Payload,
Block, BlockDto, UnsignedBlockDto,
Expand Down Expand Up @@ -64,40 +64,43 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
immutable_features,
} => {
let output = Output::from(AccountOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
&account_id,
foundry_counter,
unlock_conditions,
features,
immutable_features,
)?);
let mut output_builder = if let Some(amount) = amount {
AccountOutputBuilder::new_with_amount(amount, account_id)
} else {
AccountOutputBuilder::new_with_minimum_amount(client.get_storage_score_parameters().await?, account_id)
}
.with_mana(mana)
.with_foundry_counter(foundry_counter)
.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
output_builder = output_builder.with_features(features);
}
if let Some(immutable_features) = immutable_features {
output_builder = output_builder.with_immutable_features(immutable_features)
}

Response::Output(output)
Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildBasicOutput {
amount,
mana,
unlock_conditions,
features,
} => {
let output = Output::from(BasicOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
unlock_conditions,
features,
)?);
let mut output_builder = if let Some(amount) = amount {
BasicOutputBuilder::new_with_amount(amount)
} else {
BasicOutputBuilder::new_with_minimum_amount(client.get_storage_score_parameters().await?)
}
.with_mana(mana)
.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
output_builder = output_builder.with_features(features);
}

Response::Output(output)
Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildFoundryOutput {
amount,
Expand All @@ -107,20 +110,25 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
immutable_features,
} => {
let output = Output::from(FoundryOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
serial_number,
token_scheme,
unlock_conditions,
features,
immutable_features,
)?);
let mut output_builder = if let Some(amount) = amount {
FoundryOutputBuilder::new_with_amount(amount, serial_number, token_scheme)
} else {
FoundryOutputBuilder::new_with_minimum_amount(
client.get_storage_score_parameters().await?,
serial_number,
token_scheme,
)
}
.with_unlock_conditions(unlock_conditions);

Response::Output(output)
if let Some(features) = features {
output_builder = output_builder.with_features(features);
}
if let Some(immutable_features) = immutable_features {
output_builder = output_builder.with_immutable_features(immutable_features)
}

Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildNftOutput {
amount,
Expand All @@ -130,20 +138,22 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
immutable_features,
} => {
let output = Output::from(NftOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
&nft_id,
unlock_conditions,
features,
immutable_features,
)?);
let mut output_builder = if let Some(amount) = amount {
NftOutputBuilder::new_with_amount(amount, nft_id)
} else {
NftOutputBuilder::new_with_minimum_amount(client.get_storage_score_parameters().await?, nft_id)
}
.with_mana(mana)
.with_unlock_conditions(unlock_conditions);

Response::Output(output)
if let Some(features) = features {
output_builder = output_builder.with_features(features);
}
if let Some(immutable_features) = immutable_features {
output_builder = output_builder.with_immutable_features(immutable_features)
}

Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildBasicBlock { issuer_id, payload } => {
let payload = if let Some(payload) = payload {
Expand Down Expand Up @@ -236,11 +246,19 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetUtxoChanges { commitment_id } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot_commitment_id(&commitment_id).await?)
}
ClientMethod::GetCommitmentByIndex { index } => {
Response::SlotCommitment(client.get_slot_commitment_by_slot(index).await?)
ClientMethod::GetUtxoChangesFull { commitment_id } => Response::UtxoChangesFull(
client
.get_utxo_changes_full_by_slot_commitment_id(&commitment_id)
.await?,
),
ClientMethod::GetCommitmentByIndex { slot } => {
Response::SlotCommitment(client.get_slot_commitment_by_slot(slot).await?)
}
ClientMethod::GetUtxoChangesByIndex { slot } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot(slot).await?)
}
ClientMethod::GetUtxoChangesByIndex { index } => {
Response::UtxoChanges(client.get_utxo_changes_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?)
Expand Down
36 changes: 36 additions & 0 deletions bindings/core/src/method_handler/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,42 @@ where
return Err(iota_sdk::client::Error::SecretManagerMismatch.into());
}
}
#[cfg(feature = "stronghold")]
SecretManagerMethod::SetStrongholdPassword { password } => {
let stronghold = if let Some(secret_manager) = secret_manager.downcast::<StrongholdSecretManager>() {
secret_manager
} else if let Some(SecretManager::Stronghold(secret_manager)) = secret_manager.downcast::<SecretManager>() {
secret_manager
} else {
return Err(iota_sdk::client::Error::SecretManagerMismatch.into());
};
stronghold.set_password(password).await?;
Response::Ok
}
#[cfg(feature = "stronghold")]
SecretManagerMethod::ChangeStrongholdPassword { password } => {
let stronghold = if let Some(secret_manager) = secret_manager.downcast::<StrongholdSecretManager>() {
secret_manager
} else if let Some(SecretManager::Stronghold(secret_manager)) = secret_manager.downcast::<SecretManager>() {
secret_manager
} else {
return Err(iota_sdk::client::Error::SecretManagerMismatch.into());
};
stronghold.change_password(password).await?;
Response::Ok
}
#[cfg(feature = "stronghold")]
SecretManagerMethod::ClearStrongholdPassword => {
let stronghold = if let Some(secret_manager) = secret_manager.downcast::<StrongholdSecretManager>() {
secret_manager
} else if let Some(SecretManager::Stronghold(secret_manager)) = secret_manager.downcast::<SecretManager>() {
secret_manager
} else {
return Err(iota_sdk::client::Error::SecretManagerMismatch.into());
};
stronghold.clear_key().await;
Response::Ok
}
};
Ok(response)
}
7 changes: 6 additions & 1 deletion bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use iota_sdk::{
core::{
BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse,
InfoResponse as NodeInfo, IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputWithMetadataResponse,
TransactionMetadataResponse, UtxoChangesResponse, ValidatorResponse, ValidatorsResponse,
TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse, ValidatorResponse,
ValidatorsResponse,
},
plugins::indexer::OutputIdsResponse,
},
Expand Down Expand Up @@ -142,6 +143,10 @@ pub enum Response {
/// - [`GetUtxoChangesByIndex`](crate::method::ClientMethod::GetUtxoChangesByIndex)
UtxoChanges(UtxoChangesResponse),
/// Response for:
/// - [`GetUtxoChangesFull`](crate::method::ClientMethod::GetUtxoChangesFull)
/// - [`GetUtxoChangesFullByIndex`](crate::method::ClientMethod::GetUtxoChangesFullByIndex)
UtxoChangesFull(UtxoChangesFullResponse),
/// Response for:
/// - [`GetBlockWithMetadata`](crate::method::ClientMethod::GetBlockWithMetadata)
BlockWithMetadata(BlockWithMetadataResponse),
/// Response for:
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 1.1.4 - 2023-MM-DD
## 1.1.4 - 2023-12-07

### Added

Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ iota-sdk-bindings-core = { path = "../core", default-features = false, features
log = { version = "0.4.20", default-features = false }
napi = { version = "2.13.3", default-features = false, features = ["async"] }
napi-derive = { version = "2.13.0", default-features = false }
once_cell = { version = "1.18.0", default-features = false }
serde_json = { version = "1.0.108", default-features = false }
once_cell = { version = "1.19.0", default-features = false }
serde_json = { version = "1.0.111", default-features = false }
thiserror = { version = "1.0.49", default-features = false }
tokio = { version = "1.34.0", default-features = false }
tokio = { version = "1.35.1", default-features = false }

[build-dependencies]
napi-build = { version = "2.0.1", default-features = false }
Expand Down
Loading

0 comments on commit af58d0e

Please sign in to comment.