Skip to content

Commit

Permalink
Update WalletOptions + some Clippy (#1585)
Browse files Browse the repository at this point in the history
* Update WalletOptions + some Clippy

* Address review comments
  • Loading branch information
Thoralf-M authored Nov 7, 2023
1 parent d2e73c9 commit 8650eb0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 27 deletions.
31 changes: 23 additions & 8 deletions bindings/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use fern_logger::{logger_init, LoggerConfig, LoggerOutputConfigBuilder};
pub use iota_sdk;
use iota_sdk::{
client::secret::{SecretManager, SecretManagerDto},
types::block::address::Bech32Address,
wallet::{ClientOptions, Wallet},
};
use serde::Deserialize;
Expand All @@ -42,21 +43,23 @@ pub fn init_logger(config: String) -> std::result::Result<(), fern_logger::Error
#[derivative(Debug)]
#[serde(rename_all = "camelCase")]
pub struct WalletOptions {
pub storage_path: Option<String>,
pub client_options: Option<ClientOptions>,
pub address: Option<Bech32Address>,
pub alias: Option<String>,
pub bip_path: Option<Bip44>,
pub client_options: Option<ClientOptions>,
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
pub secret_manager: Option<SecretManagerDto>,
pub storage_path: Option<String>,
}

impl WalletOptions {
pub fn with_storage_path(mut self, storage_path: impl Into<Option<String>>) -> Self {
self.storage_path = storage_path.into();
pub fn with_address(mut self, address: impl Into<Option<Bech32Address>>) -> Self {
self.address = address.into();
self
}

pub fn with_client_options(mut self, client_options: impl Into<Option<ClientOptions>>) -> Self {
self.client_options = client_options.into();
pub fn with_alias(mut self, alias: impl Into<Option<String>>) -> Self {
self.alias = alias.into();
self
}

Expand All @@ -65,16 +68,28 @@ impl WalletOptions {
self
}

pub fn with_client_options(mut self, client_options: impl Into<Option<ClientOptions>>) -> Self {
self.client_options = client_options.into();
self
}

pub fn with_secret_manager(mut self, secret_manager: impl Into<Option<SecretManagerDto>>) -> Self {
self.secret_manager = secret_manager.into();
self
}

pub fn with_storage_path(mut self, storage_path: impl Into<Option<String>>) -> Self {
self.storage_path = storage_path.into();
self
}

pub async fn build(self) -> iota_sdk::wallet::Result<Wallet> {
log::debug!("wallet options: {self:?}");
let mut builder = Wallet::builder()
.with_client_options(self.client_options)
.with_bip_path(self.bip_path);
.with_address(self.address)
.with_alias(self.alias)
.with_bip_path(self.bip_path)
.with_client_options(self.client_options);

#[cfg(feature = "storage")]
if let Some(storage_path) = &self.storage_path {
Expand Down
2 changes: 1 addition & 1 deletion bindings/core/tests/secrets_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fn method_interface_secrets_debug() {
let wallet_options = WalletOptions::default().with_secret_manager(SecretManagerDto::Placeholder);
assert_eq!(
format!("{:?}", wallet_options),
"WalletOptions { storage_path: None, client_options: None, bip_path: None, secret_manager: Some(<omitted>) }"
"WalletOptions { address: None, alias: None, bip_path: None, client_options: None, secret_manager: Some(<omitted>), storage_path: None }"
);
}
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl StateTransitionVerifier for DelegationOutput {

fn verify_validator_address<const VERIFY: bool>(validator_address: &AccountAddress) -> Result<(), Error> {
if VERIFY && validator_address.is_null() {
return Err(Error::NullDelegationValidatorId);
Err(Error::NullDelegationValidatorId)
} else {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ where
ImplicitAccountCreationAddress::from(address.clone()),
))
} else {
return Err(Error::NonEd25519Address);
Err(Error::NonEd25519Address)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/helpers/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::{
types::block::{address::Address, output::Output, slot::SlotIndex},
wallet::types::{AddressWithUnspentOutputs, OutputData},
wallet::types::OutputData,
};

// Check if an output can be unlocked by the wallet address at the current time
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/wallet/operations/reissue.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crypto::keys::bip44::Bip44;

use crate::{
client::{
secret::{SecretManage, SignBlock},
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/wallet/operations/transaction/submit_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crypto::keys::bip44::Bip44;

#[cfg(feature = "events")]
use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent};
use crate::{
Expand Down
18 changes: 7 additions & 11 deletions sdk/src/wallet/storage/participation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ impl StorageManager {

let mut events = self
.storage
.get::<HashMap<ParticipationEventId, ParticipationEventWithNodes>>(&format!("{PARTICIPATION_EVENTS}"))
.get::<HashMap<ParticipationEventId, ParticipationEventWithNodes>>(PARTICIPATION_EVENTS)
.await?
.unwrap_or_default();

events.insert(event_with_nodes.id, event_with_nodes);

self.storage.set(&format!("{PARTICIPATION_EVENTS}"), &events).await?;
self.storage.set(PARTICIPATION_EVENTS, &events).await?;

Ok(())
}
Expand All @@ -41,7 +41,7 @@ impl StorageManager {

let mut events = match self
.storage
.get::<HashMap<ParticipationEventId, ParticipationEventWithNodes>>(&format!("{PARTICIPATION_EVENTS}"))
.get::<HashMap<ParticipationEventId, ParticipationEventWithNodes>>(PARTICIPATION_EVENTS)
.await?
{
Some(events) => events,
Expand All @@ -50,7 +50,7 @@ impl StorageManager {

events.remove(id);

self.storage.set(&format!("{PARTICIPATION_EVENTS}"), &events).await?;
self.storage.set(PARTICIPATION_EVENTS, &events).await?;

Ok(())
}
Expand All @@ -60,11 +60,7 @@ impl StorageManager {
) -> crate::wallet::Result<HashMap<ParticipationEventId, ParticipationEventWithNodes>> {
log::debug!("get_participation_events");

Ok(self
.storage
.get(&format!("{PARTICIPATION_EVENTS}"))
.await?
.unwrap_or_default())
Ok(self.storage.get(PARTICIPATION_EVENTS).await?.unwrap_or_default())
}

pub(crate) async fn set_cached_participation_output_status(
Expand All @@ -74,7 +70,7 @@ impl StorageManager {
log::debug!("set_cached_participation");

self.storage
.set(&format!("{PARTICIPATION_CACHED_OUTPUTS}"), outputs_participation)
.set(PARTICIPATION_CACHED_OUTPUTS, outputs_participation)
.await?;

Ok(())
Expand All @@ -87,7 +83,7 @@ impl StorageManager {

Ok(self
.storage
.get(&format!("{PARTICIPATION_CACHED_OUTPUTS}"))
.get(PARTICIPATION_CACHED_OUTPUTS)
.await?
.unwrap_or_default())
}
Expand Down

0 comments on commit 8650eb0

Please sign in to comment.