Skip to content

Commit

Permalink
Merge branch '2.0' into chore/tests/block-id
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 authored Nov 30, 2023
2 parents 695ac06 + e39459d commit 918e51d
Show file tree
Hide file tree
Showing 36 changed files with 339 additions and 566 deletions.
6 changes: 3 additions & 3 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use iota_sdk::{
types::block::{
address::{Bech32Address, Hrp},
output::{
dto::OutputDto, feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, AnchorId,
DelegationId, FoundryId, NftId, OutputId, TokenScheme,
feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, AnchorId, DelegationId, FoundryId,
NftId, Output, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockDto, BlockId,
Expand Down Expand Up @@ -356,7 +356,7 @@ pub enum ClientMethod {
/// Calculate the minimum required amount for an output.
/// Expected response:
/// [`OutputAmount`](crate::Response::OutputAmount)
ComputeMinimumOutputAmount { output: OutputDto },
ComputeMinimumOutputAmount { output: Output },
/// Requests funds for a given address from the faucet, for example `https://faucet.testnet.shimmer.network/api/enqueue` or `http://localhost:8091/api/enqueue`.
RequestFundsFromFaucet {
/// Faucet URL
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iota_sdk::{
client::secret::types::InputSigningDataDto,
types::block::{
address::{Bech32Address, Hrp},
output::{dto::OutputDto, AccountId, NftId, OutputId, StorageScoreParameters},
output::{AccountId, NftId, Output, OutputId, StorageScoreParameters},
payload::signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
TransactionId,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub enum UtilsMethod {
/// Computes the minimum required amount of an output.
#[serde(rename_all = "camelCase")]
ComputeMinimumOutputAmount {
output: OutputDto,
output: Output,
storage_score_parameters: StorageScoreParameters,
},
/// Checks if the given mnemonic is valid.
Expand Down Expand Up @@ -163,7 +163,7 @@ pub enum UtilsMethod {
ComputeSlotCommitmentId { slot_commitment: SlotCommitment },
/// Returns the hex representation of the serialized output bytes.
#[serde(rename_all = "camelCase")]
OutputHexBytes { output: OutputDto },
OutputHexBytes { output: Output },
/// Verifies the semantic of a transaction.
VerifyTransactionSemantic {
inputs: Vec<InputSigningDataDto>,
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use iota_sdk::{
},
types::block::{
address::{Bech32Address, Hrp},
output::{dto::OutputDto, OutputId, TokenId},
output::{Output, OutputId, TokenId},
payload::signed_transaction::TransactionId,
},
wallet::{
Expand Down Expand Up @@ -321,7 +321,7 @@ pub enum WalletMethod {
/// Prepare transaction.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareTransaction {
outputs: Vec<OutputDto>,
outputs: Vec<Output>,
options: Option<TransactionOptions>,
},
/// Vote for a participation event.
Expand Down Expand Up @@ -371,7 +371,7 @@ pub enum WalletMethod {
/// Send outputs in a transaction.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
SendOutputs {
outputs: Vec<OutputDto>,
outputs: Vec<Output>,
options: Option<TransactionOptions>,
},
/// Set the alias of the wallet.
Expand Down
12 changes: 5 additions & 7 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use iota_sdk::{
api::core::OutputWithMetadataResponse,
block::{
output::{
dto::OutputDto, AccountOutput, BasicOutput, FoundryOutput, MinimumOutputAmount, NftOutput, Output,
OutputBuilderAmount,
AccountOutput, BasicOutput, FoundryOutput, MinimumOutputAmount, NftOutput, Output, OutputBuilderAmount,
},
payload::Payload,
Block, BlockDto, UnsignedBlockDto,
Expand Down Expand Up @@ -79,7 +78,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
immutable_features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildBasicOutput {
amount,
Expand All @@ -98,7 +97,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildFoundryOutput {
amount,
Expand All @@ -121,7 +120,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
immutable_features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildNftOutput {
amount,
Expand All @@ -144,7 +143,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
immutable_features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildBasicBlock { issuer_id, payload } => {
let payload = if let Some(payload) = payload {
Expand Down Expand Up @@ -285,7 +284,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
Response::Bech32Address(client.hex_public_key_to_bech32_address(&hex, bech32_hrp).await?)
}
ClientMethod::ComputeMinimumOutputAmount { output } => {
let output = Output::try_from(output)?;
let storage_score_params = client.get_storage_score_parameters().await?;

Response::OutputAmount(output.minimum_amount(storage_score_params))
Expand Down
12 changes: 3 additions & 9 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use iota_sdk::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
input::UtxoInput,
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, Output, OutputId, TokenId},
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, OutputId, TokenId},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
Block,
},
Expand Down Expand Up @@ -78,10 +78,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
UtilsMethod::ComputeMinimumOutputAmount {
output,
storage_score_parameters: storage_params,
} => {
let out = Output::try_from(output)?;
Response::OutputAmount(out.minimum_amount(storage_params))
}
} => Response::OutputAmount(output.minimum_amount(storage_params)),
UtilsMethod::VerifyMnemonic { mnemonic } => {
let mnemonic = Mnemonic::from(mnemonic);
verify_mnemonic(mnemonic)?;
Expand All @@ -107,10 +104,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
}
UtilsMethod::OutputIdToUtxoInput { output_id } => Response::Input(UtxoInput::from(output_id)),
UtilsMethod::ComputeSlotCommitmentId { slot_commitment } => Response::SlotCommitmentId(slot_commitment.id()),
UtilsMethod::OutputHexBytes { output } => {
let output = Output::try_from(output)?;
Response::HexBytes(prefix_hex::encode(output.pack_to_vec()))
}
UtilsMethod::OutputHexBytes { output } => Response::HexBytes(prefix_hex::encode(output.pack_to_vec())),
UtilsMethod::VerifyTransactionSemantic { inputs, transaction } => {
let conflict = verify_semantic(
&inputs
Expand Down
32 changes: 5 additions & 27 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ use iota_sdk::{
client::api::{
PreparedTransactionData, PreparedTransactionDataDto, SignedTransactionData, SignedTransactionDataDto,
},
types::{
block::{
address::ToBech32Ext,
output::{dto::OutputDto, Output},
},
TryFromDto,
},
types::{block::address::ToBech32Ext, TryFromDto},
wallet::{types::TransactionWithMetadataDto, OutputDataDto, PreparedCreateNativeTokenTransactionDto, Wallet},
};

Expand Down Expand Up @@ -158,7 +152,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
WalletMethod::GetBalance => Response::Balance(wallet.balance().await?),
WalletMethod::GetFoundryOutput { token_id } => {
let output = wallet.get_foundry_output(token_id).await?;
Response::Output(OutputDto::from(&output))
Response::Output(output)
}
WalletMethod::GetIncomingTransaction { transaction_id } => {
let transaction = wallet.get_incoming_transaction(&transaction_id).await;
Expand Down Expand Up @@ -285,7 +279,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
transaction_options,
} => {
let output = wallet.prepare_output(*params, transaction_options).await?;
Response::Output(OutputDto::from(&output))
Response::Output(output)
}
WalletMethod::PrepareSend { params, options } => {
let data = wallet.prepare_send(params, options).await?;
Expand All @@ -305,15 +299,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
Response::PreparedTransaction(PreparedTransactionDataDto::from(&data))
}
WalletMethod::PrepareTransaction { outputs, options } => {
let data = wallet
.prepare_transaction(
outputs
.into_iter()
.map(Output::try_from)
.collect::<Result<Vec<Output>, _>>()?,
options,
)
.await?;
let data = wallet.prepare_transaction(outputs, options).await?;
Response::PreparedTransaction(PreparedTransactionDataDto::from(&data))
}
#[cfg(feature = "participation")]
Expand Down Expand Up @@ -349,15 +335,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SendOutputs { outputs, options } => {
let transaction = wallet
.send_outputs(
outputs
.into_iter()
.map(Output::try_from)
.collect::<Result<Vec<Output>, _>>()?,
options,
)
.await?;
let transaction = wallet.send_outputs(outputs, options).await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SetAlias { alias } => {
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use iota_sdk::{
block::{
address::{Address, Bech32Address, Hrp},
input::UtxoInput,
output::{dto::OutputDto, AccountId, FoundryId, NftId, OutputId, OutputMetadata, TokenId},
output::{AccountId, FoundryId, NftId, Output, OutputId, OutputMetadata, TokenId},
payload::{dto::SignedTransactionPayloadDto, signed_transaction::TransactionId},
protocol::ProtocolParameters,
semantic::TransactionFailureReason,
Expand Down Expand Up @@ -206,7 +206,7 @@ pub enum Response {
/// - [`BuildNftOutput`](crate::method::ClientMethod::BuildNftOutput)
/// - [`GetFoundryOutput`](crate::method::WalletMethod::GetFoundryOutput)
/// - [`PrepareOutput`](crate::method::WalletMethod::PrepareOutput)
Output(OutputDto),
Output(Output),
/// Response for:
/// - [`AccountIdToBech32`](crate::method::ClientMethod::AccountIdToBech32)
/// - [`HexPublicKeyToBech32Address`](crate::method::ClientMethod::HexPublicKeyToBech32Address)
Expand Down
3 changes: 1 addition & 2 deletions sdk/examples/how_tos/outputs/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use iota_sdk::{
types::block::{
address::Address,
output::{
dto::OutputDto,
feature::{IssuerFeature, MetadataFeature, SenderFeature, TagFeature},
unlock_condition::AddressUnlockCondition,
NftId, NftOutputBuilder,
Expand Down Expand Up @@ -66,7 +65,7 @@ async fn main() -> Result<()> {
];

// Convert output array to json array
let json_outputs = serde_json::to_string_pretty(&outputs.iter().map(OutputDto::from).collect::<Vec<OutputDto>>())?;
let json_outputs = serde_json::to_string_pretty(&outputs)?;
println!("{json_outputs}");

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions sdk/examples/how_tos/outputs/unlock_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use iota_sdk::{
types::block::{
address::Address,
output::{
dto::OutputDto,
unlock_condition::{
AddressUnlockCondition, ExpirationUnlockCondition, ImmutableAccountAddressUnlockCondition,
StorageDepositReturnUnlockCondition, TimelockUnlockCondition,
Expand Down Expand Up @@ -70,7 +69,7 @@ async fn main() -> Result<()> {
];

// Convert output array to json array
let json_outputs = serde_json::to_string_pretty(&outputs.iter().map(OutputDto::from).collect::<Vec<OutputDto>>())?;
let json_outputs = serde_json::to_string_pretty(&outputs)?;
println!("{json_outputs}");

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/client/api/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use self::transaction::verify_semantic;
use crate::{
client::{ClientInner, Result},
types::block::{
core::{basic::MaxBurnedManaAmount, BlockHeader, UnsignedBlock},
core::{BlockHeader, UnsignedBlock},
output::AccountId,
payload::Payload,
BlockBody,
Expand Down Expand Up @@ -39,15 +39,15 @@ impl ClientInner {
protocol_params.version(),
protocol_params.network_id(),
issuing_time,
issuance.commitment.id(),
issuance.latest_commitment.id(),
issuance.latest_finalized_slot,
issuer_id,
),
BlockBody::build_basic(
issuance.strong_parents()?,
(
protocol_params.work_score_parameters,
issuance.commitment.reference_mana_cost(),
issuance.latest_commitment.reference_mana_cost(),
),
)
.with_weak_parents(issuance.weak_parents()?)
Expand Down
5 changes: 1 addition & 4 deletions sdk/src/client/api/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ impl Client {
.flatten()
.map(|output_with_meta| {
Ok((
UtxoInput::new(
output_with_meta.metadata().transaction_id().to_owned(),
output_with_meta.metadata().output_index(),
),
UtxoInput::from(*output_with_meta.metadata().output_id()),
output_with_meta.output().amount(),
))
})
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/client/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
types::{
block::{
address::Address,
output::{dto::OutputDto, Output},
output::Output,
payload::{
signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct RemainderData {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct RemainderDataDto {
/// The remainder output
pub output: OutputDto,
pub output: Output,
/// The chain derived from seed, for the remainder addresses
#[serde(with = "option_bip44", default)]
pub chain: Option<Bip44>,
Expand All @@ -160,7 +160,7 @@ impl TryFrom<RemainderDataDto> for RemainderData {

fn try_from(dto: RemainderDataDto) -> Result<Self, Self::Error> {
Ok(Self {
output: Output::try_from(dto.output)?,
output: dto.output,
chain: dto.chain,
address: dto.address,
})
Expand All @@ -169,7 +169,7 @@ impl TryFrom<RemainderDataDto> for RemainderData {
impl From<&RemainderData> for RemainderDataDto {
fn from(remainder: &RemainderData) -> Self {
Self {
output: OutputDto::from(&remainder.output),
output: remainder.output.clone(),
chain: remainder.chain,
address: remainder.address.clone(),
}
Expand Down
6 changes: 2 additions & 4 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
},
block::{
address::ToBech32Ext,
output::{dto::OutputDto, AccountId, Output, OutputId, OutputMetadata},
output::{AccountId, Output, OutputId, OutputMetadata},
payload::signed_transaction::TransactionId,
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
Block, BlockDto, BlockId,
Expand Down Expand Up @@ -237,9 +237,7 @@ impl ClientInner {
pub async fn get_output(&self, output_id: &OutputId) -> Result<Output> {
let path = &format!("api/core/v3/outputs/{output_id}");

Ok(Output::try_from(
self.get_request::<OutputDto>(path, None, false, true).await?,
)?)
self.get_request(path, None, false, true).await
}

/// Finds an output by its ID and returns it as raw bytes.
Expand Down
Loading

0 comments on commit 918e51d

Please sign in to comment.