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

refactor: Rename Sol*::Tuple to Parameters/Arguments #145

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/Cargo.lock
.vscode
.idea
6 changes: 3 additions & 3 deletions crates/sol-macro/src/expand/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, error: &ItemError) -> Result<TokenStream>

#[automatically_derived]
impl ::alloy_sol_types::SolError for #name {
type Tuple<'a> = UnderlyingSolTuple<'a>;
type Token<'a> = <Self::Tuple<'a> as ::alloy_sol_types::SolType>::TokenType<'a>;
type Parameters<'a> = UnderlyingSolTuple<'a>;
type Token<'a> = <Self::Parameters<'a> as ::alloy_sol_types::SolType>::TokenType<'a>;

const SIGNATURE: &'static str = #signature;
const SELECTOR: [u8; 4] = #selector;

fn new<'a>(tuple: <Self::Tuple<'a> as ::alloy_sol_types::SolType>::RustType) -> Self {
fn new<'a>(tuple: <Self::Parameters<'a> as ::alloy_sol_types::SolType>::RustType) -> Self {
tuple.into()
}

Expand Down
6 changes: 3 additions & 3 deletions crates/sol-macro/src/expand/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ fn expand_call(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result<TokenStream>

#[automatically_derived]
impl ::alloy_sol_types::SolCall for #call_name {
type Tuple<'a> = #call_tuple;
type Token<'a> = <Self::Tuple<'a> as ::alloy_sol_types::SolType>::TokenType<'a>;
type Arguments<'a> = #call_tuple;
type Token<'a> = <Self::Arguments<'a> as ::alloy_sol_types::SolType>::TokenType<'a>;

type Return = #return_name;

Expand All @@ -136,7 +136,7 @@ fn expand_call(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result<TokenStream>
const SIGNATURE: &'static str = #signature;
const SELECTOR: [u8; 4] = #selector;

fn new<'a>(tuple: <Self::Tuple<'a> as ::alloy_sol_types::SolType>::RustType) -> Self {
fn new<'a>(tuple: <Self::Arguments<'a> as ::alloy_sol_types::SolType>::RustType) -> Self {
tuple.into()
}

Expand Down
16 changes: 8 additions & 8 deletions crates/sol-types/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait SolError: Sized {
/// The underlying tuple type which represents the error's members.
///
/// If the error has no arguments, this will be the unit type `()`
type Tuple<'a>: SolType<TokenType<'a> = Self::Token<'a>>;
type Parameters<'a>: SolType<TokenType<'a> = Self::Token<'a>>;

/// The corresponding [`TokenSeq`] type.
type Token<'a>: TokenSeq<'a>;
Expand All @@ -29,7 +29,7 @@ pub trait SolError: Sized {
const SELECTOR: [u8; 4];

/// Convert from the tuple type used for ABI encoding and decoding.
fn new(tuple: <Self::Tuple<'_> as SolType>::RustType) -> Self;
fn new(tuple: <Self::Parameters<'_> as SolType>::RustType) -> Self;

/// Convert to the token type used for EIP-712 encoding and decoding.
fn tokenize(&self) -> Self::Token<'_>;
Expand All @@ -38,7 +38,7 @@ pub trait SolError: Sized {
/// selector.
fn encoded_size(&self) -> usize {
// This avoids unnecessary clones.
if let Some(size) = <Self::Tuple<'_> as SolType>::ENCODED_SIZE {
if let Some(size) = <Self::Parameters<'_> as SolType>::ENCODED_SIZE {
return size
}
self.tokenize().total_words() * Word::len_bytes()
Expand All @@ -48,7 +48,7 @@ pub trait SolError: Sized {
/// selector.
#[inline]
fn decode_raw(data: &[u8], validate: bool) -> Result<Self> {
<Self::Tuple<'_> as SolType>::decode(data, validate).map(Self::new)
<Self::Parameters<'_> as SolType>::decode(data, validate).map(Self::new)
}

/// ABI decode this error's arguments from the given slice, **with** the
Expand Down Expand Up @@ -137,14 +137,14 @@ impl From<&str> for Revert {
}

impl SolError for Revert {
type Parameters<'a> = (crate::sol_data::String,);
type Token<'a> = (PackedSeqToken<'a>,);
type Tuple<'a> = (crate::sol_data::String,);

const SIGNATURE: &'static str = "Error(string)";
const SELECTOR: [u8; 4] = [0x08, 0xc3, 0x79, 0xa0];

#[inline]
fn new(tuple: <Self::Tuple<'_> as SolType>::RustType) -> Self {
fn new(tuple: <Self::Parameters<'_> as SolType>::RustType) -> Self {
Self { reason: tuple.0 }
}

Expand Down Expand Up @@ -246,14 +246,14 @@ impl From<U256> for Panic {
}

impl SolError for Panic {
type Parameters<'a> = (crate::sol_data::Uint<256>,);
type Token<'a> = (WordToken,);
type Tuple<'a> = (crate::sol_data::Uint<256>,);

const SIGNATURE: &'static str = "Panic(uint256)";
const SELECTOR: [u8; 4] = [0x4e, 0x48, 0x7b, 0x71];

#[inline]
fn new(tuple: <Self::Tuple<'_> as SolType>::RustType) -> Self {
fn new(tuple: <Self::Parameters<'_> as SolType>::RustType) -> Self {
Self { code: tuple.0 }
}

Expand Down
8 changes: 4 additions & 4 deletions crates/sol-types/src/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait SolCall: Sized {
/// The underlying tuple type which represents this type's arguments.
///
/// If this type has no arguments, this will be the unit type `()`.
type Tuple<'a>: SolType<TokenType<'a> = Self::Token<'a>>;
type Arguments<'a>: SolType<TokenType<'a> = Self::Token<'a>>;

/// The arguments' corresponding [TokenSeq] type.
type Token<'a>: TokenSeq<'a>;
Expand All @@ -34,15 +34,15 @@ pub trait SolCall: Sized {
const SELECTOR: [u8; 4];

/// Convert from the tuple type used for ABI encoding and decoding.
fn new(tuple: <Self::Tuple<'_> as SolType>::RustType) -> Self;
fn new(tuple: <Self::Arguments<'_> as SolType>::RustType) -> Self;

/// Tokenize the call's arguments.
fn tokenize(&self) -> Self::Token<'_>;

/// The size of the encoded data in bytes, **without** its selector.
fn encoded_size(&self) -> usize {
// This avoids unnecessary clones.
if let Some(size) = <Self::Tuple<'_> as SolType>::ENCODED_SIZE {
if let Some(size) = <Self::Arguments<'_> as SolType>::ENCODED_SIZE {
return size
}

Expand All @@ -53,7 +53,7 @@ pub trait SolCall: Sized {
/// selector.
#[inline]
fn decode_raw(data: &[u8], validate: bool) -> Result<Self> {
<Self::Tuple<'_> as SolType>::decode(data, validate).map(Self::new)
<Self::Arguments<'_> as SolType>::decode(data, validate).map(Self::new)
}

/// ABI decode this call's arguments from the given slice, **with** the
Expand Down