Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Lohachov Mykhailo <[email protected]>
  • Loading branch information
aoyako committed Nov 29, 2024
1 parent e9d1b1b commit 727df53
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 73 deletions.
22 changes: 10 additions & 12 deletions crates/iroha/examples/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ fn main() {

// Your code goes here…

domain_registration_test(config.clone())
domain_registration_test(&config)
.expect("Domain registration example is expected to work correctly");
account_definition_test().expect("Account definition example is expected to work correctly");
account_registration_test(config.clone())
account_registration_test(&config)
.expect("Account registration example is expected to work correctly");
asset_registration_test(config.clone())
asset_registration_test(&config)
.expect("Asset registration example is expected to work correctly");
asset_minting_test(config.clone())
.expect("Asset minting example is expected to work correctly");
asset_burning_test(config.clone())
.expect("Asset burning example is expected to work correctly");
asset_minting_test(&config).expect("Asset minting example is expected to work correctly");
asset_burning_test(&config).expect("Asset burning example is expected to work correctly");
// output_visualising_test(&config).expect(msg: "Visualising outputs example is expected to work correctly");
println!("Success!");
}

fn domain_registration_test(config: Config) -> Result<(), Error> {
fn domain_registration_test(config: &Config) -> Result<(), Error> {
// #region domain_register_example_crates
use iroha::{
client::Client,
Expand Down Expand Up @@ -93,7 +91,7 @@ fn account_definition_test() -> Result<(), Error> {
Ok(())
}

fn account_registration_test(config: Config) -> Result<(), Error> {
fn account_registration_test(config: &Config) -> Result<(), Error> {
// #region register_account_crates
use iroha::{
client::Client,
Expand Down Expand Up @@ -139,7 +137,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> {
Ok(())
}

fn asset_registration_test(config: Config) -> Result<(), Error> {
fn asset_registration_test(config: &Config) -> Result<(), Error> {
// #region register_asset_crates
use iroha::{
client::Client,
Expand Down Expand Up @@ -187,7 +185,7 @@ fn asset_registration_test(config: Config) -> Result<(), Error> {
Ok(())
}

fn asset_minting_test(config: Config) -> Result<(), Error> {
fn asset_minting_test(config: &Config) -> Result<(), Error> {
// #region mint_asset_crates
use iroha::{
client::Client,
Expand Down Expand Up @@ -239,7 +237,7 @@ fn asset_minting_test(config: Config) -> Result<(), Error> {
Ok(())
}

fn asset_burning_test(config: Config) -> Result<(), Error> {
fn asset_burning_test(config: &Config) -> Result<(), Error> {
// #region burn_asset_crates
use iroha::{
client::Client,
Expand Down
14 changes: 7 additions & 7 deletions crates/iroha/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ pub struct Client {
impl Client {
/// Constructor for client from configuration
#[inline]
pub fn new(configuration: Config) -> Self {
pub fn new(configuration: &Config) -> Self {
Self::with_headers(configuration, HashMap::new())
}

/// Constructor for client from configuration and headers
///
/// *Authorization* header will be added if `basic_auth` is presented
#[inline]
pub fn with_headers(config: Config, mut headers: HashMap<String, String>) -> Self {
pub fn with_headers(config: &Config, mut headers: HashMap<String, String>) -> Self {
if let Some(basic_auth) = config.basic_auth().clone() {
let credentials = format!(
"{}:{}",
Expand All @@ -167,11 +167,11 @@ impl Client {
chain: config.chain().clone(),
torii_url: config.torii_api_url().clone(),
key_pair: config.key_pair().clone(),
transaction_ttl: Some(config.transaction_ttl().clone()),
transaction_status_timeout: config.transaction_status_timeout().clone(),
transaction_ttl: Some(*config.transaction_ttl()),
transaction_status_timeout: *config.transaction_status_timeout(),
account: config.account().clone(),
headers,
add_transaction_nonce: config.transaction_add_nonce().clone(),
add_transaction_nonce: *config.transaction_add_nonce(),
}
}

Expand Down Expand Up @@ -998,7 +998,7 @@ mod tests {
.transaction_add_nonce(true)
.build()
.expect("Can't build config");
let client = Client::new(config);
let client = Client::new(&config);

let build_transaction =
|| client.build_transaction(Vec::<InstructionBox>::new(), Metadata::default());
Expand Down Expand Up @@ -1033,7 +1033,7 @@ mod tests {
}))
.build()
.expect("Can't build config");
let client = Client::new(config);
let client = Client::new(&config);

let value = client
.headers
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ trait RunContext {
fn configuration(&self) -> &Config;

fn client_from_config(&self) -> Client {
Client::new(self.configuration().clone())
Client::new(self.configuration())
}

/// Serialize and print data
Expand Down Expand Up @@ -1199,7 +1199,7 @@ mod json {
.wrap_err("Failed to submit parsed instructions")
}
Variant::Query => {
let client = Client::new(context.configuration().clone());
let client = Client::new(context.configuration());
let query: AnyQueryBox = json5::from_str(&string_content)?;

match query {
Expand Down
15 changes: 8 additions & 7 deletions crates/iroha_core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use iroha_config::{
base::WithOrigin,
parameters::{actual::Kura as Config, defaults::kura::BLOCKS_IN_MEMORY},
parameters::{actual::KuraBuilder as ConfigBuilder, defaults::kura::BLOCKS_IN_MEMORY},
};
use iroha_core::{
block::*,
Expand All @@ -21,12 +21,13 @@ use tokio::{fs, runtime::Runtime};

async fn measure_block_size_for_n_executors(n_executors: u32) {
let dir = tempfile::tempdir().expect("Could not create tempfile.");
let cfg = Config {
init_mode: iroha_config::kura::InitMode::Strict,
debug_output_new_blocks: false,
blocks_in_memory: BLOCKS_IN_MEMORY,
store_dir: WithOrigin::inline(dir.path().to_path_buf()),
};
let cfg = ConfigBuilder::default()
.init_mode(iroha_config::kura::InitMode::Strict)
.debug_output_new_blocks(false)
.blocks_in_memory(BLOCKS_IN_MEMORY)
.store_dir(WithOrigin::inline(dir.path().to_path_buf()))
.build()
.expect("Should build config");
let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000");
let (kura, _) = iroha_core::kura::Kura::new(&cfg).unwrap();
let _thread_handle = iroha_core::kura::Kura::start(kura.clone(), ShutdownSignal::new());
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl BlockSynchronizer {
peer,
sumeragi,
kura,
gossip_period: config.gossip_period().clone(),
gossip_size: config.gossip_size().clone(),
gossip_period: *config.gossip_period(),
gossip_size: *config.gossip_size(),
network,
state,
seen_blocks: BTreeSet::new(),
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/gossiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl TransactionGossiper {
) -> Self {
Self {
chain_id,
gossip_period: config.gossip_period().clone(),
gossip_size: config.gossip_size().clone(),
gossip_period: *config.gossip_period(),
gossip_size: *config.gossip_size(),
network,
queue,
state,
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/kiso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct KisoHandle {

impl KisoHandle {
/// Spawn a new actor
pub fn start(state: Config) -> (Self, Child) {
pub fn start(state: &Config) -> (Self, Child) {
let (actor_sender, actor_receiver) = mpsc::channel(DEFAULT_CHANNEL_SIZE);
let (log_level_update, _) = watch::channel(state.logger().level().clone());
let mut actor = Actor {
Expand Down Expand Up @@ -187,7 +187,7 @@ mod tests {

config.logger_mut().set_level(INIT_LOG_LEVEL.into());

let (kiso, _) = KisoHandle::start(config);
let (kiso, _) = KisoHandle::start(&config);

let mut recv = kiso
.subscribe_on_log_level()
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ impl Kura {
.debug_output_new_blocks()
.then(|| store_dir.join("blocks.json"));

let block_data = Kura::init(&mut block_store, config.init_mode().clone())?;
let block_data = Kura::init(&mut block_store, *config.init_mode())?;
let block_count = block_data.len();
info!(mode=?config.init_mode(), block_count, "Kura init complete");

let kura = Arc::new(Self {
block_store: Mutex::new(block_store),
block_data: Mutex::new(block_data),
block_plain_text_path,
blocks_in_memory: config.blocks_in_memory().clone(),
blocks_in_memory: *config.blocks_in_memory(),
init_block_count: block_count,
});

Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_core/src/peers_gossiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct PeersGossiper {
impl PeersGossiper {
/// Start actor.
pub fn start(
trusted_peers: TrustedPeers,
trusted_peers: &TrustedPeers,
network: IrohaNetwork,
shutdown_signal: ShutdownSignal,
) -> (PeersGossiperHandle, Child) {
Expand Down
6 changes: 3 additions & 3 deletions crates/iroha_core/src/query/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ impl LiveQueryStore {
Self {
queries: DashMap::new(),
queries_per_user: DashMap::new(),
idle_time: cfg.idle_time().clone(),
capacity: cfg.capacity().clone(),
capacity_per_user: cfg.capacity_per_user().clone(),
idle_time: *cfg.idle_time(),
capacity: *cfg.capacity(),
capacity_per_user: *cfg.capacity_per_user(),
shutdown_signal,
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/iroha_core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ impl Queue {
tx_hashes: ArrayQueue::new(config.capacity().get()),
txs: DashMap::new(),
txs_per_user: DashMap::new(),
capacity: config.capacity().clone(),
capacity_per_user: config.capacity_per_user().clone(),
capacity: *config.capacity(),
capacity_per_user: *config.capacity_per_user(),
time_source: TimeSource::new_system(),
tx_time_to_live: config.transaction_time_to_live().clone(),
tx_time_to_live: *config.transaction_time_to_live(),
tx_gossip: ArrayQueue::new(config.capacity().get()),
}
}
Expand Down Expand Up @@ -426,10 +426,10 @@ pub mod tests {
tx_gossip: ArrayQueue::new(cfg.capacity().get()),
txs: DashMap::new(),
txs_per_user: DashMap::new(),
capacity: cfg.capacity().clone(),
capacity_per_user: cfg.capacity_per_user().clone(),
capacity: *cfg.capacity(),
capacity_per_user: *cfg.capacity_per_user(),
time_source: time_source.clone(),
tx_time_to_live: cfg.transaction_time_to_live().clone(),
tx_time_to_live: *cfg.transaction_time_to_live(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_core/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl SnapshotMaker {
let latest_block_hash = state.view().latest_block_hash();
Some(Self {
state,
create_every: config.create_every().clone(),
create_every: *config.create_every(),
store_dir: config.store_dir().resolve_relative_path(),
latest_block_hash,
})
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl Sumeragi {
})
.collect::<Vec<_>>()
.join("\n");
panic!("Genesis contains invalid transactions:\n{}", errors);
panic!("Genesis contains invalid transactions:\n {errors}");
}

// NOTE: By this time genesis block is executed and list of trusted peers is updated
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/sumeragi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl SumeragiStartArgs {
for block in blocks_iter {
let mut state_block = state.block(block.header());
SumeragiHandle::replay_block(
&common_config.chain(),
common_config.chain(),
&genesis_account,
&block,
&mut state_block,
Expand All @@ -219,7 +219,7 @@ impl SumeragiStartArgs {
peers_gossiper,
control_message_receiver,
message_receiver,
debug_force_soft_fork: config.debug_force_soft_fork().clone(),
debug_force_soft_fork: *config.debug_force_soft_fork(),
topology,
transaction_cache: Vec::new(),
#[cfg(feature = "telemetry")]
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_p2p/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<T: Pload, K: Kex + Sync, E: Enc + Sync> NetworkBaseHandle<T, K, E> {
current_conn_id: 0,
current_topology: HashSet::new(),
current_peers_addresses: Vec::new(),
idle_timeout: config.idle_timeout().clone(),
idle_timeout: *config.idle_timeout(),
_key_exchange: core::marker::PhantomData::<K>,
_encryptor: core::marker::PhantomData::<E>,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_telemetry/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub async fn start(
write,
WebsocketSinkFactory::new(config.url().clone()),
RetryPeriod::new(
config.min_retry_period().clone(),
config.max_retry_delay_exponent().clone(),
*config.min_retry_period(),
*config.max_retry_delay_exponent(),
),
internal_sender,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ impl NetworkPeer {
.parse()
.expect("peer client config should be valid");

Client::new(config)
Client::new(&config)
}

/// Client for Alice. ([`Self::client_for`] + [`Signatory::Alice`])
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_torii/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Torii {
pub fn new(
chain_id: ChainId,
kiso: KisoHandle,
config: Config,
config: &Config,
queue: Arc<Queue>,
events: EventsSender,
query_service: LiveQueryStoreHandle,
Expand All @@ -90,7 +90,7 @@ impl Torii {
#[cfg(feature = "telemetry")]
metrics_reporter,
address: config.address().clone(),
transaction_max_content_len: config.max_content_len().clone(),
transaction_max_content_len: *config.max_content_len(),
}
}

Expand Down
Loading

0 comments on commit 727df53

Please sign in to comment.