Skip to content

Commit

Permalink
[chore]: format doc comments (#4505)
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Apr 25, 2024
1 parent c10aa04 commit 28a6e35
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 174 deletions.
6 changes: 3 additions & 3 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
newline_style="Unix"
use_field_init_shorthand=true
use_try_shorthand=true
group_imports="StdExternalCrate" # unstable https://github.com/rust-lang/rustfmt/issues/5083
imports_granularity="Crate" # unstable https://github.com/rust-lang/rustfmt/issues/4991
format_code_in_doc_comments = true # unstable (https://github.com/rust-lang/rustfmt/issues/3348)
group_imports="StdExternalCrate" # unstable (https://github.com/rust-lang/rustfmt/issues/5083)
imports_granularity="Crate" # unstable (https://github.com/rust-lang/rustfmt/issues/4991)
29 changes: 15 additions & 14 deletions client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ pub mod ws {
/// ```rust
/// use eyre::{eyre, Result};
/// use iroha_client::http::{
/// ws::conn_flow::{
/// Events as FlowEvents, Init as FlowInit,
/// InitData,
/// },
/// ws::conn_flow::{Events as FlowEvents, Init as FlowInit, InitData},
/// Method, RequestBuilder,
/// };
///
Expand All @@ -109,7 +106,12 @@ pub mod ws {
///
/// fn init(self) -> InitData<R, Self::Next> {
/// InitData::new(
/// R::new(Method::GET, "http://localhost:3000".parse().expect("`localhost` is a valid URL, port `3000` is sensible, `http` is supported")),
/// R::new(
/// Method::GET,
/// "http://localhost:3000".parse().expect(
/// "`localhost` is a valid URL, port `3000` is sensible, `http` is supported",
/// ),
/// ),
/// vec![1, 2, 3],
/// Events,
/// )
Expand Down Expand Up @@ -139,39 +141,38 @@ pub mod ws {
///
/// ```rust
/// use eyre::Result;
/// use url::Url;
/// use iroha_client::{
/// data_model::prelude::EventBox,
/// client::events_api::flow as events_api_flow,
/// data_model::prelude::EventBox,
/// http::{
/// ws::conn_flow::{Events, Init, InitData},
/// RequestBuilder, Method
/// Method, RequestBuilder,
/// },
/// };
/// use url::Url;
///
/// // Some request builder
/// struct MyBuilder;
///
/// impl RequestBuilder for MyBuilder {
/// fn new(_: Method, url: Url) -> Self {
/// todo!()
/// todo!()
/// }
///
/// fn param<K: AsRef<str>, V: ?Sized + ToString>(self, _: K, _: &V) -> Self {
/// todo!()
/// fn param<K: AsRef<str>, V: ?Sized + ToString>(self, _: K, _: &V) -> Self {
/// todo!()
/// }
///
/// fn header<N: AsRef<str>, V: ?Sized + ToString>(self, _: N, _: &V) -> Self {
/// todo!()
/// todo!()
/// }
///
/// fn body(self, data: Vec<u8>) -> Self {
/// todo!()
/// todo!()
/// }
/// }
///
/// impl MyBuilder {
///
/// fn connect(self) -> MyStream {
/// /* ... */
/// MyStream {}
Expand Down
19 changes: 12 additions & 7 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,22 @@ mod valid {
) -> Result<(), TransactionValidationError> {
let is_genesis = block.header().is_genesis();

block.transactions()
block
.transactions()
// TODO: Unnecessary clone?
.cloned()
.try_for_each(|TransactionValue{value, error}| {
.try_for_each(|TransactionValue { value, error }| {
let transaction_executor = state_block.transaction_executor();
let limits = &transaction_executor.transaction_limits;

let tx = if is_genesis {
AcceptedTransaction::accept_genesis(GenesisTransaction(value), expected_chain_id, genesis_public_key)
AcceptedTransaction::accept_genesis(
GenesisTransaction(value),
expected_chain_id,
genesis_public_key,
)
} else {
AcceptedTransaction::accept(value, expected_chain_id, limits)
AcceptedTransaction::accept(value, expected_chain_id, limits)
}?;

if error.is_some() {
Expand All @@ -389,9 +394,9 @@ mod valid {
Ok(_) => Err(TransactionValidationError::RejectedIsValid),
}?;
} else {
transaction_executor.validate(tx, state_block).map_err(|(_tx, error)| {
TransactionValidationError::NotValid(error)
})?;
transaction_executor
.validate(tx, state_block)
.map_err(|(_tx, error)| TransactionValidationError::NotValid(error))?;
}

Ok(())
Expand Down
21 changes: 11 additions & 10 deletions core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ impl Executor {
Self::UserProvided(UserProvidedExecutor(loaded_executor)) => {
let runtime =
wasm::RuntimeBuilder::<wasm::state::executor::ValidateTransaction>::new()
.with_engine(state_transaction.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_transaction.config.executor_runtime)
.build()?;
.with_engine(state_transaction.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_transaction.config.executor_runtime)
.build()?;

runtime.execute_executor_validate_transaction(
state_transaction,
Expand Down Expand Up @@ -192,9 +192,9 @@ impl Executor {
Self::UserProvided(UserProvidedExecutor(loaded_executor)) => {
let runtime =
wasm::RuntimeBuilder::<wasm::state::executor::ValidateInstruction>::new()
.with_engine(state_transaction.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_transaction.config.executor_runtime)
.build()?;
.with_engine(state_transaction.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_transaction.config.executor_runtime)
.build()?;

runtime.execute_executor_validate_instruction(
state_transaction,
Expand Down Expand Up @@ -224,10 +224,11 @@ impl Executor {
match self {
Self::Initial => Ok(()),
Self::UserProvided(UserProvidedExecutor(loaded_executor)) => {
let runtime = wasm::RuntimeBuilder::<wasm::state::executor::ValidateQuery<S>>::new()
.with_engine(state_ro.engine().clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_ro.config().executor_runtime)
.build()?;
let runtime =
wasm::RuntimeBuilder::<wasm::state::executor::ValidateQuery<S>>::new()
.with_engine(state_ro.engine().clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_ro.config().executor_runtime)
.build()?;

runtime.execute_executor_validate_query(
state_ro,
Expand Down
20 changes: 10 additions & 10 deletions core/src/smartcontracts/isi/triggers/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,16 @@ impl Set {
f: impl Fn(u32) -> Result<u32, RepeatsOverflowError>,
) -> Result<(), ModRepeatsError> {
self.inspect_by_id_mut(id, |action| match action.repeats() {
Repeats::Exactly(repeats) => {
let new_repeats = f(*repeats)?;
action.set_repeats(Repeats::Exactly(new_repeats));
Ok(())
}
_ => Err(ModRepeatsError::RepeatsOverflow(RepeatsOverflowError)),
})
.ok_or_else(|| ModRepeatsError::NotFound(id.clone()))
// .flatten() -- unstable
.and_then(std::convert::identity)
Repeats::Exactly(repeats) => {
let new_repeats = f(*repeats)?;
action.set_repeats(Repeats::Exactly(new_repeats));
Ok(())
}
_ => Err(ModRepeatsError::RepeatsOverflow(RepeatsOverflowError)),
})
.ok_or_else(|| ModRepeatsError::NotFound(id.clone()))
// .flatten() -- unstable
.and_then(std::convert::identity)
}

/// Handle [`DataEvent`].
Expand Down
14 changes: 7 additions & 7 deletions core/src/smartcontracts/isi/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ pub mod query {
) -> Result<Box<dyn Iterator<Item = RoleId> + 'state>, Error> {
Ok(Box::new(
state_ro
.world()
.roles()
.iter()
.map(|(_, role)| role)
// To me, this should probably be a method, not a field.
.map(Role::id)
.cloned(),
.world()
.roles()
.iter()
.map(|(_, role)| role)
// To me, this should probably be a method, not a field.
.map(Role::id)
.cloned(),
))
}
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ pub(crate) struct SmartContractQueryRequest(pub QueryRequest<QueryBox>);
/// # Errors
///
/// See [`Module::new`]
///
// TODO: Probably we can do some checks here such as searching for entrypoint function
pub fn load_module(engine: &Engine, bytes: impl AsRef<[u8]>) -> Result<wasmtime::Module> {
Module::new(engine, bytes).map_err(Error::ModuleLoading)
Expand Down Expand Up @@ -854,7 +853,10 @@ impl<'wrld, 'state, 'block, S>
// is validated and then it's executed. Here it's validating in both steps.
// Add a flag indicating whether smart contract is being validated or executed
let authority = state.authority.clone();
state.state.0.world
state
.state
.0
.world
.executor
.clone() // Cloning executor is a cheap operation
.validate_instruction(state.state.0, &authority, instruction)
Expand Down
3 changes: 2 additions & 1 deletion core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ impl TransactionExecutor {
let tx: SignedTransaction = tx.into();
let authority = tx.authority().clone();

state_transaction.world
state_transaction
.world
.executor
.clone() // Cloning executor is a cheap operation
.validate_transaction(state_transaction, &authority, tx)
Expand Down
6 changes: 4 additions & 2 deletions crypto/src/encryption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ fn random_bytes<T: ArrayLength<u8>>() -> Result<GenericArray<u8, T>, Error> {
/// # Usage
///
/// ```
/// use iroha_crypto::encryption::{SymmetricEncryptor, ChaCha20Poly1305};
/// use iroha_crypto::encryption::{ChaCha20Poly1305, SymmetricEncryptor};
///
/// let key: Vec<u8> = (0..0x20).collect();
/// let encryptor = SymmetricEncryptor::<ChaCha20Poly1305>::new_with_key(&key);
/// let aad = b"Using ChaCha20Poly1305 to encrypt data";
/// let message = b"Hidden message";
/// let ciphertext = encryptor.encrypt_easy(aad.as_ref(), message.as_ref()).unwrap();
/// let ciphertext = encryptor
/// .encrypt_easy(aad.as_ref(), message.as_ref())
/// .unwrap();
///
/// let res = encryptor.decrypt_easy(aad.as_ref(), ciphertext.as_slice());
/// assert_eq!(res.unwrap().as_slice(), message);
Expand Down
Loading

0 comments on commit 28a6e35

Please sign in to comment.