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

Some clippy fixes #1485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions bindings/python/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Error {

impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
Expand All @@ -31,55 +31,55 @@ impl From<Error> for PyErr {

impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyIOError, _>(err.to_string()),
}
}
}

impl From<iota_sdk_bindings_core::iota_sdk::types::block::Error> for Error {
fn from(err: iota_sdk_bindings_core::iota_sdk::types::block::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
}

impl From<iota_sdk_bindings_core::Error> for Error {
fn from(err: iota_sdk_bindings_core::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
}

impl From<iota_sdk_bindings_core::iota_sdk::client::Error> for Error {
fn from(err: iota_sdk_bindings_core::iota_sdk::client::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
}

impl From<iota_sdk_bindings_core::iota_sdk::client::mqtt::Error> for Error {
fn from(err: iota_sdk_bindings_core::iota_sdk::client::mqtt::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
}

impl From<iota_sdk_bindings_core::iota_sdk::wallet::Error> for Error {
fn from(err: iota_sdk_bindings_core::iota_sdk::wallet::Error) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
}

impl From<Infallible> for Error {
fn from(err: Infallible) -> Self {
Error {
Self {
error: PyErr::new::<exceptions::PyValueError, _>(err.to_string()),
}
}
Expand Down
27 changes: 19 additions & 8 deletions bindings/wasm/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ pub async fn destroy_wallet(method_handler: &WalletMethodHandler) -> Result<(),

#[wasm_bindgen(js_name = getClientFromWallet)]
pub async fn get_client(method_handler: &WalletMethodHandler) -> Result<ClientMethodHandler, JsValue> {
let wallet = method_handler.wallet.lock().await;

let client = wallet
let client = method_handler
.wallet
.lock()
.await
.as_ref()
.ok_or_else(|| "wallet got destroyed".to_string())?
.client()
Expand All @@ -63,9 +64,10 @@ pub async fn get_client(method_handler: &WalletMethodHandler) -> Result<ClientMe

#[wasm_bindgen(js_name = getSecretManagerFromWallet)]
pub async fn get_secret_manager(method_handler: &WalletMethodHandler) -> Result<SecretManagerMethodHandler, JsValue> {
let wallet = method_handler.wallet.lock().await;

let secret_manager = wallet
let secret_manager = method_handler
.wallet
.lock()
.await
.as_ref()
.ok_or_else(|| "wallet got destroyed".to_string())?
.get_secret_manager()
Expand All @@ -79,10 +81,19 @@ pub async fn get_secret_manager(method_handler: &WalletMethodHandler) -> Result<
/// Returns an error if the response itself is an error or panic.
#[wasm_bindgen(js_name = callWalletMethodAsync)]
pub async fn call_wallet_method_async(method: String, method_handler: &WalletMethodHandler) -> Result<String, JsValue> {
let wallet = method_handler.wallet.lock().await;
let method: WalletMethod = serde_json::from_str(&method).map_err(|err| err.to_string())?;

let response = call_wallet_method(wallet.as_ref().expect("wallet got destroyed"), method).await;
let response = call_wallet_method(
method_handler
.wallet
.lock()
.await
.as_ref()
.expect("wallet got destroyed"),
method,
)
.await;

match response {
Response::Error(e) => Err(e.to_string().into()),
Response::Panic(p) => Err(p.into()),
Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ version = "1.1.0"
authors = ["IOTA Stiftung"]
edition = "2021"
homepage = "https://iota.org"
repository = "https://github.com/iotaledger/iota-sdk"
description = "Command line interface wallet application based on the IOTA SDK"
license = "Apache-2.0"
keywords = ["iota", "tangle", "sdk", "cli", "wallet"]
categories = ["cryptography::cryptocurrencies"]

[[bin]]
name = "wallet"
Expand Down
6 changes: 3 additions & 3 deletions cli/src/command/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub async fn restore_command(storage_path: &Path, snapshot_path: &Path, backup_p
let password = get_password("Stronghold password", false)?;
let secret_manager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password(password.clone())
.password(password)
.build(snapshot_path)?,
);
builder = builder.with_secret_manager(secret_manager);
Expand Down Expand Up @@ -321,8 +321,8 @@ pub async fn sync_command(storage_path: &Path, snapshot_path: &Path) -> Result<W

pub async fn unlock_wallet(
storage_path: &Path,
snapshot_path: impl Into<Option<&Path>>,
password: impl Into<Option<Password>>,
snapshot_path: impl Into<Option<&Path>> + Send,
password: impl Into<Option<Password>> + Send,
) -> Result<Wallet, Error> {
let secret_manager = if let Some(password) = password.into() {
let snapshot_path = snapshot_path.into();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum Error {

impl From<ClientError> for Error {
fn from(error: ClientError) -> Self {
Error::Client(Box::new(error))
Self::Client(Box::new(error))
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub async fn generate_mnemonic(
println!("{}", mnemonic.as_ref());
}
if [1, 2].contains(&selected_choice) {
let file_path = output_file_name.unwrap_or(DEFAULT_MNEMONIC_FILE_PATH.to_string());
let file_path = output_file_name.unwrap_or_else(|| DEFAULT_MNEMONIC_FILE_PATH.to_string());

write_mnemonic_to_file(&file_path, &mnemonic).await?;
println_log_info!("Mnemonic has been written to '{file_path}'.");
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 @@ -23,7 +23,7 @@ async fn main() -> Result<()> {

let address: Bech32Address = std::env::args()
.nth(2)
.unwrap_or("atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r".to_string())
.unwrap_or_else(|| "atoi1qzt0nhsf38nh6rs4p6zs5knqp6psgha9wsv74uajqgjmwc75ugupx3y7x0r".to_string())
.parse()?;

// Create a node client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<()> {
Ok(())
}

async fn write_address_to_file(path: impl AsRef<std::path::Path>, address: &[Bech32Address]) -> Result<()> {
async fn write_address_to_file(path: impl AsRef<std::path::Path> + Send, address: &[Bech32Address]) -> Result<()> {
use tokio::io::AsyncWriteExt;

let json = serde_json::to_string_pretty(&address)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn main() -> Result<()> {
Ok(())
}

async fn read_addresses_from_file(path: impl AsRef<std::path::Path>) -> Result<Vec<Bech32Address>> {
async fn read_addresses_from_file(path: impl AsRef<std::path::Path> + Send) -> Result<Vec<Bech32Address>> {
use tokio::io::AsyncReadExt;

let mut file = tokio::fs::File::open(&path).await.expect("failed to open file");
Expand All @@ -78,7 +78,7 @@ async fn read_addresses_from_file(path: impl AsRef<std::path::Path>) -> Result<V
}

async fn write_prepared_transaction_to_file(
path: impl AsRef<std::path::Path>,
path: impl AsRef<std::path::Path> + Send,
prepared_transaction: &PreparedTransactionData,
) -> Result<()> {
use tokio::io::AsyncWriteExt;
Expand Down
6 changes: 4 additions & 2 deletions sdk/examples/client/offline_signing/2_transaction_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ async fn main() -> Result<()> {
Ok(())
}

async fn read_prepared_transaction_from_file(path: impl AsRef<std::path::Path>) -> Result<PreparedTransactionData> {
async fn read_prepared_transaction_from_file(
path: impl AsRef<std::path::Path> + Send,
) -> Result<PreparedTransactionData> {
use tokio::io::AsyncReadExt;

let mut file = tokio::fs::File::open(&path).await.expect("failed to open file");
Expand All @@ -62,7 +64,7 @@ async fn read_prepared_transaction_from_file(path: impl AsRef<std::path::Path>)
}

async fn write_signed_transaction_to_file(
path: impl AsRef<std::path::Path>,
path: impl AsRef<std::path::Path> + Send,
signed_transaction_data: &SignedTransactionData,
) -> Result<()> {
use tokio::io::AsyncWriteExt;
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/offline_signing/3_send_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn main() -> Result<()> {
Ok(())
}

async fn read_signed_transaction_from_file(path: impl AsRef<std::path::Path>) -> Result<SignedTransactionData> {
async fn read_signed_transaction_from_file(path: impl AsRef<std::path::Path> + Send) -> Result<SignedTransactionData> {
use tokio::io::AsyncReadExt;

let mut file = tokio::fs::File::open(path).await.expect("failed to open file");
Expand Down
4 changes: 2 additions & 2 deletions sdk/examples/client/output/build_alias_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() -> Result<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();

let metadata = std::env::args().nth(1).unwrap_or("hello".to_string());
let metadata = std::env::args().nth(1).unwrap_or_else(|| "hello".to_string());
let metadata = metadata.as_bytes();

// Create a node client.
Expand All @@ -39,7 +39,7 @@ async fn main() -> Result<()> {

let address = std::env::args()
.nth(1)
.unwrap_or("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string());
.unwrap_or_else(|| "rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string());
let address = Address::try_from_bech32(address)?;

// Alias id needs to be null the first time
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/output/build_basic_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> Result<()> {

let address = std::env::args()
.nth(1)
.unwrap_or("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string());
.unwrap_or_else(|| "rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string());
let address = Address::try_from_bech32(address)?;

let basic_output_builder =
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/client/output/build_nft_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn main() -> Result<()> {

let address = std::env::args()
.nth(1)
.unwrap_or("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string());
.unwrap_or_else(|| "rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string());
let address = Address::try_from_bech32(address)?;

// IOTA NFT Standard - IRC27: https://github.com/iotaledger/tips/blob/main/tips/TIP-0027/tip-0027.md
Expand Down
6 changes: 3 additions & 3 deletions sdk/examples/client/output/native_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ async fn main() -> Result<()> {
.unwrap();

// Replace with the token ID of native tokens you own.
let token_id = std::env::args()
.nth(1)
.unwrap_or("0x08e68f7616cd4948efebc6a77c4f935eaed770ac53869cba56d104f2b472a8836d0100000000".to_string());
let token_id = std::env::args().nth(1).unwrap_or_else(|| {
"0x08e68f7616cd4948efebc6a77c4f935eaed770ac53869cba56d104f2b472a8836d0100000000".to_string()
});
let token_id: [u8; 38] = prefix_hex::decode(token_id)?;

let outputs = [
Expand Down
4 changes: 0 additions & 4 deletions sdk/src/client/node_api/mqtt/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type TopicHandler = Box<dyn Fn(&TopicEvent) + Send + Sync>;
pub(crate) type TopicHandlerMap = HashMap<Topic, Vec<Arc<TopicHandler>>>;

/// An event from a MQTT topic.

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct TopicEvent {
/// the MQTT topic.
Expand All @@ -30,7 +29,6 @@ pub struct TopicEvent {
}

/// The payload of an `TopicEvent`.

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum MqttPayload {
Expand All @@ -45,7 +43,6 @@ pub enum MqttPayload {
}

/// Mqtt events.

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MqttEvent {
/// Client was connected.
Expand All @@ -55,7 +52,6 @@ pub enum MqttEvent {
}

/// The MQTT broker options.

#[derive(Copy, Debug, Clone, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
#[must_use]
Expand Down
1 change: 0 additions & 1 deletion sdk/src/client/secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub trait SecretManagerConfig: SecretManage {
}

/// Supported secret managers

#[non_exhaustive]
pub enum SecretManager {
/// Secret manager that uses [`iota_stronghold`] as the backing storage.
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/wallet/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl AccountInner {
..Default::default()
})
.await
.map(|res| res.get(0).cloned())
.map(|res| res.first().cloned())
}

/// Gets the unspent foundry output matching the given ID.
Expand All @@ -407,7 +407,7 @@ impl AccountInner {
..Default::default()
})
.await
.map(|res| res.get(0).cloned())
.map(|res| res.first().cloned())
}

/// Gets the unspent nft output matching the given ID.
Expand All @@ -417,7 +417,7 @@ impl AccountInner {
..Default::default()
})
.await
.map(|res| res.get(0).cloned())
.map(|res| res.first().cloned())
}

/// Returns all incoming transactions of the account
Expand Down
3 changes: 2 additions & 1 deletion sdk/tests/client/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub async fn create_client_and_secret_manager_with_funds(
) -> Result<(Client, SecretManager)> {
let client = Client::builder().with_node(NODE_LOCAL)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(mnemonic.unwrap_or(Client::generate_mnemonic().unwrap()))?;
let secret_manager =
SecretManager::try_from_mnemonic(mnemonic.unwrap_or_else(|| Client::generate_mnemonic().unwrap()))?;

let address = secret_manager
.generate_ed25519_addresses(
Expand Down
6 changes: 3 additions & 3 deletions sdk/tests/client/signing/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn sign_alias_state_transition() -> Result<()> {
.await?;

assert_eq!(unlocks.len(), 1);
assert_eq!((*unlocks).get(0).unwrap().kind(), SignatureUnlock::KIND);
assert_eq!((*unlocks).first().unwrap().kind(), SignatureUnlock::KIND);

let tx_payload = TransactionPayload::new(prepared_transaction_data.essence.clone(), unlocks)?;

Expand Down Expand Up @@ -200,7 +200,7 @@ async fn sign_alias_governance_transition() -> Result<()> {
.await?;

assert_eq!(unlocks.len(), 1);
assert_eq!((*unlocks).get(0).unwrap().kind(), SignatureUnlock::KIND);
assert_eq!((*unlocks).first().unwrap().kind(), SignatureUnlock::KIND);

let tx_payload = TransactionPayload::new(prepared_transaction_data.essence.clone(), unlocks)?;

Expand Down Expand Up @@ -330,7 +330,7 @@ async fn alias_reference_unlocks() -> Result<()> {
.await?;

assert_eq!(unlocks.len(), 3);
assert_eq!((*unlocks).get(0).unwrap().kind(), SignatureUnlock::KIND);
assert_eq!((*unlocks).first().unwrap().kind(), SignatureUnlock::KIND);
match (*unlocks).get(1).unwrap() {
Unlock::Alias(a) => {
assert_eq!(a.index(), 0);
Expand Down
Loading
Loading