Skip to content

Commit

Permalink
Merge branch '2.0' into feat/auto-txn-capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars authored Feb 29, 2024
2 parents fb8f025 + 7fd9c9b commit 59828cb
Show file tree
Hide file tree
Showing 171 changed files with 1,945 additions and 1,500 deletions.
57 changes: 41 additions & 16 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,22 @@ pub enum ClientMethod {
//////////////////////////////////////////////////////////////////////
// Node core API
//////////////////////////////////////////////////////////////////////
/// Get health
/// Returns the health of the node.
GetHealth {
/// Url
url: String,
},
/// Get node info
GetNodeInfo {
/// Returns the available API route groups of the node.
GetRoutes,
/// Returns general information about a node given its URL and - if required - the authentication data.
GetInfo {
/// Url
url: String,
/// Node authentication
auth: Option<NodeAuth>,
},
/// Returns the node information together with the url of the used node
GetInfo,
/// Returns general information about the node together with its URL.
GetNodeInfo,
/// 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.
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -224,25 +226,31 @@ pub enum ClientMethod {
/// Block ID
block_id: BlockId,
},
/// Get block raw
/// Get block as raw bytes.
#[serde(rename_all = "camelCase")]
GetBlockRaw {
/// Block ID
block_id: BlockId,
},
/// Get output
/// Get output with its output ID proof.
#[serde(rename_all = "camelCase")]
GetOutput {
/// Output ID
output_id: OutputId,
},
/// Get output metadata
/// Get output as raw bytes.
#[serde(rename_all = "camelCase")]
GetOutputRaw {
/// Output ID
output_id: OutputId,
},
/// Get output metadata.
#[serde(rename_all = "camelCase")]
GetOutputMetadata {
/// Output ID
output_id: OutputId,
},
/// Get output with its metadata
/// Get output with its metadata including the output ID proof.
#[serde(rename_all = "camelCase")]
GetOutputWithMetadata {
/// Output ID
Expand All @@ -254,6 +262,12 @@ pub enum ClientMethod {
/// Transaction ID
transaction_id: TransactionId,
},
/// Returns the raw bytes of the included block of a transaction.
#[serde(rename_all = "camelCase")]
GetIncludedBlockRaw {
/// Transaction ID
transaction_id: TransactionId,
},
/// Returns the included block metadata of the transaction.
#[serde(rename_all = "camelCase")]
GetIncludedBlockMetadata {
Expand All @@ -272,6 +286,12 @@ pub enum ClientMethod {
/// Commitment ID of the commitment to look up.
commitment_id: SlotCommitmentId,
},
/// Look up a commitment by a given commitment ID and return its raw bytes.
#[serde(rename_all = "camelCase")]
GetCommitmentRaw {
/// Commitment ID of the commitment to look up.
commitment_id: SlotCommitmentId,
},
/// Get all UTXO changes of a given slot by Commitment ID.
#[serde(rename_all = "camelCase")]
GetUtxoChanges {
Expand All @@ -285,17 +305,22 @@ pub enum ClientMethod {
commitment_id: SlotCommitmentId,
},
/// Look up a commitment by a given commitment index.
GetCommitmentByIndex {
GetCommitmentBySlot {
/// Index of the commitment to look up.
slot: SlotIndex,
},
/// Look up a commitment by a given commitment index and return its raw bytes.
GetCommitmentBySlotRaw {
/// Index of the commitment to look up.
slot: SlotIndex,
},
/// Get all UTXO changes of a given slot by commitment index.
GetUtxoChangesByIndex {
GetUtxoChangesBySlot {
/// Index of the commitment to look up.
slot: SlotIndex,
},
/// Get all full UTXO changes of a given slot by commitment index.
GetUtxoChangesFullByIndex {
GetUtxoChangesFullBySlot {
/// Index of the commitment to look up.
slot: SlotIndex,
},
Expand Down Expand Up @@ -379,16 +404,16 @@ pub enum ClientMethod {
//////////////////////////////////////////////////////////////////////
// High level API
//////////////////////////////////////////////////////////////////////
/// Fetch OutputWithMetadataResponse from provided OutputIds (requests are sent in parallel)
/// Fetch outputs with associated output ID proofs from provided OutputIds (requests are sent in parallel)
#[serde(rename_all = "camelCase")]
GetOutputs {
/// Output IDs
output_ids: Vec<OutputId>,
},
/// Try to get OutputWithMetadataResponse from provided OutputIds (requests are sent in parallel and errors are
/// ignored, can be useful for spent outputs)
/// Try to get outputs with associated output ID proofs from provided OutputIds (requests are sent in parallel and
/// errors are ignored, can be useful for spent outputs)
#[serde(rename_all = "camelCase")]
GetOutputsIgnoreErrors {
GetOutputsIgnoreNotFound {
/// Output IDs
output_ids: Vec<OutputId>,
},
Expand Down
73 changes: 27 additions & 46 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use iota_sdk::client::mqtt::{MqttPayload, Topic};
use iota_sdk::{
client::{request_funds_from_faucet, Client},
types::{
api::core::OutputWithMetadataResponse,
block::{
output::{
AccountOutputBuilder, BasicOutputBuilder, FoundryOutputBuilder, MinimumOutputAmount, NftOutputBuilder,
Expand Down Expand Up @@ -181,8 +180,9 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
#[cfg(not(target_family = "wasm"))]
ClientMethod::UnhealthyNodes => Response::UnhealthyNodes(client.unhealthy_nodes().await.into_iter().collect()),
ClientMethod::GetHealth { url } => Response::Bool(client.get_health(&url).await?),
ClientMethod::GetNodeInfo { url, auth } => Response::NodeInfo(Client::get_node_info(&url, auth).await?),
ClientMethod::GetInfo => Response::Info(client.get_info().await?),
ClientMethod::GetInfo { url, auth } => Response::Info(Client::get_info(&url, auth).await?),
ClientMethod::GetNodeInfo => Response::NodeInfo(client.get_node_info().await?),
ClientMethod::GetRoutes => Response::Routes(client.get_routes().await?),
ClientMethod::GetAccountCongestion { account_id, work_score } => {
Response::Congestion(client.get_account_congestion(&account_id, work_score).await?)
}
Expand Down Expand Up @@ -212,58 +212,57 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.await?,
),
ClientMethod::GetBlock { block_id } => Response::Block(BlockDto::from(&client.get_block(&block_id).await?)),
ClientMethod::GetBlockRaw { block_id } => Response::Raw(client.get_block_raw(&block_id).await?),
ClientMethod::GetBlockMetadata { block_id } => {
Response::BlockMetadata(client.get_block_metadata(&block_id).await?)
}
ClientMethod::GetBlockWithMetadata { block_id } => {
Response::BlockWithMetadata(client.get_block_with_metadata(&block_id).await?)
}
ClientMethod::GetBlockRaw { block_id } => Response::Raw(client.get_block_raw(&block_id).await?),
ClientMethod::GetOutput { output_id } => Response::OutputWithMetadataResponse(
client
.get_output_with_metadata(&output_id)
.await
.map(OutputWithMetadataResponse::from)?,
),
ClientMethod::GetOutput { output_id } => Response::OutputResponse(client.get_output(&output_id).await?),
ClientMethod::GetOutputRaw { output_id } => Response::Raw(client.get_output_raw(&output_id).await?),
ClientMethod::GetOutputMetadata { output_id } => {
Response::OutputMetadata(client.get_output_metadata(&output_id).await?)
}
ClientMethod::GetOutputWithMetadata { output_id } => {
Response::OutputWithMetadata(client.get_output_with_metadata(&output_id).await?)
}
ClientMethod::GetOutputs { output_ids } => Response::Outputs(client.get_outputs(&output_ids).await?),
ClientMethod::GetOutputsIgnoreNotFound { output_ids } => {
Response::Outputs(client.get_outputs_ignore_not_found(&output_ids).await?)
}
ClientMethod::GetIncludedBlock { transaction_id } => {
Response::Block(BlockDto::from(&client.get_included_block(&transaction_id).await?))
}
ClientMethod::GetIncludedBlockRaw { transaction_id } => {
Response::Raw(client.get_included_block_raw(&transaction_id).await?)
}
ClientMethod::GetIncludedBlockMetadata { transaction_id } => {
Response::BlockMetadata(client.get_included_block_metadata(&transaction_id).await?)
}
ClientMethod::GetTransactionMetadata { transaction_id } => {
Response::TransactionMetadata(client.get_transaction_metadata(&transaction_id).await?)
}
ClientMethod::GetCommitment { commitment_id } => {
Response::SlotCommitment(client.get_slot_commitment_by_id(&commitment_id).await?)
Response::SlotCommitment(client.get_commitment(&commitment_id).await?)
}
ClientMethod::GetCommitmentRaw { commitment_id } => {
Response::Raw(client.get_commitment_raw(&commitment_id).await?)
}
ClientMethod::GetUtxoChanges { commitment_id } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot_commitment_id(&commitment_id).await?)
Response::UtxoChanges(client.get_utxo_changes(&commitment_id).await?)
}
ClientMethod::GetUtxoChangesFull { commitment_id } => Response::UtxoChangesFull(
client
.get_utxo_changes_full_by_slot_commitment_id(&commitment_id)
.await?,
),
// TODO: this should be renamed to `GetCommitmentBySlot`
// https://github.com/iotaledger/iota-sdk/issues/1921
ClientMethod::GetCommitmentByIndex { slot } => {
Response::SlotCommitment(client.get_slot_commitment_by_slot(slot).await?)
}
// TODO: this should be renamed to `GetUtxoChangesBySlot`
// https://github.com/iotaledger/iota-sdk/issues/1921
ClientMethod::GetUtxoChangesByIndex { slot } => {
ClientMethod::GetUtxoChangesFull { commitment_id } => {
Response::UtxoChangesFull(client.get_utxo_changes_full(&commitment_id).await?)
}
ClientMethod::GetCommitmentBySlot { slot } => {
Response::SlotCommitment(client.get_commitment_by_slot(slot).await?)
}
ClientMethod::GetCommitmentBySlotRaw { slot } => Response::Raw(client.get_commitment_by_slot_raw(slot).await?),
ClientMethod::GetUtxoChangesBySlot { slot } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot(slot).await?)
}
// TODO: this should be renamed to `GetUtxoChangesFullBySlot`
// https://github.com/iotaledger/iota-sdk/issues/1921
ClientMethod::GetUtxoChangesFullByIndex { slot } => {
ClientMethod::GetUtxoChangesFullBySlot { slot } => {
Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(slot).await?)
}
ClientMethod::OutputIds { query_parameters } => {
Expand Down Expand Up @@ -294,24 +293,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
Response::OutputIdsResponse(client.nft_output_ids(query_parameters).await?)
}
ClientMethod::NftOutputId { nft_id } => Response::OutputId(client.nft_output_id(nft_id).await?),
ClientMethod::GetOutputs { output_ids } => {
let outputs_response = client
.get_outputs_with_metadata(&output_ids)
.await?
.iter()
.map(OutputWithMetadataResponse::from)
.collect();
Response::Outputs(outputs_response)
}
ClientMethod::GetOutputsIgnoreErrors { output_ids } => {
let outputs_response = client
.get_outputs_with_metadata_ignore_not_found(&output_ids)
.await?
.iter()
.map(OutputWithMetadataResponse::from)
.collect();
Response::Outputs(outputs_response)
}
ClientMethod::FindBlocks { block_ids } => Response::Blocks(
client
.find_blocks(&block_ids)
Expand Down
38 changes: 21 additions & 17 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ use iota_sdk::client::secret::LedgerNanoStatus;
use iota_sdk::{
client::{
api::{PreparedTransactionData, SignedTransactionDataDto},
node_api::core::routes::NodeInfoResponse,
node_manager::node::Node,
NetworkInfo, NodeInfoWrapper,
NetworkInfo,
},
types::{
api::{
core::{
BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse,
InfoResponse as NodeInfo, IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputWithMetadataResponse,
TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse, ValidatorResponse,
ValidatorsResponse,
BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse,
IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputResponse, OutputWithMetadataResponse,
RoutesResponse, TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse,
ValidatorResponse, ValidatorsResponse,
},
plugins::indexer::OutputIdsResponse,
},
block::{
address::{Address, Bech32Address, Hrp},
input::UtxoInput,
output::{
AccountId, DecayedMana, FoundryId, NftId, Output, OutputId, OutputMetadata, OutputWithMetadata, TokenId,
},
output::{AccountId, DecayedMana, FoundryId, NftId, Output, OutputId, OutputMetadata, TokenId},
payload::{dto::SignedTransactionPayloadDto, signed_transaction::TransactionId},
protocol::ProtocolParameters,
signature::Ed25519Signature,
Expand Down Expand Up @@ -101,11 +100,14 @@ pub enum Response {
#[cfg(not(target_family = "wasm"))]
UnhealthyNodes(HashSet<Node>),
/// Response for:
/// - [`GetInfo`](crate::method::ClientMethod::GetInfo)
Info(InfoResponse),
/// Response for:
/// - [`GetNodeInfo`](crate::method::ClientMethod::GetNodeInfo)
NodeInfo(NodeInfo),
NodeInfo(NodeInfoResponse),
/// Response for:
/// - [`GetInfo`](crate::method::ClientMethod::GetInfo)
Info(NodeInfoWrapper),
/// - [`GetRoutes`](crate::method::ClientMethod::GetRoutes)
Routes(RoutesResponse),
/// Response for:
/// - [`GetAccountCongestion`](crate::method::ClientMethod::GetAccountCongestion)
Congestion(CongestionResponse),
Expand Down Expand Up @@ -155,21 +157,25 @@ pub enum Response {
BlockWithMetadata(BlockWithMetadataResponse),
/// Response for:
/// - [`GetBlockRaw`](crate::method::ClientMethod::GetBlockRaw)
/// - [`GetOutputRaw`](crate::method::ClientMethod::GetOutputRaw)
/// - [`GetIncludedBlockRaw`](crate::method::ClientMethod::GetIncludedBlockRaw)
/// - [`GetCommitmentRaw`](crate::method::ClientMethod::GetCommitmentRaw)
/// - [`GetCommitmentBySlotRaw`](crate::method::ClientMethod::GetCommitmentBySlotRaw)
/// - [`BlockBytes`](crate::method::UtilsMethod::BlockBytes)
Raw(Vec<u8>),
/// Response for:
/// - [`GetOutput`](crate::method::ClientMethod::GetOutput)
OutputWithMetadataResponse(OutputWithMetadataResponse),
OutputResponse(OutputResponse),
/// Response for:
/// - [`GetOutputMetadata`](crate::method::ClientMethod::GetOutputMetadata)
OutputMetadata(OutputMetadata),
/// Response for:
/// - [`GetOutputWithMetadata`](crate::method::ClientMethod::GetOutputWithMetadata)
OutputWithMetadata(OutputWithMetadata),
OutputWithMetadata(OutputWithMetadataResponse),
/// Response for:
/// - [`GetOutputs`](crate::method::ClientMethod::GetOutputs)
/// - [`GetOutputsIgnoreErrors`](crate::method::ClientMethod::GetOutputsIgnoreErrors)
Outputs(Vec<OutputWithMetadataResponse>),
/// - [`GetOutputsIgnoreNotFound`](crate::method::ClientMethod::GetOutputsIgnoreNotFound)
Outputs(Vec<OutputResponse>),
/// Response for:
/// - [`AccountOutputId`](crate::method::ClientMethod::AccountOutputId)
/// - [`AnchorOutputId`](crate::method::ClientMethod::AnchorOutputId)
Expand Down Expand Up @@ -222,8 +228,6 @@ pub enum Response {
/// Response for:
/// - [`TransactionSigningHash`](crate::method::UtilsMethod::TransactionSigningHash)
Hash(String),
/// Response for [`GetNodeInfo`](crate::method::ClientMethod::GetNodeInfo)
NodeInfoWrapper(NodeInfoWrapper),
/// Response for [`Bech32ToHex`](crate::method::UtilsMethod::Bech32ToHex)
HexAddress(String),
/// Response for [`OutputHexBytes`](crate::method::UtilsMethod::OutputHexBytes)
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Prebuild requires that the binary is in `build/Release` as though it was built w
The following example creates a [`Client`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Client/)
instance connected to
the [Shimmer Testnet](https://api.testnet.shimmer.network), and retrieves the node's information by
calling [`Client.getInfo()`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Client/#getinfo),
calling [`Client.getNodeInfo()`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Client/#getnodeinfo),
and then print the node's information.

```javascript
Expand All @@ -85,7 +85,7 @@ async function run() {
});

try {
const nodeInfo = await client.getInfo();
const nodeInfo = await client.getNodeInfo();
console.log('Node info: ', nodeInfo);
} catch (error) {
console.error('Error: ', error);
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/client/07-get-block-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function run() {

try {
// Fetch a block ID from the node.
const blockIds = await client.getTips();
const blockIds = (await client.getIssuance()).strongParents;
console.log('Block IDs:', blockIds, '\n');

// Get the metadata for the block.
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/client/12-get-raw-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function run() {

try {
// Get a random block ID.
const blockId = (await client.getTips())[0];
const blockId = (await client.getIssuance()).strongParents[0];

const rawBytes = await client.getBlockRaw(blockId);
console.log('Block bytes: ', rawBytes);
Expand Down
Loading

0 comments on commit 59828cb

Please sign in to comment.