Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename block types #1626

Merged
merged 13 commits into from
Nov 17, 2023
6 changes: 3 additions & 3 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use iota_sdk::{
DelegationId, FoundryId, NativeToken, NftId, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockId, IssuerId, SignedBlockDto,
BlockDto, BlockId, IssuerId,
},
utils::serde::{option_string, string},
};
Expand Down Expand Up @@ -159,7 +159,7 @@ pub enum ClientMethod {
/// Post block (JSON)
PostBlock {
/// Block
block: SignedBlockDto,
block: BlockDto,
},
/// Post block (raw)
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -366,6 +366,6 @@ pub enum ClientMethod {
#[serde(rename_all = "camelCase")]
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
BlockId {
/// Block
signed_block: SignedBlockDto,
block: BlockDto,
},
}
4 changes: 2 additions & 2 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iota_sdk::types::block::{
protocol::ProtocolParameters,
signature::Ed25519Signature,
slot::SlotCommitment,
SignedBlockDto,
BlockDto,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum UtilsMethod {
#[serde(rename_all = "camelCase")]
BlockId {
/// Block
block: SignedBlockDto,
block: BlockDto,
/// Network Protocol Parameters
protocol_parameters: ProtocolParameters,
},
Expand Down
20 changes: 10 additions & 10 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iota_sdk::{
OutputBuilderAmount,
},
payload::Payload,
SignedBlock, SignedBlockDto, UnsignedBlockDto,
Block, BlockDto, UnsignedBlockDto,
},
TryFromDto,
},
Expand All @@ -37,8 +37,8 @@ where
}
let payload = match &topic_event.payload {
MqttPayload::Json(val) => serde_json::to_string(&val).expect("failed to serialize MqttPayload::Json"),
MqttPayload::Block(block) => {
serde_json::to_string(block).expect("failed to serialize MqttPayload::Block")
MqttPayload::BlockBody(block_body) => {
serde_json::to_string(block_body).expect("failed to serialize MqttPayload::Block")
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
}
e => panic!("received unknown mqtt type: {e:?}"),
};
Expand Down Expand Up @@ -190,22 +190,22 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetIssuance => Response::Issuance(client.get_issuance().await?),
ClientMethod::PostBlockRaw { block_bytes } => Response::BlockId(
client
.post_block_raw(&SignedBlock::unpack_strict(
.post_block_raw(&Block::unpack_strict(
&block_bytes[..],
&client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::PostBlock { block } => Response::BlockId(
client
.post_block(&SignedBlock::try_from_dto_with_params(
.post_block(&Block::try_from_dto_with_params(
block,
client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::GetBlock { block_id } => {
Response::SignedBlock(SignedBlockDto::from(&client.get_block(&block_id).await?))
Response::SignedBlock(BlockDto::from(&client.get_block(&block_id).await?))
}
ClientMethod::GetBlockMetadata { block_id } => {
Response::BlockMetadata(client.get_block_metadata(&block_id).await?)
Expand All @@ -221,7 +221,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
Response::OutputMetadata(client.get_output_metadata(&output_id).await?)
}
ClientMethod::GetIncludedBlock { transaction_id } => {
Response::SignedBlock(SignedBlockDto::from(&client.get_included_block(&transaction_id).await?))
Response::SignedBlock(BlockDto::from(&client.get_included_block(&transaction_id).await?))
}
ClientMethod::GetIncludedBlockMetadata { transaction_id } => {
Response::BlockMetadata(client.get_included_block_metadata(&transaction_id).await?)
Expand Down Expand Up @@ -277,7 +277,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.find_blocks(&block_ids)
.await?
.iter()
.map(SignedBlockDto::from)
.map(BlockDto::from)
.collect(),
),
ClientMethod::FindInputs { addresses, amount } => {
Expand Down Expand Up @@ -316,9 +316,9 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.await?;
Response::CustomJson(data)
}
ClientMethod::BlockId { signed_block: block } => {
ClientMethod::BlockId { block } => {
let protocol_parameters = client.get_protocol_parameters().await?;
let block = SignedBlock::try_from_dto_with_params(block, &protocol_parameters)?;
let block = Block::try_from_dto_with_params(block, &protocol_parameters)?;
Response::BlockId(block.id(&protocol_parameters))
}
};
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method_handler/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use iota_sdk::{
secret::{DowncastSecretManager, SecretManage, SecretManager, SignBlock},
},
types::{
block::{address::ToBech32Ext, core::UnsignedBlock, unlock::Unlock, SignedBlockDto},
block::{address::ToBech32Ext, core::UnsignedBlock, unlock::Unlock, BlockDto},
TryFromDto,
},
};
Expand Down Expand Up @@ -82,7 +82,7 @@ where
.map_err(iota_sdk::client::Error::from)?;
Response::SignedTransaction(transaction.into())
}
SecretManagerMethod::SignBlock { unsigned_block, chain } => Response::SignedBlock(SignedBlockDto::from(
SecretManagerMethod::SignBlock { unsigned_block, chain } => Response::SignedBlock(BlockDto::from(
&UnsignedBlock::try_from_dto(unsigned_block)?
.sign_ed25519(secret_manager, chain)
.await?,
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iota_sdk::{
input::UtxoInput,
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, Output, OutputId, TokenId},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
SignedBlock,
Block,
},
TryFromDto,
},
Expand Down Expand Up @@ -42,7 +42,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
block,
protocol_parameters,
} => {
let block = SignedBlock::try_from_dto_with_params(block, &protocol_parameters)?;
let block = Block::try_from_dto_with_params(block, &protocol_parameters)?;
Response::BlockId(block.id(&protocol_parameters))
}
UtilsMethod::TransactionId { payload } => {
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use iota_sdk::{
signature::Ed25519Signature,
slot::SlotCommitmentId,
unlock::Unlock,
BlockId, SignedBlockDto, UnsignedBlockDto,
BlockDto, BlockId, UnsignedBlockDto,
},
},
utils::serde::string,
Expand Down Expand Up @@ -112,7 +112,7 @@ pub enum Response {
/// - [`GetBlock`](crate::method::ClientMethod::GetBlock)
/// - [`GetIncludedBlock`](crate::method::ClientMethod::GetIncludedBlock)
/// - [`SignBlock`](crate::method::SecretManagerMethod::SignBlock)
SignedBlock(SignedBlockDto),
SignedBlock(BlockDto),
/// Response for:
/// - [`GetBlockMetadata`](crate::method::ClientMethod::GetBlockMetadata)
BlockMetadata(BlockMetadataResponse),
Expand Down Expand Up @@ -147,7 +147,7 @@ pub enum Response {
OutputIdsResponse(OutputIdsResponse),
/// Response for:
/// - [`FindBlocks`](crate::method::ClientMethod::FindBlocks)
Blocks(Vec<SignedBlockDto>),
Blocks(Vec<BlockDto>),
/// Response for:
/// - [`FindInputs`](crate::method::ClientMethod::FindInputs)
Inputs(Vec<UtxoInput>),
Expand Down
16 changes: 8 additions & 8 deletions bindings/core/tests/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iota_sdk::{
types::{
block::{
payload::{dto::PayloadDto, Payload, TaggedDataPayload},
BlockDto, IssuerId, SignedBlock,
Block, BlockBodyDto, IssuerId,
},
TryFromDto,
},
Expand Down Expand Up @@ -134,8 +134,8 @@ async fn client_from_wallet() -> Result<()> {
// let unsigned_block = match response {
// Response::UnsignedBlock(unsigned_block) => {
// match &unsigned_block.block {
// BlockDto::Basic(b) => assert_eq!(b.payload.as_ref(), Some(&payload)),
// BlockDto::Validation(v) => panic!("unexpected block {v:?}"),
// BlockBodyDto::Basic(b) => assert_eq!(b.payload.as_ref(), Some(&payload)),
// BlockBodyDto::Validation(v) => panic!("unexpected block body {v:?}"),
// }
// unsigned_block
// }
Expand All @@ -153,12 +153,12 @@ async fn client_from_wallet() -> Result<()> {
// .await;

// let signed_block = match response {
// Response::SignedBlock(block) => {
// match &block.block {
// BlockDto::Basic(b) => assert_eq!(b.payload.as_ref(), Some(&payload)),
// BlockDto::Validation(v) => panic!("unexpected block {v:?}"),
// Response::SignedBlock(block_body) => {
// match &block_body.block {
// BlockBodyDto::Basic(b) => assert_eq!(b.payload.as_ref(), Some(&payload)),
// BlockBodyDto::Validation(v) => panic!("unexpected block {v:?}"),
// }
// block
// block_body
// }
// _ => panic!("unexpected response {response:?}"),
// };
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/07_mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main() -> Result<()> {
println!("> Topic: {}", event.topic);
match &event.payload {
MqttPayload::Json(val) => println!("{}", serde_json::to_string(&val).unwrap()),
MqttPayload::Block(block) => println!("{block:?}"),
MqttPayload::BlockBody(block_body) => println!("{block_body:?}"),
e => println!("unknown event received: {e:?}"),
}
tx.send(()).unwrap();
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 @@ -10,7 +10,7 @@ use crate::{
types::block::{
core::{BlockHeader, UnsignedBlock},
payload::Payload,
Block, IssuerId,
BlockBody, IssuerId,
},
};

Expand Down Expand Up @@ -43,11 +43,11 @@ impl ClientInner {
issuer_id,
),
// TODO: burned mana calculation
Block::build_basic(issuance.strong_parents()?, 0)
BlockBody::build_basic(issuance.strong_parents()?, 0)
.with_weak_parents(issuance.weak_parents()?)
.with_shallow_like_parents(issuance.shallow_like_parents()?)
.with_payload(payload)
.finish_block()?,
.finish_block_body()?,
))
}
}
5 changes: 2 additions & 3 deletions sdk/src/client/api/block_builder/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ use crate::{
payload::signed_transaction::{SignedTransactionPayload, Transaction},
semantic::{SemanticValidationContext, TransactionFailureReason},
signature::Ed25519Signature,
BlockId, SignedBlock,
Block, BlockId,
},
};

// TODO this is wrong because of https://github.com/iotaledger/iota-sdk/issues/1208
const MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS: usize =
SignedBlock::LENGTH_MAX - SignedBlock::LENGTH_MIN - (7 * BlockId::LENGTH);
const MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS: usize = Block::LENGTH_MAX - Block::LENGTH_MIN - (7 * BlockId::LENGTH);
// Length for unlocks with a single signature unlock (unlocks length + unlock type + signature type + public key +
// signature)
const SINGLE_UNLOCK_LENGTH: usize = 1 + 1 + Ed25519Signature::PUBLIC_KEY_LENGTH + Ed25519Signature::SIGNATURE_LENGTH;
Expand Down
16 changes: 8 additions & 8 deletions sdk/src/client/api/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
},
types::block::{
address::Bech32Address,
core::{BasicBlock, Block, SignedBlock},
core::{BasicBlockBody, Block, BlockBody},
input::{Input, UtxoInput, INPUT_COUNT_MAX},
output::OutputWithMetadata,
payload::{signed_transaction::TransactionId, Payload},
Expand All @@ -27,10 +27,10 @@ use crate::{
impl Client {
/// Get the inputs of a transaction for the given transaction id.
pub async fn inputs_from_transaction_id(&self, transaction_id: &TransactionId) -> Result<Vec<OutputWithMetadata>> {
let signed_block = self.get_included_block(transaction_id).await?;
let block = self.get_included_block(transaction_id).await?;

if let Block::Basic(block) = signed_block.block() {
let inputs = if let Some(Payload::SignedTransaction(t)) = block.payload() {
if let BlockBody::Basic(basic_block_body) = block.body() {
let inputs = if let Some(Payload::SignedTransaction(t)) = basic_block_body.payload() {
t.transaction().inputs()
} else {
return Err(Error::MissingTransactionPayload);
Expand All @@ -45,15 +45,15 @@ impl Client {

self.get_outputs_with_metadata(&input_ids).await
} else {
Err(Error::UnexpectedBlockKind {
expected: BasicBlock::KIND,
actual: signed_block.block().kind(),
Err(Error::UnexpectedBlockBodyKind {
expected: BasicBlockBody::KIND,
actual: block.body().kind(),
})
}
}

/// Find all blocks by provided block IDs.
pub async fn find_blocks(&self, block_ids: &[BlockId]) -> Result<Vec<SignedBlock>> {
pub async fn find_blocks(&self, block_ids: &[BlockId]) -> Result<Vec<Block>> {
// Use a `HashSet` to prevent duplicate block_ids.
let block_ids = block_ids.iter().copied().collect::<HashSet<_>>();
futures::future::try_join_all(block_ids.iter().map(|block_id| self.get_block(block_id))).await
Expand Down
16 changes: 8 additions & 8 deletions sdk/src/client/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ impl TryFromDto for PreparedTransactionData {
type Dto = PreparedTransactionDataDto;
type Error = Error;

fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result<Self, Self::Error> {
Ok(Self {
transaction: Transaction::try_from_dto_with_params(dto.transaction, &params)
transaction: Transaction::try_from_dto_with_params(dto.transaction, params)
.map_err(|_| Error::InvalidField("transaction"))?,
inputs_data: dto
.inputs_data
.into_iter()
.map(|i| InputSigningData::try_from_dto_with_params(i, &params))
.map(|i| InputSigningData::try_from_dto_with_params(i, params))
.collect::<crate::client::Result<Vec<InputSigningData>>>()
.map_err(|_| Error::InvalidField("input_data"))?,
remainder: match dto.remainder {
Some(remainder) => Some(
RemainderData::try_from_dto_with_params(remainder, &params)
RemainderData::try_from_dto_with_params(remainder, params)
.map_err(|_| Error::InvalidField("remainder"))?,
),
None => None,
Expand Down Expand Up @@ -114,14 +114,14 @@ impl TryFromDto for SignedTransactionData {
type Dto = SignedTransactionDataDto;
type Error = Error;

fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result<Self, Self::Error> {
Ok(Self {
payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, &params)
payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, params)
.map_err(|_| Error::InvalidField("transaction_payload"))?,
inputs_data: dto
.inputs_data
.into_iter()
.map(|i| InputSigningData::try_from_dto_with_params(i, &params))
.map(|i| InputSigningData::try_from_dto_with_params(i, params))
.collect::<crate::client::Result<Vec<InputSigningData>>>()
.map_err(|_| Error::InvalidField("inputs_data"))?,
})
Expand Down Expand Up @@ -155,7 +155,7 @@ impl TryFromDto for RemainderData {
type Dto = RemainderDataDto;
type Error = Error;

fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result<Self, Self::Error> {
fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result<Self, Self::Error> {
Ok(Self {
output: Output::try_from_dto_with_params_inner(dto.output, params)?,
chain: dto.chain,
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ pub enum Error {
/// Missing BIP32 chain to sign with.
#[error("missing BIP32 chain to sign with")]
MissingBip32Chain,
/// Unexpected block kind.
#[error("unexpected block kind: expected {expected}, found {actual}")]
UnexpectedBlockKind { expected: u8, actual: u8 },
/// Unexpected block body kind.
#[error("unexpected block body kind: expected {expected}, found {actual}")]
UnexpectedBlockBodyKind { expected: u8, actual: u8 },
/// Missing transaction payload.
#[error("missing transaction payload")]
MissingTransactionPayload,
Expand Down
Loading
Loading