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

feature: WalletProvider #569

Merged
merged 5 commits into from
Apr 18, 2024
Merged

feature: WalletProvider #569

merged 5 commits into from
Apr 18, 2024

Conversation

prestwich
Copy link
Member

Adds a trait that allows users to access the NetworkSigner in a signing fill + provider stack.

Motivation

Allow users to view keys and add signing credentials after building the provider stack.

Solution

Add a trait that exposes the underlying signer via borrows and mut borrows, and includes convenience functions for the useful NetworkSigner functions

Note:
This trait is implemented only when both of the following are true:

  • the signer is the R filler on the joinfill,
  • the fillprovider is the outermost layer

These conditions are true for all stacks constructed by the builder. This is a bit non-intuitive, but is necessary to avoid conflicting impls when both L and R are signer provider and when multiple signers are present in a stack. While neither of those cases are expected ever, the type system allows for them. Therefore we cannot neatly describe this trait without the assumptions above

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@prestwich prestwich added the enhancement New feature or request label Apr 18, 2024
@prestwich prestwich self-assigned this Apr 18, 2024
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

makes sense, only have some naming suggestions

Comment on lines 14 to 23
/// Get a reference to the underlying signer.
fn signer(&self) -> &Self::Signer;

/// Get a mutable reference to the underlying signer.
fn signer_mut(&mut self) -> &mut Self::Signer;

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

Choose a reason for hiding this comment

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

hmm, perhaps naming could be confusing here.

default_signer vs signer perhaps we should include _address in the fn name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to rename NetworkSigner to NetworkWallet, and LocalWallet to LocalSigner, and always use Wallet to mean "a collection of credentials" and signer to mean "a single credential". but that is a more extensive refactor

Copy link
Member Author

Choose a reason for hiding this comment

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

opened a new issue #575

crates/provider/src/wallet.rs Outdated Show resolved Hide resolved
crates/provider/src/wallet.rs Outdated Show resolved Hide resolved
@prestwich prestwich force-pushed the prestwich/signer-stack-trait branch from 7bf36b5 to f407b5d Compare April 18, 2024 22:16
@prestwich prestwich merged commit c657042 into main Apr 18, 2024
18 checks passed
@prestwich prestwich deleted the prestwich/signer-stack-trait branch April 18, 2024 22:27
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* feature: WalletProvider

* feature: signer_mut

* test: a basic one

* test: bubbles up

* refactor: renames for clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants