git.delta.rocks / unique-network / refs/commits / 78a995207d2e

difftreelog

fix After rebase

Trubnikov Sergey2022-08-29parent: #c288f09.patch.diff
in: master

8 files changed

modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -28,10 +28,13 @@
 	types::{string, self},
 };
 use crate::execution::Result;
-use crate::solidity::SolidityTypeName;
 
 const ABI_ALIGNMENT: usize = 32;
 
+trait TypeHelper<T> {
+	fn is_dynamic() -> bool;
+}
+
 /// View into RLP data, which provides method to read typed items from it
 #[derive(Clone)]
 pub struct AbiReader<'i> {
@@ -330,11 +333,18 @@
 pub trait AbiRead<T> {
 	/// Read item from current position, advanding decoder
 	fn abi_read(&mut self) -> Result<T>;
+
+	/// Size for type aligned to [`ABI_ALIGNMENT`].
 	fn size() -> usize;
 }
 
 macro_rules! impl_abi_readable {
-	($ty:ty, $method:ident) => {
+	($ty:ty, $method:ident, $dynamic:literal) => {
+		impl TypeHelper<$ty> for $ty {
+			fn is_dynamic() -> bool {
+				$dynamic
+			}
+		}
 		impl AbiRead<$ty> for AbiReader<'_> {
 			fn abi_read(&mut self) -> Result<$ty> {
 				self.$method()
@@ -347,16 +357,16 @@
 	};
 }
 
-impl_abi_readable!(u8, uint8);
-impl_abi_readable!(u32, uint32);
-impl_abi_readable!(u64, uint64);
-impl_abi_readable!(u128, uint128);
-impl_abi_readable!(U256, uint256);
-impl_abi_readable!([u8; 4], bytes4);
-impl_abi_readable!(H160, address);
-impl_abi_readable!(Vec<u8>, bytes);
-impl_abi_readable!(bool, bool);
-impl_abi_readable!(string, string);
+impl_abi_readable!(u8, uint8, false);
+impl_abi_readable!(u32, uint32, false);
+impl_abi_readable!(u64, uint64, false);
+impl_abi_readable!(u128, uint128, false);
+impl_abi_readable!(U256, uint256, false);
+impl_abi_readable!([u8; 4], bytes4, false);
+impl_abi_readable!(H160, address, false);
+impl_abi_readable!(Vec<u8>, bytes, true);
+impl_abi_readable!(bool, bool, true);
+impl_abi_readable!(string, string, true);
 
 mod sealed {
 	/// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead
@@ -389,16 +399,24 @@
 
 macro_rules! impl_tuples {
 	($($ident:ident)+) => {
+		impl<$($ident: TypeHelper<$ident>,)+> TypeHelper<($($ident,)+)> for ($($ident,)+) {
+			fn is_dynamic() -> bool {
+				false
+				$(
+					|| <$ident>::is_dynamic()
+				)*
+			}
+		}
 		impl<$($ident),+> sealed::CanBePlacedInVec for ($($ident,)+) {}
 		impl<$($ident),+> AbiRead<($($ident,)+)> for AbiReader<'_>
 		where
 			$(
 				Self: AbiRead<$ident>,
 			)+
-			($($ident,)+): SolidityTypeName,
+			($($ident,)+): TypeHelper<($($ident,)+)>,
 		{
 			fn abi_read(&mut self) -> Result<($($ident,)+)> {
-				let size = if <($($ident,)+)>::is_simple() { Some(<Self as AbiRead<($($ident,)+)>>::size()) } else { None };
+				let size = if !<($($ident,)+)>::is_dynamic() { Some(<Self as AbiRead<($($ident,)+)>>::size()) } else { None };
 				let mut subresult = self.subresult(size)?;
 				Ok((
 					$(<Self as AbiRead<$ident>>::abi_read(&mut subresult)?,)+
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -192,10 +192,7 @@
 				write!(writer, "{}", tc.collect_tuple::<Self>())
 			}
 			fn is_simple() -> bool {
-				true
-				$(
-					&& <$ident>::is_simple()
-				)*
+				false
 			}
 			#[allow(unused_assignments)]
 			fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -129,7 +129,7 @@
 	}
 }
 
-#[solidity_interface(name = "ERC20Mintable")]
+#[solidity_interface(name = ERC20Mintable)]
 impl<T: Config> FungibleHandle<T> {
 	/// Mint tokens for `to` account.
 	/// @param to account that will receive minted tokens
@@ -148,7 +148,7 @@
 	}
 }
 
-#[solidity_interface(name = "ERC20UniqueExtensions")]
+#[solidity_interface(name = ERC20UniqueExtensions)]
 impl<T: Config> FungibleHandle<T> {
 	/// Burn tokens from account
 	/// @dev Function that burns an `amount` of the tokens of a given account,
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -3,13 +3,7 @@
 
 pragma solidity >=0.8.0 <0.9.0;
 
-// Anonymous struct
-struct Tuple0 {
-	address field_0;
-	uint256 field_1;
-}
-
-// Common stubs holder
+/// @dev common stubs holder
 contract Dummy {
 	uint8 dummy;
 	string stub_error = "this contract is implemented in native";
@@ -27,49 +21,8 @@
 	}
 }
 
-// Inline
-contract ERC20Events {
-	event Transfer(address indexed from, address indexed to, uint256 value);
-	event Approval(
-		address indexed owner,
-		address indexed spender,
-		uint256 value
-	);
-}
-
-// Selector: 40c10f19
-contract ERC20Mintable is Dummy, ERC165 {
-	// Selector: mint(address,uint256) 40c10f19
-	function mint(address to, uint256 amount) public returns (bool) {
-		require(false, stub_error);
-		to;
-		amount;
-		dummy = 0;
-		return false;
-	}
-}
-
-// Selector: 63034ac5
-contract ERC20UniqueExtensions is Dummy, ERC165 {
-	// Selector: burnFrom(address,uint256) 79cc6790
-	function burnFrom(address from, uint256 amount) public returns (bool) {
-		require(false, stub_error);
-		from;
-		amount;
-		dummy = 0;
-		return false;
-	}
-
-	// Selector: mintBulk((address,uint256)[]) 1acf2d55
-	function mintBulk(Tuple0[] memory amounts) public returns (bool) {
-		require(false, stub_error);
-		amounts;
-		dummy = 0;
-		return false;
-	}
-}
-
-// Selector: 6cf113cd
+/// @title A contract that allows you to work with collections.
+/// @dev the ERC-165 identifier for this interface is 0xe54be640
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -397,19 +350,51 @@
 	}
 }
 
+/// @dev the ERC-165 identifier for this interface is 0x63034ac5
+contract ERC20UniqueExtensions is Dummy, ERC165 {
+	/// Burn tokens from account
+	/// @dev Function that burns an `amount` of the tokens of a given account,
+	/// deducting from the sender's allowance for said account.
+	/// @param from The account whose tokens will be burnt.
+	/// @param amount The amount that will be burnt.
+	/// @dev EVM selector for this function is: 0x79cc6790,
+	///  or in textual repr: burnFrom(address,uint256)
+	function burnFrom(address from, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		from;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	/// Mint tokens for multiple accounts.
+	/// @param amounts array of pairs of account address and amount
+	/// @dev EVM selector for this function is: 0x1acf2d55,
+	///  or in textual repr: mintBulk((address,uint256)[])
+	function mintBulk(Tuple6[] memory amounts) public returns (bool) {
+		require(false, stub_error);
+		amounts;
+		dummy = 0;
+		return false;
+	}
+}
+
 /// @dev anonymous struct
 struct Tuple6 {
 	address field_0;
 	uint256 field_1;
 }
 
-/// @dev the ERC-165 identifier for this interface is 0x79cc6790
-contract ERC20UniqueExtensions is Dummy, ERC165 {
-	/// @dev EVM selector for this function is: 0x79cc6790,
-	///  or in textual repr: burnFrom(address,uint256)
-	function burnFrom(address from, uint256 amount) public returns (bool) {
+/// @dev the ERC-165 identifier for this interface is 0x40c10f19
+contract ERC20Mintable is Dummy, ERC165 {
+	/// Mint tokens for `to` account.
+	/// @param to account that will receive minted tokens
+	/// @param amount amount of tokens to mint
+	/// @dev EVM selector for this function is: 0x40c10f19,
+	///  or in textual repr: mint(address,uint256)
+	function mint(address to, uint256 amount) public returns (bool) {
 		require(false, stub_error);
-		from;
+		to;
 		amount;
 		dummy = 0;
 		return false;
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
before · tests/src/eth/api/UniqueFungible.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8	address field_0;9	uint256 field_1;10}1112// Common stubs holder13interface Dummy {1415}1617interface ERC165 is Dummy {18	function supportsInterface(bytes4 interfaceID) external view returns (bool);19}2021// Inline22interface ERC20Events {23	event Transfer(address indexed from, address indexed to, uint256 value);24	event Approval(25		address indexed owner,26		address indexed spender,27		uint256 value28	);29}3031// Selector: 40c10f1932interface ERC20Mintable is Dummy, ERC165 {33	// Selector: mint(address,uint256) 40c10f1934	function mint(address to, uint256 amount) external returns (bool);35}3637// Selector: 63034ac538interface ERC20UniqueExtensions is Dummy, ERC165 {39	// Selector: burnFrom(address,uint256) 79cc679040	function burnFrom(address from, uint256 amount) external returns (bool);4142	// Selector: mintBulk((address,uint256)[]) 1acf2d5543	function mintBulk(Tuple0[] memory amounts) external returns (bool);44}4546// Selector: 6cf113cd47interface Collection is Dummy, ERC165 {48	/// Set collection property.49	///50	/// @param key Property key.51	/// @param value Propery value.52	/// @dev EVM selector for this function is: 0x2f073f66,53	///  or in textual repr: setCollectionProperty(string,bytes)54	function setCollectionProperty(string memory key, bytes memory value)55		external;5657	/// Delete collection property.58	///59	/// @param key Property key.60	/// @dev EVM selector for this function is: 0x7b7debce,61	///  or in textual repr: deleteCollectionProperty(string)62	function deleteCollectionProperty(string memory key) external;6364	/// Get collection property.65	///66	/// @dev Throws error if key not found.67	///68	/// @param key Property key.69	/// @return bytes The property corresponding to the key.70	/// @dev EVM selector for this function is: 0xcf24fd6d,71	///  or in textual repr: collectionProperty(string)72	function collectionProperty(string memory key)73		external74		view75		returns (bytes memory);7677	/// Set the sponsor of the collection.78	///79	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.80	///81	/// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.82	/// @dev EVM selector for this function is: 0x7623402e,83	///  or in textual repr: setCollectionSponsor(address)84	function setCollectionSponsor(address sponsor) external;8586	/// Set the substrate sponsor of the collection.87	///88	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.89	///90	/// @param sponsor Substrate address of the sponsor from whose account funds will be debited for operations with the contract.91	/// @dev EVM selector for this function is: 0xc74d6751,92	///  or in textual repr: setCollectionSponsorSubstrate(uint256)93	function setCollectionSponsorSubstrate(uint256 sponsor) external;9495	/// @dev EVM selector for this function is: 0x058ac185,96	///  or in textual repr: hasCollectionPendingSponsor()97	function hasCollectionPendingSponsor() external view returns (bool);9899	/// Collection sponsorship confirmation.100	///101	/// @dev After setting the sponsor for the collection, it must be confirmed with this function.102	/// @dev EVM selector for this function is: 0x3c50e97a,103	///  or in textual repr: confirmCollectionSponsorship()104	function confirmCollectionSponsorship() external;105106	/// Remove collection sponsor.107	/// @dev EVM selector for this function is: 0x6e0326a3,108	///  or in textual repr: removeCollectionSponsor()109	function removeCollectionSponsor() external;110111	/// Get current sponsor.112	///113	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.114	/// @dev EVM selector for this function is: 0xb66bbc14,115	///  or in textual repr: getCollectionSponsor()116	function getCollectionSponsor() external view returns (Tuple6 memory);117118	/// Set limits for the collection.119	/// @dev Throws error if limit not found.120	/// @param limit Name of the limit. Valid names:121	/// 	"accountTokenOwnershipLimit",122	/// 	"sponsoredDataSize",123	/// 	"sponsoredDataRateLimit",124	/// 	"tokenLimit",125	/// 	"sponsorTransferTimeout",126	/// 	"sponsorApproveTimeout"127	/// @param value Value of the limit.128	/// @dev EVM selector for this function is: 0x6a3841db,129	///  or in textual repr: setCollectionLimit(string,uint32)130	function setCollectionLimit(string memory limit, uint32 value) external;131132	/// Set limits for the collection.133	/// @dev Throws error if limit not found.134	/// @param limit Name of the limit. Valid names:135	/// 	"ownerCanTransfer",136	/// 	"ownerCanDestroy",137	/// 	"transfersEnabled"138	/// @param value Value of the limit.139	/// @dev EVM selector for this function is: 0x993b7fba,140	///  or in textual repr: setCollectionLimit(string,bool)141	function setCollectionLimit(string memory limit, bool value) external;142143	/// Get contract address.144	/// @dev EVM selector for this function is: 0xf6b4dfb4,145	///  or in textual repr: contractAddress()146	function contractAddress() external view returns (address);147148	/// Add collection admin by substrate address.149	/// @param newAdmin Substrate administrator address.150	/// @dev EVM selector for this function is: 0x5730062b,151	///  or in textual repr: addCollectionAdminSubstrate(uint256)152	function addCollectionAdminSubstrate(uint256 newAdmin) external;153154	/// Remove collection admin by substrate address.155	/// @param admin Substrate administrator address.156	/// @dev EVM selector for this function is: 0x4048fcf9,157	///  or in textual repr: removeCollectionAdminSubstrate(uint256)158	function removeCollectionAdminSubstrate(uint256 admin) external;159160	/// Add collection admin.161	/// @param newAdmin Address of the added administrator.162	/// @dev EVM selector for this function is: 0x92e462c7,163	///  or in textual repr: addCollectionAdmin(address)164	function addCollectionAdmin(address newAdmin) external;165166	/// Remove collection admin.167	///168	/// @param admin Address of the removed administrator.169	/// @dev EVM selector for this function is: 0xfafd7b42,170	///  or in textual repr: removeCollectionAdmin(address)171	function removeCollectionAdmin(address admin) external;172173	/// Toggle accessibility of collection nesting.174	///175	/// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'176	/// @dev EVM selector for this function is: 0x112d4586,177	///  or in textual repr: setCollectionNesting(bool)178	function setCollectionNesting(bool enable) external;179180	/// Toggle accessibility of collection nesting.181	///182	/// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'183	/// @param collections Addresses of collections that will be available for nesting.184	/// @dev EVM selector for this function is: 0x64872396,185	///  or in textual repr: setCollectionNesting(bool,address[])186	function setCollectionNesting(bool enable, address[] memory collections)187		external;188189	/// Set the collection access method.190	/// @param mode Access mode191	/// 	0 for Normal192	/// 	1 for AllowList193	/// @dev EVM selector for this function is: 0x41835d4c,194	///  or in textual repr: setCollectionAccess(uint8)195	function setCollectionAccess(uint8 mode) external;196197	/// Add the user to the allowed list.198	///199	/// @param user Address of a trusted user.200	/// @dev EVM selector for this function is: 0x67844fe6,201	///  or in textual repr: addToCollectionAllowList(address)202	function addToCollectionAllowList(address user) external;203204	/// Remove the user from the allowed list.205	///206	/// @param user Address of a removed user.207	/// @dev EVM selector for this function is: 0x85c51acb,208	///  or in textual repr: removeFromCollectionAllowList(address)209	function removeFromCollectionAllowList(address user) external;210211	/// Switch permission for minting.212	///213	/// @param mode Enable if "true".214	/// @dev EVM selector for this function is: 0x00018e84,215	///  or in textual repr: setCollectionMintMode(bool)216	function setCollectionMintMode(bool mode) external;217218	/// Check that account is the owner or admin of the collection219	///220	/// @param user account to verify221	/// @return "true" if account is the owner or admin222	/// @dev EVM selector for this function is: 0x9811b0c7,223	///  or in textual repr: isOwnerOrAdmin(address)224	function isOwnerOrAdmin(address user) external view returns (bool);225226	/// Check that substrate account is the owner or admin of the collection227	///228	/// @param user account to verify229	/// @return "true" if account is the owner or admin230	/// @dev EVM selector for this function is: 0x68910e00,231	///  or in textual repr: isOwnerOrAdminSubstrate(uint256)232	function isOwnerOrAdminSubstrate(uint256 user) external view returns (bool);233234	/// Returns collection type235	///236	/// @return `Fungible` or `NFT` or `ReFungible`237	/// @dev EVM selector for this function is: 0xd34b55b8,238	///  or in textual repr: uniqueCollectionType()239	function uniqueCollectionType() external returns (string memory);240}241242/// @dev the ERC-165 identifier for this interface is 0x79cc6790243interface ERC20UniqueExtensions is Dummy, ERC165 {244	/// @dev EVM selector for this function is: 0x79cc6790,245	///  or in textual repr: burnFrom(address,uint256)246	function burnFrom(address from, uint256 amount) external returns (bool);247}248249/// @dev inlined interface250interface ERC20Events {251	event Transfer(address indexed from, address indexed to, uint256 value);252	event Approval(253		address indexed owner,254		address indexed spender,255		uint256 value256	);257}258259/// @dev the ERC-165 identifier for this interface is 0x942e8b22260interface ERC20 is Dummy, ERC165, ERC20Events {261	/// @dev EVM selector for this function is: 0x06fdde03,262	///  or in textual repr: name()263	function name() external view returns (string memory);264265	/// @dev EVM selector for this function is: 0x95d89b41,266	///  or in textual repr: symbol()267	function symbol() external view returns (string memory);268269	/// @dev EVM selector for this function is: 0x18160ddd,270	///  or in textual repr: totalSupply()271	function totalSupply() external view returns (uint256);272273	/// @dev EVM selector for this function is: 0x313ce567,274	///  or in textual repr: decimals()275	function decimals() external view returns (uint8);276277	/// @dev EVM selector for this function is: 0x70a08231,278	///  or in textual repr: balanceOf(address)279	function balanceOf(address owner) external view returns (uint256);280281	/// @dev EVM selector for this function is: 0xa9059cbb,282	///  or in textual repr: transfer(address,uint256)283	function transfer(address to, uint256 amount) external returns (bool);284285	/// @dev EVM selector for this function is: 0x23b872dd,286	///  or in textual repr: transferFrom(address,address,uint256)287	function transferFrom(288		address from,289		address to,290		uint256 amount291	) external returns (bool);292293	/// @dev EVM selector for this function is: 0x095ea7b3,294	///  or in textual repr: approve(address,uint256)295	function approve(address spender, uint256 amount) external returns (bool);296297	/// @dev EVM selector for this function is: 0xdd62ed3e,298	///  or in textual repr: allowance(address,address)299	function allowance(address owner, address spender)300		external301		view302		returns (uint256);303}304305interface UniqueFungible is306	Dummy,307	ERC165,308	ERC20,309	ERC20Mintable,310	ERC20UniqueExtensions,311	Collection312{}
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -94,7 +94,7 @@
   });
 
   itWeb3('ERC721 support', async ({web3}) => {
-    expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;
+    expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;
   });
 
   itWeb3('ERC721Metadata support', async ({web3}) => {
modifiedtests/src/eth/fungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/fungibleAbi.json
+++ b/tests/src/eth/fungibleAbi.json
@@ -151,33 +151,6 @@
     "type": "function"
   },
   {
-    "inputs": [
-      { "internalType": "address", "name": "to", "type": "address" },
-      { "internalType": "uint256", "name": "amount", "type": "uint256" }
-    ],
-    "name": "mint",
-    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
-    "stateMutability": "nonpayable",
-    "type": "function"
-  },
-  {
-    "inputs": [
-      {
-        "components": [
-          { "internalType": "address", "name": "field_0", "type": "address" },
-          { "internalType": "uint256", "name": "field_1", "type": "uint256" }
-        ],
-        "internalType": "struct Tuple0[]",
-        "name": "amounts",
-        "type": "tuple[]"
-      }
-    ],
-    "name": "mintBulk",
-    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
-    "stateMutability": "nonpayable",
-    "type": "function"
-  },
-  {
     "inputs": [],
     "name": "getCollectionSponsor",
     "outputs": [
@@ -220,6 +193,33 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "address", "name": "to", "type": "address" },
+      { "internalType": "uint256", "name": "amount", "type": "uint256" }
+    ],
+    "name": "mint",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "field_0", "type": "address" },
+          { "internalType": "uint256", "name": "field_1", "type": "uint256" }
+        ],
+        "internalType": "struct Tuple6[]",
+        "name": "amounts",
+        "type": "tuple[]"
+      }
+    ],
+    "name": "mintBulk",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
     "inputs": [],
     "name": "name",
     "outputs": [{ "internalType": "string", "name": "", "type": "string" }],