Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dpp::identity::accessors::IdentityGettersV0;

use dpp::identity::core_script::CoreScript;
use dpp::identity::signer::Signer;
use dpp::identity::Identity;
use dpp::identity::{Identity, IdentityPublicKey};
use dpp::prelude::UserFeeIncrease;

use crate::platform::transition::broadcast::BroadcastStateTransition;
Expand All @@ -19,13 +19,15 @@ use dpp::withdrawal::Pooling;
#[async_trait::async_trait]
pub trait WithdrawFromIdentity {
/// Function to withdraw credits from an identity. Returns the final identity balance.
/// If signing_withdrawal_key_to_use is not set, we will try to use one in the signer that is
/// available for withdrawal
async fn withdraw<S: Signer + Send>(
&self,
sdk: &Sdk,
address: Option<Address>,
amount: u64,
core_fee_per_byte: Option<u32>,
user_fee_increase: Option<UserFeeIncrease>,
signing_withdrawal_key_to_use: Option<&IdentityPublicKey>,
signer: S,
settings: Option<PutSettings>,
) -> Result<u64, Error>;
Expand All @@ -39,12 +41,15 @@ impl WithdrawFromIdentity for Identity {
address: Option<Address>,
amount: u64,
core_fee_per_byte: Option<u32>,
user_fee_increase: Option<UserFeeIncrease>,
signing_withdrawal_key_to_use: Option<&IdentityPublicKey>,
signer: S,
settings: Option<PutSettings>,
) -> Result<u64, Error> {
let new_identity_nonce = sdk.get_identity_nonce(self.id(), true, settings).await?;
let script = address.map(|address| CoreScript::new(address.script_pubkey()));
let user_fee_increase = settings
.map(|settings| settings.user_fee_increase)
.flatten();
Comment on lines +50 to +52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify Extraction of user_fee_increase

You can simplify the extraction of user_fee_increase from settings by using and_then instead of map followed by flatten:

let user_fee_increase = settings.and_then(|settings| settings.user_fee_increase);

This approach is more idiomatic and concise in Rust.

let state_transition = IdentityCreditWithdrawalTransition::try_from_identity(
self,
script,
Expand All @@ -53,7 +58,7 @@ impl WithdrawFromIdentity for Identity {
core_fee_per_byte.unwrap_or(1),
user_fee_increase.unwrap_or_default(),
signer,
None,
signing_withdrawal_key_to_use,
PreferredKeyPurposeForSigningWithdrawal::TransferPreferred,
new_identity_nonce,
sdk.version(),
Expand Down