difftreelog
fix After rebase
in: master
8 files changed
crates/evm-coder/src/abi.rsdiffbeforeafterboth28 types::{string, self},28 types::{string, self},29};29};30use crate::execution::Result;30use crate::execution::Result;31use crate::solidity::SolidityTypeName;323133const ABI_ALIGNMENT: usize = 32;32const ABI_ALIGNMENT: usize = 32;3334trait TypeHelper<T> {35 fn is_dynamic() -> bool;36}343735/// View into RLP data, which provides method to read typed items from it38/// View into RLP data, which provides method to read typed items from it36#[derive(Clone)]39#[derive(Clone)]331 /// Read item from current position, advanding decoder334 /// Read item from current position, advanding decoder332 fn abi_read(&mut self) -> Result<T>;335 fn abi_read(&mut self) -> Result<T>;336337 /// Size for type aligned to [`ABI_ALIGNMENT`].333 fn size() -> usize;338 fn size() -> usize;334}339}335340336macro_rules! impl_abi_readable {341macro_rules! impl_abi_readable {337 ($ty:ty, $method:ident) => {342 ($ty:ty, $method:ident, $dynamic:literal) => {343 impl TypeHelper<$ty> for $ty {344 fn is_dynamic() -> bool {345 $dynamic346 }347 }338 impl AbiRead<$ty> for AbiReader<'_> {348 impl AbiRead<$ty> for AbiReader<'_> {339 fn abi_read(&mut self) -> Result<$ty> {349 fn abi_read(&mut self) -> Result<$ty> {340 self.$method()350 self.$method()347 };357 };348}358}349359350impl_abi_readable!(u8, uint8);360impl_abi_readable!(u8, uint8, false);351impl_abi_readable!(u32, uint32);361impl_abi_readable!(u32, uint32, false);352impl_abi_readable!(u64, uint64);362impl_abi_readable!(u64, uint64, false);353impl_abi_readable!(u128, uint128);363impl_abi_readable!(u128, uint128, false);354impl_abi_readable!(U256, uint256);364impl_abi_readable!(U256, uint256, false);355impl_abi_readable!([u8; 4], bytes4);365impl_abi_readable!([u8; 4], bytes4, false);356impl_abi_readable!(H160, address);366impl_abi_readable!(H160, address, false);357impl_abi_readable!(Vec<u8>, bytes);367impl_abi_readable!(Vec<u8>, bytes, true);358impl_abi_readable!(bool, bool);368impl_abi_readable!(bool, bool, true);359impl_abi_readable!(string, string);369impl_abi_readable!(string, string, true);360370361mod sealed {371mod sealed {362 /// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead372 /// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead389399390macro_rules! impl_tuples {400macro_rules! impl_tuples {391 ($($ident:ident)+) => {401 ($($ident:ident)+) => {402 impl<$($ident: TypeHelper<$ident>,)+> TypeHelper<($($ident,)+)> for ($($ident,)+) {403 fn is_dynamic() -> bool {404 false405 $(406 || <$ident>::is_dynamic()407 )*408 }409 }392 impl<$($ident),+> sealed::CanBePlacedInVec for ($($ident,)+) {}410 impl<$($ident),+> sealed::CanBePlacedInVec for ($($ident,)+) {}393 impl<$($ident),+> AbiRead<($($ident,)+)> for AbiReader<'_>411 impl<$($ident),+> AbiRead<($($ident,)+)> for AbiReader<'_>394 where412 where395 $(413 $(396 Self: AbiRead<$ident>,414 Self: AbiRead<$ident>,397 )+415 )+398 ($($ident,)+): SolidityTypeName,416 ($($ident,)+): TypeHelper<($($ident,)+)>,399 {417 {400 fn abi_read(&mut self) -> Result<($($ident,)+)> {418 fn abi_read(&mut self) -> Result<($($ident,)+)> {401 let size = if <($($ident,)+)>::is_simple() { Some(<Self as AbiRead<($($ident,)+)>>::size()) } else { None };419 let size = if !<($($ident,)+)>::is_dynamic() { Some(<Self as AbiRead<($($ident,)+)>>::size()) } else { None };402 let mut subresult = self.subresult(size)?;420 let mut subresult = self.subresult(size)?;403 Ok((421 Ok((404 $(<Self as AbiRead<$ident>>::abi_read(&mut subresult)?,)+422 $(<Self as AbiRead<$ident>>::abi_read(&mut subresult)?,)+crates/evm-coder/src/solidity.rsdiffbeforeafterboth192 write!(writer, "{}", tc.collect_tuple::<Self>())192 write!(writer, "{}", tc.collect_tuple::<Self>())193 }193 }194 fn is_simple() -> bool {194 fn is_simple() -> bool {195 true195 false196 $(197 && <$ident>::is_simple()198 )*199 }196 }200 #[allow(unused_assignments)]197 #[allow(unused_assignments)]201 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {198 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {pallets/fungible/src/erc.rsdiffbeforeafterboth129 }129 }130}130}131131132#[solidity_interface(name = "ERC20Mintable")]132#[solidity_interface(name = ERC20Mintable)]133impl<T: Config> FungibleHandle<T> {133impl<T: Config> FungibleHandle<T> {134 /// Mint tokens for `to` account.134 /// Mint tokens for `to` account.135 /// @param to account that will receive minted tokens135 /// @param to account that will receive minted tokens148 }148 }149}149}150150151#[solidity_interface(name = "ERC20UniqueExtensions")]151#[solidity_interface(name = ERC20UniqueExtensions)]152impl<T: Config> FungibleHandle<T> {152impl<T: Config> FungibleHandle<T> {153 /// Burn tokens from account153 /// Burn tokens from account154 /// @dev Function that burns an `amount` of the tokens of a given account,154 /// @dev Function that burns an `amount` of the tokens of a given account,pallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth334pragma solidity >=0.8.0 <0.9.0;4pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 address field_0;9 uint256 field_1;10}11512// Common stubs holder6/// @dev common stubs holder13contract Dummy {7contract Dummy {14 uint8 dummy;8 uint8 dummy;15 string stub_error = "this contract is implemented in native";9 string stub_error = "this contract is implemented in native";27 }21 }28}22}292330// Inline24/// @title A contract that allows you to work with collections.31contract ERC20Events {25/// @dev the ERC-165 identifier for this interface is 0xe54be64032 event Transfer(address indexed from, address indexed to, uint256 value);33 event Approval(34 address indexed owner,35 address indexed spender,36 uint256 value37 );38}3940// Selector: 40c10f1941contract ERC20Mintable is Dummy, ERC165 {42 // Selector: mint(address,uint256) 40c10f1943 function mint(address to, uint256 amount) public returns (bool) {44 require(false, stub_error);45 to;46 amount;47 dummy = 0;48 return false;49 }50}5152// Selector: 63034ac553contract ERC20UniqueExtensions is Dummy, ERC165 {54 // Selector: burnFrom(address,uint256) 79cc679055 function burnFrom(address from, uint256 amount) public returns (bool) {56 require(false, stub_error);57 from;58 amount;59 dummy = 0;60 return false;61 }6263 // Selector: mintBulk((address,uint256)[]) 1acf2d5564 function mintBulk(Tuple0[] memory amounts) public returns (bool) {65 require(false, stub_error);66 amounts;67 dummy = 0;68 return false;69 }70}7172// Selector: 6cf113cd73contract Collection is Dummy, ERC165 {26contract Collection is Dummy, ERC165 {74 /// Set collection property.27 /// Set collection property.75 ///28 ///397 }350 }398}351}352353/// @dev the ERC-165 identifier for this interface is 0x63034ac5354contract ERC20UniqueExtensions is Dummy, ERC165 {355 /// Burn tokens from account356 /// @dev Function that burns an `amount` of the tokens of a given account,357 /// deducting from the sender's allowance for said account.358 /// @param from The account whose tokens will be burnt.359 /// @param amount The amount that will be burnt.360 /// @dev EVM selector for this function is: 0x79cc6790,361 /// or in textual repr: burnFrom(address,uint256)362 function burnFrom(address from, uint256 amount) public returns (bool) {363 require(false, stub_error);364 from;365 amount;366 dummy = 0;367 return false;368 }369370 /// Mint tokens for multiple accounts.371 /// @param amounts array of pairs of account address and amount372 /// @dev EVM selector for this function is: 0x1acf2d55,373 /// or in textual repr: mintBulk((address,uint256)[])374 function mintBulk(Tuple6[] memory amounts) public returns (bool) {375 require(false, stub_error);376 amounts;377 dummy = 0;378 return false;379 }380}399381400/// @dev anonymous struct382/// @dev anonymous struct401struct Tuple6 {383struct Tuple6 {402 address field_0;384 address field_0;403 uint256 field_1;385 uint256 field_1;404}386}405387406/// @dev the ERC-165 identifier for this interface is 0x79cc6790388/// @dev the ERC-165 identifier for this interface is 0x40c10f19407contract ERC20UniqueExtensions is Dummy, ERC165 {389contract ERC20Mintable is Dummy, ERC165 {390 /// Mint tokens for `to` account.391 /// @param to account that will receive minted tokens392 /// @param amount amount of tokens to mint408 /// @dev EVM selector for this function is: 0x79cc6790,393 /// @dev EVM selector for this function is: 0x40c10f19,409 /// or in textual repr: burnFrom(address,uint256)394 /// or in textual repr: mint(address,uint256)410 function burnFrom(address from, uint256 amount) public returns (bool) {395 function mint(address to, uint256 amount) public returns (bool) {411 require(false, stub_error);396 require(false, stub_error);412 from;397 to;413 amount;398 amount;414 dummy = 0;399 dummy = 0;415 return false;400 return false;tests/src/eth/api/UniqueFungible.soldiffbeforeafterboth334pragma solidity >=0.8.0 <0.9.0;4pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 address field_0;9 uint256 field_1;10}11512// Common stubs holder6/// @dev common stubs holder13interface Dummy {7interface Dummy {14815}9}18 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);19}13}201421// Inline15/// @title A contract that allows you to work with collections.22interface ERC20Events {16/// @dev the ERC-165 identifier for this interface is 0xe54be64023 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 {17interface Collection is Dummy, ERC165 {48 /// Set collection property.18 /// Set collection property.49 ///19 ///238 /// or in textual repr: uniqueCollectionType()208 /// or in textual repr: uniqueCollectionType()239 function uniqueCollectionType() external returns (string memory);209 function uniqueCollectionType() external returns (string memory);210211 /// Changes collection owner to another account212 ///213 /// @dev Owner can be changed only by current owner214 /// @param newOwner new owner account215 /// @dev EVM selector for this function is: 0x13af4035,216 /// or in textual repr: setOwner(address)217 function setOwner(address newOwner) external;218219 /// Changes collection owner to another substrate account220 ///221 /// @dev Owner can be changed only by current owner222 /// @param newOwner new owner substrate account223 /// @dev EVM selector for this function is: 0xb212138f,224 /// or in textual repr: setOwnerSubstrate(uint256)225 function setOwnerSubstrate(uint256 newOwner) external;240}226}241227242/// @dev the ERC-165 identifier for this interface is 0x79cc6790228/// @dev the ERC-165 identifier for this interface is 0x63034ac5243interface ERC20UniqueExtensions is Dummy, ERC165 {229interface ERC20UniqueExtensions is Dummy, ERC165 {230 /// Burn tokens from account231 /// @dev Function that burns an `amount` of the tokens of a given account,232 /// deducting from the sender's allowance for said account.233 /// @param from The account whose tokens will be burnt.234 /// @param amount The amount that will be burnt.244 /// @dev EVM selector for this function is: 0x79cc6790,235 /// @dev EVM selector for this function is: 0x79cc6790,245 /// or in textual repr: burnFrom(address,uint256)236 /// or in textual repr: burnFrom(address,uint256)246 function burnFrom(address from, uint256 amount) external returns (bool);237 function burnFrom(address from, uint256 amount) external returns (bool);238239 /// Mint tokens for multiple accounts.240 /// @param amounts array of pairs of account address and amount241 /// @dev EVM selector for this function is: 0x1acf2d55,242 /// or in textual repr: mintBulk((address,uint256)[])243 function mintBulk(Tuple6[] memory amounts) external returns (bool);247}244}245246/// @dev anonymous struct247struct Tuple6 {248 address field_0;249 uint256 field_1;250}251252/// @dev the ERC-165 identifier for this interface is 0x40c10f19253interface ERC20Mintable is Dummy, ERC165 {254 /// Mint tokens for `to` account.255 /// @param to account that will receive minted tokens256 /// @param amount amount of tokens to mint257 /// @dev EVM selector for this function is: 0x40c10f19,258 /// or in textual repr: mint(address,uint256)259 function mint(address to, uint256 amount) external returns (bool);260}248261249/// @dev inlined interface262/// @dev inlined interface250interface ERC20Events {263interface ERC20Events {tests/src/eth/base.test.tsdiffbeforeafterboth94 });94 });959596 itWeb3('ERC721 support', async ({web3}) => {96 itWeb3('ERC721 support', async ({web3}) => {97 expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;97 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;98 });98 });9999100 itWeb3('ERC721Metadata support', async ({web3}) => {100 itWeb3('ERC721Metadata support', async ({web3}) => {tests/src/eth/fungibleAbi.jsondiffbeforeafterboth150 "stateMutability": "nonpayable",150 "stateMutability": "nonpayable",151 "type": "function"151 "type": "function"152 },152 },153 {154 "inputs": [155 { "internalType": "address", "name": "to", "type": "address" },156 { "internalType": "uint256", "name": "amount", "type": "uint256" }157 ],158 "name": "mint",159 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],160 "stateMutability": "nonpayable",161 "type": "function"162 },163 {164 "inputs": [165 {166 "components": [167 { "internalType": "address", "name": "field_0", "type": "address" },168 { "internalType": "uint256", "name": "field_1", "type": "uint256" }169 ],170 "internalType": "struct Tuple0[]",171 "name": "amounts",172 "type": "tuple[]"173 }174 ],175 "name": "mintBulk",176 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],177 "stateMutability": "nonpayable",178 "type": "function"179 },180 {153 {181 "inputs": [],154 "inputs": [],182 "name": "getCollectionSponsor",155 "name": "getCollectionSponsor",219 "stateMutability": "view",192 "stateMutability": "view",220 "type": "function"193 "type": "function"221 },194 },195 {196 "inputs": [197 { "internalType": "address", "name": "to", "type": "address" },198 { "internalType": "uint256", "name": "amount", "type": "uint256" }199 ],200 "name": "mint",201 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],202 "stateMutability": "nonpayable",203 "type": "function"204 },205 {206 "inputs": [207 {208 "components": [209 { "internalType": "address", "name": "field_0", "type": "address" },210 { "internalType": "uint256", "name": "field_1", "type": "uint256" }211 ],212 "internalType": "struct Tuple6[]",213 "name": "amounts",214 "type": "tuple[]"215 }216 ],217 "name": "mintBulk",218 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],219 "stateMutability": "nonpayable",220 "type": "function"221 },222 {222 {223 "inputs": [],223 "inputs": [],224 "name": "name",224 "name": "name",