Skip to content

Commit

Permalink
chore: clean ups (#150)
Browse files Browse the repository at this point in the history
* chore: clean ups

* chore: rename exported prelude to 'private'

* refactor: eip712 domain macro

* test: update fixtures

* docs
  • Loading branch information
DaniPopes authored Jun 25, 2023
1 parent 393d323 commit f3e46f6
Show file tree
Hide file tree
Showing 27 changed files with 350 additions and 538 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Alloy

Core libraries at the root of the Rust Ethereum ecosystem.

Alloy is a rewrite of ethers-rs from the ground up, with exciting new features,
high performance & excellent docs.
Ethers-rs will continue to be maintained until we have feature-parity in Alloy.
Expand Down
3 changes: 1 addition & 2 deletions crates/rlp-derive/src/de.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::utils::{attributes_include, field_ident, is_optional, parse_struct, EMPTY_STRING_CODE};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Error, Result};

use crate::utils::{attributes_include, field_ident, is_optional, parse_struct, EMPTY_STRING_CODE};

pub(crate) fn impl_decodable(ast: &syn::DeriveInput) -> Result<TokenStream> {
let body = parse_struct(ast, "RlpDecodable")?;

Expand Down
6 changes: 2 additions & 4 deletions crates/rlp-derive/src/en.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::iter::Peekable;

use crate::utils::{attributes_include, field_ident, is_optional, parse_struct, EMPTY_STRING_CODE};
use proc_macro2::TokenStream;
use quote::quote;
use std::iter::Peekable;
use syn::{Error, Result};

use crate::utils::{attributes_include, field_ident, is_optional, parse_struct, EMPTY_STRING_CODE};

pub(crate) fn impl_encodable(ast: &syn::DeriveInput) -> Result<TokenStream> {
let body = parse_struct(ast, "RlpEncodable")?;

Expand Down
7 changes: 3 additions & 4 deletions crates/sol-macro/src/expand/event.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! [`ItemEvent`] expansion.

use crate::expand::r#type::expand_event_tokenize_func;

use super::{anon_name, expand_tuple_types, expand_type, ExpCtxt};
use crate::expand::r#type::expand_event_tokenize_func;
use ast::{EventParameter, ItemEvent, SolIdent};
use proc_macro2::TokenStream;
use quote::{quote, quote_spanned};
Expand Down Expand Up @@ -120,8 +119,8 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, event: &ItemEvent) -> Result<TokenStream>
type TopicList = (#(#topic_list,)*);

const SIGNATURE: &'static str = #signature;
const SIGNATURE_HASH: ::alloy_sol_types::B256 =
::alloy_sol_types::Word::new(#selector);
const SIGNATURE_HASH: ::alloy_sol_types::private::B256 =
::alloy_sol_types::private::B256::new(#selector);

const ANONYMOUS: bool = #anonymous;

Expand Down
4 changes: 2 additions & 2 deletions crates/sol-macro/src/expand/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub(super) fn expand(_cx: &ExpCtxt<'_>, s: &ItemStruct) -> Result<TokenStream> {

#[allow(non_camel_case_types, non_snake_case, clippy::style)]
const _: () = {
use ::alloy_sol_types::no_std_prelude::*;
use ::alloy_sol_types::private::*;

#convert

Expand Down Expand Up @@ -155,7 +155,7 @@ pub(super) fn expand(_cx: &ExpCtxt<'_>, s: &ItemStruct) -> Result<TokenStream> {
let mut out = Vec::new();
<Self as ::alloy_sol_types::EventTopic>::encode_topic_preimage(rust, &mut out);
::alloy_sol_types::token::WordToken(
::alloy_sol_types::keccak256(out)
::alloy_sol_types::private::keccak256(out)
)
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/sol-macro/src/expand/type.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! [`Type`] expansion.

use crate::expand::generate_name;

use super::ExpCtxt;
use crate::expand::generate_name;
use ast::{EventParameter, Item, Parameters, Type, TypeArray, VariableDeclaration};
use proc_macro2::{Literal, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
Expand Down
9 changes: 4 additions & 5 deletions crates/sol-types/src/coder/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// except according to those terms.
//

use crate::{encode, no_std_prelude::*, token::TokenSeq, util, Error, Result, TokenType, Word};
use crate::{encode, token::TokenSeq, util, Error, Result, TokenType, Word};
use alloc::borrow::Cow;
use core::{fmt, slice::SliceIndex};

/// The [`Decoder`] wraps a byte slice with necessary info to progressively
Expand Down Expand Up @@ -243,13 +244,11 @@ pub fn decode_params<'de, T: TokenSeq<'de>>(data: &'de [u8], validate: bool) ->

#[cfg(test)]
mod tests {
use crate::{sol_data, util::pad_u32, SolType};
use alloc::string::ToString;
use alloy_primitives::{Address, B256, U256};
use hex_literal::hex;

#[cfg(not(feature = "std"))]
use crate::no_std_prelude::*;
use crate::{sol_data, util::pad_u32, SolType};

#[test]
fn decode_static_tuple_of_addresses_and_uints() {
type MyTy = (sol_data::Address, sol_data::Address, sol_data::Uint<256>);
Expand Down
8 changes: 3 additions & 5 deletions crates/sol-types/src/coder/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// except according to those terms.

use crate::{
no_std_prelude::*,
token::TokenSeq,
util::{pad_u32, words_for},
TokenType, Word,
};
use alloc::vec::Vec;
use core::mem;

/// An ABI encoder.
Expand Down Expand Up @@ -171,13 +171,11 @@ pub fn encode_params<'a, T: TokenSeq<'a>>(token: &T) -> Vec<u8> {

#[cfg(test)]
mod tests {
use crate::{sol_data, SolType};
use alloc::{borrow::ToOwned, string::ToString};
use alloy_primitives::{Address, U256};
use hex_literal::hex;

#[cfg(not(feature = "std"))]
use crate::no_std_prelude::*;
use crate::{sol_data, SolType};

#[test]
fn encode_address() {
let address = Address::from([0x11u8; 20]);
Expand Down
3 changes: 2 additions & 1 deletion crates/sol-types/src/coder/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//! - Tuples (T, U, V, ...)
//! - Dynamic-length byte arrays `u8[]`

use crate::{no_std_prelude::*, Decoder, Encoder, Result, Word};
use crate::{Decoder, Encoder, Result, Word};
use alloc::vec::Vec;
use alloy_primitives::{Address, FixedBytes, I256, U256};
use core::fmt;

Expand Down
Loading

0 comments on commit f3e46f6

Please sign in to comment.