Skip to content

Commit

Permalink
fix(forge): prefer --from if specified for cast call (#7218)
Browse files Browse the repository at this point in the history
* fix(forge): use --from if specified for call

* Update crates/wallets/src/wallet.rs

Co-authored-by: Enrique <hi@enriqueortiz.dev>

* fmt

---------

Co-authored-by: Enrique <hi@enriqueortiz.dev>
  • Loading branch information
klkvr and Evalir committed Feb 23, 2024
1 parent b5fc4dc commit ac80261
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/wallets/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ of the unlocked account you want to use, or provide the --from flag with the add
Ok(signer)
}

/// Returns the sender address of the signer or `from`.
/// This function prefers the `from` field and may return a different address from the
/// configured signer
/// If from is specified, returns it
/// If from is not specified, but there is a signer configured, returns the signer's address
/// If from is not specified and there is no signer configured, returns zero address
pub async fn sender(&self) -> Address {
if let Ok(signer) = self.signer().await {
if let Some(from) = self.from {
from
} else if let Ok(signer) = self.signer().await {
signer.address().to_alloy()
} else {
self.from.unwrap_or(Address::ZERO)
Address::ZERO
}
}
}
Expand Down

0 comments on commit ac80261

Please sign in to comment.