Skip to content

Commit

Permalink
refactor: renames for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Apr 18, 2024
1 parent 7f50917 commit f407b5d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions crates/network/src/ethereum/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ impl<N> NetworkSigner<N> for EthereumSigner
where
N: Network<UnsignedTx = TypedTransaction, TxEnvelope = TxEnvelope>,
{
fn default_signer(&self) -> Address {
fn default_signer_address(&self) -> Address {
self.default
}

fn is_signer_for(&self, address: &Address) -> bool {
fn has_signer_for(&self, address: &Address) -> bool {
self.secp_signers.contains_key(address)
}

fn signers(&self) -> impl Iterator<Item = Address> {
fn signer_addresses(&self) -> impl Iterator<Item = Address> {
self.secp_signers.keys().copied()
}

Expand Down
10 changes: 5 additions & 5 deletions crates/network/src/transaction/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub trait NetworkSigner<N: Network>: std::fmt::Debug + Send + Sync {
/// Get the default signer address. This address should be used
/// in [`NetworkSigner::sign_transaction_from`] when no specific signer is
/// specified.
fn default_signer(&self) -> Address;
fn default_signer_address(&self) -> Address;

/// Return true if the signer contains a credential for the given address.
fn is_signer_for(&self, address: &Address) -> bool;
fn has_signer_for(&self, address: &Address) -> bool;

/// Return an iterator of all signer addresses.
fn signers(&self) -> impl Iterator<Item = Address>;
fn signer_addresses(&self) -> impl Iterator<Item = Address>;

/// Asynchronously sign an unsigned transaction, with a specified
/// credential.
Expand All @@ -41,7 +41,7 @@ pub trait NetworkSigner<N: Network>: std::fmt::Debug + Send + Sync {
&self,
tx: N::UnsignedTx,
) -> impl_future!(<Output = alloy_signer::Result<N::TxEnvelope>>) {
self.sign_transaction_from(self.default_signer(), tx)
self.sign_transaction_from(self.default_signer_address(), tx)
}

/// Asynchronously sign a transaction request, using the sender specified
Expand All @@ -50,7 +50,7 @@ pub trait NetworkSigner<N: Network>: std::fmt::Debug + Send + Sync {
&self,
request: N::TransactionRequest,
) -> alloy_signer::Result<N::TxEnvelope> {
let sender = request.from().unwrap_or_else(|| self.default_signer());
let sender = request.from().unwrap_or_else(|| self.default_signer_address());
let tx = request.build_unsigned().map_err(|(_, e)| alloy_signer::Error::other(e))?;
self.sign_transaction_from(sender, tx).await
}
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
};

if builder.from().is_none() {
builder.set_from(self.signer.default_signer());
builder.set_from(self.signer.default_signer_address());
if !builder.can_build() {
return Ok(SendableTx::Builder(builder));
}
Expand Down
20 changes: 11 additions & 9 deletions crates/provider/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ pub trait WalletProvider<N: Network = Ethereum> {
fn signer_mut(&mut self) -> &mut Self::Signer;

/// Get the default signer address.
fn default_signer(&self) -> Address {
self.signer().default_signer()
fn default_signer_address(&self) -> Address {
self.signer().default_signer_address()
}

/// Check if the signer can sign for the given address.
fn is_signer_for(&self, address: &Address) -> bool {
self.signer().is_signer_for(address)
fn has_signer_for(&self, address: &Address) -> bool {
self.signer().has_signer_for(address)
}

/// Get an iterator of all signer addresses.
fn signers(&self) -> impl Iterator<Item = Address> {
self.signer().signers()
/// Get an iterator of all signer addresses. Note that because the signer
/// always has at least one address, this iterator will always have at least
/// one element.
fn signer_addresses(&self) -> impl Iterator<Item = Address> {
self.signer().signer_addresses()
}
}

Expand Down Expand Up @@ -98,14 +100,14 @@ mod test {
fn basic_usage() {
let (provider, _anvil) = ProviderBuilder::new().on_anvil_with_signer();

assert_eq!(provider.default_signer(), provider.signers().next().unwrap());
assert_eq!(provider.default_signer_address(), provider.signer_addresses().next().unwrap());
}

#[test]
fn bubbles_through_fillers() {
let (provider, _anvil) =
ProviderBuilder::new().with_recommended_fillers().on_anvil_with_signer();

assert_eq!(provider.default_signer(), provider.signers().next().unwrap());
assert_eq!(provider.default_signer_address(), provider.signer_addresses().next().unwrap());
}
}

0 comments on commit f407b5d

Please sign in to comment.