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

feat: helpers for AnyNetwork #476

Merged
merged 5 commits into from
Apr 7, 2024
Merged

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Apr 6, 2024

Motivation

Small changes for foundry-rs/foundry#7106

Adds AnyNetworkSigner and alias for AnyNetwork::ReceiptResponse as it's pretty long

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes


/// A signer capable of signing any transaction for the [AnyNetwork] network.
#[derive(Clone)]
pub struct AnyNetworkSigner(Arc<dyn TxSigner<Signature> + Send + Sync>);
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense to make this Arc so we can share the same signer

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.

not sure if it makes sense to duplicate the signer type,

Perhaps for forward compatibility we can do that, in case we want to support more tx types that are don't exist on ehtereum (currently there aren't any)

so I think for now we can simply use the ethereumsigner for AnyNetwork as well but add impl NetworkSigner<AnyNetwork> for EthereumSigner { because both networks have the same UnsignedTx

I believe we could even do

impl<N> NetworkSigner<N> for EthereumSigner
    where N: Network<UnsignedTx= TypedTransaction, TxEnvelope = TxEnvelope >
        {

wdyt @prestwich

Comment on lines 11 to 12
/// Alias for a catch-all receipt type.
pub type AnyReceipt = WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>>;
Copy link
Member

@mattsse mattsse Apr 6, 2024

Choose a reason for hiding this comment

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

could move or reexport this to/from rpc types and rename AnyTransactionReceipt?


/// A signer capable of signing any transaction for the [AnyNetwork] network.
#[derive(Clone)]
pub struct AnyNetworkSigner(Arc<dyn TxSigner<Signature> + Send + Sync>);
Copy link
Member

Choose a reason for hiding this comment

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

this is the same as:

pub struct EthereumSigner(Arc<dyn TxSigner<Signature> + Send + Sync>);

so I assume we can reuse EthereumSigner but

also implement impl NetworkSigner<AnyNetwork> for EthereumSigner {

?

@prestwich
Copy link
Member

prestwich commented Apr 6, 2024

supportive of type-reuse and the blanket impl

The reason that NetworkSigner<N> is a trait and not an assoc type is to allow many different objects to be network signers. We could even do a blanket like impl<T> NetworkSigner<Ethereum> for T where T: TxSigner<alloy_primitives::Signature>

@prestwich
Copy link
Member

basically the idea of NetworkSigner<N> is "any object that can sign any subset of transactions allowed by the network"

@mattsse mattsse merged commit 6aab216 into alloy-rs:main Apr 7, 2024
18 checks passed
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* feat: helpers for AnyNetwork

* fmt

* Fixes

* fix

* fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants