difftreelog
feat implement #[weight] macro for evm support
in: master
35 files changed
crates/evm-coder-macros/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder-macros/src/lib.rs
+++ b/crates/evm-coder-macros/src/lib.rs
@@ -211,6 +211,10 @@
pub fn solidity(_args: TokenStream, stream: TokenStream) -> TokenStream {
stream
}
+#[proc_macro_attribute]
+pub fn weight(_args: TokenStream, stream: TokenStream) -> TokenStream {
+ stream
+}
#[proc_macro_derive(ToLog, attributes(indexed))]
pub fn to_log(value: TokenStream) -> TokenStream {
crates/evm-coder-macros/src/solidity_interface.rsdiffbeforeafterboth--- a/crates/evm-coder-macros/src/solidity_interface.rs
+++ b/crates/evm-coder-macros/src/solidity_interface.rs
@@ -30,11 +30,11 @@
})
}
- fn expand_call_def(&self) -> proc_macro2::TokenStream {
+ fn expand_call_def(&self, gen_ref: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let name = &self.name;
let pascal_call_name = &self.pascal_call_name;
quote! {
- #name(#pascal_call_name)
+ #name(#pascal_call_name #gen_ref)
}
}
@@ -45,18 +45,32 @@
}
}
- fn expand_supports_interface(&self) -> proc_macro2::TokenStream {
+ fn expand_supports_interface(
+ &self,
+ generics: &proc_macro2::TokenStream,
+ ) -> proc_macro2::TokenStream {
let pascal_call_name = &self.pascal_call_name;
quote! {
- #pascal_call_name::supports_interface(interface_id)
+ <#pascal_call_name #generics>::supports_interface(interface_id)
+ }
+ }
+
+ fn expand_variant_weight(&self) -> proc_macro2::TokenStream {
+ let name = &self.name;
+ quote! {
+ Self::#name(call) => call.weight()
}
}
- fn expand_variant_call(&self) -> proc_macro2::TokenStream {
+ fn expand_variant_call(
+ &self,
+ call_name: &proc_macro2::Ident,
+ generics: &proc_macro2::TokenStream,
+ ) -> proc_macro2::TokenStream {
let name = &self.name;
let pascal_call_name = &self.pascal_call_name;
quote! {
- InternalCall::#name(call) => return <Self as ::evm_coder::Callable<#pascal_call_name>>::call(self, Msg {
+ #call_name::#name(call) => return <Self as ::evm_coder::Callable<#pascal_call_name #generics>>::call(self, Msg {
call,
caller: c.caller,
value: c.value,
@@ -64,20 +78,20 @@
}
}
- fn expand_parse(&self) -> proc_macro2::TokenStream {
+ fn expand_parse(&self, generics: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let name = &self.name;
let pascal_call_name = &self.pascal_call_name;
quote! {
- if let Some(parsed_call) = #pascal_call_name::parse(method_id, reader)? {
+ if let Some(parsed_call) = <#pascal_call_name #generics>::parse(method_id, reader)? {
return Ok(Some(Self::#name(parsed_call)))
}
}
}
- fn expand_generator(&self) -> proc_macro2::TokenStream {
+ fn expand_generator(&self, generics: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pascal_call_name = &self.pascal_call_name;
quote! {
- #pascal_call_name::generate_solidity_interface(tc, is_impl);
+ <#pascal_call_name #generics>::generate_solidity_interface(tc, is_impl);
}
}
@@ -351,6 +365,25 @@
Pure,
}
+pub struct WeightAttr(syn::Expr);
+
+mod keyword {
+ syn::custom_keyword!(weight);
+}
+
+impl syn::parse::Parse for WeightAttr {
+ fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
+ input.parse::<syn::Token![#]>()?;
+ let content;
+ syn::bracketed!(content in input);
+ content.parse::<keyword::weight>()?;
+
+ let weight_content;
+ syn::parenthesized!(weight_content in content);
+ Ok(WeightAttr(weight_content.parse::<syn::Expr>()?))
+ }
+}
+
struct Method {
name: Ident,
camel_name: String,
@@ -362,6 +395,7 @@
has_normal_args: bool,
mutability: Mutability,
result: Type,
+ weight: Option<Expr>,
docs: Vec<String>,
}
impl Method {
@@ -370,6 +404,7 @@
rename_selector: None,
};
let mut docs = Vec::new();
+ let mut weight = None;
for attr in &value.attrs {
let ident = parse_ident_from_path(&attr.path, false)?;
if ident == "solidity" {
@@ -384,6 +419,8 @@
_ => unreachable!(),
};
docs.push(value);
+ } else if ident == "weight" {
+ weight = Some(syn::parse2::<WeightAttr>(attr.to_token_stream())?.0);
}
}
let ident = &value.sig.ident;
@@ -466,6 +503,7 @@
has_normal_args,
mutability,
result: result.clone(),
+ weight,
docs,
})
}
@@ -528,7 +566,7 @@
}
}
- fn expand_variant_call(&self) -> proc_macro2::TokenStream {
+ fn expand_variant_call(&self, call_name: &proc_macro2::Ident) -> proc_macro2::TokenStream {
let pascal_name = &self.pascal_name;
let name = &self.name;
@@ -555,17 +593,50 @@
let args = self.args.iter().map(|a| a.expand_call_arg());
quote! {
- InternalCall::#pascal_name #matcher => {
+ #call_name::#pascal_name #matcher => {
let result = #receiver #name(
#(
#args,
)*
)?;
- (&result).abi_write(&mut writer);
+ (&result).into_result()
}
}
}
+ fn expand_variant_weight(&self) -> proc_macro2::TokenStream {
+ let pascal_name = &self.pascal_name;
+ if let Some(weight) = &self.weight {
+ let matcher = if self.has_normal_args {
+ let names = self
+ .args
+ .iter()
+ .filter(|a| !a.is_special())
+ .map(|a| &a.name);
+
+ quote! {{
+ #(
+ #names,
+ )*
+ }}
+ } else {
+ quote! {}
+ };
+ quote! {
+ Self::#pascal_name #matcher => (#weight).into()
+ }
+ } else {
+ let matcher = if self.has_normal_args {
+ quote! {{..}}
+ } else {
+ quote! {}
+ };
+ quote! {
+ Self::#pascal_name #matcher => ().into()
+ }
+ }
+ }
+
fn expand_solidity_function(&self) -> proc_macro2::TokenStream {
let camel_name = &self.camel_name;
let mutability = match self.mutability {
@@ -600,6 +671,42 @@
}
}
+fn generics_list(gen: &Generics) -> proc_macro2::TokenStream {
+ if gen.params.is_empty() {
+ return quote! {};
+ }
+ let params = gen.params.iter().map(|p| match p {
+ syn::GenericParam::Type(id) => {
+ let v = &id.ident;
+ quote! {#v}
+ }
+ syn::GenericParam::Lifetime(lt) => {
+ let v = <.lifetime;
+ quote! {#v}
+ }
+ syn::GenericParam::Const(c) => {
+ let i = &c.ident;
+ quote! {#i}
+ }
+ });
+ quote! { #(#params),* }
+}
+fn generics_reference(gen: &Generics) -> proc_macro2::TokenStream {
+ if gen.params.is_empty() {
+ return quote! {};
+ }
+ let list = generics_list(gen);
+ quote! { <#list> }
+}
+fn generics_data(gen: &Generics) -> proc_macro2::TokenStream {
+ let list = generics_list(gen);
+ if gen.params.len() == 1 {
+ quote! {#list}
+ } else {
+ quote! { (#list) }
+ }
+}
+
pub struct SolidityInterface {
generics: Generics,
name: Box<syn::Type>,
@@ -628,6 +735,8 @@
let solidity_name = self.info.name.to_string();
let call_name = pascal_ident_to_call(&self.info.name);
let generics = self.generics;
+ let gen_ref = generics_reference(&generics);
+ let gen_data = generics_data(&generics);
let call_sub = self
.info
@@ -635,30 +744,46 @@
.0
.iter()
.chain(self.info.is.0.iter())
- .map(Is::expand_call_def);
+ .map(|c| Is::expand_call_def(c, &gen_ref));
let call_parse = self
.info
.inline_is
.0
.iter()
.chain(self.info.is.0.iter())
- .map(Is::expand_parse);
+ .map(|is| Is::expand_parse(is, &gen_ref));
let call_variants = self
.info
.inline_is
.0
.iter()
.chain(self.info.is.0.iter())
- .map(Is::expand_variant_call);
+ .map(|c| Is::expand_variant_call(c, &call_name, &gen_ref));
+ let weight_variants = self
+ .info
+ .inline_is
+ .0
+ .iter()
+ .chain(self.info.is.0.iter())
+ .map(Is::expand_variant_weight);
let inline_interface_id = self.info.inline_is.0.iter().map(Is::expand_interface_id);
- let supports_interface = self.info.is.0.iter().map(Is::expand_supports_interface);
+ let supports_interface = self
+ .info
+ .is
+ .0
+ .iter()
+ .map(|is| Is::expand_supports_interface(is, &gen_ref));
let calls = self.methods.iter().map(Method::expand_call_def);
let consts = self.methods.iter().map(Method::expand_const);
let interface_id = self.methods.iter().map(Method::expand_interface_id);
let parsers = self.methods.iter().map(Method::expand_parse);
- let call_variants_this = self.methods.iter().map(Method::expand_variant_call);
+ let call_variants_this = self
+ .methods
+ .iter()
+ .map(|m| Method::expand_variant_call(m, &call_name));
+ let weight_variants_this = self.methods.iter().map(Method::expand_variant_weight);
let solidity_functions = self.methods.iter().map(Method::expand_solidity_function);
// TODO: Inline inline_is
@@ -676,15 +801,15 @@
.0
.iter()
.chain(self.info.inline_is.0.iter())
- .map(Is::expand_generator);
+ .map(|is| Is::expand_generator(is, &gen_ref));
let solidity_event_generators = self.info.events.0.iter().map(Is::expand_event_generator);
// let methods = self.methods.iter().map(Method::solidity_def);
quote! {
#[derive(Debug)]
- pub enum #call_name {
- ERC165Call(::evm_coder::ERC165Call),
+ pub enum #call_name #gen_ref {
+ ERC165Call(::evm_coder::ERC165Call, ::core::marker::PhantomData<#gen_data>),
#(
#calls,
)*
@@ -692,11 +817,11 @@
#call_sub,
)*
}
- impl #call_name {
+ impl #gen_ref #call_name #gen_ref {
#(
#consts
)*
- pub const fn interface_id() -> u32 {
+ pub fn interface_id() -> u32 {
let mut interface_id = 0;
#(#interface_id)*
#(#inline_interface_id)*
@@ -748,11 +873,14 @@
tc.collect(out);
}
}
- impl ::evm_coder::Call for #call_name {
+ impl #gen_ref ::evm_coder::Call for #call_name #gen_ref {
fn parse(method_id: u32, 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(::evm_coder::ERC165Call::parse(method_id, reader)?.map(Self::ERC165Call)),
+ ::evm_coder::ERC165Call::INTERFACE_ID => return Ok(
+ ::evm_coder::ERC165Call::parse(method_id, reader)?
+ .map(|c| Self::ERC165Call(c, ::core::marker::PhantomData))
+ ),
#(
#parsers,
)*
@@ -764,19 +892,33 @@
return Ok(None);
}
}
- impl #generics ::evm_coder::Callable<#call_name> for #name {
+ impl #generics ::evm_coder::Weighted for #call_name #gen_ref {
+ #[allow(unused_variables)]
+ fn weight(&self) -> ::evm_coder::execution::DispatchInfo {
+ match self {
+ #(
+ #weight_variants,
+ )*
+ // TODO: It should be very cheap, but not free
+ Self::ERC165Call(::evm_coder::ERC165Call::SupportsInterface {..}, _) => 100u64.into(),
+ #(
+ #weight_variants_this,
+ )*
+ }
+ }
+ }
+ impl #generics ::evm_coder::Callable<#call_name #gen_ref> for #name {
#[allow(unreachable_code)] // In case of no inner calls
- fn call(&mut self, c: Msg<#call_name>) -> Result<::evm_coder::abi::AbiWriter> {
+ fn call(&mut self, c: Msg<#call_name #gen_ref>) -> ::evm_coder::execution::ResultWithPostInfo<::evm_coder::abi::AbiWriter> {
use ::evm_coder::abi::AbiWrite;
- type InternalCall = #call_name;
match c.call {
#(
#call_variants,
)*
- InternalCall::ERC165Call(::evm_coder::ERC165Call::SupportsInterface {interface_id}) => {
+ #call_name::ERC165Call(::evm_coder::ERC165Call::SupportsInterface {interface_id}, _) => {
let mut writer = ::evm_coder::abi::AbiWriter::default();
- writer.bool(&InternalCall::supports_interface(interface_id));
- return Ok(writer);
+ writer.bool(&<#call_name #gen_ref>::supports_interface(interface_id));
+ return Ok(writer.into());
}
_ => {},
}
@@ -787,7 +929,6 @@
)*
_ => unreachable!()
}
- Ok(writer)
}
}
}
crates/evm-coder/src/abi.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -11,7 +11,10 @@
use evm_core::ExitError;
use primitive_types::{H160, U256};
-use crate::{execution::Error, types::string};
+use crate::{
+ execution::{Error, ResultWithPostInfo, WithPostDispatchInfo},
+ types::string,
+};
use crate::execution::Result;
const ABI_ALIGNMENT: usize = 32;
@@ -244,6 +247,7 @@
}
impl_abi_readable!(u32, uint32);
+impl_abi_readable!(u64, uint64);
impl_abi_readable!(u128, uint128);
impl_abi_readable!(U256, uint256);
impl_abi_readable!(H160, address);
@@ -306,6 +310,36 @@
pub trait AbiWrite {
fn abi_write(&self, writer: &mut AbiWriter);
+ fn into_result(&self) -> ResultWithPostInfo<AbiWriter> {
+ let mut writer = AbiWriter::new();
+ self.abi_write(&mut writer);
+ Ok(writer.into())
+ }
+}
+
+impl<T: AbiWrite> AbiWrite for ResultWithPostInfo<T> {
+ // this particular AbiWrite implementation should be split to another trait,
+ // which only implements [`into_result`]
+ //
+ // But due to lack of specialization feature in stable Rust, we can't have
+ // blanket impl of this trait `for T where T: AbiWrite`, so here we abusing
+ // default trait methods for it
+ fn abi_write(&self, _writer: &mut AbiWriter) {
+ debug_assert!(false, "shouldn't be called, see comment")
+ }
+ fn into_result(&self) -> ResultWithPostInfo<AbiWriter> {
+ match self {
+ Ok(v) => Ok(WithPostDispatchInfo {
+ post_info: v.post_info.clone(),
+ data: {
+ let mut out = AbiWriter::new();
+ v.data.abi_write(&mut out);
+ out
+ },
+ }),
+ Err(e) => Err(e.clone()),
+ }
+ }
}
macro_rules! impl_abi_writeable {
crates/evm-coder/src/execution.rsdiffbeforeafterboth--- a/crates/evm-coder/src/execution.rs
+++ b/crates/evm-coder/src/execution.rs
@@ -4,7 +4,9 @@
#[cfg(feature = "std")]
use std::string::{String, ToString};
-#[derive(Debug)]
+use crate::Weight;
+
+#[derive(Debug, Clone)]
pub enum Error {
Revert(String),
Fatal(ExitFatal),
@@ -21,3 +23,55 @@
}
pub type Result<T> = core::result::Result<T, Error>;
+
+pub struct DispatchInfo {
+ pub weight: Weight,
+}
+
+impl From<Weight> for DispatchInfo {
+ fn from(weight: Weight) -> Self {
+ Self { weight }
+ }
+}
+impl From<()> for DispatchInfo {
+ fn from(_: ()) -> Self {
+ Self { weight: 0 }
+ }
+}
+
+#[derive(Default, Clone)]
+pub struct PostDispatchInfo {
+ actual_weight: Option<Weight>,
+}
+
+impl PostDispatchInfo {
+ pub fn calc_unspent(&self, info: &DispatchInfo) -> Weight {
+ info.weight - self.calc_actual_weight(info)
+ }
+
+ pub fn calc_actual_weight(&self, info: &DispatchInfo) -> Weight {
+ if let Some(actual_weight) = self.actual_weight {
+ actual_weight.min(info.weight)
+ } else {
+ info.weight
+ }
+ }
+}
+
+#[derive(Clone)]
+pub struct WithPostDispatchInfo<T> {
+ pub data: T,
+ pub post_info: PostDispatchInfo,
+}
+
+impl<T> From<T> for WithPostDispatchInfo<T> {
+ fn from(data: T) -> Self {
+ Self {
+ data,
+ post_info: Default::default(),
+ }
+ }
+}
+
+pub type ResultWithPostInfo<T> =
+ core::result::Result<WithPostDispatchInfo<T>, WithPostDispatchInfo<Error>>;
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -3,10 +3,11 @@
extern crate alloc;
use abi::{AbiRead, AbiReader, AbiWriter};
-pub use evm_coder_macros::{event_topic, fn_selector, solidity_interface, solidity, ToLog};
+pub use evm_coder_macros::{event_topic, fn_selector, solidity_interface, solidity, weight, ToLog};
pub mod abi;
pub mod events;
pub use events::ToLog;
+use execution::DispatchInfo;
pub mod execution;
pub mod solidity;
@@ -57,8 +58,14 @@
fn parse(selector: u32, input: &mut AbiReader) -> execution::Result<Option<Self>>;
}
+pub type Weight = u64;
+
+pub trait Weighted: Call {
+ fn weight(&self) -> DispatchInfo;
+}
+
pub trait Callable<C: Call> {
- fn call(&mut self, call: types::Msg<C>) -> execution::Result<AbiWriter>;
+ fn call(&mut self, call: types::Msg<C>) -> execution::ResultWithPostInfo<AbiWriter>;
}
/// Implementation is implicitly provided for all interfaces
@@ -84,15 +91,20 @@
}
}
+/// Generate "tests", which will generate solidity code on execution and print it to stdout
+/// Script at .maintain/scripts/generate_api.sh can split this output from test runtime
+///
+/// This macro receives type usage as second argument, but you can use anything as generics,
+/// because no bounds are implied
#[macro_export]
macro_rules! generate_stubgen {
- ($name:ident, $decl:ident, $is_impl:literal) => {
+ ($name:ident, $decl:ty, $is_impl:literal) => {
#[test]
#[ignore]
fn $name() {
use evm_coder::solidity::TypeCollector;
let mut out = TypeCollector::new();
- $decl::generate_solidity_interface(&mut out, $is_impl);
+ <$decl>::generate_solidity_interface(&mut out, $is_impl);
println!("=== SNIP START ===");
println!("// SPDX-License-Identifier: OTHER");
println!("// This code is automatically generated");
crates/evm-coder/tests/a.rsdiffbeforeafterboth--- a/crates/evm-coder/tests/a.rs
+++ /dev/null
@@ -1,89 +0,0 @@
-#![allow(dead_code)] // This test only checks that macros is not panicking
-
-use evm_coder::{solidity_interface, types::*, ToLog, execution::Result};
-use evm_coder_macros::solidity;
-
-struct Impls;
-
-#[solidity_interface(name = "OurInterface")]
-impl Impls {
- fn fn_a(&self, _input: uint256) -> Result<bool> {
- todo!()
- }
-}
-
-#[solidity_interface(name = "OurInterface1")]
-impl Impls {
- fn fn_b(&self, _input: uint128) -> Result<uint32> {
- todo!()
- }
-}
-
-#[solidity_interface(
- name = "OurInterface2",
- is(OurInterface),
- inline_is(OurInterface1),
- events(ERC721Log)
-)]
-impl Impls {
- #[solidity(rename_selector = "fnK")]
- fn fn_c(&self, _input: uint32) -> Result<uint8> {
- todo!()
- }
- fn fn_d(&self, _value: uint32) -> Result<uint32> {
- todo!()
- }
-
- fn caller_sensitive(&self, _caller: caller) -> Result<uint8> {
- todo!()
- }
- fn payable(&mut self, _value: value) -> Result<uint8> {
- todo!()
- }
-}
-
-#[derive(ToLog)]
-enum ERC721Log {
- Transfer {
- #[indexed]
- from: address,
- #[indexed]
- to: address,
- value: uint256,
- },
- Eee {
- #[indexed]
- aaa: address,
- bbb: uint256,
- },
-}
-
-struct ERC20;
-
-#[solidity_interface(name = "ERC20")]
-impl ERC20 {
- fn decimals(&self) -> Result<uint8> {
- todo!()
- }
- fn balance_of(&self, _owner: address) -> Result<uint256> {
- todo!()
- }
- fn transfer(&mut self, _caller: caller, _to: address, _value: uint256) -> Result<bool> {
- todo!()
- }
- fn transfer_from(
- &mut self,
- _caller: caller,
- _from: address,
- _to: address,
- _value: uint256,
- ) -> Result<bool> {
- todo!()
- }
- fn approve(&mut self, _caller: caller, _spender: address, _value: uint256) -> Result<bool> {
- todo!()
- }
- fn allowance(&self, _owner: address, _spender: address) -> Result<uint256> {
- todo!()
- }
-}
crates/evm-coder/tests/generics.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/evm-coder/tests/generics.rs
@@ -0,0 +1,20 @@
+use std::marker::PhantomData;
+use evm_coder::{execution::Result, generate_stubgen, solidity_interface, types::*};
+
+struct Generic<T>(PhantomData<T>);
+
+#[solidity_interface(name = "GenericIs")]
+impl<T> Generic<T> {
+ fn test_1(&self) -> Result<uint256> {
+ todo!()
+ }
+}
+
+#[solidity_interface(name = "Generic", is(GenericIs))]
+impl<T: Into<u32>> Generic<T> {
+ fn test_2(&self) -> Result<uint256> {
+ todo!()
+ }
+}
+
+generate_stubgen!(gen_iface, GenericCall<()>, false);
crates/evm-coder/tests/log.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/evm-coder/tests/log.rs
@@ -0,0 +1,17 @@
+use evm_coder::{ToLog, types::*};
+
+#[derive(ToLog)]
+enum ERC721Log {
+ Transfer {
+ #[indexed]
+ from: address,
+ #[indexed]
+ to: address,
+ value: uint256,
+ },
+ Eee {
+ #[indexed]
+ aaa: address,
+ bbb: uint256,
+ },
+}
crates/evm-coder/tests/random.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/evm-coder/tests/random.rs
@@ -0,0 +1,65 @@
+#![allow(dead_code)] // This test only checks that macros is not panicking
+
+use evm_coder::{ToLog, execution::Result, solidity_interface, types::*};
+use evm_coder_macros::{solidity, weight};
+
+struct Impls;
+
+#[solidity_interface(name = "OurInterface")]
+impl Impls {
+ fn fn_a(&self, _input: uint256) -> Result<bool> {
+ todo!()
+ }
+}
+
+#[solidity_interface(name = "OurInterface1")]
+impl Impls {
+ fn fn_b(&self, _input: uint128) -> Result<uint32> {
+ todo!()
+ }
+}
+
+#[derive(ToLog)]
+enum OurEvents {
+ Event1 {
+ field1: uint32,
+ },
+ Event2 {
+ field1: uint32,
+ #[indexed]
+ field2: uint32,
+ },
+}
+
+#[solidity_interface(
+ name = "OurInterface2",
+ is(OurInterface),
+ inline_is(OurInterface1),
+ events(OurEvents)
+)]
+impl Impls {
+ #[solidity(rename_selector = "fnK")]
+ fn fn_c(&self, _input: uint32) -> Result<uint8> {
+ todo!()
+ }
+ fn fn_d(&self, _value: uint32) -> Result<uint32> {
+ todo!()
+ }
+
+ fn caller_sensitive(&self, _caller: caller) -> Result<uint8> {
+ todo!()
+ }
+ fn payable(&mut self, _value: value) -> Result<uint8> {
+ todo!()
+ }
+
+ #[weight(*_weight)]
+ fn with_weight(&self, _weight: uint64) -> Result<void> {
+ todo!()
+ }
+
+ /// Doccoment example
+ fn with_doc(&self) -> Result<void> {
+ todo!()
+ }
+}
crates/evm-coder/tests/solidity_generation.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/evm-coder/tests/solidity_generation.rs
@@ -0,0 +1,35 @@
+use evm_coder::{execution::Result, generate_stubgen, solidity_interface, types::*};
+
+struct ERC20;
+
+#[solidity_interface(name = "ERC20")]
+impl ERC20 {
+ fn decimals(&self) -> Result<uint8> {
+ todo!()
+ }
+ /// Get balance of specified owner
+ fn balance_of(&self, _owner: address) -> Result<uint256> {
+ todo!()
+ }
+ fn transfer(&mut self, _caller: caller, _to: address, _value: uint256) -> Result<bool> {
+ todo!()
+ }
+ fn transfer_from(
+ &mut self,
+ _caller: caller,
+ _from: address,
+ _to: address,
+ _value: uint256,
+ ) -> Result<bool> {
+ todo!()
+ }
+ fn approve(&mut self, _caller: caller, _spender: address, _value: uint256) -> Result<bool> {
+ todo!()
+ }
+ fn allowance(&self, _owner: address, _spender: address) -> Result<uint256> {
+ todo!()
+ }
+}
+
+generate_stubgen!(gen_impl, ERC20Call, true);
+generate_stubgen!(gen_iface, ERC20Call, false);
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -268,13 +268,13 @@
jsonrpc-core = '18.0.0'
jsonrpc-pubsub = "18.0.0"
-fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-mapping-sync = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-rpc = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-db = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-rpc = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-pallet-ethereum = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-mapping-sync = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-rpc = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-db = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-rpc = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+pallet-ethereum = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
nft-rpc = { path = "../rpc" }
node/rpc/Cargo.tomldiffbeforeafterboth--- a/node/rpc/Cargo.toml
+++ b/node/rpc/Cargo.toml
@@ -41,12 +41,12 @@
substrate-frame-rpc-system = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
tokio = { version = "0.2.25", features = ["macros", "sync"] }
-pallet-ethereum = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-rpc-core = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-db = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fc-mapping-sync = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-ethereum = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-rpc-core = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-db = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fc-mapping-sync = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
pallet-nft = { path = "../../pallets/nft" }
uc-rpc = { path = "../../client/rpc" }
pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -19,7 +19,7 @@
pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
evm-coder = { default-features = false, path = '../../crates/evm-coder' }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
serde = { version = "1.0.130", default-features = false }
scale-info = { version = "1.0.0", default-features = false, features = [
"derive",
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use core::ops::{Deref, DerefMut};
+use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use sp_std::vec::Vec;
use account::CrossAccountId;
use frame_support::{
@@ -8,6 +9,7 @@
ensure, fail,
traits::{Imbalance, Get, Currency},
};
+use pallet_evm::GasWeightMapping;
use nft_data_structs::{
COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, ExistenceRequirement,
MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
@@ -27,17 +29,22 @@
pub struct CollectionHandle<T: Config> {
pub id: CollectionId,
collection: Collection<T>,
- pub recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,
+ pub recorder: SubstrateRecorder<T>,
}
+impl<T: Config> WithRecorder<T> for CollectionHandle<T> {
+ fn recorder(&self) -> &SubstrateRecorder<T> {
+ &self.recorder
+ }
+ fn into_recorder(self) -> SubstrateRecorder<T> {
+ self.recorder
+ }
+}
impl<T: Config> CollectionHandle<T> {
pub fn new_with_gas_limit(id: CollectionId, gas_limit: u64) -> Option<Self> {
<CollectionById<T>>::get(id).map(|collection| Self {
id,
collection,
- recorder: pallet_evm_coder_substrate::SubstrateRecorder::new(
- eth::collection_id_to_address(id),
- gas_limit,
- ),
+ recorder: SubstrateRecorder::new(eth::collection_id_to_address(id), gas_limit),
})
}
pub fn new(id: CollectionId) -> Option<Self> {
@@ -46,33 +53,30 @@
pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {
Ok(Self::new(id).ok_or_else(|| <Error<T>>::CollectionNotFound)?)
}
- pub fn log(&self, log: impl evm_coder::ToLog) -> DispatchResult {
- self.recorder.log_sub(log)
+ pub fn log(&self, log: impl evm_coder::ToLog) {
+ self.recorder.log(log)
}
- pub fn log_infallible(&self, log: impl evm_coder::ToLog) {
- self.recorder.log_infallible(log)
+ pub fn consume_store_reads(&self, reads: u64) -> evm_coder::execution::Result<()> {
+ self.recorder
+ .consume_gas(T::GasWeightMapping::weight_to_gas(
+ <T as frame_system::Config>::DbWeight::get()
+ .read
+ .saturating_mul(reads),
+ ))
}
- #[allow(dead_code)]
- fn consume_gas(&self, gas: u64) -> DispatchResult {
- self.recorder.consume_gas_sub(gas)
- }
- pub fn consume_sload(&self) -> DispatchResult {
- self.recorder.consume_sload_sub()
+ pub fn consume_store_writes(&self, writes: u64) -> evm_coder::execution::Result<()> {
+ self.recorder
+ .consume_gas(T::GasWeightMapping::weight_to_gas(
+ <T as frame_system::Config>::DbWeight::get()
+ .write
+ .saturating_mul(writes),
+ ))
}
- pub fn consume_sstores(&self, amount: usize) -> DispatchResult {
- self.recorder.consume_sstores_sub(amount)
- }
- pub fn consume_sstore(&self) -> DispatchResult {
- self.recorder.consume_sstore_sub()
- }
- pub fn consume_log(&self, topics: usize, data: usize) -> DispatchResult {
- self.recorder.consume_log_sub(topics, data)
- }
- pub fn submit_logs(self) -> DispatchResult {
+ pub fn submit_logs(self) {
self.recorder.submit_logs()
}
pub fn save(self) -> DispatchResult {
- self.recorder.submit_logs()?;
+ self.recorder.submit_logs();
<CollectionById<T>>::insert(self.id, self.collection);
Ok(())
}
@@ -96,24 +100,20 @@
ensure!(*subject.as_sub() == self.owner, <Error<T>>::NoPermission);
Ok(())
}
- pub fn is_owner_or_admin(&self, subject: &T::CrossAccountId) -> Result<bool, DispatchError> {
- self.consume_sload()?;
-
- Ok(*subject.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, subject)))
+ pub fn is_owner_or_admin(&self, subject: &T::CrossAccountId) -> bool {
+ *subject.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, subject))
}
pub fn check_is_owner_or_admin(&self, subject: &T::CrossAccountId) -> DispatchResult {
- ensure!(self.is_owner_or_admin(subject)?, <Error<T>>::NoPermission);
+ ensure!(self.is_owner_or_admin(subject), <Error<T>>::NoPermission);
Ok(())
}
- pub fn ignores_allowance(&self, user: &T::CrossAccountId) -> Result<bool, DispatchError> {
- Ok(self.limits.owner_can_transfer() && self.is_owner_or_admin(user)?)
+ pub fn ignores_allowance(&self, user: &T::CrossAccountId) -> bool {
+ self.limits.owner_can_transfer() && self.is_owner_or_admin(user)
}
- pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> Result<bool, DispatchError> {
- Ok(self.limits.owner_can_transfer() && self.is_owner_or_admin(user)?)
+ pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> bool {
+ self.limits.owner_can_transfer() && self.is_owner_or_admin(user)
}
pub fn check_allowlist(&self, user: &T::CrossAccountId) -> DispatchResult {
- self.consume_sload()?;
-
ensure!(
<Allowlist<T>>::get((self.id, user)),
<Error<T>>::AddressNotInAllowlist
pallets/evm-coder-substrate/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-coder-substrate/Cargo.toml
+++ b/pallets/evm-coder-substrate/Cargo.toml
@@ -4,15 +4,18 @@
edition = "2018"
[dependencies]
-scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
+scale-info = { version = "1.0.0", default-features = false, features = [
+ "derive",
+] }
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }
evm-coder = { default-features = false, path = "../../crates/evm-coder" }
-pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
+frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
[dependencies.codec]
default-features = false
@@ -31,4 +34,6 @@
"pallet-evm/std",
"frame-support/std",
"frame-system/std",
+ 'frame-benchmarking/std',
]
+runtime-benchmarks = ['frame-benchmarking']
pallets/evm-coder-substrate/src/benchmarking.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/evm-coder-substrate/src/benchmarking.rs
@@ -0,0 +1,8 @@
+use super::*;
+
+use frame_benchmarking::benchmarks;
+
+benchmarks! {
+ // gas_per_second {
+ // }: (pallet_evm::)
+}
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -2,6 +2,8 @@
#[cfg(not(feature = "std"))]
extern crate alloc;
+// #[cfg(feature = "runtime-benchmarks")]
+// pub mod benchmarking;
pub use pallet::*;
@@ -17,7 +19,10 @@
types::{Msg, value},
};
use frame_support::{ensure};
- use pallet_evm::{ExitError, ExitReason, ExitRevert, ExitSucceed, PrecompileOutput};
+ use pallet_evm::{
+ ExitError, ExitReason, ExitRevert, ExitSucceed, PrecompileOutput, GasWeightMapping,
+ };
+ use frame_system::ensure_signed;
pub use frame_support::dispatch::DispatchResult;
use pallet_ethereum::EthereumTransactionSender;
use sp_std::cell::RefCell;
@@ -25,6 +30,7 @@
use sp_core::{H160, H256};
use ethereum::Log;
use frame_support::{pallet_prelude::*, traits::PalletInfo};
+ use frame_system::pallet_prelude::*;
/// DispatchError is opaque, but we need to somehow extract correct error in case of OutOfGas failure
/// So we have this pallet, which defines OutOfGas error, and knews its own id to check if DispatchError
@@ -40,25 +46,24 @@
#[pallet::config]
pub trait Config: frame_system::Config {
type EthereumTransactionSender: pallet_ethereum::EthereumTransactionSender;
+ type GasWeightMapping: pallet_evm::GasWeightMapping;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
- // FIXME: those items are defined as private in evm_gasometer::consts, and we can't directly use it
- pub const G_LOG: u64 = 375;
- pub const G_LOGDATA: u64 = 8;
- pub const G_LOGTOPIC: u64 = 375;
+ #[pallet::call]
+ impl<T: Config> Pallet<T> {
+ #[pallet::weight(0)]
+ pub fn empty_call(origin: OriginFor<T>) -> DispatchResult {
+ let _sender = ensure_signed(origin)?;
+ Ok(())
+ }
+ }
// From instabul hardfork configuration: https://github.com/rust-blockchain/evm/blob/fd4fd6acc0ca3208d6770fdb3ba407c94cdf97c6/runtime/src/lib.rs#L284
pub const G_SLOAD_WORD: u64 = 800;
pub const G_SSTORE_WORD: u64 = 20000;
-
- fn log_price(data: usize, topics: usize) -> u64 {
- G_LOG
- .saturating_add((data as u64).saturating_mul(G_LOGDATA))
- .saturating_add((topics as u64).saturating_mul(G_LOGTOPIC))
- }
pub fn generate_transaction() -> ethereum::TransactionV0 {
use ethereum::{TransactionV0, TransactionAction, TransactionSignature};
@@ -98,16 +103,10 @@
pub fn is_empty(&self) -> bool {
self.logs.borrow().is_empty()
}
- pub fn log_sub(&self, log: impl ToLog) -> DispatchResult {
- self.log_raw_sub(log.to_log(self.contract))
- }
- pub fn log_raw_sub(&self, log: Log) -> DispatchResult {
- self.consume_gas_sub(log_price(log.data.len(), log.topics.len()))?;
- self.logs.borrow_mut().push(log);
- Ok(())
- }
+ // TODO: Replace with real storage in pallet-ethereum,
+ // same way as it is done with frame_system's Events
/// Doesn't consumes any gas, should be used after consume_log_sub
- pub fn log_infallible(&self, log: impl ToLog) {
+ pub fn log(&self, log: impl ToLog) {
self.logs.borrow_mut().push(log.to_log(self.contract));
}
pub fn retrieve_logs(self) -> Vec<Log> {
@@ -125,9 +124,6 @@
}
pub fn consume_sstore_sub(&self) -> DispatchResult {
self.consume_gas_sub(G_SSTORE_WORD)
- }
- pub fn consume_log_sub(&self, topics: usize, data: usize) -> DispatchResult {
- self.consume_gas_sub(log_price(data, topics))
}
pub fn consume_gas_sub(&self, gas: u64) -> DispatchResult {
ensure!(gas != u64::MAX, Error::<T>::OutOfGas);
@@ -154,6 +150,10 @@
*gas_limit -= gas;
Ok(())
}
+ pub fn return_gas(&self, gas: u64) {
+ let mut gas_limit = self.gas_limit.borrow_mut();
+ *gas_limit += gas;
+ }
pub fn evm_to_precompile_output(
self,
@@ -181,12 +181,16 @@
})
}
- pub fn submit_logs(self) -> DispatchResult {
+ pub fn submit_logs(self) {
let logs = self.retrieve_logs();
if logs.is_empty() {
- return Ok(());
+ return;
}
- T::EthereumTransactionSender::submit_logs_transaction(generate_transaction(), logs)
+ T::EthereumTransactionSender::submit_logs_transaction(
+ Default::default(),
+ generate_transaction(),
+ logs,
+ )
}
}
@@ -215,7 +219,31 @@
}
}
- pub fn call_internal<C: evm_coder::Call, E: evm_coder::Callable<C>>(
+ pub trait WithRecorder<T: Config> {
+ fn recorder(&self) -> &SubstrateRecorder<T>;
+ fn into_recorder(self) -> SubstrateRecorder<T>;
+ }
+
+ /// Helper to simplify implementing bridge between evm-coder definitions and pallet-evm
+ pub fn call<
+ T: Config,
+ C: evm_coder::Call + evm_coder::Weighted,
+ E: evm_coder::Callable<C> + WithRecorder<T>,
+ >(
+ caller: H160,
+ mut e: E,
+ value: value,
+ input: &[u8],
+ ) -> Option<PrecompileOutput> {
+ let result = call_internal(caller, &mut e, value, input);
+ e.into_recorder().evm_to_precompile_output(result)
+ }
+
+ fn call_internal<
+ T: Config,
+ C: evm_coder::Call + evm_coder::Weighted,
+ E: evm_coder::Callable<C> + WithRecorder<T>,
+ >(
caller: H160,
e: &mut E,
value: value,
@@ -227,11 +255,28 @@
return Ok(None);
}
let call = call.unwrap();
- e.call(Msg {
+
+ let dispatch_info = call.weight();
+ e.recorder()
+ .consume_gas(T::GasWeightMapping::weight_to_gas(dispatch_info.weight))?;
+
+ match e.call(Msg {
call,
caller,
value,
- })
- .map(Some)
+ }) {
+ Ok(v) => {
+ let unspent = v.post_info.calc_unspent(&dispatch_info);
+ e.recorder()
+ .return_gas(T::GasWeightMapping::weight_to_gas(unspent));
+ Ok(Some(v.data))
+ }
+ Err(v) => {
+ let unspent = v.post_info.calc_unspent(&dispatch_info);
+ e.recorder()
+ .return_gas(T::GasWeightMapping::weight_to_gas(unspent));
+ Err(v.data)
+ }
+ }
}
}
pallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -4,7 +4,9 @@
edition = "2018"
[dependencies]
-scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
+scale-info = { version = "1.0.0", default-features = false, features = [
+ "derive",
+] }
frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
@@ -12,7 +14,7 @@
sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
evm-coder = { default-features = false, path = '../../crates/evm-coder' }
pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
up-sponsorship = { default-features = false, path = '../../primitives/sponsorship' }
log = "0.4.14"
pallets/evm-contract-helpers/exp.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/evm-contract-helpers/exp.rs
@@ -0,0 +1,1474 @@
+#![feature(prelude_import)]
+#[prelude_import]
+use std::prelude::rust_2018::*;
+#[macro_use]
+extern crate std;
+pub use pallet::*;
+pub use eth::*;
+pub mod eth {
+ use core::marker::PhantomData;
+ use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
+ use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
+ use pallet_evm::{ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput};
+ use sp_core::H160;
+ use crate::{
+ AllowlistEnabled, Config, Owner, Pallet, SelfSponsoring, SponsorBasket, SponsoringRateLimit,
+ };
+ use frame_support::traits::Get;
+ use up_sponsorship::SponsorshipHandler;
+ use sp_std::{convert::TryInto, vec::Vec};
+ struct ContractHelpers<T: Config>(SubstrateRecorder<T>);
+ impl<T: Config> WithRecorder<T> for ContractHelpers<T> {
+ fn recorder(&self) -> &SubstrateRecorder<T> {
+ &self.0
+ }
+ fn into_recorder(self) -> SubstrateRecorder<T> {
+ self.0
+ }
+ }
+ impl<T: Config> ContractHelpers<T> {
+ fn contract_owner(&self, contract_address: address) -> Result<address> {
+ Ok(<Owner<T>>::get(contract_address))
+ }
+ fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {
+ Ok(<SelfSponsoring<T>>::get(contract_address))
+ }
+ fn toggle_sponsoring(
+ &mut self,
+ caller: caller,
+ contract_address: address,
+ enabled: bool,
+ ) -> Result<void> {
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
+ <Pallet<T>>::toggle_sponsoring(contract_address, enabled);
+ Ok(())
+ }
+ fn set_sponsoring_rate_limit(
+ &mut self,
+ caller: caller,
+ contract_address: address,
+ rate_limit: uint32,
+ ) -> Result<void> {
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
+ <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());
+ Ok(())
+ }
+ fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {
+ Ok(<SponsoringRateLimit<T>>::get(contract_address)
+ .try_into()
+ .map_err(|_| "rate limit > u32::MAX")?)
+ }
+ fn allowed(&self, contract_address: address, user: address) -> Result<bool> {
+ Ok(<Pallet<T>>::allowed(contract_address, user, true))
+ }
+ fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {
+ Ok(<AllowlistEnabled<T>>::get(contract_address))
+ }
+ fn toggle_allowlist(
+ &mut self,
+ caller: caller,
+ contract_address: address,
+ enabled: bool,
+ ) -> Result<void> {
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
+ <Pallet<T>>::toggle_allowlist(contract_address, enabled);
+ Ok(())
+ }
+ fn toggle_allowed(
+ &mut self,
+ caller: caller,
+ contract_address: address,
+ user: address,
+ allowed: bool,
+ ) -> Result<void> {
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
+ <Pallet<T>>::toggle_allowed(contract_address, user, allowed);
+ Ok(())
+ }
+ }
+ pub enum ContractHelpersCall<T: Config> {
+ ERC165Call(::evm_coder::ERC165Call, PhantomData<(T)>),
+ ContractOwner {
+ contract_address: address,
+ },
+ SponsoringEnabled {
+ contract_address: address,
+ },
+ ToggleSponsoring {
+ contract_address: address,
+ enabled: bool,
+ },
+ SetSponsoringRateLimit {
+ contract_address: address,
+ rate_limit: uint32,
+ },
+ GetSponsoringRateLimit {
+ contract_address: address,
+ },
+ Allowed {
+ contract_address: address,
+ user: address,
+ },
+ AllowlistEnabled {
+ contract_address: address,
+ },
+ ToggleAllowlist {
+ contract_address: address,
+ enabled: bool,
+ },
+ ToggleAllowed {
+ contract_address: address,
+ user: address,
+ allowed: bool,
+ },
+ }
+ #[automatically_derived]
+ #[allow(unused_qualifications)]
+ impl<T: ::core::fmt::Debug + Config> ::core::fmt::Debug for ContractHelpersCall<T> {
+ fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
+ match (&*self,) {
+ (&ContractHelpersCall::ERC165Call(ref __self_0, ref __self_1),) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_tuple(f, "ERC165Call");
+ let _ = ::core::fmt::DebugTuple::field(debug_trait_builder, &&(*__self_0));
+ let _ = ::core::fmt::DebugTuple::field(debug_trait_builder, &&(*__self_1));
+ ::core::fmt::DebugTuple::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::ContractOwner {
+ contract_address: ref __self_0,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "ContractOwner");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::SponsoringEnabled {
+ contract_address: ref __self_0,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "SponsoringEnabled");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::ToggleSponsoring {
+ contract_address: ref __self_0,
+ enabled: ref __self_1,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "ToggleSponsoring");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "enabled",
+ &&(*__self_1),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::SetSponsoringRateLimit {
+ contract_address: ref __self_0,
+ rate_limit: ref __self_1,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "SetSponsoringRateLimit");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "rate_limit",
+ &&(*__self_1),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::GetSponsoringRateLimit {
+ contract_address: ref __self_0,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "GetSponsoringRateLimit");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::Allowed {
+ contract_address: ref __self_0,
+ user: ref __self_1,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "Allowed");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ let _ =
+ ::core::fmt::DebugStruct::field(debug_trait_builder, "user", &&(*__self_1));
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::AllowlistEnabled {
+ contract_address: ref __self_0,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "AllowlistEnabled");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::ToggleAllowlist {
+ contract_address: ref __self_0,
+ enabled: ref __self_1,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "ToggleAllowlist");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "enabled",
+ &&(*__self_1),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ (&ContractHelpersCall::ToggleAllowed {
+ contract_address: ref __self_0,
+ user: ref __self_1,
+ allowed: ref __self_2,
+ },) => {
+ let debug_trait_builder =
+ &mut ::core::fmt::Formatter::debug_struct(f, "ToggleAllowed");
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "contract_address",
+ &&(*__self_0),
+ );
+ let _ =
+ ::core::fmt::DebugStruct::field(debug_trait_builder, "user", &&(*__self_1));
+ let _ = ::core::fmt::DebugStruct::field(
+ debug_trait_builder,
+ "allowed",
+ &&(*__self_2),
+ );
+ ::core::fmt::DebugStruct::finish(debug_trait_builder)
+ }
+ }
+ }
+ }
+ impl<T: Config> ContractHelpersCall<T> {
+ #[doc = "contractOwner(address)"]
+ const CONTRACT_OWNER: u32 = 1364373836u32;
+ #[doc = "sponsoringEnabled(address)"]
+ const SPONSORING_ENABLED: u32 = 1613225057u32;
+ #[doc = "toggleSponsoring(address,bool)"]
+ const TOGGLE_SPONSORING: u32 = 4239158662u32;
+ #[doc = "setSponsoringRateLimit(address,uint32)"]
+ const SET_SPONSORING_RATE_LIMIT: u32 = 2008467720u32;
+ #[doc = "getSponsoringRateLimit(address)"]
+ const GET_SPONSORING_RATE_LIMIT: u32 = 1628240573u32;
+ #[doc = "allowed(address,address)"]
+ const ALLOWED: u32 = 1550156133u32;
+ #[doc = "allowlistEnabled(address)"]
+ const ALLOWLIST_ENABLED: u32 = 3346198380u32;
+ #[doc = "toggleAllowlist(address,bool)"]
+ const TOGGLE_ALLOWLIST: u32 = 920527093u32;
+ #[doc = "toggleAllowed(address,address,bool)"]
+ const TOGGLE_ALLOWED: u32 = 1191627804u32;
+ pub const fn interface_id() -> u32 {
+ let mut interface_id = 0;
+ interface_id ^= Self::CONTRACT_OWNER;
+ interface_id ^= Self::SPONSORING_ENABLED;
+ interface_id ^= Self::TOGGLE_SPONSORING;
+ interface_id ^= Self::SET_SPONSORING_RATE_LIMIT;
+ interface_id ^= Self::GET_SPONSORING_RATE_LIMIT;
+ interface_id ^= Self::ALLOWED;
+ interface_id ^= Self::ALLOWLIST_ENABLED;
+ interface_id ^= Self::TOGGLE_ALLOWLIST;
+ interface_id ^= Self::TOGGLE_ALLOWED;
+ interface_id
+ }
+ pub fn supports_interface(interface_id: u32) -> bool {
+ interface_id != 0xffffff
+ && (interface_id == ::evm_coder::ERC165Call::INTERFACE_ID
+ || interface_id == Self::interface_id())
+ }
+ pub fn generate_solidity_interface(tc: &evm_coder::solidity::TypeCollector, is_impl: bool) {
+ use evm_coder::solidity::*;
+ use core::fmt::Write;
+ let interface = SolidityInterface {
+ name: "ContractHelpers",
+ selector: Self::interface_id(),
+ is: &["Dummy", "ERC165"],
+ functions: (
+ SolidityFunction {
+ docs: &[],
+ selector: "contractOwner(address) 5152b14c",
+ name: "contractOwner",
+ mutability: SolidityMutability::View,
+ args: (<NamedArgument<address>>::new("contractAddress"),),
+ result: <UnnamedArgument<address>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "sponsoringEnabled(address) 6027dc61",
+ name: "sponsoringEnabled",
+ mutability: SolidityMutability::View,
+ args: (<NamedArgument<address>>::new("contractAddress"),),
+ result: <UnnamedArgument<bool>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "toggleSponsoring(address,bool) fcac6d86",
+ name: "toggleSponsoring",
+ mutability: SolidityMutability::Mutable,
+ args: (
+ <NamedArgument<address>>::new("contractAddress"),
+ <NamedArgument<bool>>::new("enabled"),
+ ),
+ result: <UnnamedArgument<void>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "setSponsoringRateLimit(address,uint32) 77b6c908",
+ name: "setSponsoringRateLimit",
+ mutability: SolidityMutability::Mutable,
+ args: (
+ <NamedArgument<address>>::new("contractAddress"),
+ <NamedArgument<uint32>>::new("rateLimit"),
+ ),
+ result: <UnnamedArgument<void>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "getSponsoringRateLimit(address) 610cfabd",
+ name: "getSponsoringRateLimit",
+ mutability: SolidityMutability::View,
+ args: (<NamedArgument<address>>::new("contractAddress"),),
+ result: <UnnamedArgument<uint32>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "allowed(address,address) 5c658165",
+ name: "allowed",
+ mutability: SolidityMutability::View,
+ args: (
+ <NamedArgument<address>>::new("contractAddress"),
+ <NamedArgument<address>>::new("user"),
+ ),
+ result: <UnnamedArgument<bool>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "allowlistEnabled(address) c772ef6c",
+ name: "allowlistEnabled",
+ mutability: SolidityMutability::View,
+ args: (<NamedArgument<address>>::new("contractAddress"),),
+ result: <UnnamedArgument<bool>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "toggleAllowlist(address,bool) 36de20f5",
+ name: "toggleAllowlist",
+ mutability: SolidityMutability::Mutable,
+ args: (
+ <NamedArgument<address>>::new("contractAddress"),
+ <NamedArgument<bool>>::new("enabled"),
+ ),
+ result: <UnnamedArgument<void>>::default(),
+ },
+ SolidityFunction {
+ docs: &[],
+ selector: "toggleAllowed(address,address,bool) 4706cc1c",
+ name: "toggleAllowed",
+ mutability: SolidityMutability::Mutable,
+ args: (
+ <NamedArgument<address>>::new("contractAddress"),
+ <NamedArgument<address>>::new("user"),
+ <NamedArgument<bool>>::new("allowed"),
+ ),
+ result: <UnnamedArgument<void>>::default(),
+ },
+ ),
+ };
+ if is_impl {
+ tc . collect ("// Common stubs holder\ncontract Dummy {\n\tuint8 dummy;\n\tstring stub_error = \"this contract is implemented in native\";\n}\ncontract ERC165 is Dummy {\n\tfunction supportsInterface(bytes4 interfaceID) external view returns (bool) {\n\t\trequire(false, stub_error);\n\t\tinterfaceID;\n\t\treturn true;\n\t}\n}\n" . into ()) ;
+ } else {
+ tc . collect ("// Common stubs holder\ninterface Dummy {\n}\ninterface ERC165 is Dummy {\n\tfunction supportsInterface(bytes4 interfaceID) external view returns (bool);\n}\n" . into ()) ;
+ }
+ let mut out = string::new();
+ if "ContractHelpers".starts_with("Inline") {
+ out.push_str("// Inline\n");
+ }
+ let _ = interface.format(is_impl, &mut out, tc);
+ tc.collect(out);
+ }
+ }
+ impl<T: Config> ::evm_coder::Call for ContractHelpersCall<T> {
+ fn parse(
+ method_id: u32,
+ 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(
+ ::evm_coder::ERC165Call::parse(method_id, reader)?.map(Self::ERC165Call)
+ )
+ }
+ Self::CONTRACT_OWNER => {
+ return Ok(Some(Self::ContractOwner {
+ contract_address: reader.abi_read()?,
+ }))
+ }
+ Self::SPONSORING_ENABLED => {
+ return Ok(Some(Self::SponsoringEnabled {
+ contract_address: reader.abi_read()?,
+ }))
+ }
+ Self::TOGGLE_SPONSORING => {
+ return Ok(Some(Self::ToggleSponsoring {
+ contract_address: reader.abi_read()?,
+ enabled: reader.abi_read()?,
+ }))
+ }
+ Self::SET_SPONSORING_RATE_LIMIT => {
+ return Ok(Some(Self::SetSponsoringRateLimit {
+ contract_address: reader.abi_read()?,
+ rate_limit: reader.abi_read()?,
+ }))
+ }
+ Self::GET_SPONSORING_RATE_LIMIT => {
+ return Ok(Some(Self::GetSponsoringRateLimit {
+ contract_address: reader.abi_read()?,
+ }))
+ }
+ Self::ALLOWED => {
+ return Ok(Some(Self::Allowed {
+ contract_address: reader.abi_read()?,
+ user: reader.abi_read()?,
+ }))
+ }
+ Self::ALLOWLIST_ENABLED => {
+ return Ok(Some(Self::AllowlistEnabled {
+ contract_address: reader.abi_read()?,
+ }))
+ }
+ Self::TOGGLE_ALLOWLIST => {
+ return Ok(Some(Self::ToggleAllowlist {
+ contract_address: reader.abi_read()?,
+ enabled: reader.abi_read()?,
+ }))
+ }
+ Self::TOGGLE_ALLOWED => {
+ return Ok(Some(Self::ToggleAllowed {
+ contract_address: reader.abi_read()?,
+ user: reader.abi_read()?,
+ allowed: reader.abi_read()?,
+ }))
+ }
+ _ => {}
+ }
+ return Ok(None);
+ }
+ }
+ impl<T: Config> ::evm_coder::Weighted for ContractHelpersCall<T> {
+ fn weight(&self) -> ::evm_coder::execution::DispatchInfo {
+ type InternalCall = ContractHelpersCall;
+ match self {
+ InternalCall::ERC165Call(::evm_coder::ERC165Call::SupportsInterface { .. }) => {
+ 100u64.into()
+ }
+ InternalCall::ContractOwner { .. } => ().into(),
+ InternalCall::SponsoringEnabled { .. } => ().into(),
+ InternalCall::ToggleSponsoring { .. } => ().into(),
+ InternalCall::SetSponsoringRateLimit { .. } => ().into(),
+ InternalCall::GetSponsoringRateLimit { .. } => ().into(),
+ InternalCall::Allowed { .. } => ().into(),
+ InternalCall::AllowlistEnabled { .. } => ().into(),
+ InternalCall::ToggleAllowlist { .. } => ().into(),
+ InternalCall::ToggleAllowed { .. } => ().into(),
+ }
+ }
+ }
+ impl<T: Config> ::evm_coder::Callable<ContractHelpersCall<T>> for ContractHelpers<T> {
+ #[allow(unreachable_code)]
+ fn call(
+ &mut self,
+ c: Msg<ContractHelpersCall>,
+ ) -> ::evm_coder::execution::ResultWithPostInfo<::evm_coder::abi::AbiWriter> {
+ use ::evm_coder::abi::AbiWrite;
+ type InternalCall = ContractHelpersCall;
+ match c.call {
+ InternalCall::ERC165Call(::evm_coder::ERC165Call::SupportsInterface {
+ interface_id,
+ }) => {
+ let mut writer = ::evm_coder::abi::AbiWriter::default();
+ writer.bool(&InternalCall::supports_interface(interface_id));
+ return Ok(writer.into());
+ }
+ _ => {}
+ }
+ let mut writer = ::evm_coder::abi::AbiWriter::default();
+ match c.call {
+ InternalCall::ContractOwner { contract_address } => {
+ let result = self.contract_owner(contract_address)?;
+ (&result).into_result()
+ }
+ InternalCall::SponsoringEnabled { contract_address } => {
+ let result = self.sponsoring_enabled(contract_address)?;
+ (&result).into_result()
+ }
+ InternalCall::ToggleSponsoring {
+ contract_address,
+ enabled,
+ } => {
+ let result =
+ self.toggle_sponsoring(c.caller.clone(), contract_address, enabled)?;
+ (&result).into_result()
+ }
+ InternalCall::SetSponsoringRateLimit {
+ contract_address,
+ rate_limit,
+ } => {
+ let result = self.set_sponsoring_rate_limit(
+ c.caller.clone(),
+ contract_address,
+ rate_limit,
+ )?;
+ (&result).into_result()
+ }
+ InternalCall::GetSponsoringRateLimit { contract_address } => {
+ let result = self.get_sponsoring_rate_limit(contract_address)?;
+ (&result).into_result()
+ }
+ InternalCall::Allowed {
+ contract_address,
+ user,
+ } => {
+ let result = self.allowed(contract_address, user)?;
+ (&result).into_result()
+ }
+ InternalCall::AllowlistEnabled { contract_address } => {
+ let result = self.allowlist_enabled(contract_address)?;
+ (&result).into_result()
+ }
+ InternalCall::ToggleAllowlist {
+ contract_address,
+ enabled,
+ } => {
+ let result =
+ self.toggle_allowlist(c.caller.clone(), contract_address, enabled)?;
+ (&result).into_result()
+ }
+ InternalCall::ToggleAllowed {
+ contract_address,
+ user,
+ allowed,
+ } => {
+ let result =
+ self.toggle_allowed(c.caller.clone(), contract_address, user, allowed)?;
+ (&result).into_result()
+ }
+ _ => ::core::panicking::panic("internal error: entered unreachable code"),
+ }
+ }
+ }
+ pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);
+ impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T> {
+ fn is_reserved(contract: &sp_core::H160) -> bool {
+ contract == &T::ContractAddress::get()
+ }
+ fn is_used(contract: &sp_core::H160) -> bool {
+ contract == &T::ContractAddress::get()
+ }
+ fn call(
+ source: &sp_core::H160,
+ target: &sp_core::H160,
+ gas_left: u64,
+ input: &[u8],
+ value: sp_core::U256,
+ ) -> Option<PrecompileOutput> {
+ if !<Pallet<T>>::allowed(*target, *source, true) {
+ return Some(PrecompileOutput {
+ exit_status: ExitReason::Revert(ExitRevert::Reverted),
+ cost: 0,
+ output: {
+ let mut writer = AbiWriter::new_call(147028384u32);
+ writer.string("Target contract is allowlisted");
+ writer.finish()
+ },
+ logs: ::alloc::vec::Vec::new(),
+ });
+ }
+ if target != &T::ContractAddress::get() {
+ return None;
+ }
+ let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(*target, gas_left));
+ pallet_evm_coder_substrate::call(*source, helpers, value, input)
+ }
+ fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
+ (contract == & T :: ContractAddress :: get ()) . then (| | b"`\xe0`@R`&`\x80\x81\x81R\x90a\x04\xf4`\xa09\x80Qa\x00&\x91`\x01\x91` \x90\x91\x01\x90a\x009V[P4\x80\x15a\x003W`\x00\x80\xfd[Pa\x01\rV[\x82\x80Ta\x00E\x90a\x00\xd2V[\x90`\x00R` `\x00 \x90`\x1f\x01` \x90\x04\x81\x01\x92\x82a\x00gW`\x00\x85Ua\x00\xadV[\x82`\x1f\x10a\x00\x80W\x80Q`\xff\x19\x16\x83\x80\x01\x17\x85Ua\x00\xadV[\x82\x80\x01`\x01\x01\x85U\x82\x15a\x00\xadW\x91\x82\x01[\x82\x81\x11\x15a\x00\xadW\x82Q\x82U\x91` \x01\x91\x90`\x01\x01\x90a\x00\x92V[Pa\x00\xb9\x92\x91Pa\x00\xbdV[P\x90V[[\x80\x82\x11\x15a\x00\xb9W`\x00\x81U`\x01\x01a\x00\xbeV[`\x01\x81\x81\x1c\x90\x82\x16\x80a\x00\xe6W`\x7f\x82\x16\x91P[` \x82\x10\x81\x14\x15a\x01\x07WcNH{q`\xe0\x1b`\x00R`\"`\x04R`$`\x00\xfd[P\x91\x90PV[a\x03\xd8\x80a\x01\x1c`\x009`\x00\xf3\xfe`\x80`@R4\x80\x15a\x00\x10W`\x00\x80\xfd[P`\x046\x10a\x00\x9eW`\x005`\xe0\x1c\x80c`\'\xdca\x11a\x00fW\x80c`\'\xdca\x14a\x01\"W\x80ca\x0c\xfa\xbd\x14a\x010W\x80cw\xb6\xc9\x08\x14a\x01SW\x80c\xc7r\xefl\x14a\x01\"W\x80c\xfc\xacm\x86\x14a\x00\xcbW`\x00\x80\xfd[\x80c\x01\xff\xc9\xa7\x14a\x00\xa3W\x80c6\xde \xf5\x14a\x00\xcbW\x80cG\x06\xcc\x1c\x14a\x00\xe0W\x80cQR\xb1L\x14a\x00\xeeW\x80c\\e\x81e\x14a\x01\x14W[`\x00\x80\xfd[a\x00\xb6a\x00\xb16`\x04a\x01\xa2V[a\x01aV[`@Q\x90\x15\x15\x81R` \x01[`@Q\x80\x91\x03\x90\xf3[a\x00\xdea\x00\xd96`\x04a\x01\xffV[a\x01\x87V[\x00[a\x00\xdea\x00\xd96`\x04a\x022V[a\x00\xfca\x00\xb16`\x04a\x02uV[`@Q`\x01`\x01`\xa0\x1b\x03\x90\x91\x16\x81R` \x01a\x00\xc2V[a\x00\xb6a\x00\xb16`\x04a\x02\x90V[a\x00\xb6a\x00\xb16`\x04a\x02uV[a\x01>a\x00\xb16`\x04a\x02uV[`@Qc\xff\xff\xff\xff\x90\x91\x16\x81R` \x01a\x00\xc2V[a\x00\xdea\x00\xd96`\x04a\x02\xbaV[`\x00`\x01`@QbF\x1b\xcd`\xe5\x1b\x81R`\x04\x01a\x01~\x91\x90a\x02\xfaV[`@Q\x80\x91\x03\x90\xfd[`\x01`@QbF\x1b\xcd`\xe5\x1b\x81R`\x04\x01a\x01~\x91\x90a\x02\xfaV[`\x00` \x82\x84\x03\x12\x15a\x01\xb4W`\x00\x80\xfd[\x815`\x01`\x01`\xe0\x1b\x03\x19\x81\x16\x81\x14a\x01\xccW`\x00\x80\xfd[\x93\x92PPPV[\x805`\x01`\x01`\xa0\x1b\x03\x81\x16\x81\x14a\x01\xeaW`\x00\x80\xfd[\x91\x90PV[\x805\x80\x15\x15\x81\x14a\x01\xeaW`\x00\x80\xfd[`\x00\x80`@\x83\x85\x03\x12\x15a\x02\x12W`\x00\x80\xfd[a\x02\x1b\x83a\x01\xd3V[\x91Pa\x02)` \x84\x01a\x01\xefV[\x90P\x92P\x92\x90PV[`\x00\x80`\x00``\x84\x86\x03\x12\x15a\x02GW`\x00\x80\xfd[a\x02P\x84a\x01\xd3V[\x92Pa\x02^` \x85\x01a\x01\xd3V[\x91Pa\x02l`@\x85\x01a\x01\xefV[\x90P\x92P\x92P\x92V[`\x00` \x82\x84\x03\x12\x15a\x02\x87W`\x00\x80\xfd[a\x01\xcc\x82a\x01\xd3V[`\x00\x80`@\x83\x85\x03\x12\x15a\x02\xa3W`\x00\x80\xfd[a\x02\xac\x83a\x01\xd3V[\x91Pa\x02)` \x84\x01a\x01\xd3V[`\x00\x80`@\x83\x85\x03\x12\x15a\x02\xcdW`\x00\x80\xfd[a\x02\xd6\x83a\x01\xd3V[\x91P` \x83\x015c\xff\xff\xff\xff\x81\x16\x81\x14a\x02\xefW`\x00\x80\xfd[\x80\x91PP\x92P\x92\x90PV[`\x00` \x80\x83R`\x00\x84T\x81`\x01\x82\x81\x1c\x91P\x80\x83\x16\x80a\x03\x1cW`\x7f\x83\x16\x92P[\x85\x83\x10\x81\x14\x15a\x03:WcNH{q`\xe0\x1b\x85R`\"`\x04R`$\x85\xfd[\x87\x86\x01\x83\x81R` \x01\x81\x80\x15a\x03WW`\x01\x81\x14a\x03hWa\x03\x93V[`\xff\x19\x86\x16\x82R\x87\x82\x01\x96Pa\x03\x93V[`\x00\x8b\x81R` \x90 `\x00[\x86\x81\x10\x15a\x03\x8dW\x81T\x84\x82\x01R\x90\x85\x01\x90\x89\x01a\x03tV[\x83\x01\x97PP[P\x94\x99\x98PPPPPPPPPV\xfe\xa2dipfsX\"\x12 \xde\xe1\xb0gnP\xa0\xbb\xa7\xaf\xbek+\xe6S6\n\xcd?\x0c+\x81\xebEq\x8c\xe3\xab\xaaC6UdsolcC\x00\x08\t\x003this contract is implemented in native" . to_vec ())
+ }
+ }
+ pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);
+ impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {
+ fn on_create(owner: H160, contract: H160) {
+ <Owner<T>>::insert(contract, owner);
+ }
+ }
+ pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);
+ impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {
+ fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {
+ if <SelfSponsoring<T>>::get(&call.0) && <Pallet<T>>::allowed(call.0, *who, false) {
+ let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
+ if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
+ let rate_limit = <SponsoringRateLimit<T>>::get(&call.0);
+ let limit_time = last_tx_block + rate_limit;
+ if block_number > limit_time {
+ <SponsorBasket<T>>::insert(&call.0, who, block_number);
+ return Some(call.0);
+ }
+ } else {
+ <SponsorBasket<T>>::insert(&call.0, who, block_number);
+ return Some(call.0);
+ }
+ }
+ None
+ }
+ }
+}
+#[doc = r"
+ The module that hosts all the
+ [FRAME](https://docs.substrate.io/v3/runtime/frame)
+ types needed to add this pallet to a
+ runtime.
+ "]
+pub mod pallet {
+ use evm_coder::execution::Result;
+ use frame_support::pallet_prelude::*;
+ use sp_core::H160;
+ #[doc = r"
+ Configuration trait of this pallet.
+
+ Implement this type for a runtime in order to customize this pallet.
+ "]
+ pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {
+ type ContractAddress: Get<H160>;
+ type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;
+ }
+ #[scale_info(skip_type_params(T), capture_docs = "always")]
+ #[doc = r"
+ Custom [dispatch errors](https://docs.substrate.io/v3/runtime/events-and-errors)
+ of this pallet.
+ "]
+ pub enum Error<T> {
+ #[doc(hidden)]
+ #[codec(skip)]
+ __Ignore(
+ frame_support::sp_std::marker::PhantomData<(T)>,
+ frame_support::Never,
+ ),
+ #[doc = " This method is only executable by owner"]
+ NoPermission,
+ }
+ #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
+ const _: () = {
+ impl<T> ::scale_info::TypeInfo for Error<T>
+ where
+ frame_support::sp_std::marker::PhantomData<(T)>: ::scale_info::TypeInfo + 'static,
+ T: 'static,
+ {
+ type Identity = Self;
+ fn type_info() -> ::scale_info::Type {
+ :: scale_info :: Type :: builder () . path (:: scale_info :: Path :: new ("Error" , "pallet_evm_contract_helpers::pallet")) . type_params (< [_] > :: into_vec (box [:: scale_info :: TypeParameter :: new ("T" , :: core :: option :: Option :: None)])) . docs_always (& ["\n\t\t\tCustom [dispatch errors](https://docs.substrate.io/v3/runtime/events-and-errors)\n\t\t\tof this pallet.\n\t\t\t"]) . variant (:: scale_info :: build :: Variants :: new () . variant ("NoPermission" , | v | v . index (0usize as :: core :: primitive :: u8) . docs_always (& ["This method is only executable by owner"])))
+ }
+ };
+ };
+ #[doc = r"
+ The [pallet](https://docs.substrate.io/v3/runtime/frame#pallets) implementing
+ the on-chain logic.
+ "]
+ pub struct Pallet<T>(frame_support::sp_std::marker::PhantomData<(T)>);
+ const _: () = {
+ impl<T> core::clone::Clone for Pallet<T> {
+ fn clone(&self) -> Self {
+ Self(core::clone::Clone::clone(&self.0))
+ }
+ }
+ };
+ const _: () = {
+ impl<T> core::cmp::Eq for Pallet<T> {}
+ };
+ const _: () = {
+ impl<T> core::cmp::PartialEq for Pallet<T> {
+ fn eq(&self, other: &Self) -> bool {
+ true && self.0 == other.0
+ }
+ }
+ };
+ const _: () = {
+ impl<T> core::fmt::Debug for Pallet<T> {
+ fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
+ fmt.debug_tuple("Pallet").field(&self.0).finish()
+ }
+ }
+ };
+ #[allow(type_alias_bounds)]
+ pub(super) type Owner<T: Config> = StorageMap<
+ _GeneratedPrefixForStorageOwner<T>,
+ Twox128,
+ H160,
+ H160,
+ ValueQuery,
+ frame_support::traits::GetDefault,
+ frame_support::traits::GetDefault,
+ >;
+ #[allow(type_alias_bounds)]
+ pub(super) type SelfSponsoring<T: Config> = StorageMap<
+ _GeneratedPrefixForStorageSelfSponsoring<T>,
+ Twox128,
+ H160,
+ bool,
+ ValueQuery,
+ frame_support::traits::GetDefault,
+ frame_support::traits::GetDefault,
+ >;
+ #[allow(type_alias_bounds)]
+ pub(super) type SponsoringRateLimit<T: Config> = StorageMap<
+ _GeneratedPrefixForStorageSponsoringRateLimit<T>,
+ Twox128,
+ H160,
+ T::BlockNumber,
+ ValueQuery,
+ T::DefaultSponsoringRateLimit,
+ frame_support::traits::GetDefault,
+ >;
+ #[allow(type_alias_bounds)]
+ pub(super) type SponsorBasket<T: Config> = StorageDoubleMap<
+ _GeneratedPrefixForStorageSponsorBasket<T>,
+ Twox128,
+ H160,
+ Twox128,
+ H160,
+ T::BlockNumber,
+ OptionQuery,
+ frame_support::traits::GetDefault,
+ frame_support::traits::GetDefault,
+ >;
+ #[allow(type_alias_bounds)]
+ pub(super) type AllowlistEnabled<T: Config> = StorageMap<
+ _GeneratedPrefixForStorageAllowlistEnabled<T>,
+ Twox128,
+ H160,
+ bool,
+ ValueQuery,
+ frame_support::traits::GetDefault,
+ frame_support::traits::GetDefault,
+ >;
+ #[allow(type_alias_bounds)]
+ pub(super) type Allowlist<T: Config> = StorageDoubleMap<
+ _GeneratedPrefixForStorageAllowlist<T>,
+ Twox128,
+ H160,
+ Twox128,
+ H160,
+ bool,
+ ValueQuery,
+ frame_support::traits::GetDefault,
+ frame_support::traits::GetDefault,
+ >;
+ impl<T: Config> Pallet<T> {
+ pub fn toggle_sponsoring(contract: H160, enabled: bool) {
+ <SelfSponsoring<T>>::insert(contract, enabled);
+ }
+ pub fn set_sponsoring_rate_limit(contract: H160, rate_limit: T::BlockNumber) {
+ <SponsoringRateLimit<T>>::insert(contract, rate_limit);
+ }
+ #[doc = " Default is returned if allowlist is disabled"]
+ pub fn allowed(contract: H160, user: H160, default: bool) -> bool {
+ if !<AllowlistEnabled<T>>::get(contract) {
+ return default;
+ }
+ <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user
+ }
+ pub fn toggle_allowlist(contract: H160, enabled: bool) {
+ <AllowlistEnabled<T>>::insert(contract, enabled)
+ }
+ pub fn toggle_allowed(contract: H160, user: H160, allowed: bool) {
+ <Allowlist<T>>::insert(contract, user, allowed);
+ }
+ pub fn ensure_owner(contract: H160, user: H160) -> Result<()> {
+ {
+ if !(<Owner<T>>::get(&contract) == user) {
+ {
+ return Err("no permission".into());
+ };
+ }
+ };
+ Ok(())
+ }
+ }
+ impl<T: Config> Pallet<T> {
+ #[doc(hidden)]
+ pub fn pallet_constants_metadata(
+ ) -> frame_support::sp_std::vec::Vec<frame_support::metadata::PalletConstantMetadata>
+ {
+ ::alloc::vec::Vec::new()
+ }
+ }
+ impl<T: Config> Pallet<T> {
+ pub fn error_metadata() -> Option<frame_support::metadata::PalletErrorMetadata> {
+ Some(frame_support::metadata::PalletErrorMetadata {
+ ty: frame_support::scale_info::meta_type::<Error<T>>(),
+ })
+ }
+ }
+ #[doc = r" Type alias to `Pallet`, to be used by `construct_runtime`."]
+ #[doc = r""]
+ #[doc = r" Generated by `pallet` attribute macro."]
+ #[deprecated(note = "use `Pallet` instead")]
+ #[allow(dead_code)]
+ pub type Module<T> = Pallet<T>;
+ impl<T: Config> frame_support::traits::GetStorageVersion for Pallet<T> {
+ fn current_storage_version() -> frame_support::traits::StorageVersion {
+ frame_support::traits::StorageVersion::default()
+ }
+ fn on_chain_storage_version() -> frame_support::traits::StorageVersion {
+ frame_support::traits::StorageVersion::get::<Self>()
+ }
+ }
+ impl<T: Config> frame_support::traits::OnGenesis for Pallet<T> {
+ fn on_genesis() {
+ let storage_version = frame_support::traits::StorageVersion::default();
+ storage_version.put::<Self>();
+ }
+ }
+ impl<T: Config> frame_support::traits::PalletInfoAccess for Pallet<T> {
+ fn index() -> usize {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::index::<
+ Self,
+ >()
+ .expect(
+ "Pallet is part of the runtime because pallet `Config` trait is \
+ implemented by the runtime",
+ )
+ }
+ fn name() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Self,
+ >()
+ .expect(
+ "Pallet is part of the runtime because pallet `Config` trait is \
+ implemented by the runtime",
+ )
+ }
+ fn module_name() -> &'static str {
+ < < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: module_name :: < Self > () . expect ("Pallet is part of the runtime because pallet `Config` trait is \
+ implemented by the runtime")
+ }
+ fn crate_version() -> frame_support::traits::CrateVersion {
+ frame_support::traits::CrateVersion {
+ major: 0u16,
+ minor: 1u8,
+ patch: 0u8,
+ }
+ }
+ }
+ impl<T: Config> frame_support::traits::StorageInfoTrait for Pallet<T> {
+ fn storage_info() -> frame_support::sp_std::vec::Vec<frame_support::traits::StorageInfo> {
+ #[allow(unused_mut)]
+ let mut res = ::alloc::vec::Vec::new();
+ {
+ let mut storage_info = < Owner < T > as frame_support :: traits :: PartialStorageInfoTrait > :: partial_storage_info () ;
+ res.append(&mut storage_info);
+ }
+ {
+ let mut storage_info = < SelfSponsoring < T > as frame_support :: traits :: PartialStorageInfoTrait > :: partial_storage_info () ;
+ res.append(&mut storage_info);
+ }
+ {
+ let mut storage_info = < SponsoringRateLimit < T > as frame_support :: traits :: PartialStorageInfoTrait > :: partial_storage_info () ;
+ res.append(&mut storage_info);
+ }
+ {
+ let mut storage_info = < SponsorBasket < T > as frame_support :: traits :: PartialStorageInfoTrait > :: partial_storage_info () ;
+ res.append(&mut storage_info);
+ }
+ {
+ let mut storage_info = < AllowlistEnabled < T > as frame_support :: traits :: PartialStorageInfoTrait > :: partial_storage_info () ;
+ res.append(&mut storage_info);
+ }
+ {
+ let mut storage_info = < Allowlist < T > as frame_support :: traits :: PartialStorageInfoTrait > :: partial_storage_info () ;
+ res.append(&mut storage_info);
+ }
+ res
+ }
+ }
+ #[doc(hidden)]
+ pub mod __substrate_call_check {
+ #[doc(hidden)]
+ pub use __is_call_part_defined_0 as is_call_part_defined;
+ }
+ #[doc = r"Contains one variant per dispatchable that can be called by an extrinsic."]
+ #[codec(encode_bound())]
+ #[codec(decode_bound())]
+ #[scale_info(skip_type_params(T), capture_docs = "always")]
+ #[allow(non_camel_case_types)]
+ pub enum Call<T: Config> {
+ #[doc(hidden)]
+ #[codec(skip)]
+ __Ignore(
+ frame_support::sp_std::marker::PhantomData<(T,)>,
+ frame_support::Never,
+ ),
+ }
+ const _: () = {
+ impl<T: Config> core::fmt::Debug for Call<T> {
+ fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
+ match *self {
+ Self::__Ignore(ref _0, ref _1) => fmt
+ .debug_tuple("Call::__Ignore")
+ .field(&_0)
+ .field(&_1)
+ .finish(),
+ }
+ }
+ }
+ };
+ const _: () = {
+ impl<T: Config> core::clone::Clone for Call<T> {
+ fn clone(&self) -> Self {
+ match self {
+ Self::__Ignore(ref _0, ref _1) => {
+ Self::__Ignore(core::clone::Clone::clone(_0), core::clone::Clone::clone(_1))
+ }
+ }
+ }
+ }
+ };
+ const _: () = {
+ impl<T: Config> core::cmp::Eq for Call<T> {}
+ };
+ const _: () = {
+ impl<T: Config> core::cmp::PartialEq for Call<T> {
+ fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::__Ignore(_0, _1), Self::__Ignore(_0_other, _1_other)) => {
+ true && _0 == _0_other && _1 == _1_other
+ }
+ }
+ }
+ }
+ };
+ const _: () = {
+ #[allow(non_camel_case_types)]
+ impl<T: Config> ::codec::Encode for Call<T> {}
+ impl<T: Config> ::codec::EncodeLike for Call<T> {}
+ };
+ const _: () = {
+ #[allow(non_camel_case_types)]
+ impl<T: Config> ::codec::Decode for Call<T> {
+ fn decode<__CodecInputEdqy: ::codec::Input>(
+ __codec_input_edqy: &mut __CodecInputEdqy,
+ ) -> ::core::result::Result<Self, ::codec::Error> {
+ match __codec_input_edqy
+ .read_byte()
+ .map_err(|e| e.chain("Could not decode `Call`, failed to read variant byte"))?
+ {
+ _ => ::core::result::Result::Err(<_ as ::core::convert::Into<_>>::into(
+ "Could not decode `Call`, variant doesn\'t exist",
+ )),
+ }
+ }
+ }
+ };
+ #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
+ const _: () = {
+ impl<T: Config> ::scale_info::TypeInfo for Call<T>
+ where
+ frame_support::sp_std::marker::PhantomData<(T,)>: ::scale_info::TypeInfo + 'static,
+ T: Config + 'static,
+ {
+ type Identity = Self;
+ fn type_info() -> ::scale_info::Type {
+ ::scale_info::Type::builder()
+ .path(::scale_info::Path::new(
+ "Call",
+ "pallet_evm_contract_helpers::pallet",
+ ))
+ .type_params(<[_]>::into_vec(box [::scale_info::TypeParameter::new(
+ "T",
+ ::core::option::Option::None,
+ )]))
+ .docs_always(&[
+ "Contains one variant per dispatchable that can be called by an extrinsic.",
+ ])
+ .variant(::scale_info::build::Variants::new())
+ }
+ };
+ };
+ impl<T: Config> Call<T> {}
+ impl<T: Config> frame_support::dispatch::GetDispatchInfo for Call<T> {
+ fn get_dispatch_info(&self) -> frame_support::dispatch::DispatchInfo {
+ match *self {
+ Self::__Ignore(_, _) => {
+ ::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1(
+ &["internal error: entered unreachable code: "],
+ &match (&"__Ignore cannot be used",) {
+ (arg0,) => [::core::fmt::ArgumentV1::new(
+ arg0,
+ ::core::fmt::Display::fmt,
+ )],
+ },
+ ))
+ }
+ }
+ }
+ }
+ impl<T: Config> frame_support::dispatch::GetCallName for Call<T> {
+ fn get_call_name(&self) -> &'static str {
+ match *self {
+ Self::__Ignore(_, _) => {
+ ::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1(
+ &["internal error: entered unreachable code: "],
+ &match (&"__PhantomItem cannot be used.",) {
+ (arg0,) => [::core::fmt::ArgumentV1::new(
+ arg0,
+ ::core::fmt::Display::fmt,
+ )],
+ },
+ ))
+ }
+ }
+ }
+ fn get_call_names() -> &'static [&'static str] {
+ &[]
+ }
+ }
+ impl<T: Config> frame_support::traits::UnfilteredDispatchable for Call<T> {
+ type Origin = frame_system::pallet_prelude::OriginFor<T>;
+ fn dispatch_bypass_filter(
+ self,
+ origin: Self::Origin,
+ ) -> frame_support::dispatch::DispatchResultWithPostInfo {
+ match self {
+ Self::__Ignore(_, _) => {
+ let _ = origin;
+ {
+ {
+ ::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1(
+ &["internal error: entered unreachable code: "],
+ &match (&"__PhantomItem cannot be used.",) {
+ (arg0,) => [::core::fmt::ArgumentV1::new(
+ arg0,
+ ::core::fmt::Display::fmt,
+ )],
+ },
+ ))
+ }
+ };
+ }
+ }
+ }
+ }
+ impl<T: Config> frame_support::dispatch::Callable<T> for Pallet<T> {
+ type Call = Call<T>;
+ }
+ impl<T: Config> Pallet<T> {
+ #[doc(hidden)]
+ pub fn call_functions() -> frame_support::metadata::PalletCallMetadata {
+ frame_support::scale_info::meta_type::<Call<T>>().into()
+ }
+ }
+ impl<T: Config> frame_support::sp_std::fmt::Debug for Error<T> {
+ fn fmt(
+ &self,
+ f: &mut frame_support::sp_std::fmt::Formatter<'_>,
+ ) -> frame_support::sp_std::fmt::Result {
+ f.write_str(self.as_str())
+ }
+ }
+ impl<T: Config> Error<T> {
+ pub fn as_u8(&self) -> u8 {
+ match &self {
+ Self::__Ignore(_, _) => {
+ ::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1(
+ &["internal error: entered unreachable code: "],
+ &match (&"`__Ignore` can never be constructed",) {
+ (arg0,) => [::core::fmt::ArgumentV1::new(
+ arg0,
+ ::core::fmt::Display::fmt,
+ )],
+ },
+ ))
+ }
+ Self::NoPermission => 0usize as u8,
+ }
+ }
+ pub fn as_str(&self) -> &'static str {
+ match &self {
+ Self::__Ignore(_, _) => {
+ ::core::panicking::panic_fmt(::core::fmt::Arguments::new_v1(
+ &["internal error: entered unreachable code: "],
+ &match (&"`__Ignore` can never be constructed",) {
+ (arg0,) => [::core::fmt::ArgumentV1::new(
+ arg0,
+ ::core::fmt::Display::fmt,
+ )],
+ },
+ ))
+ }
+ Self::NoPermission => "NoPermission",
+ }
+ }
+ }
+ impl<T: Config> From<Error<T>> for &'static str {
+ fn from(err: Error<T>) -> &'static str {
+ err.as_str()
+ }
+ }
+ impl<T: Config> From<Error<T>> for frame_support::sp_runtime::DispatchError {
+ fn from(err: Error<T>) -> Self {
+ let index = < < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: index :: < Pallet < T > > () . expect ("Every active module has an index in the runtime; qed") as u8 ;
+ frame_support::sp_runtime::DispatchError::Module {
+ index,
+ error: err.as_u8(),
+ message: Some(err.as_str()),
+ }
+ }
+ }
+ #[doc(hidden)]
+ pub mod __substrate_event_check {
+ #[doc(hidden)]
+ pub use __is_event_part_defined_1 as is_event_part_defined;
+ }
+ impl<T: Config> Pallet<T> {
+ #[doc(hidden)]
+ pub fn storage_metadata() -> frame_support::metadata::PalletStorageMetadata {
+ frame_support :: metadata :: PalletStorageMetadata { prefix : < < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: name :: < Pallet < T > > () . expect ("Every active pallet has a name in the runtime; qed") , entries : { # [allow (unused_mut)] let mut entries = :: alloc :: vec :: Vec :: new () ; { < Owner < T > as frame_support :: storage :: StorageEntryMetadataBuilder > :: build_metadata (:: alloc :: vec :: Vec :: new () , & mut entries) ; } { < SelfSponsoring < T > as frame_support :: storage :: StorageEntryMetadataBuilder > :: build_metadata (:: alloc :: vec :: Vec :: new () , & mut entries) ; } { < SponsoringRateLimit < T > as frame_support :: storage :: StorageEntryMetadataBuilder > :: build_metadata (:: alloc :: vec :: Vec :: new () , & mut entries) ; } { < SponsorBasket < T > as frame_support :: storage :: StorageEntryMetadataBuilder > :: build_metadata (:: alloc :: vec :: Vec :: new () , & mut entries) ; } { < AllowlistEnabled < T > as frame_support :: storage :: StorageEntryMetadataBuilder > :: build_metadata (:: alloc :: vec :: Vec :: new () , & mut entries) ; } { < Allowlist < T > as frame_support :: storage :: StorageEntryMetadataBuilder > :: build_metadata (:: alloc :: vec :: Vec :: new () , & mut entries) ; } entries } , }
+ }
+ }
+ pub(super) struct _GeneratedPrefixForStorageOwner<T>(core::marker::PhantomData<(T,)>);
+ impl<T: Config> frame_support::traits::StorageInstance for _GeneratedPrefixForStorageOwner<T> {
+ fn pallet_prefix() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Pallet<T>,
+ >()
+ .expect("Every active pallet has a name in the runtime; qed")
+ }
+ const STORAGE_PREFIX: &'static str = "Owner";
+ }
+ pub(super) struct _GeneratedPrefixForStorageSelfSponsoring<T>(core::marker::PhantomData<(T,)>);
+ impl<T: Config> frame_support::traits::StorageInstance
+ for _GeneratedPrefixForStorageSelfSponsoring<T>
+ {
+ fn pallet_prefix() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Pallet<T>,
+ >()
+ .expect("Every active pallet has a name in the runtime; qed")
+ }
+ const STORAGE_PREFIX: &'static str = "SelfSponsoring";
+ }
+ pub(super) struct _GeneratedPrefixForStorageSponsoringRateLimit<T>(
+ core::marker::PhantomData<(T,)>,
+ );
+ impl<T: Config> frame_support::traits::StorageInstance
+ for _GeneratedPrefixForStorageSponsoringRateLimit<T>
+ {
+ fn pallet_prefix() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Pallet<T>,
+ >()
+ .expect("Every active pallet has a name in the runtime; qed")
+ }
+ const STORAGE_PREFIX: &'static str = "SponsoringRateLimit";
+ }
+ pub(super) struct _GeneratedPrefixForStorageSponsorBasket<T>(core::marker::PhantomData<(T,)>);
+ impl<T: Config> frame_support::traits::StorageInstance
+ for _GeneratedPrefixForStorageSponsorBasket<T>
+ {
+ fn pallet_prefix() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Pallet<T>,
+ >()
+ .expect("Every active pallet has a name in the runtime; qed")
+ }
+ const STORAGE_PREFIX: &'static str = "SponsorBasket";
+ }
+ pub(super) struct _GeneratedPrefixForStorageAllowlistEnabled<T>(
+ core::marker::PhantomData<(T,)>,
+ );
+ impl<T: Config> frame_support::traits::StorageInstance
+ for _GeneratedPrefixForStorageAllowlistEnabled<T>
+ {
+ fn pallet_prefix() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Pallet<T>,
+ >()
+ .expect("Every active pallet has a name in the runtime; qed")
+ }
+ const STORAGE_PREFIX: &'static str = "AllowlistEnabled";
+ }
+ pub(super) struct _GeneratedPrefixForStorageAllowlist<T>(core::marker::PhantomData<(T,)>);
+ impl<T: Config> frame_support::traits::StorageInstance for _GeneratedPrefixForStorageAllowlist<T> {
+ fn pallet_prefix() -> &'static str {
+ <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
+ Pallet<T>,
+ >()
+ .expect("Every active pallet has a name in the runtime; qed")
+ }
+ const STORAGE_PREFIX: &'static str = "Allowlist";
+ }
+ #[doc(hidden)]
+ pub mod __substrate_inherent_check {
+ #[doc(hidden)]
+ pub use __is_inherent_part_defined_2 as is_inherent_part_defined;
+ }
+ #[doc = r" Hidden instance generated to be internally used when module is used without"]
+ #[doc = r" instance."]
+ #[doc(hidden)]
+ pub type __InherentHiddenInstance = ();
+ pub(super) trait Store {
+ type Owner;
+ type SelfSponsoring;
+ type SponsoringRateLimit;
+ type SponsorBasket;
+ type AllowlistEnabled;
+ type Allowlist;
+ }
+ impl<T: Config> Store for Pallet<T> {
+ type Owner = Owner<T>;
+ type SelfSponsoring = SelfSponsoring<T>;
+ type SponsoringRateLimit = SponsoringRateLimit<T>;
+ type SponsorBasket = SponsorBasket<T>;
+ type AllowlistEnabled = AllowlistEnabled<T>;
+ type Allowlist = Allowlist<T>;
+ }
+ impl<T: Config> frame_support::traits::Hooks<<T as frame_system::Config>::BlockNumber>
+ for Pallet<T>
+ {
+ }
+ impl<T: Config> frame_support::traits::OnFinalize<<T as frame_system::Config>::BlockNumber>
+ for Pallet<T>
+ {
+ fn on_finalize(n: <T as frame_system::Config>::BlockNumber) {
+ let __within_span__ = {
+ use ::tracing::__macro_support::Callsite as _;
+ static CALLSITE: ::tracing::__macro_support::MacroCallsite = {
+ use ::tracing::__macro_support::MacroCallsite;
+ static META: ::tracing::Metadata<'static> = {
+ ::tracing_core::metadata::Metadata::new(
+ "on_finalize",
+ "pallet_evm_contract_helpers::pallet",
+ ::tracing::Level::TRACE,
+ Some("pallets/evm-contract-helpers/src/lib.rs"),
+ Some(7u32),
+ Some("pallet_evm_contract_helpers::pallet"),
+ ::tracing_core::field::FieldSet::new(
+ &[],
+ ::tracing_core::callsite::Identifier(&CALLSITE),
+ ),
+ ::tracing::metadata::Kind::SPAN,
+ )
+ };
+ MacroCallsite::new(&META)
+ };
+ let mut interest = ::tracing::subscriber::Interest::never();
+ if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
+ && ::tracing::Level::TRACE <= ::tracing::level_filters::LevelFilter::current()
+ && {
+ interest = CALLSITE.interest();
+ !interest.is_never()
+ }
+ && CALLSITE.is_enabled(interest)
+ {
+ let meta = CALLSITE.metadata();
+ ::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
+ } else {
+ let span = CALLSITE.disabled_span();
+ {};
+ span
+ }
+ };
+ let __tracing_guard__ = __within_span__.enter();
+ < Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_finalize (n)
+ }
+ }
+ impl<T: Config> frame_support::traits::OnIdle<<T as frame_system::Config>::BlockNumber>
+ for Pallet<T>
+ {
+ fn on_idle(
+ n: <T as frame_system::Config>::BlockNumber,
+ remaining_weight: frame_support::weights::Weight,
+ ) -> frame_support::weights::Weight {
+ < Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_idle (n , remaining_weight)
+ }
+ }
+ impl<T: Config> frame_support::traits::OnInitialize<<T as frame_system::Config>::BlockNumber>
+ for Pallet<T>
+ {
+ fn on_initialize(
+ n: <T as frame_system::Config>::BlockNumber,
+ ) -> frame_support::weights::Weight {
+ let __within_span__ = {
+ use ::tracing::__macro_support::Callsite as _;
+ static CALLSITE: ::tracing::__macro_support::MacroCallsite = {
+ use ::tracing::__macro_support::MacroCallsite;
+ static META: ::tracing::Metadata<'static> = {
+ ::tracing_core::metadata::Metadata::new(
+ "on_initialize",
+ "pallet_evm_contract_helpers::pallet",
+ ::tracing::Level::TRACE,
+ Some("pallets/evm-contract-helpers/src/lib.rs"),
+ Some(7u32),
+ Some("pallet_evm_contract_helpers::pallet"),
+ ::tracing_core::field::FieldSet::new(
+ &[],
+ ::tracing_core::callsite::Identifier(&CALLSITE),
+ ),
+ ::tracing::metadata::Kind::SPAN,
+ )
+ };
+ MacroCallsite::new(&META)
+ };
+ let mut interest = ::tracing::subscriber::Interest::never();
+ if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
+ && ::tracing::Level::TRACE <= ::tracing::level_filters::LevelFilter::current()
+ && {
+ interest = CALLSITE.interest();
+ !interest.is_never()
+ }
+ && CALLSITE.is_enabled(interest)
+ {
+ let meta = CALLSITE.metadata();
+ ::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
+ } else {
+ let span = CALLSITE.disabled_span();
+ {};
+ span
+ }
+ };
+ let __tracing_guard__ = __within_span__.enter();
+ < Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_initialize (n)
+ }
+ }
+ impl<T: Config> frame_support::traits::OnRuntimeUpgrade for Pallet<T> {
+ fn on_runtime_upgrade() -> frame_support::weights::Weight {
+ let __within_span__ = {
+ use ::tracing::__macro_support::Callsite as _;
+ static CALLSITE: ::tracing::__macro_support::MacroCallsite = {
+ use ::tracing::__macro_support::MacroCallsite;
+ static META: ::tracing::Metadata<'static> = {
+ ::tracing_core::metadata::Metadata::new(
+ "on_runtime_update",
+ "pallet_evm_contract_helpers::pallet",
+ ::tracing::Level::TRACE,
+ Some("pallets/evm-contract-helpers/src/lib.rs"),
+ Some(7u32),
+ Some("pallet_evm_contract_helpers::pallet"),
+ ::tracing_core::field::FieldSet::new(
+ &[],
+ ::tracing_core::callsite::Identifier(&CALLSITE),
+ ),
+ ::tracing::metadata::Kind::SPAN,
+ )
+ };
+ MacroCallsite::new(&META)
+ };
+ let mut interest = ::tracing::subscriber::Interest::never();
+ if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
+ && ::tracing::Level::TRACE <= ::tracing::level_filters::LevelFilter::current()
+ && {
+ interest = CALLSITE.interest();
+ !interest.is_never()
+ }
+ && CALLSITE.is_enabled(interest)
+ {
+ let meta = CALLSITE.metadata();
+ ::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
+ } else {
+ let span = CALLSITE.disabled_span();
+ {};
+ span
+ }
+ };
+ let __tracing_guard__ = __within_span__.enter();
+ let pallet_name = < < T as frame_system :: Config > :: PalletInfo as frame_support :: traits :: PalletInfo > :: name :: < Self > () . unwrap_or ("<unknown pallet name>") ;
+ {
+ let lvl = ::log::Level::Info;
+ if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() {
+ ::log::__private_api_log(
+ ::core::fmt::Arguments::new_v1(
+ &["\u{2705} no migration for "],
+ &match (&pallet_name,) {
+ (arg0,) => [::core::fmt::ArgumentV1::new(
+ arg0,
+ ::core::fmt::Display::fmt,
+ )],
+ },
+ ),
+ lvl,
+ &(
+ frame_support::LOG_TARGET,
+ "pallet_evm_contract_helpers::pallet",
+ "pallets/evm-contract-helpers/src/lib.rs",
+ 7u32,
+ ),
+ );
+ }
+ };
+ < Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: on_runtime_upgrade ()
+ }
+ }
+ impl<T: Config> frame_support::traits::OffchainWorker<<T as frame_system::Config>::BlockNumber>
+ for Pallet<T>
+ {
+ fn offchain_worker(n: <T as frame_system::Config>::BlockNumber) {
+ < Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: offchain_worker (n)
+ }
+ }
+ impl<T: Config> frame_support::traits::IntegrityTest for Pallet<T> {
+ fn integrity_test() {
+ < Self as frame_support :: traits :: Hooks < < T as frame_system :: Config > :: BlockNumber > > :: integrity_test ()
+ }
+ }
+ #[doc(hidden)]
+ pub mod __substrate_genesis_config_check {
+ #[doc(hidden)]
+ pub use __is_genesis_config_defined_3 as is_genesis_config_defined;
+ #[doc(hidden)]
+ pub use __is_std_enabled_for_genesis_3 as is_std_enabled_for_genesis;
+ }
+ #[doc(hidden)]
+ pub mod __substrate_origin_check {
+ #[doc(hidden)]
+ pub use __is_origin_part_defined_4 as is_origin_part_defined;
+ }
+ #[doc(hidden)]
+ pub mod __substrate_validate_unsigned_check {
+ #[doc(hidden)]
+ pub use __is_validate_unsigned_part_defined_5 as is_validate_unsigned_part_defined;
+ }
+}
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -1,6 +1,6 @@
use core::marker::PhantomData;
use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
-use pallet_evm_coder_substrate::SubstrateRecorder;
+use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use pallet_evm::{ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput};
use sp_core::H160;
use crate::{
@@ -11,16 +11,23 @@
use sp_std::{convert::TryInto, vec::Vec};
struct ContractHelpers<T: Config>(SubstrateRecorder<T>);
+impl<T: Config> WithRecorder<T> for ContractHelpers<T> {
+ fn recorder(&self) -> &SubstrateRecorder<T> {
+ &self.0
+ }
+ fn into_recorder(self) -> SubstrateRecorder<T> {
+ self.0
+ }
+}
+
#[solidity_interface(name = "ContractHelpers")]
impl<T: Config> ContractHelpers<T> {
fn contract_owner(&self, contract_address: address) -> Result<address> {
- self.0.consume_sload()?;
Ok(<Owner<T>>::get(contract_address))
}
fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {
- self.0.consume_sload()?;
Ok(<SelfSponsoring<T>>::get(contract_address))
}
@@ -30,9 +37,7 @@
contract_address: address,
enabled: bool,
) -> Result<void> {
- self.0.consume_sload()?;
<Pallet<T>>::ensure_owner(contract_address, caller)?;
- self.0.consume_sstore()?;
<Pallet<T>>::toggle_sponsoring(contract_address, enabled);
Ok(())
}
@@ -43,27 +48,22 @@
contract_address: address,
rate_limit: uint32,
) -> Result<void> {
- self.0.consume_sload()?;
<Pallet<T>>::ensure_owner(contract_address, caller)?;
- self.0.consume_sstore()?;
<Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());
Ok(())
}
fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {
- self.0.consume_sload()?;
Ok(<SponsoringRateLimit<T>>::get(contract_address)
.try_into()
.map_err(|_| "rate limit > u32::MAX")?)
}
fn allowed(&self, contract_address: address, user: address) -> Result<bool> {
- self.0.consume_sload()?;
Ok(<Pallet<T>>::allowed(contract_address, user, true))
}
fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {
- self.0.consume_sload()?;
Ok(<AllowlistEnabled<T>>::get(contract_address))
}
@@ -73,9 +73,7 @@
contract_address: address,
enabled: bool,
) -> Result<void> {
- self.0.consume_sload()?;
<Pallet<T>>::ensure_owner(contract_address, caller)?;
- self.0.consume_sstore()?;
<Pallet<T>>::toggle_allowlist(contract_address, enabled);
Ok(())
}
@@ -87,9 +85,7 @@
user: address,
allowed: bool,
) -> Result<void> {
- self.0.consume_sload()?;
<Pallet<T>>::ensure_owner(contract_address, caller)?;
- self.0.consume_sstore()?;
<Pallet<T>>::toggle_allowed(contract_address, user, allowed);
Ok(())
}
@@ -130,9 +126,8 @@
return None;
}
- let mut helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(*target, gas_left));
- let result = pallet_evm_coder_substrate::call_internal(*source, &mut helpers, value, input);
- helpers.0.evm_to_precompile_output(result)
+ let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(*target, gas_left));
+ pallet_evm_coder_substrate::call(*source, helpers, value, input)
}
fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
@@ -170,5 +165,5 @@
}
}
-generate_stubgen!(contract_helpers_impl, ContractHelpersCall, true);
-generate_stubgen!(contract_helpers_iface, ContractHelpersCall, false);
+generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);
+generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -21,6 +21,7 @@
}
}
+// Selector: 31acb1fe
contract ContractHelpers is Dummy, ERC165 {
// Selector: contractOwner(address) 5152b14c
function contractOwner(address contractAddress)
pallets/evm-migration/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-migration/Cargo.toml
+++ b/pallets/evm-migration/Cargo.toml
@@ -4,7 +4,9 @@
edition = "2018"
[dependencies]
-scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
+scale-info = { version = "1.0.0", default-features = false, features = [
+ "derive",
+] }
frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
@@ -12,8 +14,8 @@
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
[dependencies.codec]
default-features = false
pallets/evm-transaction-payment/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-transaction-payment/Cargo.toml
+++ b/pallets/evm-transaction-payment/Cargo.toml
@@ -4,16 +4,18 @@
edition = "2018"
[dependencies]
-scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
+scale-info = { version = "1.0.0", default-features = false, features = [
+ "derive",
+] }
frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
up-sponsorship = { default-features = false, path = '../../primitives/sponsorship' }
[dependencies.codec]
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -1,15 +1,18 @@
use core::char::{REPLACEMENT_CHARACTER, decode_utf16};
use core::convert::TryInto;
-use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
use nft_data_structs::CollectionMode;
use pallet_common::erc::CommonEvmHandler;
use sp_core::{H160, U256};
use sp_std::vec::Vec;
use pallet_common::account::CrossAccountId;
use pallet_common::erc::PrecompileOutput;
-use pallet_evm_coder_substrate::{call_internal, dispatch_to_evm};
+use pallet_evm_coder_substrate::{call, dispatch_to_evm};
-use crate::{Allowance, Balance, Config, FungibleHandle, Pallet, TotalSupply};
+use crate::{
+ Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,
+ weights::WeightInfo,
+};
#[derive(ToLog)]
pub enum ERC20Events {
@@ -40,6 +43,7 @@
Ok(string::from_utf8_lossy(&self.token_prefix).into())
}
fn total_supply(&self) -> Result<uint256> {
+ self.consume_store_reads(1)?;
Ok(<TotalSupply<T>>::get(self.id).into())
}
@@ -51,10 +55,12 @@
})
}
fn balance_of(&self, owner: address) -> Result<uint256> {
+ self.consume_store_reads(1)?;
let owner = T::CrossAccountId::from_eth(owner);
let balance = <Balance<T>>::get((self.id, owner));
Ok(balance.into())
}
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -63,6 +69,7 @@
<Pallet<T>>::transfer(self, &caller, &to, amount).map_err(|_| "transfer error")?;
Ok(true)
}
+ #[weight(<SelfWeightOf<T>>::transfer_from())]
fn transfer_from(
&mut self,
caller: caller,
@@ -79,6 +86,7 @@
.map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
+ #[weight(<SelfWeightOf<T>>::approve())]
fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let spender = T::CrossAccountId::from_eth(spender);
@@ -89,6 +97,7 @@
Ok(true)
}
fn allowance(&self, owner: address, spender: address) -> Result<uint256> {
+ self.consume_store_reads(1)?;
let owner = T::CrossAccountId::from_eth(owner);
let spender = T::CrossAccountId::from_eth(spender);
@@ -98,6 +107,7 @@
#[solidity_interface(name = "ERC20UniqueExtensions")]
impl<T: Config> FungibleHandle<T> {
+ #[weight(<SelfWeightOf<T>>::burn_from())]
fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let from = T::CrossAccountId::from_eth(from);
@@ -111,14 +121,13 @@
#[solidity_interface(name = "UniqueFungible", is(ERC20))]
impl<T: Config> FungibleHandle<T> {}
-generate_stubgen!(gen_impl, UniqueFungibleCall, true);
-generate_stubgen!(gen_iface, UniqueFungibleCall, false);
+generate_stubgen!(gen_impl, UniqueFungibleCall<()>, true);
+generate_stubgen!(gen_iface, UniqueFungibleCall<()>, false);
impl<T: Config> CommonEvmHandler for FungibleHandle<T> {
const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");
- fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
- let result = call_internal::<UniqueFungibleCall, _>(*source, &mut self, value, input);
- self.0.recorder.evm_to_precompile_output(result)
+ fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
+ call::<T, UniqueFungibleCall<T>, _>(*source, self, value, input)
}
}
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -6,6 +6,7 @@
use pallet_common::{
Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
};
+use pallet_evm_coder_substrate::WithRecorder;
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
@@ -82,6 +83,14 @@
self.0
}
}
+impl<T: Config> WithRecorder<T> for FungibleHandle<T> {
+ fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {
+ self.0.recorder()
+ }
+ fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {
+ self.0.into_recorder()
+ }
+}
impl<T: Config> Deref for FungibleHandle<T> {
type Target = pallet_common::CollectionHandle<T>;
@@ -136,7 +145,7 @@
}
<TotalSupply<T>>::insert(collection.id, total_supply);
- collection.log_infallible(ERC20Events::Transfer {
+ collection.log(ERC20Events::Transfer {
from: *owner.as_eth(),
to: H160::default(),
value: amount.into(),
@@ -179,11 +188,6 @@
} else {
None
};
-
- collection.consume_sstore()?;
- collection.consume_sstore()?;
- collection.consume_log(2, 32)?;
- collection.consume_sstore()?;
// =========
@@ -197,7 +201,7 @@
<Balance<T>>::insert((collection.id, to), balance_to);
}
- collection.log_infallible(ERC20Events::Transfer {
+ collection.log(ERC20Events::Transfer {
from: *from.as_eth(),
to: *to.as_eth(),
value: amount.into(),
@@ -217,8 +221,7 @@
sender: &T::CrossAccountId,
data: Vec<CreateItemData<T>>,
) -> DispatchResult {
- let unrestricted_minting = collection.is_owner_or_admin(sender)?;
- if !unrestricted_minting {
+ if !collection.is_owner_or_admin(sender) {
ensure!(
collection.mint_mode,
<CommonError<T>>::PublicMintingNotAllowed
@@ -241,20 +244,12 @@
.ok_or(ArithmeticError::Overflow)?;
for (user, amount) in data.into_iter() {
- collection.consume_sload()?;
let balance = balances
.entry(user.clone())
.or_insert_with(|| <Balance<T>>::get((collection.id, user)));
*balance = (*balance)
.checked_add(amount)
.ok_or(ArithmeticError::Overflow)?;
- }
-
- collection.consume_sstore()?;
- for _ in &balances {
- collection.consume_sstore()?;
- collection.consume_log(2, 32)?;
- collection.consume_sstore()?;
}
// =========
@@ -263,7 +258,7 @@
for (user, amount) in balances {
<Balance<T>>::insert((collection.id, &user), amount);
- collection.log_infallible(ERC20Events::Transfer {
+ collection.log(ERC20Events::Transfer {
from: H160::default(),
to: *user.as_eth(),
value: amount.into(),
@@ -287,7 +282,7 @@
) {
<Allowance<T>>::insert((collection.id, owner, spender), amount);
- collection.log_infallible(ERC20Events::Approval {
+ collection.log(ERC20Events::Approval {
owner: *owner.as_eth(),
spender: *spender.as_eth(),
value: amount.into(),
@@ -314,7 +309,7 @@
if <Balance<T>>::get((collection.id, owner)) < amount {
ensure!(
- collection.ignores_owned_amount(owner)?,
+ collection.ignores_owned_amount(owner),
<CommonError<T>>::CantApproveMoreThanOwned
);
}
@@ -343,7 +338,7 @@
let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);
if allowance.is_none() {
ensure!(
- collection.ignores_allowance(spender)?,
+ collection.ignores_allowance(spender),
<CommonError<T>>::TokenValueNotEnough
);
}
@@ -374,7 +369,7 @@
let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);
if allowance.is_none() {
ensure!(
- collection.ignores_allowance(spender)?,
+ collection.ignores_allowance(spender),
<CommonError<T>>::TokenValueNotEnough
);
}
pallets/nft/Cargo.tomldiffbeforeafterboth--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -146,9 +146,9 @@
"serde_no_std",
] }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
hex-literal = "0.3.3"
pallet-common = { default-features = false, path = "../common" }
pallets/nft/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nft/src/benchmarking.rs
+++ b/pallets/nft/src/benchmarking.rs
@@ -155,12 +155,13 @@
let cl = CollectionLimits {
account_token_ownership_limit: Some(0),
- sponsored_data_size: 0,
- token_limit: 1,
- sponsor_transfer_timeout: 0,
- owner_can_destroy: true,
- owner_can_transfer: true,
+ sponsored_data_size: Some(0),
+ token_limit: Some(1),
+ sponsor_transfer_timeout: Some(0),
+ owner_can_destroy: Some(true),
+ owner_can_transfer: Some(true),
sponsored_data_rate_limit: None,
+ transfers_enabled: Some(true),
};
}: set_collection_limits(RawOrigin::Signed(caller.clone()), collection, cl)
pallets/nft/src/dispatch.rsdiffbeforeafterboth--- a/pallets/nft/src/dispatch.rs
+++ b/pallets/nft/src/dispatch.rs
@@ -83,10 +83,6 @@
_ => {}
}
- // TODO: Make submit_logs infallible, but it shouldn't fail here anyway
- dispatched
- .into_inner()
- .submit_logs()
- .expect("should succeed");
+ dispatched.into_inner().submit_logs();
result
}
pallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth--- a/pallets/nft/src/eth/sponsoring.rs
+++ b/pallets/nft/src/eth/sponsoring.rs
@@ -31,7 +31,7 @@
let (method_id, mut reader) = AbiReader::new_call(call).map_err(|_| AnyError)?;
match &collection.mode {
crate::CollectionMode::NFT => {
- let call: UniqueNFTCall = UniqueNFTCall::parse(method_id, &mut reader)
+ let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader)
.map_err(|_| AnyError)?
.ok_or(AnyError)?;
match call {
@@ -63,7 +63,7 @@
}
}
crate::CollectionMode::Fungible(_) => {
- let call: UniqueFungibleCall = UniqueFungibleCall::parse(method_id, &mut reader)
+ let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader)
.map_err(|_| AnyError)?
.ok_or(AnyError)?;
#[allow(clippy::single_match)]
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -2,18 +2,19 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
use frame_support::BoundedVec;
use nft_data_structs::TokenId;
use pallet_evm_coder_substrate::dispatch_to_evm;
use sp_core::{H160, U256};
use sp_std::{vec::Vec, vec};
use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};
-use pallet_evm_coder_substrate::call_internal;
+use pallet_evm_coder_substrate::call;
use pallet_common::erc::PrecompileOutput;
use crate::{
AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
+ SelfWeightOf, weights::WeightInfo,
};
#[derive(ToLog)]
@@ -64,6 +65,7 @@
/// Returns token's const_metadata
#[solidity(rename_selector = "tokenURI")]
fn token_uri(&self, token_id: uint256) -> Result<string> {
+ self.consume_store_reads(1)?;
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
Ok(string::from_utf8_lossy(
&<TokenData<T>>::get((self.id, token_id))
@@ -87,6 +89,7 @@
}
fn total_supply(&self) -> Result<uint256> {
+ self.consume_store_reads(1)?;
Ok(<Pallet<T>>::total_supply(self).into())
}
}
@@ -94,11 +97,13 @@
#[solidity_interface(name = "ERC721", events(ERC721Events))]
impl<T: Config> NonfungibleHandle<T> {
fn balance_of(&self, owner: address) -> Result<uint256> {
+ self.consume_store_reads(1)?;
let owner = T::CrossAccountId::from_eth(owner);
let balance = <AccountBalance<T>>::get((self.id, owner));
Ok(balance.into())
}
fn owner_of(&self, token_id: uint256) -> Result<address> {
+ self.consume_store_reads(1)?;
let token: TokenId = token_id.try_into()?;
Ok(*<TokenData<T>>::get((self.id, token))
.ok_or("token not found")?
@@ -129,6 +134,7 @@
Err("not implemented".into())
}
+ #[weight(<SelfWeightOf<T>>::transfer_from())]
fn transfer_from(
&mut self,
caller: caller,
@@ -147,6 +153,7 @@
Ok(())
}
+ #[weight(<SelfWeightOf<T>>::approve())]
fn approve(
&mut self,
caller: caller,
@@ -189,6 +196,7 @@
#[solidity_interface(name = "ERC721Burnable")]
impl<T: Config> NonfungibleHandle<T> {
+ #[weight(<SelfWeightOf<T>>::burn_item())]
fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
let token = token_id.try_into()?;
@@ -206,6 +214,7 @@
/// `token_id` should be obtained with `next_token_id` method,
/// unlike standard, you can't specify it manually
+ #[weight(<SelfWeightOf<T>>::create_item())]
fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -235,6 +244,7 @@
/// `token_id` should be obtained with `next_token_id` method,
/// unlike standard, you can't specify it manually
#[solidity(rename_selector = "mintWithTokenURI")]
+ #[weight(<SelfWeightOf<T>>::create_item())]
fn mint_with_token_uri(
&mut self,
caller: caller,
@@ -276,6 +286,7 @@
#[solidity_interface(name = "ERC721UniqueExtensions")]
impl<T: Config> NonfungibleHandle<T> {
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer(
&mut self,
caller: caller,
@@ -291,6 +302,7 @@
Ok(())
}
+ #[weight(<SelfWeightOf<T>>::burn_from())]
fn burn_from(
&mut self,
caller: caller,
@@ -307,12 +319,14 @@
}
fn next_token_id(&self) -> Result<uint256> {
+ self.consume_store_reads(1)?;
Ok(<TokensMinted<T>>::get(self.id)
.checked_add(1)
.ok_or("item id overflow")?
.into())
}
+ #[weight(<SelfWeightOf<T>>::set_variable_metadata(data.len() as u32))]
fn set_variable_metadata(
&mut self,
caller: caller,
@@ -328,6 +342,7 @@
}
fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {
+ self.consume_store_reads(1)?;
let token: TokenId = token_id.try_into()?;
Ok(<TokenData<T>>::get((self.id, token))
@@ -335,6 +350,7 @@
.variable_data)
}
+ #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]
fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -363,6 +379,7 @@
}
#[solidity(rename_selector = "mintBulkWithTokenURI")]
+ #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]
fn mint_bulk_with_token_uri(
&mut self,
caller: caller,
@@ -411,16 +428,13 @@
impl<T: Config> NonfungibleHandle<T> {}
// Not a tests, but code generators
-generate_stubgen!(gen_impl, UniqueNFTCall, true);
-generate_stubgen!(gen_iface, UniqueNFTCall, false);
-
-pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");
+generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);
+generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);
impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {
const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");
- fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
- let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);
- self.0.recorder.evm_to_precompile_output(result)
+ fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
+ call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)
}
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -8,6 +8,7 @@
use pallet_common::{
Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,
};
+use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
use sp_std::{vec::Vec, vec};
@@ -114,6 +115,14 @@
self.0
}
}
+impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {
+ fn recorder(&self) -> &SubstrateRecorder<T> {
+ self.0.recorder()
+ }
+ fn into_recorder(self) -> SubstrateRecorder<T> {
+ self.0.into_recorder()
+ }
+}
impl<T: Config> Deref for NonfungibleHandle<T> {
type Target = pallet_common::CollectionHandle<T>;
@@ -164,8 +173,7 @@
.ok_or_else(|| <CommonError<T>>::TokenNotFound)?;
ensure!(
&token_data.owner == sender
- || (collection.limits.owner_can_transfer()
- && collection.is_owner_or_admin(sender)?),
+ || (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),
<CommonError<T>>::NoPermission
);
@@ -194,7 +202,7 @@
));
}
- collection.log_infallible(ERC721Events::Transfer {
+ collection.log(ERC721Events::Transfer {
from: *token_data.owner.as_eth(),
to: H160::default(),
token_id: token.into(),
@@ -223,8 +231,7 @@
.ok_or_else(|| <CommonError<T>>::TokenNotFound)?;
ensure!(
&token_data.owner == from
- || (collection.limits.owner_can_transfer()
- && collection.is_owner_or_admin(from)?),
+ || (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),
<CommonError<T>>::NoPermission
);
@@ -251,9 +258,6 @@
} else {
None
};
-
- collection.consume_sstores(4)?;
- collection.consume_log(3, 0)?;
// =========
@@ -278,7 +282,7 @@
}
Self::set_allowance_unchecked(collection, from, token, None, true);
- collection.log_infallible(ERC721Events::Transfer {
+ collection.log(ERC721Events::Transfer {
from: *from.as_eth(),
to: *to.as_eth(),
token_id: token.into(),
@@ -298,8 +302,7 @@
sender: &T::CrossAccountId,
data: Vec<CreateItemData<T>>,
) -> DispatchResult {
- let unrestricted_minting = collection.is_owner_or_admin(sender)?;
- if !unrestricted_minting {
+ if !collection.is_owner_or_admin(sender) {
ensure!(
collection.mint_mode,
<CommonError<T>>::PublicMintingNotAllowed
@@ -313,14 +316,6 @@
for data in data.iter() {
<PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;
- if !data.const_data.is_empty() {
- collection.consume_sstore()?;
- }
- if !data.variable_data.is_empty() {
- collection.consume_sstore()?;
- }
- collection.consume_sstore()?;
- collection.consume_log(3, 0)?;
}
let first_token = <TokensMinted<T>>::get(collection.id);
@@ -331,7 +326,6 @@
tokens_minted < collection.limits.token_limit(),
<CommonError<T>>::CollectionTokenLimitExceeded
);
- collection.consume_sstore()?;
let mut balances = BTreeMap::new();
for data in &data {
@@ -345,7 +339,6 @@
<CommonError<T>>::AccountTokenLimitExceeded,
);
}
- collection.consume_sstores(balances.len())?;
// =========
@@ -366,7 +359,7 @@
);
<Owned<T>>::insert((collection.id, &data.owner, token), true);
- collection.log_infallible(ERC721Events::Transfer {
+ collection.log(ERC721Events::Transfer {
from: H160::default(),
to: *data.owner.as_eth(),
token_id: token.into(),
@@ -393,7 +386,7 @@
<Allowance<T>>::insert((collection.id, token), spender);
// In ERC721 there is only one possible approved user of token, so we set
// approved user to spender
- collection.log_infallible(ERC721Events::Approval {
+ collection.log(ERC721Events::Approval {
owner: *sender.as_eth(),
approved: *spender.as_eth(),
token_id: token.into(),
@@ -423,7 +416,7 @@
if !assume_implicit_eth {
// In ERC721 there is only one possible approved user of token, so we set
// approved user to zero address
- collection.log_infallible(ERC721Events::Approval {
+ collection.log(ERC721Events::Approval {
owner: *sender.as_eth(),
approved: H160::default(),
token_id: token.into(),
@@ -463,7 +456,7 @@
<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
if &token_data.owner != sender {
ensure!(
- collection.ignores_owned_amount(sender)?,
+ collection.ignores_owned_amount(sender),
<CommonError<T>>::CantApproveMoreThanOwned
);
}
@@ -491,7 +484,7 @@
if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {
ensure!(
- collection.ignores_allowance(spender)?,
+ collection.ignores_allowance(spender),
<CommonError<T>>::TokenValueNotEnough
);
}
@@ -519,7 +512,7 @@
if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {
ensure!(
- collection.ignores_allowance(spender)?,
+ collection.ignores_allowance(spender),
<CommonError<T>>::TokenValueNotEnough
);
}
@@ -542,8 +535,6 @@
let token_data =
<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
collection.check_can_update_meta(sender, &token_data.owner)?;
-
- collection.consume_sstore()?;
// =========
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -58,7 +58,7 @@
}
fn burn_from() -> Weight {
- 0
+ <SelfWeightOf<T>>::burn_from()
}
fn set_variable_metadata(bytes: u32) -> Weight {
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -359,8 +359,7 @@
sender: &T::CrossAccountId,
data: Vec<CreateItemData<T>>,
) -> DispatchResult {
- let unrestricted_minting = collection.is_owner_or_admin(sender)?;
- if !unrestricted_minting {
+ if !collection.is_owner_or_admin(sender) {
ensure!(
collection.mint_mode,
<CommonError<T>>::PublicMintingNotAllowed
@@ -492,7 +491,7 @@
if <Balance<T>>::get((collection.id, token, sender)) < amount {
ensure!(
- collection.ignores_owned_amount(sender)? && Self::token_exists(collection, token),
+ collection.ignores_owned_amount(sender) && Self::token_exists(collection, token),
<CommonError<T>>::CantApproveMoreThanOwned
);
}
@@ -523,7 +522,7 @@
<Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);
if allowance.is_none() {
ensure!(
- collection.ignores_allowance(spender)?,
+ collection.ignores_allowance(spender),
<CommonError<T>>::TokenValueNotEnough
);
}
@@ -556,7 +555,7 @@
<Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);
if allowance.is_none() {
ensure!(
- collection.ignores_allowance(spender)?,
+ collection.ignores_allowance(spender),
<CommonError<T>>::TokenValueNotEnough
);
}
@@ -585,7 +584,6 @@
&T::CrossAccountId::from_sub(collection.owner.clone()),
)?;
- collection.consume_sstore()?;
let token_data = <TokenData<T>>::get((collection.id, token));
// =========
runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -387,10 +387,10 @@
pallet-evm-transaction-payment = { path = '../pallets/evm-transaction-payment', default-features = false }
pallet-evm-coder-substrate = { default-features = false, path = "../pallets/evm-coder-substrate" }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
+fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
################################################################################
# Build Dependencies
runtime/src/lib.rsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56//! The Substrate Node Template runtime. This can be compiled with `#[no_std]`, ready for Wasm.78#![cfg_attr(not(feature = "std"), no_std)]9// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.10#![recursion_limit = "1024"]11#![allow(clippy::from_over_into, clippy::identity_op)]12#![allow(clippy::fn_to_numeric_cast_with_truncation)]13// Make the WASM binary available.14#[cfg(feature = "std")]15include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1617use sp_api::impl_runtime_apis;18use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};19// #[cfg(any(feature = "std", test))]20// pub use sp_runtime::BuildStorage;2122use sp_runtime::{23 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,24 traits::{25 AccountIdLookup, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify,26 AccountIdConversion,27 },28 transaction_validity::{TransactionSource, TransactionValidity},29 ApplyExtrinsicResult, MultiSignature,30};3132use sp_std::prelude::*;3334#[cfg(feature = "std")]35use sp_version::NativeVersion;36use sp_version::RuntimeVersion;37pub use pallet_transaction_payment::{38 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,39};40// A few exports that help ease life for downstream crates.41pub use pallet_balances::Call as BalancesCall;42pub use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping, Runner};43pub use frame_support::{44 construct_runtime, match_type,45 dispatch::DispatchResult,46 PalletId, parameter_types, StorageValue, ConsensusEngineId,47 traits::{48 Everything, Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem,49 LockIdentifier, OnUnbalanced, Randomness, FindAuthor,50 },51 weights::{52 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},53 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,54 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,55 },56};57use nft_data_structs::*;58// use pallet_contracts::weights::WeightInfo;59// #[cfg(any(feature = "std", test))]60use frame_system::{61 self as system, EnsureRoot, EnsureSigned,62 limits::{BlockWeights, BlockLength},63};64use sp_arithmetic::{65 traits::{BaseArithmetic, Unsigned},66};67use smallvec::smallvec;68use codec::{Encode, Decode};69use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall};70use fp_rpc::TransactionStatus;71use sp_core::crypto::Public;72use sp_runtime::{73 traits::{Dispatchable, PostDispatchInfoOf},74 transaction_validity::TransactionValidityError,75};7677// pub use pallet_timestamp::Call as TimestampCall;78pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;7980// Polkadot imports81use pallet_xcm::XcmPassthrough;82use polkadot_parachain::primitives::Sibling;83use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};84use xcm_builder::{85 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,86 EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,87 ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,88 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,89 SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,90};91use xcm_executor::{Config, XcmExecutor};9293// mod chain_extension;94// use crate::chain_extension::{NFTExtension, Imbalance};9596/// An index to a block.97pub type BlockNumber = u32;9899/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.100pub type Signature = MultiSignature;101102/// Some way of identifying an account on the chain. We intentionally make it equivalent103/// to the public key of our transaction signing scheme.104pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;105106pub type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;107108/// The type for looking up accounts. We don't expect more than 4 billion of them, but you109/// never know...110pub type AccountIndex = u32;111112/// Balance of an account.113pub type Balance = u128;114115/// Index of a transaction in the chain.116pub type Index = u32;117118/// A hash of some data used by the chain.119pub type Hash = sp_core::H256;120121/// Digest item type.122pub type DigestItem = generic::DigestItem<Hash>;123124/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know125/// the specifics of the runtime. They can then be made to be agnostic over specific formats126/// of data like extrinsics, allowing for them to continue syncing the network through upgrades127/// to even the core data structures.128pub mod opaque {129 use super::*;130131 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;132133 /// Opaque block type.134 pub type Block = generic::Block<Header, UncheckedExtrinsic>;135136 pub type SessionHandlers = ();137138 impl_opaque_keys! {139 pub struct SessionKeys {140 pub aura: Aura,141 }142 }143}144145/// This runtime version.146pub const VERSION: RuntimeVersion = RuntimeVersion {147 spec_name: create_runtime_str!("opal"),148 impl_name: create_runtime_str!("opal"),149 authoring_version: 1,150 spec_version: 912200,151 impl_version: 1,152 apis: RUNTIME_API_VERSIONS,153 transaction_version: 1,154};155156pub const MILLISECS_PER_BLOCK: u64 = 12000;157158pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;159160// These time units are defined in number of blocks.161pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);162pub const HOURS: BlockNumber = MINUTES * 60;163pub const DAYS: BlockNumber = HOURS * 24;164165parameter_types! {166 pub const DefaultSponsoringRateLimit: BlockNumber = 1 * DAYS;167}168169#[derive(codec::Encode, codec::Decode)]170pub enum XCMPMessage<XAccountId, XBalance> {171 /// Transfer tokens to the given account from the Parachain account.172 TransferToken(XAccountId, XBalance),173}174175/// The version information used to identify this runtime when compiled natively.176#[cfg(feature = "std")]177pub fn native_version() -> NativeVersion {178 NativeVersion {179 runtime_version: VERSION,180 can_author_with: Default::default(),181 }182}183184type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;185186pub struct DealWithFees;187impl OnUnbalanced<NegativeImbalance> for DealWithFees {188 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {189 if let Some(fees) = fees_then_tips.next() {190 // for fees, 100% to treasury191 let mut split = fees.ration(100, 0);192 if let Some(tips) = fees_then_tips.next() {193 // for tips, if any, 100% to treasury194 tips.ration_merge_into(100, 0, &mut split);195 }196 Treasury::on_unbalanced(split.0);197 // Author::on_unbalanced(split.1);198 }199 }200}201202/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.203/// This is used to limit the maximal weight of a single extrinsic.204const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);205/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used206/// by Operational extrinsics.207const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);208/// We allow for 2 seconds of compute with a 6 second average block time.209const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;210211parameter_types! {212 pub const BlockHashCount: BlockNumber = 2400;213 pub RuntimeBlockLength: BlockLength =214 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);215 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);216 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;217 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()218 .base_block(BlockExecutionWeight::get())219 .for_class(DispatchClass::all(), |weights| {220 weights.base_extrinsic = ExtrinsicBaseWeight::get();221 })222 .for_class(DispatchClass::Normal, |weights| {223 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);224 })225 .for_class(DispatchClass::Operational, |weights| {226 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);227 // Operational transactions have some extra reserved space, so that they228 // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.229 weights.reserved = Some(230 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT231 );232 })233 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)234 .build_or_panic();235 pub const Version: RuntimeVersion = VERSION;236 pub const SS58Prefix: u8 = 42;237}238239parameter_types! {240 pub const ChainId: u64 = 8888;241}242243pub struct FixedFee;244impl FeeCalculator for FixedFee {245 fn min_gas_price() -> U256 {246 1.into()247 }248}249250impl pallet_evm::Config for Runtime {251 type BlockGasLimit = BlockGasLimit;252 type FeeCalculator = FixedFee;253 type GasWeightMapping = ();254 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;255 type CallOrigin = EnsureAddressTruncated;256 type WithdrawOrigin = EnsureAddressTruncated;257 type AddressMapping = HashedAddressMapping<Self::Hashing>;258 type Precompiles = ();259 type Currency = Balances;260 type Event = Event;261 type OnMethodCall = (262 pallet_evm_migration::OnMethodCall<Self>,263 pallet_nft::NftErcSupport<Self>,264 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,265 );266 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;267 type ChainId = ChainId;268 type Runner = pallet_evm::runner::stack::Runner<Self>;269 type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;270 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;271 type FindAuthor = EthereumFindAuthor<Aura>;272}273274impl pallet_evm_migration::Config for Runtime {275 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;276}277278pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);279impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {280 fn find_author<'a, I>(digests: I) -> Option<H160>281 where282 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,283 {284 if let Some(author_index) = F::find_author(digests) {285 let authority_id = Aura::authorities()[author_index as usize].clone();286 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));287 }288 None289 }290}291292parameter_types! {293 pub BlockGasLimit: U256 = U256::from(u32::max_value());294}295296impl pallet_ethereum::Config for Runtime {297 type Event = Event;298 type StateRoot = pallet_ethereum::IntermediateStateRoot;299 type EvmSubmitLog = pallet_evm::Pallet<Self>;300}301302impl pallet_randomness_collective_flip::Config for Runtime {}303304impl system::Config for Runtime {305 /// The data to be stored in an account.306 type AccountData = pallet_balances::AccountData<Balance>;307 /// The identifier used to distinguish between accounts.308 type AccountId = AccountId;309 /// The basic call filter to use in dispatchable.310 type BaseCallFilter = Everything;311 /// Maximum number of block number to block hash mappings to keep (oldest pruned first).312 type BlockHashCount = BlockHashCount;313 /// The maximum length of a block (in bytes).314 type BlockLength = RuntimeBlockLength;315 /// The index type for blocks.316 type BlockNumber = BlockNumber;317 /// The weight of the overhead invoked on the block import process, independent of the extrinsics included in that block.318 type BlockWeights = RuntimeBlockWeights;319 /// The aggregated dispatch type that is available for extrinsics.320 type Call = Call;321 /// The weight of database operations that the runtime can invoke.322 type DbWeight = RocksDbWeight;323 /// The ubiquitous event type.324 type Event = Event;325 /// The type for hashing blocks and tries.326 type Hash = Hash;327 /// The hashing algorithm used.328 type Hashing = BlakeTwo256;329 /// The header type.330 type Header = generic::Header<BlockNumber, BlakeTwo256>;331 /// The index type for storing how many extrinsics an account has signed.332 type Index = Index;333 /// The lookup mechanism to get account ID from whatever is passed in dispatchers.334 type Lookup = AccountIdLookup<AccountId, ()>;335 /// What to do if an account is fully reaped from the system.336 type OnKilledAccount = ();337 /// What to do if a new account is created.338 type OnNewAccount = ();339 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;340 /// The ubiquitous origin type.341 type Origin = Origin;342 /// This type is being generated by `construct_runtime!`.343 type PalletInfo = PalletInfo;344 /// This is used as an identifier of the chain. 42 is the generic substrate prefix.345 type SS58Prefix = SS58Prefix;346 /// Weight information for the extrinsics of this pallet.347 type SystemWeightInfo = system::weights::SubstrateWeight<Self>;348 /// Version of the runtime.349 type Version = Version;350}351352parameter_types! {353 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;354}355356impl pallet_timestamp::Config for Runtime {357 /// A timestamp: milliseconds since the unix epoch.358 type Moment = u64;359 type OnTimestampSet = ();360 type MinimumPeriod = MinimumPeriod;361 type WeightInfo = ();362}363364parameter_types! {365 // pub const ExistentialDeposit: u128 = 500;366 pub const ExistentialDeposit: u128 = 0;367 pub const MaxLocks: u32 = 50;368}369370impl pallet_balances::Config for Runtime {371 type MaxLocks = MaxLocks;372 type MaxReserves = ();373 type ReserveIdentifier = [u8; 8];374 /// The type for recording an account's balance.375 type Balance = Balance;376 /// The ubiquitous event type.377 type Event = Event;378 type DustRemoval = Treasury;379 type ExistentialDeposit = ExistentialDeposit;380 type AccountStore = System;381 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;382}383384pub const MICROUNIQUE: Balance = 1_000_000_000;385pub const MILLIUNIQUE: Balance = 1_000 * MICROUNIQUE;386pub const CENTIUNIQUE: Balance = 10 * MILLIUNIQUE;387pub const UNIQUE: Balance = 100 * CENTIUNIQUE;388389pub const fn deposit(items: u32, bytes: u32) -> Balance {390 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE391}392393/*394parameter_types! {395 pub TombstoneDeposit: Balance = deposit(396 1,397 sp_std::mem::size_of::<pallet_contracts::Pallet<Runtime>> as u32,398 );399 pub DepositPerContract: Balance = TombstoneDeposit::get();400 pub const DepositPerStorageByte: Balance = deposit(0, 1);401 pub const DepositPerStorageItem: Balance = deposit(1, 0);402 pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);403 pub const SurchargeReward: Balance = 150 * MILLIUNIQUE;404 pub const SignedClaimHandicap: u32 = 2;405 pub const MaxDepth: u32 = 32;406 pub const MaxValueSize: u32 = 16 * 1024;407 pub const MaxCodeSize: u32 = 1024 * 1024 * 25; // 25 Mb408 // The lazy deletion runs inside on_initialize.409 pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *410 RuntimeBlockWeights::get().max_block;411 // The weight needed for decoding the queue should be less or equal than a fifth412 // of the overall weight dedicated to the lazy deletion.413 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (414 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -415 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)416 )) / 5) as u32;417 pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();418}419420impl pallet_contracts::Config for Runtime {421 type Time = Timestamp;422 type Randomness = RandomnessCollectiveFlip;423 type Currency = Balances;424 type Event = Event;425 type RentPayment = ();426 type SignedClaimHandicap = SignedClaimHandicap;427 type TombstoneDeposit = TombstoneDeposit;428 type DepositPerContract = DepositPerContract;429 type DepositPerStorageByte = DepositPerStorageByte;430 type DepositPerStorageItem = DepositPerStorageItem;431 type RentFraction = RentFraction;432 type SurchargeReward = SurchargeReward;433 type WeightPrice = pallet_transaction_payment::Pallet<Self>;434 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;435 type ChainExtension = NFTExtension;436 type DeletionQueueDepth = DeletionQueueDepth;437 type DeletionWeightLimit = DeletionWeightLimit;438 type Schedule = Schedule;439 type CallStack = [pallet_contracts::Frame<Self>; 31];440}441*/442443parameter_types! {444 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; // Targeting 0.1 Unique per NFT transfer445 /// This value increases the priority of `Operational` transactions by adding446 /// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.447 pub const OperationalFeeMultiplier: u8 = 5;448}449450/// Linear implementor of `WeightToFeePolynomial`451pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);452453impl<T> WeightToFeePolynomial for LinearFee<T>454where455 T: BaseArithmetic + From<u32> + Copy + Unsigned,456{457 type Balance = T;458459 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {460 smallvec!(WeightToFeeCoefficient {461 coeff_integer: 146_700u32.into(), // Targeting 0.1 Unique per NFT transfer462 coeff_frac: Perbill::zero(),463 negative: false,464 degree: 1,465 })466 }467}468469impl pallet_transaction_payment::Config for Runtime {470 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;471 type TransactionByteFee = TransactionByteFee;472 type OperationalFeeMultiplier = OperationalFeeMultiplier;473 type WeightToFee = LinearFee<Balance>;474 type FeeMultiplierUpdate = ();475}476477parameter_types! {478 pub const ProposalBond: Permill = Permill::from_percent(5);479 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;480 pub const SpendPeriod: BlockNumber = 5 * MINUTES;481 pub const Burn: Permill = Permill::from_percent(0);482 pub const TipCountdown: BlockNumber = 1 * DAYS;483 pub const TipFindersFee: Percent = Percent::from_percent(20);484 pub const TipReportDepositBase: Balance = 1 * UNIQUE;485 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;486 pub const BountyDepositBase: Balance = 1 * UNIQUE;487 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;488 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");489 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;490 pub const MaximumReasonLength: u32 = 16384;491 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);492 pub const BountyValueMinimum: Balance = 5 * UNIQUE;493 pub const MaxApprovals: u32 = 100;494}495496impl pallet_treasury::Config for Runtime {497 type PalletId = TreasuryModuleId;498 type Currency = Balances;499 type ApproveOrigin = EnsureRoot<AccountId>;500 type RejectOrigin = EnsureRoot<AccountId>;501 type Event = Event;502 type OnSlash = ();503 type ProposalBond = ProposalBond;504 type ProposalBondMinimum = ProposalBondMinimum;505 type SpendPeriod = SpendPeriod;506 type Burn = Burn;507 type BurnDestination = ();508 type SpendFunds = ();509 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;510 type MaxApprovals = MaxApprovals;511}512513impl pallet_sudo::Config for Runtime {514 type Event = Event;515 type Call = Call;516}517518parameter_types! {519 pub const MinVestedTransfer: Balance = 10 * UNIQUE;520}521522impl pallet_vesting::Config for Runtime {523 type Event = Event;524 type Currency = Balances;525 type BlockNumberToBalance = ConvertInto;526 type MinVestedTransfer = MinVestedTransfer;527 type WeightInfo = ();528 const MAX_VESTING_SCHEDULES: u32 = 28;529}530531parameter_types! {532 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;533 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;534}535536impl cumulus_pallet_parachain_system::Config for Runtime {537 type Event = Event;538 type OnValidationData = ();539 type SelfParaId = parachain_info::Pallet<Self>;540 // type DownwardMessageHandlers = cumulus_primitives_utility::UnqueuedDmpAsParent<541 // MaxDownwardMessageWeight,542 // XcmExecutor<XcmConfig>,543 // Call,544 // >;545 type OutboundXcmpMessageSource = XcmpQueue;546 type DmpMessageHandler = DmpQueue;547 type ReservedDmpWeight = ReservedDmpWeight;548 type ReservedXcmpWeight = ReservedXcmpWeight;549 type XcmpMessageHandler = XcmpQueue;550}551552impl parachain_info::Config for Runtime {}553554impl cumulus_pallet_aura_ext::Config for Runtime {}555556parameter_types! {557 pub const RelayLocation: MultiLocation = MultiLocation::parent();558 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;559 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();560 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();561}562563/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used564/// when determining ownership of accounts for asset transacting and when attempting to use XCM565/// `Transact` in order to determine the dispatch Origin.566pub type LocationToAccountId = (567 // The parent (Relay-chain) origin converts to the default `AccountId`.568 ParentIsDefault<AccountId>,569 // Sibling parachain origins convert to AccountId via the `ParaId::into`.570 SiblingParachainConvertsVia<Sibling, AccountId>,571 // Straight up local `AccountId32` origins just alias directly to `AccountId`.572 AccountId32Aliases<RelayNetwork, AccountId>,573);574575/// Means for transacting assets on this chain.576pub type LocalAssetTransactor = CurrencyAdapter<577 // Use this currency:578 Balances,579 // Use this currency when it is a fungible asset matching the given location or name:580 IsConcrete<RelayLocation>,581 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:582 LocationToAccountId,583 // Our chain's account ID type (we can't get away without mentioning it explicitly):584 AccountId,585 // We don't track any teleports.586 (),587>;588589/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,590/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can591/// biases the kind of local `Origin` it will become.592pub type XcmOriginToTransactDispatchOrigin = (593 // Sovereign account converter; this attempts to derive an `AccountId` from the origin location594 // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for595 // foreign chains who want to have a local sovereign account on this chain which they control.596 SovereignSignedViaLocation<LocationToAccountId, Origin>,597 // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when598 // recognised.599 RelayChainAsNative<RelayOrigin, Origin>,600 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when601 // recognised.602 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,603 // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a604 // transaction from the Root origin.605 ParentAsSuperuser<Origin>,606 // Native signed account converter; this just converts an `AccountId32` origin into a normal607 // `Origin::Signed` origin of the same 32-byte value.608 SignedAccountId32AsNative<RelayNetwork, Origin>,609 // Xcm origins can be represented natively under the Xcm pallet's Xcm origin.610 XcmPassthrough<Origin>,611);612613parameter_types! {614 // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.615 pub UnitWeightCost: Weight = 1_000_000;616 // 1200 UNIQUEs buy 1 second of weight.617 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);618 pub const MaxInstructions: u32 = 100;619 pub const MaxAuthorities: u32 = 100_000;620}621622match_type! {623 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {624 MultiLocation { parents: 1, interior: Here } |625 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }626 };627}628629pub type Barrier = (630 TakeWeightCredit,631 AllowTopLevelPaidExecutionFrom<Everything>,632 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,633 // ^^^ Parent & its unit plurality gets free execution634);635636pub struct XcmConfig;637impl Config for XcmConfig {638 type Call = Call;639 type XcmSender = XcmRouter;640 // How to withdraw and deposit an asset.641 type AssetTransactor = LocalAssetTransactor;642 type OriginConverter = XcmOriginToTransactDispatchOrigin;643 type IsReserve = NativeAsset;644 type IsTeleporter = (); // Teleportation is disabled645 type LocationInverter = LocationInverter<Ancestry>;646 type Barrier = Barrier;647 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;648 type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, ()>;649 type ResponseHandler = (); // Don't handle responses for now.650 type SubscriptionService = PolkadotXcm;651652 type AssetTrap = PolkadotXcm;653 type AssetClaims = PolkadotXcm;654}655656// parameter_types! {657// pub const MaxDownwardMessageWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10;658// }659660/// No local origins on this chain are allowed to dispatch XCM sends/executions.661pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);662663/// The means for routing XCM messages which are not for local execution into the right message664/// queues.665pub type XcmRouter = (666 // Two routers - use UMP to communicate with the relay chain:667 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,668 // ..and XCMP to communicate with the sibling chains.669 XcmpQueue,670);671672impl pallet_evm_coder_substrate::Config for Runtime {673 type EthereumTransactionSender = pallet_ethereum::Pallet<Self>;674}675676impl pallet_xcm::Config for Runtime {677 type Event = Event;678 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;679 type XcmRouter = XcmRouter;680 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;681 type XcmExecuteFilter = Everything;682 type XcmExecutor = XcmExecutor<XcmConfig>;683 type XcmTeleportFilter = Everything;684 type XcmReserveTransferFilter = Everything;685 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;686 type LocationInverter = LocationInverter<Ancestry>;687 type Origin = Origin;688 type Call = Call;689 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;690 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;691}692693impl cumulus_pallet_xcm::Config for Runtime {694 type Event = Event;695 type XcmExecutor = XcmExecutor<XcmConfig>;696}697698impl cumulus_pallet_xcmp_queue::Config for Runtime {699 type Event = Event;700 type XcmExecutor = XcmExecutor<XcmConfig>;701 type ChannelInfo = ParachainSystem;702 type VersionWrapper = ();703}704705impl cumulus_pallet_dmp_queue::Config for Runtime {706 type Event = Event;707 type XcmExecutor = XcmExecutor<XcmConfig>;708 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;709}710711impl pallet_aura::Config for Runtime {712 type AuthorityId = AuraId;713 type DisabledValidators = ();714 type MaxAuthorities = MaxAuthorities;715}716717parameter_types! {718 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();719 pub const CollectionCreationPrice: Balance = 100 * UNIQUE;720}721722impl pallet_common::Config for Runtime {723 type Event = Event;724 type EvmBackwardsAddressMapping = pallet_common::account::MapBackwardsAddressTruncated;725 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;726 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;727728 type Currency = Balances;729 type CollectionCreationPrice = CollectionCreationPrice;730 type TreasuryAccountId = TreasuryAccountId;731}732733impl pallet_fungible::Config for Runtime {734 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;735}736impl pallet_refungible::Config for Runtime {737 type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;738}739impl pallet_nonfungible::Config for Runtime {740 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;741}742743/// Used for the pallet nft in `./nft.rs`744impl pallet_nft::Config for Runtime {745 type WeightInfo = pallet_nft::weights::SubstrateWeight<Self>;746}747748parameter_types! {749 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied750}751752/// Used for the pallet inflation753impl pallet_inflation::Config for Runtime {754 type Currency = Balances;755 type TreasuryAccountId = TreasuryAccountId;756 type InflationBlockInterval = InflationBlockInterval;757}758759parameter_types! {760 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *761 RuntimeBlockWeights::get().max_block;762 pub const MaxScheduledPerBlock: u32 = 50;763}764765pub struct Sponsoring;766impl SponsoringResolve<AccountId, Call> for Sponsoring {767 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>768 where769 Call: Dispatchable<Info = DispatchInfo>,770 AccountId: AsRef<[u8]>,771 {772 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)773 }774}775776type SponsorshipHandler = (777 pallet_nft::NftSponsorshipHandler<Runtime>,778 //pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,779);780781impl pallet_unq_scheduler::Config for Runtime {782 type Event = Event;783 type Origin = Origin;784 type PalletsOrigin = OriginCaller;785 type Call = Call;786 type MaximumWeight = MaximumSchedulerWeight;787 type ScheduleOrigin = EnsureSigned<AccountId>;788 type MaxScheduledPerBlock = MaxScheduledPerBlock;789 type SponsorshipHandler = SponsorshipHandler;790 type WeightInfo = ();791}792793impl pallet_nft_transaction_payment::Config for Runtime {794 type SponsorshipHandler = SponsorshipHandler;795}796797impl pallet_evm_transaction_payment::Config for Runtime {798 type SponsorshipHandler = (799 pallet_nft::NftEthSponsorshipHandler<Self>,800 pallet_evm_contract_helpers::HelpersContractSponsoring<Self>,801 );802 type Currency = Balances;803}804805impl pallet_nft_charge_transaction::Config for Runtime {}806807// impl pallet_contract_helpers::Config for Runtime {808// type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;809// }810811parameter_types! {812 // 0x842899ECF380553E8a4de75bF534cdf6fBF64049813 pub const HelpersContractAddress: H160 = H160([814 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,815 ]);816}817818impl pallet_evm_contract_helpers::Config for Runtime {819 type ContractAddress = HelpersContractAddress;820 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;821}822823construct_runtime!(824 pub enum Runtime where825 Block = Block,826 NodeBlock = opaque::Block,827 UncheckedExtrinsic = UncheckedExtrinsic828 {829 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,830 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,831832 Aura: pallet_aura::{Pallet, Config<T>} = 22,833 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,834835 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,836 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,837 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,838 TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,839 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,840 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,841 System: system::{Pallet, Call, Storage, Config, Event<T>} = 36,842 Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,843 // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,844845 // XCM helpers.846 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,847 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,848 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,849 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,850851 // Unique Pallets852 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,853 Nft: pallet_nft::{Pallet, Call, Storage} = 61,854 Scheduler: pallet_unq_scheduler::{Pallet, Call, Storage, Event<T>} = 62,855 NftPayment: pallet_nft_transaction_payment::{Pallet, Call, Storage} = 63,856 Charging: pallet_nft_charge_transaction::{Pallet, Call, Storage } = 64,857 // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,858 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,859 Fungible: pallet_fungible::{Pallet, Storage} = 67,860 Refungible: pallet_refungible::{Pallet, Storage} = 68,861 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,862863 // Frontier864 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,865 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,866867 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,868 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,869 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,870 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,871 }872);873874pub struct TransactionConverter;875876impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {877 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {878 UncheckedExtrinsic::new_unsigned(879 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),880 )881 }882}883884impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {885 fn convert_transaction(886 &self,887 transaction: pallet_ethereum::Transaction,888 ) -> opaque::UncheckedExtrinsic {889 let extrinsic = UncheckedExtrinsic::new_unsigned(890 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),891 );892 let encoded = extrinsic.encode();893 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])894 .expect("Encoded extrinsic is always valid")895 }896}897898/// The address format for describing accounts.899pub type Address = sp_runtime::MultiAddress<AccountId, ()>;900/// Block header type as expected by this runtime.901pub type Header = generic::Header<BlockNumber, BlakeTwo256>;902/// Block type as expected by this runtime.903pub type Block = generic::Block<Header, UncheckedExtrinsic>;904/// A Block signed with a Justification905pub type SignedBlock = generic::SignedBlock<Block>;906/// BlockId type as expected by this runtime.907pub type BlockId = generic::BlockId<Block>;908/// The SignedExtension to the basic transaction logic.909pub type SignedExtra = (910 system::CheckSpecVersion<Runtime>,911 // system::CheckTxVersion<Runtime>,912 system::CheckGenesis<Runtime>,913 system::CheckEra<Runtime>,914 system::CheckNonce<Runtime>,915 system::CheckWeight<Runtime>,916 pallet_nft_charge_transaction::ChargeTransactionPayment<Runtime>,917 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,918);919/// Unchecked extrinsic type as expected by this runtime.920pub type UncheckedExtrinsic =921 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;922/// Extrinsic type that has already been checked.923pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, Call, SignedExtra, H160>;924/// Executive: handles dispatch to the various modules.925pub type Executive = frame_executive::Executive<926 Runtime,927 Block,928 frame_system::ChainContext<Runtime>,929 Runtime,930 AllPallets,931>;932933impl_opaque_keys! {934 pub struct SessionKeys {935 pub aura: Aura,936 }937}938939impl fp_self_contained::SelfContainedCall for Call {940 type SignedInfo = H160;941942 fn is_self_contained(&self) -> bool {943 match self {944 Call::Ethereum(call) => call.is_self_contained(),945 _ => false,946 }947 }948949 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {950 match self {951 Call::Ethereum(call) => call.check_self_contained(),952 _ => None,953 }954 }955956 fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option<TransactionValidity> {957 match self {958 Call::Ethereum(call) => call.validate_self_contained(info),959 _ => None,960 }961 }962963 fn pre_dispatch_self_contained(964 &self,965 info: &Self::SignedInfo,966 ) -> Option<Result<(), TransactionValidityError>> {967 match self {968 Call::Ethereum(call) => call.pre_dispatch_self_contained(info),969 _ => None,970 }971 }972973 fn apply_self_contained(974 self,975 info: Self::SignedInfo,976 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {977 match self {978 call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch(979 Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)),980 )),981 _ => None,982 }983 }984}985986macro_rules! dispatch_nft_runtime {987 ($collection:ident.$method:ident($($name:ident),*)) => {{988 use pallet_nft::dispatch::Dispatched;989990 let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::new($collection).unwrap());991 let dispatch = collection.as_dyn();992993 dispatch.$method($($name),*)994 }};995}996impl_runtime_apis! {997 impl up_rpc::NftApi<Block, CrossAccountId, AccountId>998 for Runtime999 {1000 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId> {1001 dispatch_nft_runtime!(collection.account_tokens(account))1002 }1003 fn token_exists(collection: CollectionId, token: TokenId) -> bool {1004 dispatch_nft_runtime!(collection.token_exists(token))1005 }10061007 fn token_owner(collection: CollectionId, token: TokenId) -> CrossAccountId {1008 dispatch_nft_runtime!(collection.token_owner(token))1009 }1010 fn const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8> {1011 dispatch_nft_runtime!(collection.const_metadata(token))1012 }1013 fn variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8> {1014 dispatch_nft_runtime!(collection.variable_metadata(token))1015 }10161017 fn collection_tokens(collection: CollectionId) -> u32 {1018 dispatch_nft_runtime!(collection.collection_tokens())1019 }1020 fn account_balance(collection: CollectionId, account: CrossAccountId) -> u32 {1021 dispatch_nft_runtime!(collection.account_balance(account))1022 }1023 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> u128 {1024 dispatch_nft_runtime!(collection.balance(account, token))1025 }1026 fn allowance(1027 collection: CollectionId,1028 sender: CrossAccountId,1029 spender: CrossAccountId,1030 token: TokenId,1031 ) -> u128 {1032 dispatch_nft_runtime!(collection.allowance(sender, spender, token))1033 }10341035 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {1036 <pallet_nft::NftErcSupport<Runtime>>::get_code(&account)1037 .or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))1038 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))1039 }1040 fn adminlist(collection: CollectionId) -> Vec<CrossAccountId> {1041 <pallet_nft::Pallet<Runtime>>::adminlist(collection)1042 }1043 fn allowlist(collection: CollectionId) -> Vec<CrossAccountId> {1044 <pallet_nft::Pallet<Runtime>>::allowlist(collection)1045 }1046 fn last_token_id(collection: CollectionId) -> TokenId {1047 dispatch_nft_runtime!(collection.last_token_id())1048 }1049 }10501051 impl sp_api::Core<Block> for Runtime {1052 fn version() -> RuntimeVersion {1053 VERSION1054 }10551056 fn execute_block(block: Block) {1057 Executive::execute_block(block)1058 }10591060 fn initialize_block(header: &<Block as BlockT>::Header) {1061 Executive::initialize_block(header)1062 }1063 }10641065 impl sp_api::Metadata<Block> for Runtime {1066 fn metadata() -> OpaqueMetadata {1067 OpaqueMetadata::new(Runtime::metadata().into())1068 }1069 }10701071 impl sp_block_builder::BlockBuilder<Block> for Runtime {1072 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {1073 Executive::apply_extrinsic(extrinsic)1074 }10751076 fn finalize_block() -> <Block as BlockT>::Header {1077 Executive::finalize_block()1078 }10791080 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {1081 data.create_extrinsics()1082 }10831084 fn check_inherents(1085 block: Block,1086 data: sp_inherents::InherentData,1087 ) -> sp_inherents::CheckInherentsResult {1088 data.check_extrinsics(&block)1089 }10901091 // fn random_seed() -> <Block as BlockT>::Hash {1092 // RandomnessCollectiveFlip::random_seed().01093 // }1094 }10951096 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {1097 fn validate_transaction(1098 source: TransactionSource,1099 tx: <Block as BlockT>::Extrinsic,1100 hash: <Block as BlockT>::Hash,1101 ) -> TransactionValidity {1102 Executive::validate_transaction(source, tx, hash)1103 }1104 }11051106 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {1107 fn offchain_worker(header: &<Block as BlockT>::Header) {1108 Executive::offchain_worker(header)1109 }1110 }11111112 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {1113 fn chain_id() -> u64 {1114 <Runtime as pallet_evm::Config>::ChainId::get()1115 }11161117 fn account_basic(address: H160) -> EVMAccount {1118 EVM::account_basic(&address)1119 }11201121 fn gas_price() -> U256 {1122 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()1123 }11241125 fn account_code_at(address: H160) -> Vec<u8> {1126 EVM::account_codes(address)1127 }11281129 fn author() -> H160 {1130 <pallet_evm::Pallet<Runtime>>::find_author()1131 }11321133 fn storage_at(address: H160, index: U256) -> H256 {1134 let mut tmp = [0u8; 32];1135 index.to_big_endian(&mut tmp);1136 EVM::account_storages(address, H256::from_slice(&tmp[..]))1137 }11381139 fn call(1140 from: H160,1141 to: H160,1142 data: Vec<u8>,1143 value: U256,1144 gas_limit: U256,1145 gas_price: Option<U256>,1146 nonce: Option<U256>,1147 estimate: bool,1148 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {1149 let config = if estimate {1150 let mut config = <Runtime as pallet_evm::Config>::config().clone();1151 config.estimate = true;1152 Some(config)1153 } else {1154 None1155 };11561157 <Runtime as pallet_evm::Config>::Runner::call(1158 from,1159 to,1160 data,1161 value,1162 gas_limit.low_u64(),1163 gas_price,1164 nonce,1165 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),1166 ).map_err(|err| err.into())1167 }11681169 fn create(1170 from: H160,1171 data: Vec<u8>,1172 value: U256,1173 gas_limit: U256,1174 gas_price: Option<U256>,1175 nonce: Option<U256>,1176 estimate: bool,1177 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {1178 let config = if estimate {1179 let mut config = <Runtime as pallet_evm::Config>::config().clone();1180 config.estimate = true;1181 Some(config)1182 } else {1183 None1184 };11851186 <Runtime as pallet_evm::Config>::Runner::create(1187 from,1188 data,1189 value,1190 gas_limit.low_u64(),1191 gas_price,1192 nonce,1193 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),1194 ).map_err(|err| err.into())1195 }11961197 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {1198 Ethereum::current_transaction_statuses()1199 }12001201 fn current_block() -> Option<pallet_ethereum::Block> {1202 Ethereum::current_block()1203 }12041205 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {1206 Ethereum::current_receipts()1207 }12081209 fn current_all() -> (1210 Option<pallet_ethereum::Block>,1211 Option<Vec<pallet_ethereum::Receipt>>,1212 Option<Vec<TransactionStatus>>1213 ) {1214 (1215 Ethereum::current_block(),1216 Ethereum::current_receipts(),1217 Ethereum::current_transaction_statuses()1218 )1219 }12201221 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {1222 xts.into_iter().filter_map(|xt| match xt.0.function {1223 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),1224 _ => None1225 }).collect()1226 }1227 }12281229 impl sp_session::SessionKeys<Block> for Runtime {1230 fn decode_session_keys(1231 encoded: Vec<u8>,1232 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {1233 SessionKeys::decode_into_raw_public_keys(&encoded)1234 }12351236 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {1237 SessionKeys::generate(seed)1238 }1239 }12401241 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {1242 fn slot_duration() -> sp_consensus_aura::SlotDuration {1243 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())1244 }12451246 fn authorities() -> Vec<AuraId> {1247 Aura::authorities().to_vec()1248 }1249 }12501251 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {1252 fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {1253 ParachainSystem::collect_collation_info()1254 }1255 }12561257 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {1258 fn account_nonce(account: AccountId) -> Index {1259 System::account_nonce(account)1260 }1261 }12621263 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {1264 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {1265 TransactionPayment::query_info(uxt, len)1266 }1267 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {1268 TransactionPayment::query_fee_details(uxt, len)1269 }1270 }12711272 /*1273 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>1274 for Runtime1275 {1276 fn call(1277 origin: AccountId,1278 dest: AccountId,1279 value: Balance,1280 gas_limit: u64,1281 input_data: Vec<u8>,1282 ) -> pallet_contracts_primitives::ContractExecResult {1283 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)1284 }12851286 fn instantiate(1287 origin: AccountId,1288 endowment: Balance,1289 gas_limit: u64,1290 code: pallet_contracts_primitives::Code<Hash>,1291 data: Vec<u8>,1292 salt: Vec<u8>,1293 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>1294 {1295 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)1296 }12971298 fn get_storage(1299 address: AccountId,1300 key: [u8; 32],1301 ) -> pallet_contracts_primitives::GetStorageResult {1302 Contracts::get_storage(address, key)1303 }13041305 fn rent_projection(1306 address: AccountId,1307 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {1308 Contracts::rent_projection(address)1309 }1310 }1311 */13121313 #[cfg(feature = "runtime-benchmarks")]1314 impl frame_benchmarking::Benchmark<Block> for Runtime {1315 fn benchmark_metadata(extra: bool) -> (1316 Vec<frame_benchmarking::BenchmarkList>,1317 Vec<frame_support::traits::StorageInfo>,1318 ) {1319 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};1320 use frame_support::traits::StorageInfoTrait;13211322 let mut list = Vec::<BenchmarkList>::new();13231324 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);1325 list_benchmark!(list, extra, pallet_nft, Nft);1326 list_benchmark!(list, extra, pallet_inflation, Inflation);1327 list_benchmark!(list, extra, pallet_fungible, Fungible);1328 list_benchmark!(list, extra, pallet_refungible, Refungible);1329 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);1330 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);13311332 let storage_info = AllPalletsWithSystem::storage_info();13331334 return (list, storage_info)1335 }13361337 fn dispatch_benchmark(1338 config: frame_benchmarking::BenchmarkConfig1339 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {1340 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};13411342 let whitelist: Vec<TrackedStorageKey> = vec![1343 // Block Number1344 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),1345 // Total Issuance1346 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),1347 // Execution Phase1348 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),1349 // Event Count1350 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),1351 // System Events1352 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),1353 ];13541355 let mut batches = Vec::<BenchmarkBatch>::new();1356 let params = (&config, &whitelist);13571358 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);1359 add_benchmark!(params, batches, pallet_nft, Nft);1360 add_benchmark!(params, batches, pallet_inflation, Inflation);1361 add_benchmark!(params, batches, pallet_fungible, Fungible);1362 add_benchmark!(params, batches, pallet_refungible, Refungible);1363 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);1364 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);13651366 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }1367 Ok(batches)1368 }1369 }1370}13711372struct CheckInherents;13731374impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {1375 fn check_inherents(1376 block: &Block,1377 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,1378 ) -> sp_inherents::CheckInherentsResult {1379 let relay_chain_slot = relay_state_proof1380 .read_slot()1381 .expect("Could not read the relay chain slot from the proof");13821383 let inherent_data =1384 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(1385 relay_chain_slot,1386 sp_std::time::Duration::from_secs(6),1387 )1388 .create_inherent_data()1389 .expect("Could not create the timestamp inherent data");13901391 inherent_data.check_extrinsics(block)1392 }1393}13941395cumulus_pallet_parachain_system::register_validate_block!(1396 Runtime = Runtime,1397 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1398 CheckInherents = CheckInherents,1399);