difftreelog
refac: rename bytes4 -> Bytes4
in: master
6 files changed
crates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/solidity_interface.rs
+++ b/crates/evm-coder/procedural/src/solidity_interface.rs
@@ -610,7 +610,7 @@
let custom_signature = self.expand_custom_signature();
quote! {
const #screaming_name_signature: ::evm_coder::custom_signature::SignatureUnit = #custom_signature;
- const #screaming_name: ::evm_coder::types::bytes4 = {
+ const #screaming_name: ::evm_coder::types::Bytes4 = {
let mut sum = ::evm_coder::sha3_const::Keccak256::new();
let mut pos = 0;
while pos < Self::#screaming_name_signature.len {
@@ -974,7 +974,7 @@
#consts
)*
/// Return this call ERC165 selector
- pub const fn interface_id() -> ::evm_coder::types::bytes4 {
+ pub const fn interface_id() -> ::evm_coder::types::Bytes4 {
let mut interface_id = 0;
#(#interface_id)*
#(#inline_interface_id)*
@@ -1019,7 +1019,7 @@
}
}
impl #gen_ref ::evm_coder::Call for #call_name #gen_ref {
- fn parse(method_id: ::evm_coder::types::bytes4, reader: &mut ::evm_coder::abi::AbiReader) -> ::evm_coder::execution::Result<Option<Self>> {
+ fn parse(method_id: ::evm_coder::types::Bytes4, reader: &mut ::evm_coder::abi::AbiReader) -> ::evm_coder::execution::Result<Option<Self>> {
use ::evm_coder::abi::AbiRead;
match method_id {
::evm_coder::ERC165Call::INTERFACE_ID => return Ok(
@@ -1041,7 +1041,7 @@
#gen_where
{
/// Is this contract implements specified ERC165 selector
- pub fn supports_interface(this: &#name, interface_id: ::evm_coder::types::bytes4) -> bool {
+ pub fn supports_interface(this: &#name, interface_id: ::evm_coder::types::Bytes4) -> bool {
interface_id != u32::to_be_bytes(0xffffff) && (
interface_id == ::evm_coder::ERC165Call::INTERFACE_ID ||
interface_id == Self::interface_id()
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -81,9 +81,9 @@
}
}
-impl_abi_type!(bytes4, bytes4, false);
-impl AbiRead for bytes4 {
- fn abi_read(reader: &mut AbiReader) -> Result<bytes4> {
+impl_abi_type!(Bytes4, bytes4, false);
+impl AbiRead for Bytes4 {
+ fn abi_read(reader: &mut AbiReader) -> Result<Bytes4> {
reader.bytes4()
}
}
crates/evm-coder/src/abi/mod.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/mod.rs
+++ b/crates/evm-coder/src/abi/mod.rs
@@ -54,7 +54,7 @@
}
}
/// Start reading RLP buffer, parsing first 4 bytes as selector
- pub fn new_call(buf: &'i [u8]) -> Result<(bytes4, Self)> {
+ pub fn new_call(buf: &'i [u8]) -> Result<(Bytes4, Self)> {
if buf.len() < 4 {
return Err(Error::Error(ExitError::OutOfOffset));
}
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -132,7 +132,7 @@
use primitive_types::{U256, H160, H256};
pub type Address = H160;
- pub type bytes4 = [u8; 4];
+ pub type Bytes4 = [u8; 4];
pub type topic = H256;
#[cfg(not(feature = "std"))]
@@ -191,7 +191,7 @@
/// Parseable EVM call, this trait should be implemented with [`solidity_interface`] macro
pub trait Call: Sized {
/// Parse call buffer into typed call enum
- fn parse(selector: types::bytes4, input: &mut AbiReader) -> execution::Result<Option<Self>>;
+ fn parse(selector: types::Bytes4, input: &mut AbiReader) -> execution::Result<Option<Self>>;
}
/// Intended to be used as `#[weight]` output type
@@ -227,22 +227,22 @@
/// implements specified interface
SupportsInterface {
/// Requested interface
- interface_id: types::bytes4,
+ interface_id: types::Bytes4,
},
}
impl ERC165Call {
/// ERC165 selector is provided by standard
- pub const INTERFACE_ID: types::bytes4 = u32::to_be_bytes(0x01ffc9a7);
+ pub const INTERFACE_ID: types::Bytes4 = u32::to_be_bytes(0x01ffc9a7);
}
impl Call for ERC165Call {
- fn parse(selector: types::bytes4, input: &mut AbiReader) -> execution::Result<Option<Self>> {
+ fn parse(selector: types::Bytes4, input: &mut AbiReader) -> execution::Result<Option<Self>> {
if selector != Self::INTERFACE_ID {
return Ok(None);
}
Ok(Some(Self::SupportsInterface {
- interface_id: types::bytes4::abi_read(input)?,
+ interface_id: types::Bytes4::abi_read(input)?,
}))
}
}
crates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth1use super::{TypeCollector, SolidityTypeName, SolidityTupleTy};2use crate::{sealed, types::*};3use core::fmt;4use primitive_types::{U256, H160};56macro_rules! solidity_type_name {7 ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => {8 $(9 impl SolidityTypeName for $ty {10 fn solidity_name(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {11 write!(writer, $name)12 }13 fn is_simple() -> bool {14 $simple15 }16 fn solidity_default(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {17 write!(writer, $default)18 }19 }20 )*21 };22}2324solidity_type_name! {25 u8 => "uint8" true = "0",26 u32 => "uint32" true = "0",27 u64 => "uint64" true = "0",28 u128 => "uint128" true = "0",29 U256 => "uint256" true = "0",30 bytes4 => "bytes4" true = "bytes4(0)",31 H160 => "address" true = "0x0000000000000000000000000000000000000000",32 string => "string" false = "\"\"",33 bytes => "bytes" false = "hex\"\"",34 bool => "bool" true = "false",35}3637impl SolidityTypeName for () {38 fn solidity_name(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {39 Ok(())40 }41 fn is_simple() -> bool {42 true43 }44 fn solidity_default(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {45 Ok(())46 }47 fn is_void() -> bool {48 true49 }50}5152impl<T: SolidityTypeName + sealed::CanBePlacedInVec> SolidityTypeName for Vec<T> {53 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {54 T::solidity_name(writer, tc)?;55 write!(writer, "[]")56 }57 fn is_simple() -> bool {58 false59 }60 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {61 write!(writer, "new ")?;62 T::solidity_name(writer, tc)?;63 write!(writer, "[](0)")64 }65}6667macro_rules! count {68 () => (0usize);69 ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));70}7172macro_rules! impl_tuples {73 ($($ident:ident)+) => {74 impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {75 fn fields(tc: &TypeCollector) -> Vec<string> {76 let mut collected = Vec::with_capacity(Self::len());77 $({78 let mut out = string::new();79 $ident::solidity_name(&mut out, tc).expect("no fmt error");80 collected.push(out);81 })*;82 collected83 }8485 fn len() -> usize {86 count!($($ident)*)87 }88 }89 impl<$($ident: SolidityTypeName + 'static),+> SolidityTypeName for ($($ident,)+) {90 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {91 write!(writer, "{}", tc.collect_tuple::<Self>())92 }93 fn is_simple() -> bool {94 false95 }96 #[allow(unused_assignments)]97 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {98 write!(writer, "{}(", tc.collect_tuple::<Self>())?;99 let mut first = true;100 $(101 if !first {102 write!(writer, ",")?;103 } else {104 first = false;105 }106 <$ident>::solidity_default(writer, tc)?;107 )*108 write!(writer, ")")109 }110 }111 };112}113114impl_tuples! {A}115impl_tuples! {A B}116impl_tuples! {A B C}117impl_tuples! {A B C D}118impl_tuples! {A B C D E}119impl_tuples! {A B C D E F}120impl_tuples! {A B C D E F G}121impl_tuples! {A B C D E F G H}122impl_tuples! {A B C D E F G H I}123impl_tuples! {A B C D E F G H I J}124125//----- impls for Option -----126impl<T: SolidityTypeName + 'static> SolidityTypeName for Option<T> {127 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {128 write!(writer, "{}", tc.collect_struct::<Self>())129 }130 fn is_simple() -> bool {131 false132 }133 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {134 write!(writer, "{}(", tc.collect_struct::<Self>())?;135 bool::solidity_default(writer, tc)?;136 write!(writer, ", ");137 T::solidity_default(writer, tc)?;138 write!(writer, ")")139 }140}141142impl<T: SolidityTypeName> super::SolidityStructTy for Option<T> {143 fn generate_solidity_interface(tc: &TypeCollector) -> String {144 let mut solidity_name = "Option".to_string();145 let mut generic_name = String::new();146 T::solidity_name(&mut generic_name, tc);147 solidity_name.push(148 generic_name149 .chars()150 .next()151 .expect("Generic name is empty")152 .to_ascii_uppercase(),153 );154 solidity_name.push_str(&generic_name[1..]);155156 let interface = super::SolidityStruct {157 docs: &[" Optional value"],158 name: solidity_name.as_str(),159 fields: (160 super::SolidityStructField::<bool> {161 docs: &[" Shows the status of accessibility of value"],162 name: "status",163 ty: ::core::marker::PhantomData,164 },165 super::SolidityStructField::<T> {166 docs: &[" Actual value if `status` is true"],167 name: "value",168 ty: ::core::marker::PhantomData,169 },170 ),171 };172173 let mut out = String::new();174 let _ = interface.format(&mut out, tc);175 tc.collect(out);176177 solidity_name.to_string()178 }179}crates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity/mod.rs
+++ b/crates/evm-coder/src/solidity/mod.rs
@@ -360,7 +360,7 @@
pub struct SolidityInterface<F: SolidityFunctions> {
pub docs: &'static [&'static str],
- pub selector: bytes4,
+ pub selector: Bytes4,
pub name: &'static str,
pub is: &'static [&'static str],
pub functions: F,