Skip to content

Commit

Permalink
no need to import alloc or sp-std
Browse files Browse the repository at this point in the history
  • Loading branch information
yjhmelody committed May 13, 2024
1 parent 581a958 commit e53ab86
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion precompiles/macro/docs/precompile_macro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `#[precompile]` procedural macro.
# `#[precompile]` procedural macro

This procedural macro allows to simplify the implementation of an EVM precompile or precompile set
using an `impl` block with annotations to automatically generate:
Expand Down
6 changes: 3 additions & 3 deletions precompiles/macro/src/precompile/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Precompile {
}
)*

pub fn encode(self) -> ::alloc::vec::Vec<u8> {
pub fn encode(self) -> ::precompile_utils::__alloc::vec::Vec<u8> {
use ::precompile_utils::solidity::codec::Writer;
match self {
#(
Expand All @@ -232,10 +232,10 @@ impl Precompile {
}
}

impl #impl_generics From<#enum_ident #ty_generics> for ::alloc::vec::Vec<u8>
impl #impl_generics From<#enum_ident #ty_generics> for ::precompile_utils::__alloc::vec::Vec<u8>
#where_clause
{
fn from(a: #enum_ident #ty_generics) -> ::alloc::vec::Vec<u8> {
fn from(a: #enum_ident #ty_generics) -> ::precompile_utils::__alloc::vec::Vec<u8> {
a.encode()
}
}
Expand Down
6 changes: 3 additions & 3 deletions precompiles/macro/tests/expand/precompile.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ where
pub fn fallback_selectors() -> &'static [u32] {
&[]
}
pub fn encode(self) -> ::alloc::vec::Vec<u8> {
pub fn encode(self) -> ::precompile_utils::__alloc::vec::Vec<u8> {
use precompile_utils::solidity::codec::Writer;
match self {
Self::batch_all {
Expand Down Expand Up @@ -283,11 +283,11 @@ where
}
}
}
impl<Runtime> From<BatchPrecompileCall<Runtime>> for ::alloc::vec::Vec<u8>
impl<Runtime> From<BatchPrecompileCall<Runtime>> for ::precompile_utils::__alloc::vec::Vec<u8>
where
Runtime: Get<u32>,
{
fn from(a: BatchPrecompileCall<Runtime>) -> ::alloc::vec::Vec<u8> {
fn from(a: BatchPrecompileCall<Runtime>) -> ::precompile_utils::__alloc::vec::Vec<u8> {
a.encode()
}
}
Expand Down
6 changes: 3 additions & 3 deletions precompiles/macro/tests/expand/precompileset.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ where
pub fn transfer_ownership_selectors() -> &'static [u32] {
&[4076725131u32, 4030008324u32]
}
pub fn encode(self) -> ::alloc::vec::Vec<u8> {
pub fn encode(self) -> ::precompile_utils::__alloc::vec::Vec<u8> {
use precompile_utils::solidity::codec::Writer;
match self {
Self::allowance { owner, spender } => Writer::new_with_selector(3714247998u32)
Expand Down Expand Up @@ -1012,11 +1012,11 @@ where
}
}
}
impl<Runtime> From<PrecompileSetCall<Runtime>> for ::alloc::vec::Vec<u8>
impl<Runtime> From<PrecompileSetCall<Runtime>> for ::precompile_utils::__alloc::vec::Vec<u8>
where
Runtime: Get<u32>,
{
fn from(a: PrecompileSetCall<Runtime>) -> ::alloc::vec::Vec<u8> {
fn from(a: PrecompileSetCall<Runtime>) -> ::precompile_utils::__alloc::vec::Vec<u8> {
a.encode()
}
}
Expand Down
6 changes: 3 additions & 3 deletions precompiles/macro/tests/expand/returns_tuple.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ExamplePrecompileCall {
pub fn example_selectors() -> &'static [u32] {
&[1412775727u32]
}
pub fn encode(self) -> ::alloc::vec::Vec<u8> {
pub fn encode(self) -> ::precompile_utils::__alloc::vec::Vec<u8> {
use precompile_utils::solidity::codec::Writer;
match self {
Self::example {} => Writer::new_with_selector(1412775727u32).build(),
Expand All @@ -82,8 +82,8 @@ impl ExamplePrecompileCall {
}
}
}
impl From<ExamplePrecompileCall> for ::alloc::vec::Vec<u8> {
fn from(a: ExamplePrecompileCall) -> ::alloc::vec::Vec<u8> {
impl From<ExamplePrecompileCall> for ::precompile_utils::__alloc::vec::Vec<u8> {
fn from(a: ExamplePrecompileCall) -> ::precompile_utils::__alloc::vec::Vec<u8> {
a.encode()
}
}
Expand Down
5 changes: 5 additions & 0 deletions precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ extern crate alloc;
// `precompile_utils` being in the list of imported crates.
extern crate self as precompile_utils;

#[doc(hidden)]
pub mod __alloc {
pub use ::alloc::*;
}

pub mod evm;
pub mod precompile_set;
pub mod substrate;
Expand Down

0 comments on commit e53ab86

Please sign in to comment.