Skip to content

Commit

Permalink
Merge branch '2.0' into native-token-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Oct 30, 2023
2 parents 9d5ebd3 + 3f1dc46 commit 6e2356f
Show file tree
Hide file tree
Showing 168 changed files with 4,496 additions and 5,129 deletions.
20 changes: 11 additions & 9 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use iota_sdk::{
NativeToken, NftId, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockId, BlockWrapperDto,
BlockId, IssuerId, SignedBlockDto,
},
utils::serde::{option_string, string},
};
Expand All @@ -43,8 +43,6 @@ pub enum ClientMethod {
#[serde(default, with = "string")]
mana: u64,
account_id: AccountId,
state_index: Option<u32>,
state_metadata: Option<String>,
foundry_counter: Option<u32>,
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
Expand Down Expand Up @@ -126,10 +124,13 @@ pub enum ClientMethod {
query_params: Vec<String>,
request_object: Option<String>,
},
/// Build a block containing the specified payload and post it to the network.
PostBlockPayload {
/// The payload to send
payload: PayloadDto,
#[serde(rename_all = "camelCase")]
BuildBasicBlock {
/// The issuer's ID.
issuer_id: IssuerId,
/// The block payload.
#[serde(default)]
payload: Option<PayloadDto>,
},
//////////////////////////////////////////////////////////////////////
// Node core API
Expand All @@ -155,7 +156,7 @@ pub enum ClientMethod {
/// Post block (JSON)
PostBlock {
/// Block
block: BlockWrapperDto,
block: SignedBlockDto,
},
/// Post block (raw)
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -335,8 +336,9 @@ pub enum ClientMethod {
address: Bech32Address,
},
/// Returns a block ID from a block
#[serde(rename_all = "camelCase")]
BlockId {
/// Block
block: BlockWrapperDto,
signed_block: SignedBlockDto,
},
}
9 changes: 9 additions & 0 deletions bindings/core/src/method/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crypto::keys::bip44::Bip44;
use derivative::Derivative;
use iota_sdk::{
client::api::{GetAddressesOptions, PreparedTransactionDataDto},
types::block::UnsignedBlockDto,
utils::serde::bip44::Bip44Def,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -61,6 +62,14 @@ pub enum SecretManagerMethod {
/// Prepared transaction data
prepared_transaction_data: PreparedTransactionDataDto,
},
// Sign a block.
#[serde(rename_all = "camelCase")]
SignBlock {
unsigned_block: UnsignedBlockDto,
/// Chain to sign the essence hash with
#[serde(with = "Bip44Def")]
chain: Bip44,
},
/// Store a mnemonic in the Stronghold vault
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
Expand Down
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,
BlockWrapperDto,
SignedBlockDto,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum UtilsMethod {
#[serde(rename_all = "camelCase")]
BlockId {
/// Block
block: BlockWrapperDto,
block: SignedBlockDto,
/// Network Protocol Parameters
protocol_parameters: ProtocolParameters,
},
Expand Down
15 changes: 10 additions & 5 deletions bindings/core/src/method_handler/call_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use std::pin::Pin;

use futures::Future;
use iota_sdk::{
client::{secret::SecretManager, Client},
client::{
secret::{DowncastSecretManager, SecretManage},
Client,
},
wallet::Wallet,
};
use tokio::sync::RwLock;

use crate::{
method::{ClientMethod, SecretManagerMethod, WalletMethod},
Expand Down Expand Up @@ -78,10 +80,13 @@ pub fn call_utils_method(method: UtilsMethod) -> Response {
}

/// Call a secret manager method.
pub async fn call_secret_manager_method(
secret_manager: &RwLock<SecretManager>,
pub async fn call_secret_manager_method<S: SecretManage + DowncastSecretManager>(
secret_manager: &S,
method: SecretManagerMethod,
) -> Response {
) -> Response
where
iota_sdk::client::Error: From<S::Error>,
{
log::debug!("Secret manager method: {method:?}");
let result =
convert_async_panics(|| async { call_secret_manager_method_internal(secret_manager, method).await }).await;
Expand Down
58 changes: 24 additions & 34 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#[cfg(feature = "mqtt")]
use iota_sdk::client::mqtt::{MqttPayload, Topic};
use iota_sdk::{
client::{request_funds_from_faucet, secret::SecretManager, Client},
client::{request_funds_from_faucet, Client},
types::{
api::core::OutputWithMetadataResponse,
block::{
output::{
dto::OutputDto, AccountOutput, BasicOutput, FoundryOutput, NftOutput, Output, OutputBuilderAmount, Rent,
},
payload::Payload,
BlockWrapper, BlockWrapperDto,
SignedBlock, SignedBlockDto, UnsignedBlockDto,
},
TryFromDto,
},
Expand Down Expand Up @@ -59,8 +59,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
amount,
mana,
account_id,
state_index,
state_metadata,
foundry_counter,
unlock_conditions,
features,
Expand All @@ -74,8 +72,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
},
mana,
&account_id,
state_index,
state_metadata.map(prefix_hex::decode).transpose()?,
foundry_counter,
unlock_conditions,
features,
Expand Down Expand Up @@ -157,6 +153,19 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM

Response::Output(OutputDto::from(&output))
}
ClientMethod::BuildBasicBlock { issuer_id, payload } => {
let payload = if let Some(payload) = payload {
Some(Payload::try_from_dto_with_params(
payload,
&client.get_protocol_parameters().await?,
)?)
} else {
None
};
Response::UnsignedBlock(UnsignedBlockDto::from(
&client.build_basic_block(issuer_id, payload).await?,
))
}
#[cfg(feature = "mqtt")]
ClientMethod::ClearListeners { topics } => {
client.unsubscribe(topics).await?;
Expand All @@ -167,25 +176,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetNetworkId => Response::NetworkId(client.get_network_id().await?.to_string()),
ClientMethod::GetBech32Hrp => Response::Bech32Hrp(client.get_bech32_hrp().await?),
ClientMethod::GetProtocolParameters => Response::ProtocolParameters(client.get_protocol_parameters().await?),
ClientMethod::PostBlockPayload { payload } => {
let block = client
.build_basic_block::<SecretManager>(
todo!("issuer id"),
todo!("issuing time"),
None,
Some(Payload::try_from_dto_with_params(
payload,
&client.get_protocol_parameters().await?,
)?),
todo!("secret manager"),
todo!("chain"),
)
.await?;

let block_id = client.block_id(&block).await?;

Response::BlockIdWithBlock(block_id, BlockWrapperDto::from(&block))
}
#[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?),
Expand All @@ -195,22 +185,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(&BlockWrapper::unpack_strict(
.post_block_raw(&SignedBlock::unpack_strict(
&block_bytes[..],
&client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::PostBlock { block } => Response::BlockId(
client
.post_block(&BlockWrapper::try_from_dto_with_params(
.post_block(&SignedBlock::try_from_dto_with_params(
block,
client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::GetBlock { block_id } => {
Response::Block(BlockWrapperDto::from(&client.get_block(&block_id).await?))
Response::SignedBlock(SignedBlockDto::from(&client.get_block(&block_id).await?))
}
ClientMethod::GetBlockMetadata { block_id } => {
Response::BlockMetadata(client.get_block_metadata(&block_id).await?)
Expand All @@ -225,9 +215,9 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetOutputMetadata { output_id } => {
Response::OutputMetadata(client.get_output_metadata(&output_id).await?)
}
ClientMethod::GetIncludedBlock { transaction_id } => Response::Block(BlockWrapperDto::from(
&client.get_included_block(&transaction_id).await?,
)),
ClientMethod::GetIncludedBlock { transaction_id } => {
Response::SignedBlock(SignedBlockDto::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 @@ -272,7 +262,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.find_blocks(&block_ids)
.await?
.iter()
.map(BlockWrapperDto::from)
.map(SignedBlockDto::from)
.collect(),
),
ClientMethod::FindInputs { addresses, amount } => {
Expand Down Expand Up @@ -313,9 +303,9 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.await?;
Response::CustomJson(data)
}
ClientMethod::BlockId { block } => {
ClientMethod::BlockId { signed_block: block } => {
let protocol_parameters = client.get_protocol_parameters().await?;
let block = BlockWrapper::try_from_dto_with_params(block, &protocol_parameters)?;
let block = SignedBlock::try_from_dto_with_params(block, &protocol_parameters)?;
Response::BlockId(block.id(&protocol_parameters))
}
};
Expand Down
Loading

0 comments on commit 6e2356f

Please sign in to comment.