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

Rework block signing API #1461

Merged
merged 25 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use iota_sdk::{
client::{node_api::indexer::query_parameters::QueryParameter, node_manager::node::NodeAuth},
types::block::{
address::{Bech32Address, Hrp},
core::basic,
output::{
dto::OutputDto, feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, FoundryId,
NativeToken, NftId, OutputId, TokenScheme,
Expand Down Expand Up @@ -127,9 +126,6 @@ pub enum ClientMethod {
BuildBasicBlock {
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
/// The issuer's ID.
issuer_id: IssuerId,
/// Optional strong parents for the block.
#[serde(default)]
strong_parents: Option<basic::StrongParents>,
/// The block payload.
#[serde(default)]
payload: Option<PayloadDto>,
Expand Down
10 changes: 2 additions & 8 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM

Response::Output(OutputDto::from(&output))
}
ClientMethod::BuildBasicBlock {
issuer_id,
strong_parents,
payload,
} => {
ClientMethod::BuildBasicBlock { issuer_id, payload } => {
let payload = if let Some(payload) = payload {
Some(Payload::try_from_dto_with_params(
payload,
Expand All @@ -175,9 +171,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
None
};
Response::UnsignedBlock(UnsignedBlockDto::from(
&client
.build_basic_block(issuer_id, None, strong_parents, payload)
.await?,
&client.build_basic_block(issuer_id, payload).await?,
))
}
#[cfg(feature = "mqtt")]
Expand Down
1 change: 0 additions & 1 deletion bindings/core/tests/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ async fn build_and_sign_block() -> Result<()> {
&client,
ClientMethod::BuildBasicBlock {
issuer_id: IssuerId::null(),
strong_parents: None,
payload: Some(payload.clone()),
},
)
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/block/00_block_no_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() -> Result<()> {

// Create and send the block.
let block = client
.build_basic_block(issuer_id, None, None, None)
.build_basic_block(issuer_id, None)
.await?
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/block/01_block_confirmation_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() -> Result<()> {

// Create and send a block.
let block = client
.build_basic_block(issuer_id, None, None, None)
.build_basic_block(issuer_id, None)
.await?
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/client/block/02_block_custom_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ async fn main() -> Result<()> {
println!("Issuance:\n{issuance:#?}");

// Create and send the block with custom parents.
// TODO set Some(issuance.strong_parents()?
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
let block = client
.build_basic_block(issuer_id, None, Some(issuance.strong_parents()?), None)
.build_basic_block(issuer_id, None)
.await?
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/block/03_block_custom_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn main() -> Result<()> {

// Create and send the block with the custom payload.
let block = client
.build_basic_block(issuer_id, None, None, Some(Payload::from(tagged_data_payload)))
.build_basic_block(issuer_id, Some(Payload::from(tagged_data_payload)))
.await?
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
Expand Down
2 changes: 0 additions & 2 deletions sdk/examples/client/block/04_block_tagged_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ async fn main() -> Result<()> {
let block = client
.build_basic_block(
issuer_id,
None,
None,
Some(Payload::TaggedData(Box::new(
TaggedDataPayload::new(
std::env::args()
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/node_api_core/04_post_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn main() -> Result<()> {

// Create the block.
let block = client
.build_basic_block(issuer_id, None, None, None)
.build_basic_block(issuer_id, None)
.await?
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/node_api_core/05_post_block_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn main() -> Result<()> {

// Create the block.
let block = client
.build_basic_block(issuer_id, None, None, None)
.build_basic_block(issuer_id, None)
.await?
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
Expand Down
18 changes: 6 additions & 12 deletions sdk/src/client/api/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@ pub use self::transaction::verify_semantic;
use crate::{
client::{ClientInner, Result},
types::block::{
core::{basic, BlockHeader, UnsignedBlock},
core::{BlockHeader, UnsignedBlock},
payload::Payload,
Block, IssuerId,
},
};

impl ClientInner {
pub async fn build_basic_block(
&self,
issuer_id: IssuerId,
issuing_time: Option<u64>,
strong_parents: Option<basic::StrongParents>,
payload: Option<Payload>,
) -> Result<UnsignedBlock> {
pub async fn build_basic_block(&self, issuer_id: IssuerId, payload: Option<Payload>) -> Result<UnsignedBlock> {
let issuance = self.get_issuance().await?;
let strong_parents = strong_parents.unwrap_or(issuance.strong_parents()?);

let issuing_time = issuing_time.unwrap_or_else(|| {
let issuing_time = {
#[cfg(feature = "std")]
let issuing_time = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand All @@ -36,7 +29,7 @@ impl ClientInner {
#[cfg(not(feature = "std"))]
let issuing_time = 0;
issuing_time
});
};

let protocol_params = self.get_protocol_parameters().await?;

Expand All @@ -49,7 +42,8 @@ impl ClientInner {
issuance.latest_finalized_slot,
issuer_id,
),
Block::build_basic(strong_parents, 0) // TODO: burned mana calculation
// TODO: burned mana calculation
Block::build_basic(issuance.strong_parents()?, 0)
.with_weak_parents(issuance.weak_parents()?)
.with_shallow_like_parents(issuance.shallow_like_parents()?)
.with_payload(payload)
Expand Down
4 changes: 0 additions & 4 deletions sdk/src/wallet/account/operations/reissue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ where
.client()
.build_basic_block(
todo!("issuer id"),
todo!("issuing time"),
None,
Some(Payload::SignedTransaction(Box::new(transaction.payload.clone()))),
)
.await?
Expand Down Expand Up @@ -113,8 +111,6 @@ where
.client()
.build_basic_block(
todo!("issuer id"),
todo!("issuing time"),
None,
Some(Payload::SignedTransaction(Box::new(transaction.payload.clone()))),
)
.await?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ where

let block = self
.client()
.build_basic_block(
todo!("issuer id"),
todo!("issuing time"),
None,
Some(Payload::from(transaction_payload)),
)
.build_basic_block(todo!("issuer id"), Some(Payload::from(transaction_payload)))
.await?
.sign_ed25519(
&*self.get_secret_manager().read().await,
Expand Down
2 changes: 0 additions & 2 deletions sdk/tests/client/node_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ async fn setup_tagged_data_block(secret_manager: &SecretManager) -> BlockId {
client
.build_basic_block(
IssuerId::null(),
None,
None,
Some(Payload::TaggedData(Box::new(
TaggedDataPayload::new(b"Hello".to_vec(), b"Tangle".to_vec()).unwrap(),
))),
Expand Down
Loading