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

chore: use crates.io uint, move crates to crates/* #31

Merged
merged 5 commits into from
May 12, 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
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

28 changes: 10 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
[workspace]
resolver = "2"
members = [
"abi",
"abi/sol-type-parser",
"dyn-abi",
"primitives",
"rlp",
"rlp/rlp-derive",
"uint",
"uint/ruint-macro",
]
members = ["crates/*"]

[workspace.package]
edition = "2021"
Expand All @@ -21,14 +12,15 @@ repository = "https://github.com/ethers-rs/core"

[workspace.dependencies]
# workspace crates
ethers-abi-enc = { version = "0.1.0", path = "abi", default-features = false }
sol-type-parser = { version = "0.1.0", path = "abi/sol-type-parser", default-features = false }
ethers-dyn-abi = { version = "0.1.0", path = "dyn-abi", default-features = false }
ethers-primitives = { version = "0.1.0", path = "primitives", default-features = false }
ethers-rlp = { version = "0.1.0", path = "rlp", default-features = false }
ethers-rlp-derive = { version = "0.1.0", path = "rlp/rlp-derive", default-features = false }
ruint = { version = "1.0.2", path = "uint", default-features = false }
ruint-macro = { version = "1.7.0", path = "uint/ruint-macro", default-features = false }
ethers-abi-enc = { version = "0.1.0", path = "crates/abi", default-features = false }
ethers-dyn-abi = { version = "0.1.0", path = "crates/dyn-abi", default-features = false }
ethers-primitives = { version = "0.1.0", path = "crates/primitives", default-features = false }
ethers-rlp = { version = "0.1.0", path = "crates/rlp", default-features = false }
ethers-rlp-derive = { version = "0.1.0", path = "crates/rlp-derive", default-features = false }
ethers-sol-type = { version = "0.1.0", path = "crates/sol-type", default-features = false }

ruint = { version = "1.8.0", git = "https://github.com/recmo/uint", default-features = false }
ruint-macro = { version = "1.0.2", git = "https://github.com/recmo/uint", default-features = false }

# serde
serde = { version = "1.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion abi/Cargo.toml → crates/abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository.workspace = true

[dependencies]
ethers-primitives.workspace = true
sol-type-parser.workspace = true
ethers-sol-type.workspace = true

hex = { workspace = true, features = ["alloc"] }

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion abi/src/lib.rs → crates/abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub mod no_std_prelude {
///
/// See the root crate docs for more information.
#[doc(inline)]
pub use sol_type_parser::sol;
pub use ethers_sol_type::sol;

/// The Word type for ABI Encoding
pub type Word = ethers_primitives::B256;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ mod tests {
BigIntConversionError, ParseSignedError,
};
use ruint::{
aliases::{U0, U1, U128, U160, U192, U256},
aliases::{U0, U1, U128, U160, U256},
BaseConvertError, ParseError,
};
use std::ops::Neg;
Expand All @@ -529,6 +529,9 @@ mod tests {
type I96 = Signed<96, 2>;
type U96 = Uint<96, 2>;

// TODO: ruint::aliases::U192 is bugged
type U192 = Uint<192, 3>;

#[test]
fn identities() {
macro_rules! test_identities {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 5 additions & 6 deletions rlp/src/decode.rs → crates/rlp/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,11 @@ mod alloc_impl {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "alloc"))]
mod tests {
extern crate alloc;

use super::*;
use alloc::vec;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt::Debug;
use hex_literal::hex;

Expand All @@ -414,10 +413,10 @@ mod tests {
fn check_decode_list<T, IT>(fixtures: IT)
where
T: Decodable + PartialEq + Debug,
IT: IntoIterator<Item = (Result<alloc::vec::Vec<T>, DecodeError>, &'static [u8])>,
IT: IntoIterator<Item = (Result<Vec<T>, DecodeError>, &'static [u8])>,
{
for (expected, mut input) in fixtures {
assert_eq!(vec::Vec::<T>::decode(&mut input), expected);
assert_eq!(Vec::<T>::decode(&mut input), expected);
if expected.is_ok() {
assert_eq!(input, &[]);
}
Expand Down
152 changes: 74 additions & 78 deletions rlp/src/encode.rs → crates/rlp/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub unsafe trait MaxEncodedLenAssoc: Encodable {
/// Use this to define length of an encoded entity
///
/// # Safety
/// Invalid value can cause the encoder to crash.
///
/// An invalid value can cause the encoder to crash.
#[macro_export]
macro_rules! impl_max_encoded_len {
($t:ty, $len:expr) => {
Expand Down Expand Up @@ -80,85 +81,63 @@ impl<'a, T: ?Sized + Encodable> Encodable for &'a mut T {
}
}

#[cfg(feature = "alloc")]
impl<'a, T: ?Sized + alloc::borrow::ToOwned + Encodable> Encodable for alloc::borrow::Cow<'a, T> {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

fn length(&self) -> usize {
(**self).length()
}
}

#[cfg(feature = "alloc")]
impl<T: ?Sized + Encodable> Encodable for alloc::boxed::Box<T> {
impl Encodable for [u8] {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
Header {
list: false,
payload_length: self.len(),
}
.encode(out);
}
out.put_slice(self);
}

fn length(&self) -> usize {
(**self).length()
let mut len = self.len();
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
len += length_of_length(self.len());
}
len
}
}

#[cfg(feature = "alloc")]
impl<T: ?Sized + Encodable> Encodable for alloc::rc::Rc<T> {
impl<const N: usize> Encodable for [u8; N] {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
Encodable::encode(&self[..], out)
}

fn length(&self) -> usize {
(**self).length()
Encodable::length(&self[..])
}
}

#[cfg(feature = "alloc")]
impl<T: ?Sized + Encodable> Encodable for alloc::sync::Arc<T> {
impl Encodable for str {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
Encodable::encode(self.as_bytes(), out)
}

fn length(&self) -> usize {
(**self).length()
Encodable::length(self.as_bytes())
}
}

impl Encodable for [u8] {
fn length(&self) -> usize {
let mut len = self.len();
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
len += length_of_length(self.len());
}
len
}

fn encode(&self, out: &mut dyn BufMut) {
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
Header {
list: false,
payload_length: self.len(),
}
.encode(out);
}
out.put_slice(self);
}
unsafe impl<const N: usize> MaxEncodedLenAssoc for [u8; N] {
const LEN: usize = N + length_of_length(N);
}

impl<const LEN: usize> Encodable for [u8; LEN] {
impl Encodable for bool {
#[inline]
fn length(&self) -> usize {
(self as &[u8]).length()
1
}

#[inline]
fn encode(&self, out: &mut dyn BufMut) {
(self as &[u8]).encode(out)
out.put_u8(*self as u8)
}
}

unsafe impl<const LEN: usize> MaxEncodedLenAssoc for [u8; LEN] {
const LEN: usize = LEN + length_of_length(LEN);
}

macro_rules! encodable_uint {
($t:ty) => {
#[allow(clippy::cmp_owned)]
Expand Down Expand Up @@ -213,16 +192,6 @@ max_encoded_len_uint!(u64);
encodable_uint!(u128);
max_encoded_len_uint!(u128);

impl Encodable for bool {
fn length(&self) -> usize {
(*self as u8).length()
}

fn encode(&self, out: &mut dyn BufMut) {
(*self as u8).encode(out)
}
}

impl_max_encoded_len!(bool, { <u8 as MaxEncodedLenAssoc>::LEN });

#[cfg(feature = "std")]
Expand Down Expand Up @@ -271,6 +240,46 @@ mod std_support {
mod alloc_support {
use super::*;

impl<'a, T: ?Sized + alloc::borrow::ToOwned + Encodable> Encodable for alloc::borrow::Cow<'a, T> {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::boxed::Box<T> {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::rc::Rc<T> {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

fn length(&self) -> usize {
(**self).length()
}
}

impl<T: ?Sized + Encodable> Encodable for alloc::sync::Arc<T> {
fn encode(&self, out: &mut dyn BufMut) {
(**self).encode(out)
}

fn length(&self) -> usize {
(**self).length()
}
}

impl<T: Encodable> Encodable for alloc::vec::Vec<T> {
fn length(&self) -> usize {
list_length(self)
Expand All @@ -292,25 +301,15 @@ mod alloc_support {
}
}

impl Encodable for &str {
fn encode(&self, out: &mut dyn BufMut) {
self.as_bytes().encode(out);
}

fn length(&self) -> usize {
self.as_bytes().length()
}
}

macro_rules! slice_impl {
($t:ty) => {
impl $crate::Encodable for $t {
fn length(&self) -> usize {
(&self[..]).length()
fn encode(&self, out: &mut dyn BufMut) {
Encodable::encode(&self[..], out)
}

fn encode(&self, out: &mut dyn bytes::BufMut) {
(&self[..]).encode(out)
fn length(&self) -> usize {
Encodable::length(&self[..])
}
}
};
Expand Down Expand Up @@ -391,12 +390,9 @@ pub fn encode_fixed_size<E: MaxEncodedLen<LEN>, const LEN: usize>(v: &E) -> Arra
out
}

#[cfg(test)]
#[cfg(all(test, feature = "alloc"))]
mod tests {
extern crate alloc;

use super::*;
use alloc::vec;
use bytes::BytesMut;
use hex_literal::hex;

Expand Down
5 changes: 5 additions & 0 deletions rlp/src/lib.rs → crates/rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#[cfg(feature = "alloc")]
extern crate alloc;

// Used in alloc tests.
#[cfg(test)]
#[allow(unused_extern_crates)]
extern crate hex_literal;

mod decode;
mod encode;
mod types;
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions rlp/tests/derive.rs → crates/rlp/tests/derive.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "derive")]

use ethers_rlp::*;

#[derive(RlpEncodable, RlpDecodable, RlpMaxEncodedLen, PartialEq, Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "sol-type-parser"
name = "ethers-sol-type"
version = "0.1.0"
description = "Solidity type parsing & generation for the ethers-abi-enc"
readme = "README.md"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sol-type-parser
# ethers-sol-type

This crate provides a proc macro that parses solidity types and generates
SolType types from them. This allows developers to specify complex solidity
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion uint
Submodule uint deleted from 7f93d3