difftreelog
refactor unify function and type signature handling
in: master
12 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
@@ -24,8 +24,8 @@
use quote::{quote, format_ident};
use inflector::cases;
use syn::{
- Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,
- MetaNameValue, PatType, PathArguments, ReturnType, Type,
+ Expr, FnArg, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue,
+ PatType, ReturnType, Type,
spanned::Spanned,
parse::{Parse, ParseStream},
parenthesized, Token, LitInt, LitStr,
@@ -601,12 +601,12 @@
let screaming_name_signature = format_ident!("{}_SIGNATURE", &self.screaming_name);
let custom_signature = self.expand_custom_signature();
quote! {
- const #screaming_name_signature: ::evm_coder::custom_signature::FunctionSignature = #custom_signature;
+ const #screaming_name_signature: ::evm_coder::custom_signature::SignatureUnit = #custom_signature;
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.unit.len {
- sum = sum.update(&[Self::#screaming_name_signature.unit.data[pos]; 1]);
+ while pos < Self::#screaming_name_signature.len {
+ sum = sum.update(&[Self::#screaming_name_signature.data[pos]; 1]);
pos += 1;
}
let a = sum.finalize();
@@ -710,192 +710,28 @@
};
quote! {
Self::#pascal_name #matcher => ().into()
- }
- }
- }
-
- fn expand_type(ty: &Type, token_stream: &mut proc_macro2::TokenStream, read_signature: bool) {
- match ty {
- Type::Path(tp) => {
- if let Some(qself) = &tp.qself {
- panic!("no receiver expected {:?}", qself.ty.span());
- }
- let path = &tp.path;
- if path.segments.len() != 1 {
- panic!("expected path to have only one segment {:?}", path.span());
- }
- let last_segment = path.segments.last().unwrap();
-
- if last_segment.ident == "Vec" {
- let args = match &last_segment.arguments {
- PathArguments::AngleBracketed(e) => e,
- _ => {
- panic!("missing Vec generic {:?}", last_segment.arguments.span());
- }
- };
- let args = &args.args;
- if args.len() != 1 {
- panic!("expected only one generic for vec {:?}", args.span());
- }
- let arg = args.first().expect("first arg");
-
- let ty = match arg {
- GenericArgument::Type(ty) => ty,
- _ => {
- panic!("expected first generic to be type {:?}", arg.span());
- }
- };
-
- let mut vec_token = proc_macro2::TokenStream::new();
- Self::expand_type(ty, &mut vec_token, false);
- vec_token = if read_signature {
- quote! { (<Vec<#vec_token>>::SIGNATURE) }
- } else {
- quote! { <Vec<#vec_token>> }
- };
- token_stream.extend(vec_token);
- } else {
- if !last_segment.arguments.is_empty() {
- panic!(
- "unexpected generic arguments for non-vec type {:?}",
- last_segment.arguments.span()
- );
- }
-
- let ident = &last_segment.ident;
- let plain_token = if read_signature {
- quote! {
- (<#ident>::SIGNATURE)
- }
- } else {
- quote! {
- #ident
- }
- };
-
- token_stream.extend(plain_token);
- }
- }
-
- Type::Tuple(tt) => {
- // for ty in tt.elems.iter() {
- // out.push(AbiType::try_from(ty)?)
- // }
-
- let mut tuple_types = proc_macro2::TokenStream::new();
- let mut is_first = true;
-
- for ty in tt.elems.iter() {
- if is_first {
- is_first = false
- } else {
- tuple_types.extend(quote!(,));
- }
- Self::expand_type(ty, &mut tuple_types, false);
- }
- tuple_types = if read_signature {
- quote! { (<(#tuple_types)>::SIGNATURE) }
- } else {
- quote! { (#tuple_types) }
- };
- token_stream.extend(tuple_types);
}
-
- // Type::Array(arr) => {
- // let wrapped = AbiType::try_from(&arr.elem)?;
- // match &arr.len {
- // Expr::Lit(l) => match &l.lit {
- // Lit::Int(i) => {
- // let num = i.base10_parse::<usize>()?;
- // Ok(AbiType::Array(Box::new(wrapped), num as usize))
- // }
- // _ => Err(syn::Error::new(arr.len.span(), "should be int literal")),
- // },
- // _ => Err(syn::Error::new(arr.len.span(), "should be literal")),
- // }
- // }
- _ => panic!("Unexpected type {ty:?}"),
}
- // match ty {
- // AbiType::Plain(ref ident) => {
- // let plain_token = if read_signature {
- // quote! {
- // (<#ident>::SIGNATURE)
- // }
- // } else {
- // quote! {
- // #ident
- // }
- // };
-
- // token_stream.extend(plain_token);
- // }
-
- // AbiType::Tuple(ref tuple_type) => {
- // let mut tuple_types = proc_macro2::TokenStream::new();
- // let mut is_first = true;
-
- // for ty in tuple_type {
- // if is_first {
- // is_first = false
- // } else {
- // tuple_types.extend(quote!(,));
- // }
- // Self::expand_type(ty, &mut tuple_types, false);
- // }
- // tuple_types = if read_signature {
- // quote! { (<(#tuple_types)>::SIGNATURE) }
- // } else {
- // quote! { (#tuple_types) }
- // };
- // token_stream.extend(tuple_types);
- // }
-
- // AbiType::Vec(ref vec_type) => {
- // let mut vec_token = proc_macro2::TokenStream::new();
- // Self::expand_type(vec_type.as_ref(), &mut vec_token, false);
- // vec_token = if read_signature {
- // quote! { (<Vec<#vec_token>>::SIGNATURE) }
- // } else {
- // quote! { <Vec<#vec_token>> }
- // };
- // token_stream.extend(vec_token);
- // }
-
- // AbiType::Array(_, _) => todo!("Array eth signature"),
- // };
}
fn expand_custom_signature(&self) -> proc_macro2::TokenStream {
- let mut token_stream = TokenStream::new();
+ let mut args = TokenStream::new();
let mut is_first = true;
- for arg in &self.args {
- if arg.is_special() {
- continue;
- }
-
- if is_first {
- is_first = false;
- } else {
- token_stream.extend(quote!(,));
- }
- Self::expand_type(&arg.ty, &mut token_stream, true);
+ for arg in self.args.iter().filter(|a| !a.is_special()) {
+ is_first = false;
+ let ty = &arg.ty;
+ args.extend(quote! {nameof(#ty)});
+ args.extend(quote! {fixed(",")})
}
+ // Remove trailing comma
if !is_first {
- token_stream.extend(quote!(,));
+ args.extend(quote! {shift_left(1)})
}
let func_name = self.camel_name.clone();
- let func_name = quote!(SignaturePreferences {
- open_name: Some(SignatureUnit::new(#func_name)),
- open_delimiter: Some(SignatureUnit::new("(")),
- param_delimiter: Some(SignatureUnit::new(",")),
- close_delimiter: Some(SignatureUnit::new(")")),
- close_name: None,
- });
- quote!({ ::evm_coder::make_signature!(new fn(#func_name), #token_stream) })
+ quote! { ::evm_coder::make_signature!(new fixed(#func_name) fixed("(") #args fixed(")")) }
}
fn expand_solidity_function(&self) -> proc_macro2::TokenStream {
@@ -916,12 +752,6 @@
let screaming_name = &self.screaming_name;
let hide = self.hide;
let custom_signature = self.expand_custom_signature();
- let custom_signature = quote!(
- {
- const cs: FunctionSignature = #custom_signature;
- cs
- }
- );
let is_payable = self.has_value_args;
quote! {
crates/evm-coder/src/abi.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -27,7 +27,7 @@
execution::{Error, ResultWithPostInfo, WithPostDispatchInfo},
types::*,
make_signature,
- custom_signature::{SignatureUnit, SIGNATURE_SIZE_LIMIT},
+ custom_signature::{SignatureUnit},
};
use crate::execution::Result;
@@ -428,7 +428,7 @@
}
impl<R: Signature> Signature for Vec<R> {
- make_signature!(new nameof(R) fixed("[]"));
+ const SIGNATURE: SignatureUnit = make_signature!(new nameof(R) fixed("[]"));
}
impl sealed::CanBePlacedInVec for EthCrossAccount {}
@@ -522,7 +522,7 @@
where
$($ident: Signature,)+
{
- make_signature!(
+ const SIGNATURE: SignatureUnit = make_signature!(
new fixed("(")
$(nameof($ident) fixed(","))+
shift_left(1)
@@ -758,13 +758,13 @@
1ACF2D55
0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]
0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]
-
+
0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address
000000000000000000000000000000000000000000000000000000000000000A // uint256
-
+
000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address
0000000000000000000000000000000000000000000000000000000000000014 // uint256
-
+
0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address
000000000000000000000000000000000000000000000000000000000000001E // uint256
"
crates/evm-coder/src/custom_signature.rsdiffbeforeafterboth--- a/crates/evm-coder/src/custom_signature.rs
+++ b/crates/evm-coder/src/custom_signature.rs
@@ -74,132 +74,11 @@
//! impl<T: SoliditySignature> SoliditySignature for Vec<T> {
//! make_signature!(new nameof(T) fixed("[]"));
//! }
-//!
-//! // Function signature settings
-//! const SIGNATURE_PREFERENCES: SignaturePreferences = SignaturePreferences {
-//! open_name: Some(SignatureUnit::new("some_funk")),
-//! open_delimiter: Some(SignatureUnit::new("(")),
-//! param_delimiter: Some(SignatureUnit::new(",")),
-//! close_delimiter: Some(SignatureUnit::new(")")),
-//! close_name: None,
-//! };
-//!
-//! // Create functions signatures
-//! fn make_func_without_args() {
-//! const SIG: FunctionSignature = make_signature!(
-//! new fn(SIGNATURE_PREFERENCES),
-//! );
-//! let name = SIG.as_str();
-//! similar_asserts::assert_eq!(name, "some_funk()");
-//! }
-//!
-//! fn make_func_with_3_args() {
-//! const SIG: FunctionSignature = make_signature!(
-//! new fn(SIGNATURE_PREFERENCES),
-//! (<u8>::SIGNATURE),
-//! (<u8>::SIGNATURE),
-//! (<Vec<u8>>::SIGNATURE),
-//! );
-//! let name = SIG.as_str();
-//! similar_asserts::assert_eq!(name, "some_funk(uint8,uint8,uint8[])");
-//! }
//! ```
-use core::str::from_utf8;
/// The maximum length of the signature.
pub const SIGNATURE_SIZE_LIMIT: usize = 256;
-
-/// Function signature formatting preferences.
-#[derive(Debug)]
-pub struct SignaturePreferences {
- /// The name of the function before the list of parameters: `*some*(param1,param2)func`
- pub open_name: Option<SignatureUnit>,
- /// Opening separator: `some*(*param1,param2)func`
- pub open_delimiter: Option<SignatureUnit>,
- /// Parameters separator: `some(param1*,*param2)func`
- pub param_delimiter: Option<SignatureUnit>,
- /// Closinging separator: `some(param1,param2*)*func`
- pub close_delimiter: Option<SignatureUnit>,
- /// The name of the function after the list of parameters: `some(param1,param2)*func*`
- pub close_name: Option<SignatureUnit>,
-}
-
-/// Constructs and stores the signature of the function.
-#[derive(Debug)]
-pub struct FunctionSignature {
- /// Storage for function signature.
- pub unit: SignatureUnit,
- preferences: SignaturePreferences,
-}
-impl FunctionSignature {
- /// Start constructing the signature. It is written to the storage
- /// [`SignaturePreferences::open_name`] and [`SignaturePreferences::open_delimiter`].
- pub const fn new(preferences: SignaturePreferences) -> FunctionSignature {
- let mut dst = [0_u8; SIGNATURE_SIZE_LIMIT];
- let mut dst_offset = 0;
- if let Some(ref name) = preferences.open_name {
- crate::make_signature!(@copy(name.data, dst, name.len, dst_offset));
- }
- if let Some(ref delimiter) = preferences.open_delimiter {
- crate::make_signature!(@copy(delimiter.data, dst, delimiter.len, dst_offset));
- }
- FunctionSignature {
- unit: SignatureUnit {
- data: dst,
- len: dst_offset,
- },
- preferences,
- }
- }
-
- /// Add a function parameter to the signature. It is written to the storage
- /// `param` [`SignatureUnit`] and [`SignaturePreferences::param_delimiter`].
- pub const fn add_param(
- signature: FunctionSignature,
- param: SignatureUnit,
- ) -> FunctionSignature {
- let mut dst = signature.unit.data;
- let mut dst_offset = signature.unit.len;
- crate::make_signature!(@copy(param.data, dst, param.len, dst_offset));
- if let Some(ref delimiter) = signature.preferences.param_delimiter {
- crate::make_signature!(@copy(delimiter.data, dst, delimiter.len, dst_offset));
- }
- FunctionSignature {
- unit: SignatureUnit {
- data: dst,
- len: dst_offset,
- },
- ..signature
- }
- }
-
- /// Complete signature construction. It is written to the storage
- /// [`SignaturePreferences::close_delimiter`] and [`SignaturePreferences::close_name`].
- pub const fn done(signature: FunctionSignature, owerride: bool) -> FunctionSignature {
- let mut dst = signature.unit.data;
- let mut dst_offset = signature.unit.len - if owerride { 1 } else { 0 };
- if let Some(ref delimiter) = signature.preferences.close_delimiter {
- crate::make_signature!(@copy(delimiter.data, dst, delimiter.len, dst_offset));
- }
- if let Some(ref name) = signature.preferences.close_name {
- crate::make_signature!(@copy(name.data, dst, name.len, dst_offset));
- }
- FunctionSignature {
- unit: SignatureUnit {
- data: dst,
- len: dst_offset,
- },
- ..signature
- }
- }
-
- /// Represent the signature as `&str'.
- pub fn as_str(&self) -> &str {
- from_utf8(&self.unit.data[..self.unit.len]).expect("bad utf-8")
- }
-}
-
/// Storage for the signature or its elements.
#[derive(Debug)]
pub struct SignatureUnit {
@@ -222,6 +101,10 @@
len: name_len,
}
}
+ /// String conversion
+ pub fn as_str(&self) -> Option<&str> {
+ core::str::from_utf8(&self.data[0..self.len]).ok()
+ }
}
/// ### Macro to create signatures of types and functions.
@@ -231,85 +114,52 @@
/// make_signature!(new fixed("uint8")); // Simple type
/// make_signature!(new fixed("(") nameof(u8) fixed(",") nameof(u8) fixed(")")); // Composite type
/// ```
-/// Format for creating a function of the function:
-/// ```ignore
-/// const SIG: FunctionSignature = make_signature!(
-/// new fn(SIGNATURE_PREFERENCES),
-/// (u8::SIGNATURE),
-/// (<(u8,u8)>::SIGNATURE),
-/// );
-/// ```
#[macro_export]
macro_rules! make_signature {
- (new fn($func:expr)$(,)*) => {
- {
- let fs = FunctionSignature::new($func);
- let fs = FunctionSignature::done(fs, false);
- fs
- }
- };
- (new fn($func:expr), $($tt:tt,)*) => {
- {
- let fs = FunctionSignature::new($func);
- let fs = make_signature!(@param; fs, $($tt),*);
- fs
- }
+ (new $($tt:tt)*) => {
+ ($crate::custom_signature::SignatureUnit {
+ data: {
+ let mut out = [0u8; $crate::custom_signature::SIGNATURE_SIZE_LIMIT];
+ let mut dst_offset = 0;
+ $crate::make_signature!(@data(out, dst_offset); $($tt)*);
+ out
+ },
+ len: {0 + $crate::make_signature!(@size; $($tt)*)},
+ })
};
- (@param; $func:expr) => {
- FunctionSignature::done($func, true)
+ (@size;) => {
+ 0
};
- (@param; $func:expr, $param:expr) => {
- make_signature!(@param; FunctionSignature::add_param($func, $param))
+ (@size; fixed($expr:expr) $($tt:tt)*) => {
+ $expr.len() + $crate::make_signature!(@size; $($tt)*)
};
- (@param; $func:expr, $param:expr, $($tt:tt),*) => {
- make_signature!(@param; FunctionSignature::add_param($func, $param), $($tt),*)
+ (@size; nameof($expr:ty) $($tt:tt)*) => {
+ <$expr>::SIGNATURE.len + $crate::make_signature!(@size; $($tt)*)
};
-
- (new $($tt:tt)*) => {
- const SIGNATURE: SignatureUnit = SignatureUnit {
- data: {
- let mut out = [0u8; SIGNATURE_SIZE_LIMIT];
- let mut dst_offset = 0;
- make_signature!(@data(out, dst_offset); $($tt)*);
- out
- },
- len: {0 + make_signature!(@size; $($tt)*)},
- };
- };
-
- (@size;) => {
- 0
- };
- (@size; fixed($expr:expr) $($tt:tt)*) => {
- $expr.len() + make_signature!(@size; $($tt)*)
- };
- (@size; nameof($expr:ty) $($tt:tt)*) => {
- <$expr>::SIGNATURE.len + make_signature!(@size; $($tt)*)
- };
(@size; shift_left($expr:expr) $($tt:tt)*) => {
- make_signature!(@size; $($tt)*) - $expr
+ $crate::make_signature!(@size; $($tt)*) - $expr
};
- (@data($dst:ident, $dst_offset:ident);) => {};
- (@data($dst:ident, $dst_offset:ident); fixed($expr:expr) $($tt:tt)*) => {
- {
- let data = $expr.as_bytes();
+ (@data($dst:ident, $dst_offset:ident);) => {};
+ (@data($dst:ident, $dst_offset:ident); fixed($expr:expr) $($tt:tt)*) => {
+ {
+ let data = $expr.as_bytes();
let data_len = data.len();
- make_signature!(@copy(data, $dst, data_len, $dst_offset));
- }
- make_signature!(@data($dst, $dst_offset); $($tt)*)
- };
- (@data($dst:ident, $dst_offset:ident); nameof($expr:ty) $($tt:tt)*) => {
- {
- make_signature!(@copy(&<$expr>::SIGNATURE.data, $dst, <$expr>::SIGNATURE.len, $dst_offset));
- }
- make_signature!(@data($dst, $dst_offset); $($tt)*)
- };
+ $crate::make_signature!(@copy(data, $dst, data_len, $dst_offset));
+ }
+ $crate::make_signature!(@data($dst, $dst_offset); $($tt)*)
+ };
+ (@data($dst:ident, $dst_offset:ident); nameof($expr:ty) $($tt:tt)*) => {
+ {
+ $crate::make_signature!(@copy(&<$expr>::SIGNATURE.data, $dst, <$expr>::SIGNATURE.len, $dst_offset));
+ }
+ $crate::make_signature!(@data($dst, $dst_offset); $($tt)*)
+ };
(@data($dst:ident, $dst_offset:ident); shift_left($expr:expr) $($tt:tt)*) => {
- $dst_offset -= $expr;
- make_signature!(@data($dst, $dst_offset); $($tt)*)
- };
+ $dst_offset -= $expr;
+ $crate::make_signature!(@data($dst, $dst_offset); $($tt)*)
+ };
(@copy($src:expr, $dst:expr, $src_len:expr, $dst_offset:ident)) => {
{
@@ -328,7 +178,7 @@
mod test {
use core::str::from_utf8;
- use super::{SIGNATURE_SIZE_LIMIT, SignatureUnit, FunctionSignature, SignaturePreferences};
+ use super::{SIGNATURE_SIZE_LIMIT, SignatureUnit};
trait Name {
const SIGNATURE: SignatureUnit;
@@ -339,19 +189,21 @@
}
impl Name for u8 {
- make_signature!(new fixed("uint8"));
+ const SIGNATURE: SignatureUnit = make_signature!(new fixed("uint8"));
}
impl Name for u32 {
- make_signature!(new fixed("uint32"));
+ const SIGNATURE: SignatureUnit = make_signature!(new fixed("uint32"));
}
impl<T: Name> Name for Vec<T> {
- make_signature!(new nameof(T) fixed("[]"));
+ const SIGNATURE: SignatureUnit = make_signature!(new nameof(T) fixed("[]"));
}
impl<A: Name, B: Name> Name for (A, B) {
- make_signature!(new fixed("(") nameof(A) fixed(",") nameof(B) fixed(")"));
+ const SIGNATURE: SignatureUnit =
+ make_signature!(new fixed("(") nameof(A) fixed(",") nameof(B) fixed(")"));
}
impl<A: Name> Name for (A,) {
- make_signature!(new fixed("(") nameof(A) fixed(",") shift_left(1) fixed(")"));
+ const SIGNATURE: SignatureUnit =
+ make_signature!(new fixed("(") nameof(A) fixed(",") shift_left(1) fixed(")"));
}
struct MaxSize();
@@ -361,14 +213,6 @@
len: SIGNATURE_SIZE_LIMIT,
};
}
-
- const SIGNATURE_PREFERENCES: SignaturePreferences = SignaturePreferences {
- open_name: Some(SignatureUnit::new("some_funk")),
- open_delimiter: Some(SignatureUnit::new("(")),
- param_delimiter: Some(SignatureUnit::new(",")),
- close_delimiter: Some(SignatureUnit::new(")")),
- close_name: None,
- };
#[test]
fn simple() {
@@ -421,68 +265,6 @@
#[test]
fn max_size() {
assert_eq!(<MaxSize>::name(), "!".repeat(SIGNATURE_SIZE_LIMIT));
- }
-
- #[test]
- fn make_func_without_args() {
- const SIG: FunctionSignature = make_signature!(
- new fn(SIGNATURE_PREFERENCES)
- );
- let name = SIG.as_str();
- similar_asserts::assert_eq!(name, "some_funk()");
- }
-
- #[test]
- fn make_func_with_1_args() {
- const SIG: FunctionSignature = make_signature!(
- new fn(SIGNATURE_PREFERENCES),
- (<u8>::SIGNATURE),
- );
- let name = SIG.as_str();
- similar_asserts::assert_eq!(name, "some_funk(uint8)");
- }
-
- #[test]
- fn make_func_with_2_args() {
- const SIG: FunctionSignature = make_signature!(
- new fn(SIGNATURE_PREFERENCES),
- (u8::SIGNATURE),
- (<Vec<u32>>::SIGNATURE),
- );
- let name = SIG.as_str();
- similar_asserts::assert_eq!(name, "some_funk(uint8,uint32[])");
- }
-
- #[test]
- fn make_func_with_3_args() {
- const SIG: FunctionSignature = make_signature!(
- new fn(SIGNATURE_PREFERENCES),
- (<u8>::SIGNATURE),
- (<u32>::SIGNATURE),
- (<Vec<u32>>::SIGNATURE),
- );
- let name = SIG.as_str();
- similar_asserts::assert_eq!(name, "some_funk(uint8,uint32,uint32[])");
- }
-
- #[test]
- fn make_slice_from_signature() {
- const SIG: FunctionSignature = make_signature!(
- new fn(SIGNATURE_PREFERENCES),
- (<u8>::SIGNATURE),
- (<u32>::SIGNATURE),
- (<Vec<u32>>::SIGNATURE),
- );
- const NAME: [u8; SIG.unit.len] = {
- let mut name: [u8; SIG.unit.len] = [0; SIG.unit.len];
- let mut i = 0;
- while i < SIG.unit.len {
- name[i] = SIG.unit.data[i];
- i += 1;
- }
- name
- };
- similar_asserts::assert_eq!(&NAME, b"some_funk(uint8,uint32,uint32[])");
}
#[test]
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -122,7 +122,7 @@
use primitive_types::{U256, H160, H256};
use core::str::from_utf8;
- use crate::custom_signature::{SignatureUnit, SIGNATURE_SIZE_LIMIT};
+ use crate::custom_signature::SignatureUnit;
pub trait Signature {
const SIGNATURE: SignatureUnit;
@@ -133,14 +133,14 @@
}
impl Signature for bool {
- make_signature!(new fixed("bool"));
+ const SIGNATURE: SignatureUnit = make_signature!(new fixed("bool"));
}
macro_rules! define_simple_type {
(type $ident:ident = $ty:ty) => {
pub type $ident = $ty;
impl Signature for $ty {
- make_signature!(new fixed(stringify!($ident)));
+ const SIGNATURE: SignatureUnit = make_signature!(new fixed(stringify!($ident)));
}
};
}
@@ -165,7 +165,7 @@
#[derive(Default, Debug)]
pub struct bytes(pub Vec<u8>);
impl Signature for bytes {
- make_signature!(new fixed("bytes"));
+ const SIGNATURE: SignatureUnit = make_signature!(new fixed("bytes"));
}
/// Solidity doesn't have `void` type, however we have special implementation
@@ -259,7 +259,7 @@
}
impl Signature for EthCrossAccount {
- make_signature!(new fixed("(address,uint256)"));
+ const SIGNATURE: SignatureUnit = make_signature!(new fixed("(address,uint256)"));
}
/// Convert `CrossAccountId` to `uint256`.
crates/evm-coder/src/solidity.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -32,7 +32,7 @@
cmp::Reverse,
};
use impl_trait_for_tuples::impl_for_tuples;
-use crate::{types::*, custom_signature::FunctionSignature};
+use crate::{types::*, custom_signature::SignatureUnit};
#[derive(Default)]
pub struct TypeCollector {
@@ -486,7 +486,7 @@
pub docs: &'static [&'static str],
pub selector: u32,
pub hide: bool,
- pub custom_signature: FunctionSignature,
+ pub custom_signature: SignatureUnit,
pub name: &'static str,
pub args: A,
pub result: R,
@@ -512,7 +512,7 @@
writeln!(
writer,
"\t{hide_comment}/// or in textual repr: {}",
- self.custom_signature.as_str()
+ self.custom_signature.as_str().expect("bad utf-8")
)?;
write!(writer, "\t{hide_comment}function {}(", self.name)?;
self.args.solidity_name(writer, tc)?;
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -21,8 +21,6 @@
types::*,
execution::{Result, Error},
weight,
- custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
- make_signature,
};
pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};
use pallet_evm_coder_substrate::dispatch_to_evm;
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -19,13 +19,7 @@
extern crate alloc;
use core::marker::PhantomData;
use evm_coder::{
- abi::AbiWriter,
- execution::Result,
- generate_stubgen, solidity_interface,
- types::*,
- ToLog,
- custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
- make_signature,
+ abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*, ToLog,
};
use pallet_evm::{
ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -19,15 +19,7 @@
extern crate alloc;
use core::char::{REPLACEMENT_CHARACTER, decode_utf16};
use core::convert::TryInto;
-use evm_coder::{
- ToLog,
- execution::*,
- generate_stubgen, solidity_interface,
- types::*,
- weight,
- custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
- make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
use up_data_structs::CollectionMode;
use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
use sp_std::vec::Vec;
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -24,15 +24,7 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{
- ToLog,
- execution::*,
- generate_stubgen, solidity, solidity_interface,
- types::*,
- weight,
- custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
- make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
use frame_support::BoundedVec;
use up_data_structs::{
TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -25,15 +25,7 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{
- ToLog,
- execution::*,
- generate_stubgen, solidity, solidity_interface,
- types::*,
- weight,
- custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
- make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
use frame_support::{BoundedBTreeMap, BoundedVec};
use pallet_common::{
CollectionHandle, CollectionPropertyPermissions,
pallets/refungible/src/erc_token.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122extern crate alloc;2324#[cfg(not(feature = "std"))]25use alloc::format;2627use core::{28 char::{REPLACEMENT_CHARACTER, decode_utf16},29 convert::TryInto,30 ops::Deref,31};32use evm_coder::{33 ToLog,34 execution::*,35 generate_stubgen, solidity_interface,36 types::*,37 weight,38 custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},39 make_signature,40};41use pallet_common::{42 CommonWeightInfo,43 erc::{CommonEvmHandler, PrecompileResult},44 eth::collection_id_to_address,45};46use pallet_evm::{account::CrossAccountId, PrecompileHandle};47use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};48use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};49use sp_std::vec::Vec;50use up_data_structs::TokenId;5152use crate::{53 Allowance, Balance, common::CommonWeights, Config, Pallet, RefungibleHandle, SelfWeightOf,54 TotalSupply, weights::WeightInfo,55};5657pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);5859#[solidity_interface(name = ERC1633)]60impl<T: Config> RefungibleTokenHandle<T> {61 fn parent_token(&self) -> Result<address> {62 Ok(collection_id_to_address(self.id))63 }6465 fn parent_token_id(&self) -> Result<uint256> {66 Ok(self.1.into())67 }68}6970#[derive(ToLog)]71pub enum ERC20Events {72 /// @dev This event is emitted when the amount of tokens (value) is sent73 /// from the from address to the to address. In the case of minting new74 /// tokens, the transfer is usually from the 0 address while in the case75 /// of burning tokens the transfer is to 0.76 Transfer {77 #[indexed]78 from: address,79 #[indexed]80 to: address,81 value: uint256,82 },83 /// @dev This event is emitted when the amount of tokens (value) is approved84 /// by the owner to be used by the spender.85 Approval {86 #[indexed]87 owner: address,88 #[indexed]89 spender: address,90 value: uint256,91 },92}9394/// @title Standard ERC20 token95///96/// @dev Implementation of the basic standard token.97/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md98#[solidity_interface(name = ERC20, events(ERC20Events))]99impl<T: Config> RefungibleTokenHandle<T> {100 /// @return the name of the token.101 fn name(&self) -> Result<string> {102 Ok(decode_utf16(self.name.iter().copied())103 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))104 .collect::<string>())105 }106107 /// @return the symbol of the token.108 fn symbol(&self) -> Result<string> {109 Ok(string::from_utf8_lossy(&self.token_prefix).into())110 }111112 /// @dev Total number of tokens in existence113 fn total_supply(&self) -> Result<uint256> {114 self.consume_store_reads(1)?;115 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())116 }117118 /// @dev Not supported119 fn decimals(&self) -> Result<uint8> {120 // Decimals aren't supported for refungible tokens121 Ok(0)122 }123124 /// @dev Gets the balance of the specified address.125 /// @param owner The address to query the balance of.126 /// @return An uint256 representing the amount owned by the passed address.127 fn balance_of(&self, owner: address) -> Result<uint256> {128 self.consume_store_reads(1)?;129 let owner = T::CrossAccountId::from_eth(owner);130 let balance = <Balance<T>>::get((self.id, self.1, owner));131 Ok(balance.into())132 }133134 /// @dev Transfer token for a specified address135 /// @param to The address to transfer to.136 /// @param amount The amount to be transferred.137 #[weight(<CommonWeights<T>>::transfer())]138 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {139 let caller = T::CrossAccountId::from_eth(caller);140 let to = T::CrossAccountId::from_eth(to);141 let amount = amount.try_into().map_err(|_| "amount overflow")?;142 let budget = self143 .recorder144 .weight_calls_budget(<StructureWeight<T>>::find_parent());145146 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)147 .map_err(dispatch_to_evm::<T>)?;148 Ok(true)149 }150151 /// @dev Transfer tokens from one address to another152 /// @param from address The address which you want to send tokens from153 /// @param to address The address which you want to transfer to154 /// @param amount uint256 the amount of tokens to be transferred155 #[weight(<CommonWeights<T>>::transfer_from())]156 fn transfer_from(157 &mut self,158 caller: caller,159 from: address,160 to: address,161 amount: uint256,162 ) -> Result<bool> {163 let caller = T::CrossAccountId::from_eth(caller);164 let from = T::CrossAccountId::from_eth(from);165 let to = T::CrossAccountId::from_eth(to);166 let amount = amount.try_into().map_err(|_| "amount overflow")?;167 let budget = self168 .recorder169 .weight_calls_budget(<StructureWeight<T>>::find_parent());170171 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)172 .map_err(dispatch_to_evm::<T>)?;173 Ok(true)174 }175176 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.177 /// Beware that changing an allowance with this method brings the risk that someone may use both the old178 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this179 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:180 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729181 /// @param spender The address which will spend the funds.182 /// @param amount The amount of tokens to be spent.183 #[weight(<SelfWeightOf<T>>::approve())]184 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {185 let caller = T::CrossAccountId::from_eth(caller);186 let spender = T::CrossAccountId::from_eth(spender);187 let amount = amount.try_into().map_err(|_| "amount overflow")?;188189 <Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)190 .map_err(dispatch_to_evm::<T>)?;191 Ok(true)192 }193194 /// @dev Function to check the amount of tokens that an owner allowed to a spender.195 /// @param owner address The address which owns the funds.196 /// @param spender address The address which will spend the funds.197 /// @return A uint256 specifying the amount of tokens still available for the spender.198 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {199 self.consume_store_reads(1)?;200 let owner = T::CrossAccountId::from_eth(owner);201 let spender = T::CrossAccountId::from_eth(spender);202203 Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())204 }205}206207#[solidity_interface(name = ERC20UniqueExtensions)]208impl<T: Config> RefungibleTokenHandle<T> {209 /// @dev Function that burns an amount of the token of a given account,210 /// deducting from the sender's allowance for said account.211 /// @param from The account whose tokens will be burnt.212 /// @param amount The amount that will be burnt.213 #[weight(<SelfWeightOf<T>>::burn_from())]214 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {215 let caller = T::CrossAccountId::from_eth(caller);216 let from = T::CrossAccountId::from_eth(from);217 let amount = amount.try_into().map_err(|_| "amount overflow")?;218 let budget = self219 .recorder220 .weight_calls_budget(<StructureWeight<T>>::find_parent());221222 <Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)223 .map_err(dispatch_to_evm::<T>)?;224 Ok(true)225 }226227 /// @dev Function that changes total amount of the tokens.228 /// Throws if `msg.sender` doesn't owns all of the tokens.229 /// @param amount New total amount of the tokens.230 #[weight(<SelfWeightOf<T>>::repartition_item())]231 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {232 let caller = T::CrossAccountId::from_eth(caller);233 let amount = amount.try_into().map_err(|_| "amount overflow")?;234235 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;236 Ok(true)237 }238}239240impl<T: Config> RefungibleTokenHandle<T> {241 pub fn into_inner(self) -> RefungibleHandle<T> {242 self.0243 }244 pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {245 &mut self.0246 }247}248249impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {250 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {251 self.0.recorder()252 }253 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {254 self.0.into_recorder()255 }256}257258impl<T: Config> Deref for RefungibleTokenHandle<T> {259 type Target = RefungibleHandle<T>;260261 fn deref(&self) -> &Self::Target {262 &self.0263 }264}265266#[solidity_interface(267 name = UniqueRefungibleToken,268 is(ERC20, ERC20UniqueExtensions, ERC1633)269)]270impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}271272generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);273generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);274275impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>276where277 T::AccountId: From<[u8; 32]>,278{279 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");280281 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {282 call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)283 }284}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122extern crate alloc;2324#[cfg(not(feature = "std"))]25use alloc::format;2627use core::{28 char::{REPLACEMENT_CHARACTER, decode_utf16},29 convert::TryInto,30 ops::Deref,31};32use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};33use pallet_common::{34 CommonWeightInfo,35 erc::{CommonEvmHandler, PrecompileResult},36 eth::collection_id_to_address,37};38use pallet_evm::{account::CrossAccountId, PrecompileHandle};39use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};40use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};41use sp_std::vec::Vec;42use up_data_structs::TokenId;4344use crate::{45 Allowance, Balance, common::CommonWeights, Config, Pallet, RefungibleHandle, SelfWeightOf,46 TotalSupply, weights::WeightInfo,47};4849pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);5051#[solidity_interface(name = ERC1633)]52impl<T: Config> RefungibleTokenHandle<T> {53 fn parent_token(&self) -> Result<address> {54 Ok(collection_id_to_address(self.id))55 }5657 fn parent_token_id(&self) -> Result<uint256> {58 Ok(self.1.into())59 }60}6162#[derive(ToLog)]63pub enum ERC20Events {64 /// @dev This event is emitted when the amount of tokens (value) is sent65 /// from the from address to the to address. In the case of minting new66 /// tokens, the transfer is usually from the 0 address while in the case67 /// of burning tokens the transfer is to 0.68 Transfer {69 #[indexed]70 from: address,71 #[indexed]72 to: address,73 value: uint256,74 },75 /// @dev This event is emitted when the amount of tokens (value) is approved76 /// by the owner to be used by the spender.77 Approval {78 #[indexed]79 owner: address,80 #[indexed]81 spender: address,82 value: uint256,83 },84}8586/// @title Standard ERC20 token87///88/// @dev Implementation of the basic standard token.89/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md90#[solidity_interface(name = ERC20, events(ERC20Events))]91impl<T: Config> RefungibleTokenHandle<T> {92 /// @return the name of the token.93 fn name(&self) -> Result<string> {94 Ok(decode_utf16(self.name.iter().copied())95 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))96 .collect::<string>())97 }9899 /// @return the symbol of the token.100 fn symbol(&self) -> Result<string> {101 Ok(string::from_utf8_lossy(&self.token_prefix).into())102 }103104 /// @dev Total number of tokens in existence105 fn total_supply(&self) -> Result<uint256> {106 self.consume_store_reads(1)?;107 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())108 }109110 /// @dev Not supported111 fn decimals(&self) -> Result<uint8> {112 // Decimals aren't supported for refungible tokens113 Ok(0)114 }115116 /// @dev Gets the balance of the specified address.117 /// @param owner The address to query the balance of.118 /// @return An uint256 representing the amount owned by the passed address.119 fn balance_of(&self, owner: address) -> Result<uint256> {120 self.consume_store_reads(1)?;121 let owner = T::CrossAccountId::from_eth(owner);122 let balance = <Balance<T>>::get((self.id, self.1, owner));123 Ok(balance.into())124 }125126 /// @dev Transfer token for a specified address127 /// @param to The address to transfer to.128 /// @param amount The amount to be transferred.129 #[weight(<CommonWeights<T>>::transfer())]130 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {131 let caller = T::CrossAccountId::from_eth(caller);132 let to = T::CrossAccountId::from_eth(to);133 let amount = amount.try_into().map_err(|_| "amount overflow")?;134 let budget = self135 .recorder136 .weight_calls_budget(<StructureWeight<T>>::find_parent());137138 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)139 .map_err(dispatch_to_evm::<T>)?;140 Ok(true)141 }142143 /// @dev Transfer tokens from one address to another144 /// @param from address The address which you want to send tokens from145 /// @param to address The address which you want to transfer to146 /// @param amount uint256 the amount of tokens to be transferred147 #[weight(<CommonWeights<T>>::transfer_from())]148 fn transfer_from(149 &mut self,150 caller: caller,151 from: address,152 to: address,153 amount: uint256,154 ) -> Result<bool> {155 let caller = T::CrossAccountId::from_eth(caller);156 let from = T::CrossAccountId::from_eth(from);157 let to = T::CrossAccountId::from_eth(to);158 let amount = amount.try_into().map_err(|_| "amount overflow")?;159 let budget = self160 .recorder161 .weight_calls_budget(<StructureWeight<T>>::find_parent());162163 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)164 .map_err(dispatch_to_evm::<T>)?;165 Ok(true)166 }167168 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.169 /// Beware that changing an allowance with this method brings the risk that someone may use both the old170 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this171 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:172 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729173 /// @param spender The address which will spend the funds.174 /// @param amount The amount of tokens to be spent.175 #[weight(<SelfWeightOf<T>>::approve())]176 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {177 let caller = T::CrossAccountId::from_eth(caller);178 let spender = T::CrossAccountId::from_eth(spender);179 let amount = amount.try_into().map_err(|_| "amount overflow")?;180181 <Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)182 .map_err(dispatch_to_evm::<T>)?;183 Ok(true)184 }185186 /// @dev Function to check the amount of tokens that an owner allowed to a spender.187 /// @param owner address The address which owns the funds.188 /// @param spender address The address which will spend the funds.189 /// @return A uint256 specifying the amount of tokens still available for the spender.190 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {191 self.consume_store_reads(1)?;192 let owner = T::CrossAccountId::from_eth(owner);193 let spender = T::CrossAccountId::from_eth(spender);194195 Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())196 }197}198199#[solidity_interface(name = ERC20UniqueExtensions)]200impl<T: Config> RefungibleTokenHandle<T> {201 /// @dev Function that burns an amount of the token of a given account,202 /// deducting from the sender's allowance for said account.203 /// @param from The account whose tokens will be burnt.204 /// @param amount The amount that will be burnt.205 #[weight(<SelfWeightOf<T>>::burn_from())]206 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {207 let caller = T::CrossAccountId::from_eth(caller);208 let from = T::CrossAccountId::from_eth(from);209 let amount = amount.try_into().map_err(|_| "amount overflow")?;210 let budget = self211 .recorder212 .weight_calls_budget(<StructureWeight<T>>::find_parent());213214 <Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)215 .map_err(dispatch_to_evm::<T>)?;216 Ok(true)217 }218219 /// @dev Function that changes total amount of the tokens.220 /// Throws if `msg.sender` doesn't owns all of the tokens.221 /// @param amount New total amount of the tokens.222 #[weight(<SelfWeightOf<T>>::repartition_item())]223 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {224 let caller = T::CrossAccountId::from_eth(caller);225 let amount = amount.try_into().map_err(|_| "amount overflow")?;226227 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;228 Ok(true)229 }230}231232impl<T: Config> RefungibleTokenHandle<T> {233 pub fn into_inner(self) -> RefungibleHandle<T> {234 self.0235 }236 pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {237 &mut self.0238 }239}240241impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {242 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {243 self.0.recorder()244 }245 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {246 self.0.into_recorder()247 }248}249250impl<T: Config> Deref for RefungibleTokenHandle<T> {251 type Target = RefungibleHandle<T>;252253 fn deref(&self) -> &Self::Target {254 &self.0255 }256}257258#[solidity_interface(259 name = UniqueRefungibleToken,260 is(ERC20, ERC20UniqueExtensions, ERC1633)261)]262impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}263264generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);265generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);266267impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>268where269 T::AccountId: From<[u8; 32]>,270{271 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");272273 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {274 call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)275 }276}pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -18,13 +18,7 @@
use core::marker::PhantomData;
use ethereum as _;
-use evm_coder::{
- execution::*,
- generate_stubgen, solidity, solidity_interface,
- types::*,
- custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
- make_signature, weight,
-};
+use evm_coder::{execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
use frame_support::traits::Get;
use crate::Pallet;