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
28 types::{string, self},28 types::{string, self},
29};29};
30use crate::execution::Result;30use crate::execution::Result;
31use crate::solidity::SolidityTypeName;
3231
33const ABI_ALIGNMENT: usize = 32;32const ABI_ALIGNMENT: usize = 32;
33
34trait TypeHelper<T> {
35 fn is_dynamic() -> bool;
36}
3437
35/// 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 it
36#[derive(Clone)]39#[derive(Clone)]
331 /// Read item from current position, advanding decoder334 /// Read item from current position, advanding decoder
332 fn abi_read(&mut self) -> Result<T>;335 fn abi_read(&mut self) -> Result<T>;
336
337 /// Size for type aligned to [`ABI_ALIGNMENT`].
333 fn size() -> usize;338 fn size() -> usize;
334}339}
335340
336macro_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 $dynamic
346 }
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}
349359
350impl_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);
360370
361mod 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 instead
389399
390macro_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 false
405 $(
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 where
395 $(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)?,)+
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
192 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 false
196 $(
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 {
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
129 }129 }
130}130}
131131
132#[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 tokens
148 }148 }
149}149}
150150
151#[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 account
154 /// @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,
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
33
4pragma solidity >=0.8.0 <0.9.0;4pragma solidity >=0.8.0 <0.9.0;
5
6// Anonymous struct
7struct Tuple0 {
8 address field_0;
9 uint256 field_1;
10}
115
12// Common stubs holder6/// @dev common stubs holder
13contract 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}
2923
30// Inline24/// @title A contract that allows you to work with collections.
31contract ERC20Events {25/// @dev the ERC-165 identifier for this interface is 0xe54be640
32 event Transfer(address indexed from, address indexed to, uint256 value);
33 event Approval(
34 address indexed owner,
35 address indexed spender,
36 uint256 value
37 );
38}
39
40// Selector: 40c10f19
41contract ERC20Mintable is Dummy, ERC165 {
42 // Selector: mint(address,uint256) 40c10f19
43 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}
51
52// Selector: 63034ac5
53contract ERC20UniqueExtensions is Dummy, ERC165 {
54 // Selector: burnFrom(address,uint256) 79cc6790
55 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 }
62
63 // Selector: mintBulk((address,uint256)[]) 1acf2d55
64 function mintBulk(Tuple0[] memory amounts) public returns (bool) {
65 require(false, stub_error);
66 amounts;
67 dummy = 0;
68 return false;
69 }
70}
71
72// Selector: 6cf113cd
73contract Collection is Dummy, ERC165 {26contract Collection is Dummy, ERC165 {
74 /// Set collection property.27 /// Set collection property.
75 ///28 ///
397 }350 }
398}351}
352
353/// @dev the ERC-165 identifier for this interface is 0x63034ac5
354contract ERC20UniqueExtensions is Dummy, ERC165 {
355 /// Burn tokens from account
356 /// @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 }
369
370 /// Mint tokens for multiple accounts.
371 /// @param amounts array of pairs of account address and amount
372 /// @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}
399381
400/// @dev anonymous struct382/// @dev anonymous struct
401struct Tuple6 {383struct Tuple6 {
402 address field_0;384 address field_0;
403 uint256 field_1;385 uint256 field_1;
404}386}
405387
406/// @dev the ERC-165 identifier for this interface is 0x79cc6790388/// @dev the ERC-165 identifier for this interface is 0x40c10f19
407contract ERC20UniqueExtensions is Dummy, ERC165 {389contract ERC20Mintable is Dummy, ERC165 {
390 /// Mint tokens for `to` account.
391 /// @param to account that will receive minted tokens
392 /// @param amount amount of tokens to mint
408 /// @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;
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
33
4pragma solidity >=0.8.0 <0.9.0;4pragma solidity >=0.8.0 <0.9.0;
5
6// Anonymous struct
7struct Tuple0 {
8 address field_0;
9 uint256 field_1;
10}
115
12// Common stubs holder6/// @dev common stubs holder
13interface Dummy {7interface Dummy {
148
15}9}
18 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);
19}13}
2014
21// Inline15/// @title A contract that allows you to work with collections.
22interface ERC20Events {16/// @dev the ERC-165 identifier for this interface is 0xe54be640
23 event Transfer(address indexed from, address indexed to, uint256 value);
24 event Approval(
25 address indexed owner,
26 address indexed spender,
27 uint256 value
28 );
29}
30
31// Selector: 40c10f19
32interface ERC20Mintable is Dummy, ERC165 {
33 // Selector: mint(address,uint256) 40c10f19
34 function mint(address to, uint256 amount) external returns (bool);
35}
36
37// Selector: 63034ac5
38interface ERC20UniqueExtensions is Dummy, ERC165 {
39 // Selector: burnFrom(address,uint256) 79cc6790
40 function burnFrom(address from, uint256 amount) external returns (bool);
41
42 // Selector: mintBulk((address,uint256)[]) 1acf2d55
43 function mintBulk(Tuple0[] memory amounts) external returns (bool);
44}
45
46// Selector: 6cf113cd
47interface 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);
210
211 /// Changes collection owner to another account
212 ///
213 /// @dev Owner can be changed only by current owner
214 /// @param newOwner new owner account
215 /// @dev EVM selector for this function is: 0x13af4035,
216 /// or in textual repr: setOwner(address)
217 function setOwner(address newOwner) external;
218
219 /// Changes collection owner to another substrate account
220 ///
221 /// @dev Owner can be changed only by current owner
222 /// @param newOwner new owner substrate account
223 /// @dev EVM selector for this function is: 0xb212138f,
224 /// or in textual repr: setOwnerSubstrate(uint256)
225 function setOwnerSubstrate(uint256 newOwner) external;
240}226}
241227
242/// @dev the ERC-165 identifier for this interface is 0x79cc6790228/// @dev the ERC-165 identifier for this interface is 0x63034ac5
243interface ERC20UniqueExtensions is Dummy, ERC165 {229interface ERC20UniqueExtensions is Dummy, ERC165 {
230 /// Burn tokens from account
231 /// @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);
238
239 /// Mint tokens for multiple accounts.
240 /// @param amounts array of pairs of account address and amount
241 /// @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}
245
246/// @dev anonymous struct
247struct Tuple6 {
248 address field_0;
249 uint256 field_1;
250}
251
252/// @dev the ERC-165 identifier for this interface is 0x40c10f19
253interface ERC20Mintable is Dummy, ERC165 {
254 /// Mint tokens for `to` account.
255 /// @param to account that will receive minted tokens
256 /// @param amount amount of tokens to mint
257 /// @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}
248261
249/// @dev inlined interface262/// @dev inlined interface
250interface ERC20Events {263interface ERC20Events {
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
94 });94 });
9595
96 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 });
9999
100 itWeb3('ERC721Metadata support', async ({web3}) => {100 itWeb3('ERC721Metadata support', async ({web3}) => {
modifiedtests/src/eth/fungibleAbi.jsondiffbeforeafterboth
150 "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",