git.delta.rocks / unique-network / refs/commits / 36b556a0c992

difftreelog

feat(evm-coder) implementation generator

Yaroslav Bolyukin2021-08-11parent: #aa106c3.patch.diff
in: master

8 files changed

modifiedcrates/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
@@ -73,6 +73,20 @@
 			}
 		}
 	}
+
+	fn expand_generator(&self) -> proc_macro2::TokenStream {
+		let pascal_call_name = &self.pascal_call_name;
+		quote! {
+			#pascal_call_name::generate_solidity_interface(out_set, is_impl);
+		}
+	}
+
+	fn expand_event_generator(&self) -> proc_macro2::TokenStream {
+		let name = &self.name;
+		quote! {
+			#name::generate_solidity_interface(out_set, is_impl);
+		}
+	}
 }
 
 #[derive(Default)]
@@ -109,12 +123,15 @@
 
 struct MethodArg {
 	name: Ident,
+	camel_name: String,
 	ty: Ident,
 }
 impl MethodArg {
 	fn try_from(value: &PatType) -> syn::Result<Self> {
+		let name = parse_ident_from_pat(&value.pat)?.clone();
 		Ok(Self {
-			name: parse_ident_from_pat(&value.pat)?.clone(),
+			camel_name: cases::camelcase::to_camel_case(&name.to_string()),
+			name,
 			ty: parse_ident_from_type(&value.ty, false)?.clone(),
 		})
 	}
@@ -168,10 +185,10 @@
 	}
 
 	fn expand_solidity_argument(&self) -> proc_macro2::TokenStream {
-		let name = &self.name.to_string();
+		let camel_name = &self.camel_name.to_string();
 		let ty = &self.ty;
 		quote! {
-			<NamedArgument<#ty>>::new(#name)
+			<NamedArgument<#ty>>::new(#camel_name)
 		}
 	}
 }
@@ -397,7 +414,11 @@
 		};
 		let result = &self.result;
 
-		let args = self.args.iter().map(MethodArg::expand_solidity_argument);
+		let args = self
+			.args
+			.iter()
+			.filter(|a| !a.is_special())
+			.map(MethodArg::expand_solidity_argument);
 
 		quote! {
 			SolidityFunction {
@@ -475,6 +496,24 @@
 		let call_variants_this = self.methods.iter().map(Method::expand_variant_call);
 		let solidity_functions = self.methods.iter().map(Method::expand_solidity_function);
 
+		// TODO: Inline inline_is
+		let solidity_is = self
+			.info
+			.is
+			.0
+			.iter()
+			.chain(self.info.inline_is.0.iter())
+			.map(|is| is.name.to_string());
+		let solidity_events_is = self.info.events.0.iter().map(|is| is.name.to_string());
+		let solidity_generators = self
+			.info
+			.is
+			.0
+			.iter()
+			.chain(self.info.inline_is.0.iter())
+			.map(Is::expand_generator);
+		let solidity_event_generators = self.info.events.0.iter().map(Is::expand_event_generator);
+
 		// let methods = self.methods.iter().map(Method::solidity_def);
 
 		quote! {
@@ -505,18 +544,40 @@
 						)*
 					)
 				}
-				pub fn generate_solidity_interface() -> string {
+				pub fn generate_solidity_interface(out_set: &mut sp_std::collections::btree_set::BTreeSet<string>, is_impl: bool) {
 					use evm_coder::solidity::*;
 					use core::fmt::Write;
 					let interface = SolidityInterface {
 						name: #solidity_name,
+						is: &["Dummy", #(
+							#solidity_is,
+						)* #(
+							#solidity_events_is,
+						)* ],
 						functions: (#(
 							#solidity_functions,
 						)*),
 					};
+					if is_impl {
+						out_set.insert("// Common stubs holder\ncontract Dummy {\n\tuint8 dummy;\n\tstring stub_error = \"this contract is implemented in native\";\n}\n".into());
+					} else {
+						out_set.insert("// Common stubs holder\ninterface Dummy {\n}\n".into());
+					}
+					#(
+						#solidity_generators
+					)*
+					#(
+						#solidity_event_generators
+					)*
+
 					let mut out = string::new();
-					let _ = interface.format(&mut out);
-					out
+					// In solidity interface usage (is) should be preceeded by interface definition
+					// This comment helps to sort it in a set
+					if #solidity_name.starts_with("Inline") {
+						out.push_str("// Inline\n");
+					}
+					let _ = interface.format(is_impl, &mut out);
+					out_set.insert(out);
 				}
 			}
 			impl ::evm_coder::Call for #call_name {
modifiedcrates/evm-coder-macros/src/to_log.rsdiffbeforeafterboth
--- a/crates/evm-coder-macros/src/to_log.rs
+++ b/crates/evm-coder-macros/src/to_log.rs
@@ -1,3 +1,4 @@
+use inflector::cases;
 use syn::{Data, DeriveInput, Field, Fields, Ident, Variant, spanned::Spanned};
 use std::fmt::Write;
 use quote::quote;
@@ -6,6 +7,7 @@
 
 struct EventField {
 	name: Ident,
+	camel_name: String,
 	ty: Ident,
 	indexed: bool,
 }
@@ -24,10 +26,18 @@
 		}
 		Ok(Self {
 			name: name.to_owned(),
+			camel_name: cases::camelcase::to_camel_case(&name.to_string()),
 			ty: ty.to_owned(),
 			indexed,
 		})
 	}
+	fn expand_solidity_argument(&self) -> proc_macro2::TokenStream {
+		let camel_name = &self.camel_name;
+		let ty = &self.ty;
+		quote! {
+			<NamedArgument<#ty>>::new(#camel_name)
+		}
+	}
 }
 
 struct Event {
@@ -116,6 +126,21 @@
 			)*];
 		}
 	}
+
+	fn expand_solidity_function(&self) -> proc_macro2::TokenStream {
+		let name = self.name.to_string();
+		let args = self.fields.iter().map(EventField::expand_solidity_argument);
+		quote! {
+			SolidityEvent {
+				name: #name,
+				args: (
+					#(
+						#args,
+					)*
+				),
+			}
+		}
+	}
 }
 
 pub struct Events {
@@ -144,12 +169,30 @@
 
 		let consts = self.events.iter().map(Event::expand_consts);
 		let serializers = self.events.iter().map(Event::expand_serializers);
+		let solidity_name = self.name.to_string();
+		let solidity_functions = self.events.iter().map(Event::expand_solidity_function);
 
 		quote! {
 			impl #name {
 				#(
 					#consts
 				)*
+
+				pub fn generate_solidity_interface(out_set: &mut sp_std::collections::btree_set::BTreeSet<string>, is_impl: bool) {
+					use evm_coder::solidity::*;
+					use core::fmt::Write;
+					let interface = SolidityInterface {
+						name: #solidity_name,
+						is: &[],
+						functions: (#(
+							#solidity_functions,
+						)*),
+					};
+					let mut out = string::new();
+					out.push_str("// Inline\n");
+					let _ = interface.format(is_impl, &mut out);
+					out_set.insert(out);
+				}
 			}
 
 			#[automatically_derived]
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -6,37 +6,44 @@
 
 pub trait SolidityTypeName: 'static {
 	fn solidity_name(writer: &mut impl fmt::Write) -> fmt::Result;
+	fn solidity_default(writer: &mut impl fmt::Write) -> fmt::Result;
 	fn is_void() -> bool {
 		false
 	}
 }
 
 macro_rules! solidity_type_name {
-    ($($ty:ident => $name:expr),* $(,)?) => {
+    ($($ty:ident => $name:literal = $default:literal),* $(,)?) => {
         $(
             impl SolidityTypeName for $ty {
                 fn solidity_name(writer: &mut impl core::fmt::Write) -> core::fmt::Result {
                     write!(writer, $name)
                 }
+				fn solidity_default(writer: &mut impl core::fmt::Write) -> core::fmt::Result {
+					write!(writer, $default)
+				}
             }
         )*
     };
 }
 
 solidity_type_name! {
-	uint8 => "uint8",
-	uint32 => "uint32",
-	uint128 => "uint128",
-	uint256 => "uint256",
-	address => "address",
-	string => "memory string",
-	bytes => "memory bytes",
-	bool => "bool",
+	uint8 => "uint8" = "0",
+	uint32 => "uint32" = "0",
+	uint128 => "uint128" = "0",
+	uint256 => "uint256" = "0",
+	address => "address" = "0x0000000000000000000000000000000000000000",
+	string => "string memory" = "\"\"",
+	bytes => "bytes memory" = "hex\"\"",
+	bool => "bool" = "false",
 }
 impl SolidityTypeName for void {
 	fn solidity_name(_writer: &mut impl fmt::Write) -> fmt::Result {
 		Ok(())
 	}
+	fn solidity_default(_writer: &mut impl fmt::Write) -> fmt::Result {
+		Ok(())
+	}
 	fn is_void() -> bool {
 		true
 	}
@@ -44,6 +51,8 @@
 
 pub trait SolidityArguments {
 	fn solidity_name(&self, writer: &mut impl fmt::Write) -> fmt::Result;
+	fn solidity_get(&self, writer: &mut impl fmt::Write) -> fmt::Result;
+	fn solidity_default(&self, writer: &mut impl fmt::Write) -> fmt::Result;
 	fn is_empty(&self) -> bool {
 		self.len() == 0
 	}
@@ -61,6 +70,12 @@
 			Ok(())
 		}
 	}
+	fn solidity_get(&self, _writer: &mut impl fmt::Write) -> fmt::Result {
+		Ok(())
+	}
+	fn solidity_default(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+		T::solidity_default(writer)
+	}
 	fn len(&self) -> usize {
 		if T::is_void() {
 			0
@@ -87,6 +102,12 @@
 			Ok(())
 		}
 	}
+	fn solidity_get(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+		writeln!(writer, "\t\t{};", self.0)
+	}
+	fn solidity_default(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+		T::solidity_default(writer)
+	}
 	fn len(&self) -> usize {
 		if T::is_void() {
 			0
@@ -100,6 +121,12 @@
 	fn solidity_name(&self, _writer: &mut impl fmt::Write) -> fmt::Result {
 		Ok(())
 	}
+	fn solidity_get(&self, _writer: &mut impl fmt::Write) -> fmt::Result {
+		Ok(())
+	}
+	fn solidity_default(&self, _writer: &mut impl fmt::Write) -> fmt::Result {
+		Ok(())
+	}
 	fn len(&self) -> usize {
 		0
 	}
@@ -122,13 +149,43 @@
         )* );
 		Ok(())
 	}
+	fn solidity_get(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+		for_tuples!( #(
+            Tuple.solidity_get(writer)?;
+        )* );
+		Ok(())
+	}
+	fn solidity_default(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+		if self.is_empty() {
+			Ok(())
+		} else if self.len() == 1 {
+			for_tuples!( #(
+				Tuple.solidity_default(writer)?;
+			)* );
+			Ok(())
+		} else {
+			write!(writer, "(")?;
+			let mut first = true;
+			for_tuples!( #(
+				if !Tuple.is_empty() {
+					if !first {
+						write!(writer, ", ")?;
+					}
+					first = false;
+					Tuple.solidity_name(writer)?;
+				}
+			)* );
+			write!(writer, ")")?;
+			Ok(())
+		}
+	}
 	fn len(&self) -> usize {
 		for_tuples!( #( Tuple.len() )+* )
 	}
 }
 
 pub trait SolidityFunctions {
-	fn solidity_name(&self, writer: &mut impl fmt::Write) -> fmt::Result;
+	fn solidity_name(&self, is_impl: bool, writer: &mut impl fmt::Write) -> fmt::Result;
 }
 
 pub enum SolidityMutability {
@@ -143,10 +200,15 @@
 	pub mutability: SolidityMutability,
 }
 impl<A: SolidityArguments, R: SolidityArguments> SolidityFunctions for SolidityFunction<A, R> {
-	fn solidity_name(&self, writer: &mut impl fmt::Write) -> fmt::Result {
-		write!(writer, "function {}(", self.name)?;
+	fn solidity_name(&self, is_impl: bool, writer: &mut impl fmt::Write) -> fmt::Result {
+		write!(writer, "\tfunction {}(", self.name)?;
 		self.args.solidity_name(writer)?;
-		write!(writer, ") external")?;
+		write!(writer, ")")?;
+		if is_impl {
+			write!(writer, " public")?;
+		} else {
+			write!(writer, " external")?;
+		}
 		match &self.mutability {
 			SolidityMutability::Pure => write!(writer, " pure")?,
 			SolidityMutability::View => write!(writer, " view")?,
@@ -157,7 +219,25 @@
 			self.result.solidity_name(writer)?;
 			write!(writer, ")")?;
 		}
-		writeln!(writer, ";")
+		if is_impl {
+			writeln!(writer, " {{")?;
+			writeln!(writer, "\t\trequire(false, stub_error);")?;
+			self.args.solidity_get(writer)?;
+			match &self.mutability {
+				SolidityMutability::Pure => {}
+				SolidityMutability::View => writeln!(writer, "\t\tdummy;")?,
+				SolidityMutability::Mutable => writeln!(writer, "\t\tdummy = 0;")?,
+			}
+			if !self.result.is_empty() {
+				write!(writer, "\t\treturn ")?;
+				self.result.solidity_default(writer)?;
+				writeln!(writer, ";")?;
+			}
+			writeln!(writer, "\t}}")?;
+		} else {
+			writeln!(writer, ";")?;
+		}
+		Ok(())
 	}
 }
 
@@ -165,10 +245,10 @@
 impl SolidityFunctions for Tuple {
 	for_tuples!( where #( Tuple: SolidityFunctions ),* );
 
-	fn solidity_name(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+	fn solidity_name(&self, is_impl: bool, writer: &mut impl fmt::Write) -> fmt::Result {
 		let mut first = false;
 		for_tuples!( #(
-            Tuple.solidity_name(writer)?;
+            Tuple.solidity_name(is_impl, writer)?;
         )* );
 		Ok(())
 	}
@@ -176,14 +256,43 @@
 
 pub struct SolidityInterface<F: SolidityFunctions> {
 	pub name: &'static str,
+	pub is: &'static [&'static str],
 	pub functions: F,
 }
 
 impl<F: SolidityFunctions> SolidityInterface<F> {
-	pub fn format(&self, out: &mut impl fmt::Write) -> fmt::Result {
-		writeln!(out, "interface {} {{", self.name)?;
-		self.functions.solidity_name(out)?;
+	pub fn format(&self, is_impl: bool, out: &mut impl fmt::Write) -> fmt::Result {
+		if is_impl {
+			write!(out, "contract ")?;
+		} else {
+			write!(out, "interface ")?;
+		}
+		write!(out, "{}", self.name)?;
+		if !self.is.is_empty() {
+			write!(out, " is")?;
+			for (i, n) in self.is.iter().enumerate() {
+				if i != 0 {
+					write!(out, ",")?;
+				}
+				write!(out, " {}", n)?;
+			}
+		}
+		writeln!(out, " {{")?;
+		self.functions.solidity_name(is_impl, out)?;
 		writeln!(out, "}}")?;
 		Ok(())
 	}
 }
+
+pub struct SolidityEvent<A> {
+	pub name: &'static str,
+	pub args: A,
+}
+
+impl<A: SolidityArguments> SolidityFunctions for SolidityEvent<A> {
+	fn solidity_name(&self, _is_impl: bool, writer: &mut impl fmt::Write) -> fmt::Result {
+		write!(writer, "\tevent {}(", self.name)?;
+		self.args.solidity_name(writer)?;
+		writeln!(writer, ");")
+	}
+}
modifiedpallets/nft/src/eth/erc.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/erc.rs
+++ b/pallets/nft/src/eth/erc.rs
@@ -395,3 +395,32 @@
 
 #[solidity_interface(name = "UniqueFungible", is(ERC165, ERC20))]
 impl<T: Config> CollectionHandle<T> {}
+
+macro_rules! generate_code {
+	($name:ident, $decl:ident, $is_impl:literal) => {
+		#[test]
+		#[ignore]
+		fn $name() {
+			use sp_std::collections::btree_set::BTreeSet;
+			let mut out = BTreeSet::new();
+			$decl::generate_solidity_interface(&mut out, $is_impl);
+			println!("=== SNIP START ===");
+			println!("// SPDX-License-Identifier: OTHER");
+			println!("// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::{} --exact --nocapture --ignored`", stringify!(name));
+			println!();
+			println!("pragma solidity >=0.8.0 <0.9.0;");
+			println!();
+			for b in out {
+				println!("{}", b);
+			}
+			println!("=== SNIP END ===");
+		}
+	};
+}
+
+// Not a tests, but code generators
+generate_code!(nft_impl, UniqueNFTCall, true);
+generate_code!(nft_iface, UniqueNFTCall, false);
+
+generate_code!(fungible_impl, UniqueFungibleCall, true);
+generate_code!(fungible_iface, UniqueFungibleCall, false);
modifiedpallets/nft/src/eth/stubs/ERC20.bindiffbeforeafterboth

binary blob — no preview

modifiedpallets/nft/src/eth/stubs/ERC20.soldiffbeforeafterboth
--- a/pallets/nft/src/eth/stubs/ERC20.sol
+++ b/pallets/nft/src/eth/stubs/ERC20.sol
@@ -1,69 +1,94 @@
 // SPDX-License-Identifier: OTHER
+// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::name --exact --nocapture --ignored`
 
 pragma solidity >=0.8.0 <0.9.0;
 
-contract ERC20 {
-	uint8 _dummy = 0;
-	string stub_error = "this contract does not exists, code for collections is implemented at pallet side";
+// Common stubs holder
+contract Dummy {
+	uint8 dummy;
+	string stub_error = "this contract is implemented in native";
+}
 
-	// 0x18160ddd
-	function totalSupply() external view returns (uint256) {
+// Inline
+contract ERC20Events {
+	event Transfer(address from, address to, uint256 value);
+	event Approval(address owner, address spender, uint256 value);
+}
+
+// Inline
+contract InlineNameSymbol is Dummy {
+	function name() public view returns (string memory) {
 		require(false, stub_error);
-		_dummy;
-		return 0;
+		dummy;
+		return "";
 	}
+	function symbol() public view returns (string memory) {
+		require(false, stub_error);
+		dummy;
+		return "";
+	}
+}
 
-	// 0x70a08231
-	function balanceOf(address account) external view returns (uint256) {
+// Inline
+contract InlineTotalSupply is Dummy {
+	function totalSupply() public view returns (uint256) {
 		require(false, stub_error);
-		account;
-		_dummy;
+		dummy;
 		return 0;
 	}
+}
 
-	// 0xa9059cbb
-	function transfer(address recipient, uint256 amount) external returns (bool) {
+contract ERC165 is Dummy {
+	function supportsInterface(uint32 interfaceId) public view returns (bool) {
 		require(false, stub_error);
-		recipient;
-		amount;
-		_dummy = 0;
+		interfaceId;
+		dummy;
 		return false;
 	}
+}
 
-	// 0xdd62ed3e
-	function allowance(address owner, address spender) external view returns (uint256) {
+contract ERC20 is Dummy, InlineNameSymbol, InlineTotalSupply, ERC20Events {
+	function decimals() public view returns (uint8) {
 		require(false, stub_error);
+		dummy;
+		return 0;
+	}
+	function balanceOf(address owner) public view returns (uint256) {
+		require(false, stub_error);
 		owner;
-		spender;
-		return _dummy;
+		dummy;
+		return 0;
+	}
+	function transfer(address to, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		to;
+		amount;
+		dummy = 0;
+		return false;
 	}
-
-	// 0x095ea7b3
-	function approve(address spender, uint256 amount) external returns (bool) {
+	function transferFrom(address from, address to, uint256 amount) public returns (bool) {
 		require(false, stub_error);
-		spender;
+		from;
+		to;
 		amount;
-		_dummy = 0;
+		dummy = 0;
 		return false;
 	}
-
-	// 0x23b872dd
-	function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) {
+	function approve(address spender, uint256 amount) public returns (bool) {
 		require(false, stub_error);
-		sender;
-		recipient;
+		spender;
 		amount;
-		_dummy = 0;
+		dummy = 0;
 		return false;
 	}
+	function allowance(address owner, address spender) public view returns (uint256) {
+		require(false, stub_error);
+		owner;
+		spender;
+		dummy;
+		return 0;
+	}
+}
 
-	// While ERC165 is not required by spec of ERC20, better implement it
-	// 0x01ffc9a7
-	function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
-		return 
-			// ERC20
-			interfaceID == 0x36372b07 || 
-			// ERC165
-			interfaceID == 0x01ffc9a7;
-	}
+contract UniqueFungible is Dummy, ERC165, ERC20 {
 }
\ No newline at end of file
modifiedpallets/nft/src/eth/stubs/ERC721.bindiffbeforeafterboth

binary blob — no preview

modifiedpallets/nft/src/eth/stubs/ERC721.soldiffbeforeafterboth
before · pallets/nft/src/eth/stubs/ERC721.sol
1// SPDX-License-Identifier: OTHER23pragma solidity >=0.8.0 <0.9.0;45contract ERC721 {6    uint8 _dummy = 0;7    address _dummy_addr = 0x0000000000000000000000000000000000000000;8    string _dummy_string = "";9    string stub_error =10        "this contract does not exists, code for collections is implemented at pallet side";1112    event Transfer(13        address indexed from,14        address indexed to,15        uint256 indexed tokenId16    );1718    event Approval(19        address indexed owner,20        address indexed approved,21        uint256 indexed tokenId22    );2324    event ApprovalForAll(25        address indexed owner,26        address indexed operator,27        bool approved28    );2930	// 0x18160ddd31    function totalSupply() external view returns (uint256) {32        require(false, stub_error);33        return 0;34    }3536    function name() external view returns (string memory res_name) {37        require(false, stub_error);38        res_name = _dummy_string;39    }4041    function symbol() external view returns (string memory res_symbol) {42        require(false, stub_error);43        res_symbol = _dummy_string;44    }4546    function tokenURI(uint256 tokenId) external view returns (string memory) {47        require(false, stub_error);48        tokenId;49        return _dummy_string;50    }5152    function tokenByIndex(uint256 index) external view returns (uint256) {53        require(false, stub_error);54        index;55		return 0;56    }5758    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256) {59        require(false, stub_error);60		owner;61		index;62		return 0;63    }6465    // 0x70a0823166    function balanceOf(address owner) external view returns (uint256) {67        require(false, stub_error);68        owner;69        return 0;70    }7172    // 0x6352211e73    function ownerOf(uint256 tokenId) external view returns (address) {74        require(false, stub_error);75        tokenId;76        return _dummy_addr;77    }7879    // 0xb88d4fde80    function safeTransferFrom(81        address from,82        address to,83        uint256 tokenId,84        bytes calldata data85    ) external payable {86        require(false, stub_error);87        from;88        to;89        tokenId;90        data;91    }9293    // 0x42842e0e94    function safeTransferFrom(95        address from,96        address to,97        uint256 tokenId98    ) external payable {99        require(false, stub_error);100        from;101        to;102        tokenId;103    }104105    // 0x23b872dd106    function transferFrom(107        address from,108        address to,109        uint256 tokenId110    ) external payable {111        require(false, stub_error);112        from;113        to;114        tokenId;115    }116117    // 0x095ea7b3118    function approve(address approved, uint256 tokenId) external payable {119        require(false, stub_error);120        approved;121        tokenId;122    }123124    // 0xa22cb465125    function setApprovalForAll(address operator, bool approved) external {126        require(false, stub_error);127        operator;128        approved;129        _dummy = 0;130    }131132    // 0x081812fc133    function getApproved(uint256 tokenId) external view returns (address) {134        require(false, stub_error);135        tokenId;136        return _dummy_addr;137    }138139    // 0xe985e9c5140    function isApprovedForAll(address owner, address operator)141        external142        view143        returns (bool)144    {145        require(false, stub_error);146        owner;147        operator;148        return false;149    }150151    // 0x01ffc9a7152    function supportsInterface(bytes4 interfaceID) public pure returns (bool) {153        return154            // ERC721155            interfaceID == 0x80ac58cd ||156            // ERC721Metadata157            interfaceID == 0x5b5e139f ||158            // ERC721Enumerable159            interfaceID == 0x780e9d63 ||160            // ERC165161            interfaceID == 0x01ffc9a7;162    }163}
after · pallets/nft/src/eth/stubs/ERC721.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::name --exact --nocapture --ignored`34pragma solidity >=0.8.0 <0.9.0;56// Common stubs holder7contract Dummy {8	uint8 dummy;9	string stub_error = "this contract is implemented in native";10}1112// Inline13contract ERC721Events {14	event Transfer(address from, address to, uint256 tokenId);15	event Approval(address owner, address approved, uint256 tokenId);16	event ApprovalForAll(address owner, address operator, bool approved);17}1819// Inline20contract ERC721MintableEvents {21	event MintingFinished();22}2324// Inline25contract InlineNameSymbol is Dummy {26	function name() public view returns (string memory) {27		require(false, stub_error);28		dummy;29		return "";30	}31	function symbol() public view returns (string memory) {32		require(false, stub_error);33		dummy;34		return "";35	}36}3738// Inline39contract InlineTotalSupply is Dummy {40	function totalSupply() public view returns (uint256) {41		require(false, stub_error);42		dummy;43		return 0;44	}45}4647contract ERC165 is Dummy {48	function supportsInterface(uint32 interfaceId) public view returns (bool) {49		require(false, stub_error);50		interfaceId;51		dummy;52		return false;53	}54}5556contract ERC721 is Dummy, ERC165, ERC721Events {57	function balanceOf(address owner) public view returns (uint256) {58		require(false, stub_error);59		owner;60		dummy;61		return 0;62	}63	function ownerOf(uint256 tokenId) public view returns (address) {64		require(false, stub_error);65		tokenId;66		dummy;67		return 0x0000000000000000000000000000000000000000;68	}69	function safeTransferFromWithData(address from, address to, uint256 tokenId, bytes memory data) public {70		require(false, stub_error);71		from;72		to;73		tokenId;74		data;75		dummy = 0;76	}77	function safeTransferFrom(address from, address to, uint256 tokenId) public {78		require(false, stub_error);79		from;80		to;81		tokenId;82		dummy = 0;83	}84	function transferFrom(address from, address to, uint256 tokenId) public {85		require(false, stub_error);86		from;87		to;88		tokenId;89		dummy = 0;90	}91	function approve(address approved, uint256 tokenId) public {92		require(false, stub_error);93		approved;94		tokenId;95		dummy = 0;96	}97	function setApprovalForAll(address operator, bool approved) public {98		require(false, stub_error);99		operator;100		approved;101		dummy = 0;102	}103	function getApproved(uint256 tokenId) public view returns (address) {104		require(false, stub_error);105		tokenId;106		dummy;107		return 0x0000000000000000000000000000000000000000;108	}109	function isApprovedForAll(address owner, address operator) public view returns (address) {110		require(false, stub_error);111		owner;112		operator;113		dummy;114		return 0x0000000000000000000000000000000000000000;115	}116}117118contract ERC721Burnable is Dummy {119	function burn(uint256 tokenId) public {120		require(false, stub_error);121		tokenId;122		dummy = 0;123	}124}125126contract ERC721Enumerable is Dummy, InlineTotalSupply {127	function tokenByIndex(uint256 index) public view returns (uint256) {128		require(false, stub_error);129		index;130		dummy;131		return 0;132	}133	function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) {134		require(false, stub_error);135		owner;136		index;137		dummy;138		return 0;139	}140}141142contract ERC721Metadata is Dummy, InlineNameSymbol {143	function tokenUri(uint256 tokenId) public view returns (string memory) {144		require(false, stub_error);145		tokenId;146		dummy;147		return "";148	}149}150151contract ERC721Mintable is Dummy, ERC721MintableEvents {152	function mintingFinished() public view returns (bool) {153		require(false, stub_error);154		dummy;155		return false;156	}157	function mint(address to, uint256 tokenId) public returns (bool) {158		require(false, stub_error);159		to;160		tokenId;161		dummy = 0;162		return false;163	}164	function mintWithTokenURI(address to, uint256 tokenId, string memory tokenUri) public returns (bool) {165		require(false, stub_error);166		to;167		tokenId;168		tokenUri;169		dummy = 0;170		return false;171	}172	function finishMinting() public returns (bool) {173		require(false, stub_error);174		dummy = 0;175		return false;176	}177}178179contract ERC721UniqueExtensions is Dummy {180	function transfer(address to, uint256 tokenId) public {181		require(false, stub_error);182		to;183		tokenId;184		dummy = 0;185	}186	function nextTokenId() public view returns (uint256) {187		require(false, stub_error);188		dummy;189		return 0;190	}191}192193contract UniqueNFT is Dummy, ERC165, ERC721, ERC721Metadata, ERC721Enumerable, ERC721UniqueExtensions, ERC721Mintable, ERC721Burnable {194}