git.delta.rocks / unique-network / refs/commits / 2293f038f8e5

difftreelog

Merge branch 'develop' into tests/eth-helpers

Max Andreev2022-12-03parents: #a851f1b #bf1349a.patch.diff
in: master

59 files changed

modified.maintain/scripts/generate_abi.shdiffbeforeafterboth
4dir=$PWD4dir=$PWD
55
6tmp=$(mktemp -d)6tmp=$(mktemp -d)
7echo "Tmp file: $tmp/input.sol"
7cd $tmp8cd $tmp
8cp $dir/$INPUT input.sol9cp $dir/$INPUT input.sol
9solcjs --abi -p input.sol10solcjs --abi -p input.sol
modifiedCargo.lockdiffbeforeafterboth
1057 "unicode-width",1057 "unicode-width",
1058]1058]
1059
1060[[package]]
1061name = "concat-idents"
1062version = "1.1.4"
1063source = "registry+https://github.com/rust-lang/crates.io-index"
1064checksum = "0fe0e1d9f7de897d18e590a7496b5facbe87813f746cf4b8db596ba77e07e832"
1065dependencies = [
1066 "quote",
1067 "syn",
1068]
10691059
1070[[package]]1060[[package]]
1071name = "concurrent-queue"1061name = "concurrent-queue"
23472337
2348[[package]]2338[[package]]
2349name = "evm-coder"2339name = "evm-coder"
2350version = "0.1.4"2340version = "0.1.5"
2351dependencies = [2341dependencies = [
2352 "concat-idents",
2353 "ethereum",2342 "ethereum",
2354 "evm-coder-procedural",2343 "evm-coder-procedural",
2355 "evm-core",2344 "evm-core",
23672356
2368[[package]]2357[[package]]
2369name = "evm-coder-procedural"2358name = "evm-coder-procedural"
2370version = "0.2.1"2359version = "0.2.2"
2371dependencies = [2360dependencies = [
2372 "Inflector",2361 "Inflector",
2373 "hex",2362 "hex",
modifiedcrates/evm-coder/CHANGELOG.mddiffbeforeafterboth
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->
6## [v0.1.5] - 2022-11-30
67
8### Added
9- Derive macro to support structures and enums.
10
7## [v0.1.4] - 2022-11-0211## [v0.1.4] - 2022-11-02
812
9### Added13### Added
modifiedcrates/evm-coder/Cargo.tomldiffbeforeafterboth
1[package]1[package]
2name = "evm-coder"2name = "evm-coder"
3version = "0.1.4"3version = "0.1.5"
4license = "GPLv3"4license = "GPLv3"
5edition = "2021"5edition = "2021"
66
26hex = "0.4.3"26hex = "0.4.3"
27hex-literal = "0.3.4"27hex-literal = "0.3.4"
28similar-asserts = "1.4.2"28similar-asserts = "1.4.2"
29concat-idents = "1.1.3"
30trybuild = "1.0"29trybuild = "1.0"
3130
32[features]31[features]
modifiedcrates/evm-coder/procedural/Cargo.tomldiffbeforeafterboth
1[package]1[package]
2name = "evm-coder-procedural"2name = "evm-coder-procedural"
3version = "0.2.1"3version = "0.2.2"
4license = "GPLv3"4license = "GPLv3"
5edition = "2021"5edition = "2021"
66
addedcrates/evm-coder/procedural/src/abi_derive/derive_enum.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/procedural/src/abi_derive/derive_struct.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/procedural/src/abi_derive/mod.rsdiffbeforeafterboth

no changes

modifiedcrates/evm-coder/procedural/src/lib.rsdiffbeforeafterboth
25 parse_macro_input, spanned::Spanned,25 parse_macro_input, spanned::Spanned,
26};26};
2727
28mod abi_derive;
28mod solidity_interface;29mod solidity_interface;
29mod to_log;30mod to_log;
3031
243 .into()244 .into()
244}245}
246
247#[proc_macro_derive(AbiCoder)]
248pub fn abi_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
249 let ast = syn::parse(input).unwrap();
250 let ts = match abi_derive::impl_abi_macro(&ast) {
251 Ok(e) => e,
252 Err(e) => e.to_compile_error(),
253 };
254 ts.into()
255}
245256
modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
404 let name = &self.name;404 let name = &self.name;
405 let ty = &self.ty;405 let ty = &self.ty;
406 quote! {406 quote! {
407 #name: <#ty>::abi_read(reader)?407 #name: {
408 let value = <#ty as ::evm_coder::abi::AbiRead>::abi_read(reader)?;
409 if !is_dynamic {reader.bytes_read(<#ty as ::evm_coder::abi::AbiType>::size())};
410 value
411 }
408 }412 }
409 }413 }
410414
630 let pascal_name = &self.pascal_name;634 let pascal_name = &self.pascal_name;
631 let screaming_name = &self.screaming_name;635 let screaming_name = &self.screaming_name;
632 if self.has_normal_args {636 if self.has_normal_args {
633 let parsers = self637 let args_iter = self.args.iter().filter(|a| !a.is_special());
634 .args638 let arg_type = args_iter.clone().map(|a| &a.ty);
635 .iter()
636 .filter(|a| !a.is_special())
637 .map(|a| a.expand_parse());639 let parsers = args_iter.map(|a| a.expand_parse());
638 quote! {640 quote! {
639 Self::#screaming_name => return Ok(Some(Self::#pascal_name {641 Self::#screaming_name => {
642 let is_dynamic = false #(|| <#arg_type as ::evm_coder::abi::AbiType>::is_dynamic())*;
643 return Ok(Some(Self::#pascal_name {
640 #(644 #(
641 #parsers,645 #parsers,
642 )*646 )*
643 }))647 }))
648 }
644 }649 }
645 } else {650 } else {
646 quote! { Self::#screaming_name => return Ok(Some(Self::#pascal_name)) }651 quote! { Self::#screaming_name => return Ok(Some(Self::#pascal_name)) }
modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
1use crate::{1use crate::{
2 custom_signature::SignatureUnit,
2 execution::{Result, ResultWithPostInfo, WithPostDispatchInfo},3 execution::{Result, ResultWithPostInfo, WithPostDispatchInfo},
4 make_signature, sealed,
3 types::*,5 types::*,
4 make_signature,
5 custom_signature::SignatureUnit,
6};6};
7use super::{traits::*, ABI_ALIGNMENT, AbiReader, AbiWriter};7use super::{traits::*, ABI_ALIGNMENT, AbiReader, AbiWriter};
8use primitive_types::{U256, H160};8use primitive_types::{U256, H160};
99
10#[cfg(not(feature = "std"))]10#[cfg(not(feature = "std"))]
11use alloc::vec::Vec;11use alloc::vec::Vec;
1212
13macro_rules! impl_abi_readable {13macro_rules! impl_abi_type {
14 ($ty:ty, $method:ident, $dynamic:literal) => {14 ($ty:ty, $name:ident, $dynamic:literal) => {
15 impl sealed::CanBePlacedInVec for $ty {}15 impl sealed::CanBePlacedInVec for $ty {}
1616
17 impl AbiType for $ty {17 impl AbiType for $ty {
18 const SIGNATURE: SignatureUnit = make_signature!(new fixed(stringify!($ty)));18 const SIGNATURE: SignatureUnit = make_signature!(new fixed(stringify!($name)));
1919
20 fn is_dynamic() -> bool {20 fn is_dynamic() -> bool {
21 $dynamic21 $dynamic
26 }26 }
27 }27 }
28
29 impl AbiRead for $ty {
30 fn abi_read(reader: &mut AbiReader) -> Result<$ty> {
31 reader.$method()
32 }
33 }
34 };28 };
35}29}
3630
31macro_rules! impl_abi_readable {
32 ($ty:ty, $method:ident) => {
33 impl AbiRead for $ty {
34 fn abi_read(reader: &mut AbiReader) -> Result<$ty> {
35 reader.$method()
36 }
37 }
38 };
39}
40
41macro_rules! impl_abi_writeable {
42 ($ty:ty, $method:ident) => {
43 impl AbiWrite for $ty {
44 fn abi_write(&self, writer: &mut AbiWriter) {
45 writer.$method(&self)
46 }
47 }
48 };
49}
50
51macro_rules! impl_abi {
52 ($ty:ty, $method:ident, $dynamic:literal) => {
53 impl_abi_type!($ty, $method, $dynamic);
37impl_abi_readable!(uint32, uint32, false);54 impl_abi_readable!($ty, $method);
55 impl_abi_writeable!($ty, $method);
56 };
57}
58
38impl_abi_readable!(uint64, uint64, false);59impl_abi!(bool, bool, false);
39impl_abi_readable!(uint128, uint128, false);60impl_abi!(u8, uint8, false);
40impl_abi_readable!(uint256, uint256, false);61impl_abi!(u32, uint32, false);
41impl_abi_readable!(bytes4, bytes4, false);62impl_abi!(u64, uint64, false);
42impl_abi_readable!(address, address, false);63impl_abi!(u128, uint128, false);
43impl_abi_readable!(string, string, true);64impl_abi!(U256, uint256, false);
44
45impl sealed::CanBePlacedInVec for bool {}
46
47impl AbiType for bool {
48 const SIGNATURE: SignatureUnit = make_signature!(new fixed("bool"));65impl_abi!(H160, address, false);
49
50 fn is_dynamic() -> bool {
51 false
52 }
53 fn size() -> usize {
54 ABI_ALIGNMENT
55 }
56}
57impl AbiRead for bool {
58 fn abi_read(reader: &mut AbiReader) -> Result<bool> {
59 reader.bool()
60 }
61}
62
63impl AbiType for uint8 {
64 const SIGNATURE: SignatureUnit = make_signature!(new fixed("uint8"));66impl_abi!(string, string, true);
6567
66 fn is_dynamic() -> bool {
67 false
68 }
69 fn size() -> usize {
70 ABI_ALIGNMENT
71 }
72}
73impl AbiRead for uint8 {
74 fn abi_read(reader: &mut AbiReader) -> Result<uint8> {68impl_abi_writeable!(&str, string);
75 reader.uint8()69
76 }
77}
78
79impl AbiType for bytes {
80 const SIGNATURE: SignatureUnit = make_signature!(new fixed("bytes"));70impl_abi_type!(bytes, bytes, true);
8171
82 fn is_dynamic() -> bool {
83 true
84 }
85 fn size() -> usize {
86 ABI_ALIGNMENT
87 }
88}
89impl AbiRead for bytes {72impl AbiRead for bytes {
90 fn abi_read(reader: &mut AbiReader) -> Result<bytes> {73 fn abi_read(reader: &mut AbiReader) -> Result<bytes> {
91 Ok(bytes(reader.bytes()?))74 Ok(bytes(reader.bytes()?))
92 }75 }
93}76}
77
78impl AbiWrite for bytes {
79 fn abi_write(&self, writer: &mut AbiWriter) {
80 writer.bytes(self.0.as_slice())
81 }
82}
83
84impl_abi_type!(bytes4, bytes4, false);
85impl AbiRead for bytes4 {
86 fn abi_read(reader: &mut AbiReader) -> Result<bytes4> {
87 reader.bytes4()
88 }
89}
90
91impl<T: AbiWrite> AbiWrite for &T {
92 fn abi_write(&self, writer: &mut AbiWriter) {
93 T::abi_write(self, writer);
94 }
95}
96
97impl<T: AbiType> AbiType for &T {
98 const SIGNATURE: SignatureUnit = T::SIGNATURE;
99
100 fn is_dynamic() -> bool {
101 T::is_dynamic()
102 }
103
104 fn size() -> usize {
105 T::size()
106 }
107}
94108
95impl<R: AbiRead + sealed::CanBePlacedInVec> AbiRead for Vec<R> {109impl<T: AbiType + AbiRead + sealed::CanBePlacedInVec> AbiRead for Vec<T> {
96 fn abi_read(reader: &mut AbiReader) -> Result<Vec<R>> {110 fn abi_read(reader: &mut AbiReader) -> Result<Vec<T>> {
97 let mut sub = reader.subresult(None)?;111 let mut sub = reader.subresult(None)?;
98 let size = sub.uint32()? as usize;112 let size = sub.uint32()? as usize;
99 sub.subresult_offset = sub.offset;113 sub.subresult_offset = sub.offset;
114 let is_dynamic = <T as AbiType>::is_dynamic();
100 let mut out = Vec::with_capacity(size);115 let mut out = Vec::with_capacity(size);
101 for _ in 0..size {116 for _ in 0..size {
102 out.push(<R>::abi_read(&mut sub)?);117 out.push(<T as AbiRead>::abi_read(&mut sub)?);
118 if !is_dynamic {
119 sub.bytes_read(<T as AbiType>::size());
120 };
103 }121 }
104 Ok(out)122 Ok(out)
105 }123 }
106}124}
107125
108impl<R: AbiType> AbiType for Vec<R> {126impl<T: AbiType> AbiType for Vec<T> {
109 const SIGNATURE: SignatureUnit = make_signature!(new nameof(R::SIGNATURE) fixed("[]"));127 const SIGNATURE: SignatureUnit = make_signature!(new nameof(T::SIGNATURE) fixed("[]"));
110128
111 fn is_dynamic() -> bool {129 fn is_dynamic() -> bool {
112 true130 true
117 }135 }
118}136}
119
120impl sealed::CanBePlacedInVec for EthCrossAccount {}
121
122impl AbiType for EthCrossAccount {
123 const SIGNATURE: SignatureUnit = make_signature!(new fixed("(address,uint256)"));
124
125 fn is_dynamic() -> bool {
126 address::is_dynamic() || uint256::is_dynamic()
127 }
128
129 fn size() -> usize {
130 <address as AbiType>::size() + <uint256 as AbiType>::size()
131 }
132}
133
134impl AbiRead for EthCrossAccount {
135 fn abi_read(reader: &mut AbiReader) -> Result<EthCrossAccount> {
136 let size = if !EthCrossAccount::is_dynamic() {
137 Some(<EthCrossAccount as AbiType>::size())
138 } else {
139 None
140 };
141 let mut subresult = reader.subresult(size)?;
142 let eth = <address>::abi_read(&mut subresult)?;
143 let sub = <uint256>::abi_read(&mut subresult)?;
144
145 Ok(EthCrossAccount { eth, sub })
146 }
147}
148
149impl AbiWrite for EthCrossAccount {
150 fn abi_write(&self, writer: &mut AbiWriter) {
151 self.eth.abi_write(writer);
152 self.sub.abi_write(writer);
153 }
154}
155137
156impl sealed::CanBePlacedInVec for Property {}138impl sealed::CanBePlacedInVec for Property {}
157139
188 }170 }
189}171}
190
191macro_rules! impl_abi_writeable {
192 ($ty:ty, $method:ident) => {
193 impl AbiWrite for $ty {
194 fn abi_write(&self, writer: &mut AbiWriter) {
195 writer.$method(&self)
196 }
197 }
198 };
199}
200
201impl_abi_writeable!(u8, uint8);
202impl_abi_writeable!(u32, uint32);
203impl_abi_writeable!(u128, uint128);
204impl_abi_writeable!(U256, uint256);
205impl_abi_writeable!(H160, address);
206impl_abi_writeable!(bool, bool);
207impl_abi_writeable!(&str, string);
208
209impl AbiWrite for string {
210 fn abi_write(&self, writer: &mut AbiWriter) {
211 writer.string(self)
212 }
213}
214
215impl AbiWrite for bytes {
216 fn abi_write(&self, writer: &mut AbiWriter) {
217 writer.bytes(self.0.as_slice())
218 }
219}
220172
221impl<T: AbiWrite + AbiType> AbiWrite for Vec<T> {173impl<T: AbiWrite + AbiType> AbiWrite for Vec<T> {
222 fn abi_write(&self, writer: &mut AbiWriter) {174 fn abi_write(&self, writer: &mut AbiWriter) {
295247
296 impl<$($ident),+> AbiRead for ($($ident,)+)248 impl<$($ident),+> AbiRead for ($($ident,)+)
297 where249 where
250 Self: AbiType,
298 $($ident: AbiRead,)+251 $($ident: AbiRead + AbiType,)+
299 ($($ident,)+): AbiType,
300 {252 {
301 fn abi_read(reader: &mut AbiReader) -> Result<($($ident,)+)> {253 fn abi_read(reader: &mut AbiReader) -> Result<($($ident,)+)> {
302 let size = if !<($($ident,)+)>::is_dynamic() { Some(<($($ident,)+)>::size()) } else { None };254 let is_dynamic = <Self>::is_dynamic();
255 let size = if !is_dynamic { Some(<Self>::size()) } else { None };
303 let mut subresult = reader.subresult(size)?;256 let mut subresult = reader.subresult(size)?;
304 Ok((257 Ok((
305 $(<$ident>::abi_read(&mut subresult)?,)+258 $({
259 let value = <$ident>::abi_read(&mut subresult)?;
260 if !is_dynamic {subresult.bytes_read(<$ident as AbiType>::size())};
261 value
262 },)+
306 ))263 ))
307 }264 }
308 }265 }
309266
310 #[allow(non_snake_case)]267 #[allow(non_snake_case)]
311 impl<$($ident),+> AbiWrite for ($($ident,)+)268 impl<$($ident),+> AbiWrite for ($($ident,)+)
312 where269 where
313 $($ident: AbiWrite,)+270 $($ident: AbiWrite + AbiType,)+
314 {271 {
315 fn abi_write(&self, writer: &mut AbiWriter) {272 fn abi_write(&self, writer: &mut AbiWriter) {
316 let ($($ident,)+) = self;273 let ($($ident,)+) = self;
317 if writer.is_dynamic {274 if <Self as AbiType>::is_dynamic() {
318 let mut sub = AbiWriter::new();275 let mut sub = AbiWriter::new();
319 $($ident.abi_write(&mut sub);)+276 $($ident.abi_write(&mut sub);)+
320 writer.write_subresult(sub);277 writer.write_subresult(sub);
modifiedcrates/evm-coder/src/abi/mod.rsdiffbeforeafterboth
75 buf: &[u8],75 buf: &[u8],
76 offset: usize,76 offset: usize,
77 pad_start: usize,77 pad_start: usize,
78 pad_size: usize,78 pad_end: usize,
79 block_start: usize,79 block_start: usize,
80 block_size: usize,80 block_end: usize,
81 ) -> Result<[u8; S]> {81 ) -> Result<[u8; S]> {
82 if buf.len() - offset < ABI_ALIGNMENT {82 if buf.len() - offset < ABI_ALIGNMENT {
83 return Err(Error::Error(ExitError::OutOfOffset));83 return Err(Error::Error(ExitError::OutOfOffset));
84 }84 }
85 let mut block = [0; S];85 let mut block = [0; S];
86 let is_pad_zeroed = buf[pad_start..pad_size].iter().all(|&v| v == 0);86 let is_pad_zeroed = buf[pad_start..pad_end].iter().all(|&v| v == 0);
87 if !is_pad_zeroed {87 if !is_pad_zeroed {
88 return Err(Error::Error(ExitError::InvalidRange));88 return Err(Error::Error(ExitError::InvalidRange));
89 }89 }
90 block.copy_from_slice(&buf[block_start..block_size]);90 block.copy_from_slice(&buf[block_start..block_end]);
91 Ok(block)91 Ok(block)
92 }92 }
9393
186186
187 /// Slice recursive buffer, advance one word for buffer offset187 /// Slice recursive buffer, advance one word for buffer offset
188 /// If `size` is [`None`] then [`Self::offset`] and [`Self::subresult_offset`] evals from [`Self::buf`].188 /// If `size` is [`None`] then [`Self::offset`] and [`Self::subresult_offset`] evals from [`Self::buf`].
189 fn subresult(&mut self, size: Option<usize>) -> Result<AbiReader<'i>> {189 pub fn subresult(&mut self, size: Option<usize>) -> Result<AbiReader<'i>> {
190 let subresult_offset = self.subresult_offset;190 let subresult_offset = self.subresult_offset;
191 let offset = if let Some(size) = size {191 let offset = if let Some(size) = size {
192 self.offset += size;192 self.offset += size;
193 self.subresult_offset += size;
194 0193 0
195 } else {194 } else {
196 self.uint32()? as usize195 self.uint32()? as usize
208 })207 })
209 }208 }
209
210 /// Notify about readed data portion.
211 pub fn bytes_read(&mut self, size: usize) {
212 self.subresult_offset += size;
213 }
210214
211 /// Is this parser reached end of buffer?215 /// Is this parser reached end of buffer?
212 pub fn is_finished(&self) -> bool {216 pub fn is_finished(&self) -> bool {
277 self.write_padleft(&u32::to_be_bytes(*value))281 self.write_padleft(&u32::to_be_bytes(*value))
278 }282 }
283
284 /// Write [`u64`] to end of buffer
285 pub fn uint64(&mut self, value: &u64) {
286 self.write_padleft(&u64::to_be_bytes(*value))
287 }
279288
280 /// Write [`u128`] to end of buffer289 /// Write [`u128`] to end of buffer
281 pub fn uint128(&mut self, value: &u128) {290 pub fn uint128(&mut self, value: &u128) {
modifiedcrates/evm-coder/src/abi/test.rsdiffbeforeafterboth
6use super::{AbiReader, AbiWriter};6use super::{AbiReader, AbiWriter};
7use hex_literal::hex;7use hex_literal::hex;
8use primitive_types::{H160, U256};8use primitive_types::{H160, U256};
9use concat_idents::concat_idents;
109
11macro_rules! test_impl {10fn test_impl<T>(function_identifier: u32, decoded_data: T, encoded_data: &[u8])
11where
12 ($name:ident, $type:ty, $function_identifier:expr, $decoded_data:expr, $encoded_data:expr) => {12 T: AbiWrite + AbiRead + std::cmp::PartialEq + std::fmt::Debug,
13 concat_idents!(test_name = encode_decode_, $name {13{
14 #[test]
15 fn test_name() {
16 let function_identifier: u32 = $function_identifier;
17 let decoded_data = $decoded_data;
18 let encoded_data = $encoded_data;
19
20 let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();14 let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();
21 assert_eq!(call, u32::to_be_bytes(function_identifier));15 assert_eq!(call, u32::to_be_bytes(function_identifier));
22 let data = <$type>::abi_read(&mut decoder).unwrap();16 let data = <T>::abi_read(&mut decoder).unwrap();
23 assert_eq!(data, decoded_data);17 assert_eq!(data, decoded_data);
2418
25 let mut writer = AbiWriter::new_call(function_identifier);19 let mut writer = AbiWriter::new_call(function_identifier);
26 decoded_data.abi_write(&mut writer);20 decoded_data.abi_write(&mut writer);
27 let ed = writer.finish();21 let ed = writer.finish();
28 similar_asserts::assert_eq!(encoded_data, ed.as_slice());22 similar_asserts::assert_eq!(encoded_data, ed.as_slice());
29 }
30 });
31 };23}
32}
3324
34macro_rules! test_impl_uint {25macro_rules! test_impl_uint {
35 ($type:ident) => {26 ($type:ident) => {
36 test_impl!(27 test_impl::<$type>(
37 $type,
38 $type,
39 0xdeadbeef,28 0xdeadbeef,
40 255 as $type,29 255 as $type,
41 &hex!(30 &hex!(
42 "31 "
43 deadbeef32 deadbeef
44 00000000000000000000000000000000000000000000000000000000000000ff33 00000000000000000000000000000000000000000000000000000000000000ff
45 "34 "
46 )35 ),
47 );36 );
48 };37 };
49}38}
5039
40#[test]
41fn encode_decode_uint8() {
51test_impl_uint!(uint8);42 test_impl_uint!(uint8);
43}
44
45#[test]
46fn encode_decode_uint32() {
52test_impl_uint!(uint32);47 test_impl_uint!(uint32);
48}
49
50#[test]
51fn encode_decode_uint128() {
53test_impl_uint!(uint128);52 test_impl_uint!(uint128);
5453}
54
55#[test]
56fn encode_decode_uint256() {
55test_impl!(57 test_impl::<uint256>(
56 uint256,
57 uint256,
58 0xdeadbeef,58 0xdeadbeef,
59 U256([255, 0, 0, 0]),59 U256([255, 0, 0, 0]),
60 &hex!(60 &hex!(
61 "61 "
62 deadbeef62 deadbeef
63 00000000000000000000000000000000000000000000000000000000000000ff63 00000000000000000000000000000000000000000000000000000000000000ff
64 "64 "
65 )65 ),
66);66 );
6767}
68
69#[test]
70fn encode_decode_string() {
71 test_impl::<String>(
72 0xdeadbeef,
73 "some string".to_string(),
74 &hex!(
75 "
76 deadbeef
77 0000000000000000000000000000000000000000000000000000000000000020
78 000000000000000000000000000000000000000000000000000000000000000b
79 736f6d6520737472696e67000000000000000000000000000000000000000000
80 "
81 ),
82 );
83}
84
85#[test]
86fn encode_decode_tuple_string() {
87 test_impl::<(String,)>(
88 0xdeadbeef,
89 ("some string".to_string(),),
90 &hex!(
91 "
92 deadbeef
93 0000000000000000000000000000000000000000000000000000000000000020
94 0000000000000000000000000000000000000000000000000000000000000020
95 000000000000000000000000000000000000000000000000000000000000000b
96 736f6d6520737472696e67000000000000000000000000000000000000000000
97 "
98 ),
99 );
100}
101
102#[test]
103fn encode_decode_vec_tuple_address_uint256() {
68test_impl!(104 test_impl::<Vec<(address, uint256)>>(
69 vec_tuple_address_uint256,
70 Vec<(address, uint256)>,
71 0x1ACF2D55,105 0x1ACF2D55,
72 vec![106 vec![
73 (107 (
84 ),118 ),
85 ],119 ],
86 &hex!(120 &hex!(
87 "121 "
88 1ACF2D55122 1ACF2D55
89 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]123 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]
90 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]124 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]
91125
92 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address126 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address
93 000000000000000000000000000000000000000000000000000000000000000A // uint256127 000000000000000000000000000000000000000000000000000000000000000A // uint256
94128
95 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address129 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address
96 0000000000000000000000000000000000000000000000000000000000000014 // uint256130 0000000000000000000000000000000000000000000000000000000000000014 // uint256
97131
98 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address132 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address
99 000000000000000000000000000000000000000000000000000000000000001E // uint256133 000000000000000000000000000000000000000000000000000000000000001E // uint256
100 "134 "
101 )135 )
102);136 );
103137}
138
139#[test]
140fn encode_decode_vec_tuple_uint256_string() {
104test_impl!(141 test_impl::<Vec<(uint256, string)>>(
105 vec_tuple_uint256_string,
106 Vec<(uint256, string)>,
107 0xdeadbeef,142 0xdeadbeef,
108 vec![143 vec![
109 (1.into(), "Test URI 0".to_string()),144 (1.into(), "Test URI 0".to_string()),
110 (11.into(), "Test URI 1".to_string()),145 (11.into(), "Test URI 1".to_string()),
111 (12.into(), "Test URI 2".to_string()),146 (12.into(), "Test URI 2".to_string()),
112 ],147 ],
113 &hex!(148 &hex!(
114 "149 "
115 deadbeef150 deadbeef
116 0000000000000000000000000000000000000000000000000000000000000020 // offset of (uint256, string)[]151 0000000000000000000000000000000000000000000000000000000000000020 // offset of (uint256, string)[]
117 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]152 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]
118153
119 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem154 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem
120 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem155 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem
121 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem156 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem
122157
123 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60158 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60
124 0000000000000000000000000000000000000000000000000000000000000040 // offset of string159 0000000000000000000000000000000000000000000000000000000000000040 // offset of string
125 000000000000000000000000000000000000000000000000000000000000000a // size of string160 000000000000000000000000000000000000000000000000000000000000000a // size of string
126 5465737420555249203000000000000000000000000000000000000000000000 // string161 5465737420555249203000000000000000000000000000000000000000000000 // string
127162
128 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0163 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0
129 0000000000000000000000000000000000000000000000000000000000000040 // offset of string164 0000000000000000000000000000000000000000000000000000000000000040 // offset of string
130 000000000000000000000000000000000000000000000000000000000000000a // size of string165 000000000000000000000000000000000000000000000000000000000000000a // size of string
131 5465737420555249203100000000000000000000000000000000000000000000 // string166 5465737420555249203100000000000000000000000000000000000000000000 // string
132167
133 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160168 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160
134 0000000000000000000000000000000000000000000000000000000000000040 // offset of string169 0000000000000000000000000000000000000000000000000000000000000040 // offset of string
135 000000000000000000000000000000000000000000000000000000000000000a // size of string170 000000000000000000000000000000000000000000000000000000000000000a // size of string
136 5465737420555249203200000000000000000000000000000000000000000000 // string171 5465737420555249203200000000000000000000000000000000000000000000 // string
137 "172 "
138 )173 )
139);174 );
175}
140176
141#[test]177#[test]
142fn dynamic_after_static() {178fn dynamic_after_static() {
235 similar_asserts::assert_eq!(encoded_data, ed.as_slice());271 similar_asserts::assert_eq!(encoded_data, ed.as_slice());
236}272}
237273
274#[test]
275fn encode_decode_vec_tuple_string_bytes() {
238test_impl!(276 test_impl::<Vec<(string, bytes)>>(
239 vec_tuple_string_bytes,
240 Vec<(string, bytes)>,
241 0xdeadbeef,277 0xdeadbeef,
242 vec![278 vec![
243 (279 (
261 ("Test URI 2".to_string(), bytes(vec![0x33, 0x33])),297 ("Test URI 2".to_string(), bytes(vec![0x33, 0x33])),
262 ],298 ],
263 &hex!(299 &hex!(
264 "300 "
265 deadbeef301 deadbeef
266 0000000000000000000000000000000000000000000000000000000000000020302 0000000000000000000000000000000000000000000000000000000000000020
267 0000000000000000000000000000000000000000000000000000000000000003303 0000000000000000000000000000000000000000000000000000000000000003
304
268 305 0000000000000000000000000000000000000000000000000000000000000060
269 0000000000000000000000000000000000000000000000000000000000000060306 0000000000000000000000000000000000000000000000000000000000000140
270 0000000000000000000000000000000000000000000000000000000000000140307 0000000000000000000000000000000000000000000000000000000000000220
271 0000000000000000000000000000000000000000000000000000000000000220308
272309 0000000000000000000000000000000000000000000000000000000000000040
273 0000000000000000000000000000000000000000000000000000000000000040310 0000000000000000000000000000000000000000000000000000000000000080
274 0000000000000000000000000000000000000000000000000000000000000080311 000000000000000000000000000000000000000000000000000000000000000a
275 000000000000000000000000000000000000000000000000000000000000000a312 5465737420555249203000000000000000000000000000000000000000000000
276 5465737420555249203000000000000000000000000000000000000000000000313 0000000000000000000000000000000000000000000000000000000000000030
277 0000000000000000000000000000000000000000000000000000000000000030314 1111111111111111111111111111111111111111111111111111111111111111
278 1111111111111111111111111111111111111111111111111111111111111111315 1111111111111111111111111111111100000000000000000000000000000000
279 1111111111111111111111111111111100000000000000000000000000000000316
280317 0000000000000000000000000000000000000000000000000000000000000040
281 0000000000000000000000000000000000000000000000000000000000000040318 0000000000000000000000000000000000000000000000000000000000000080
282 0000000000000000000000000000000000000000000000000000000000000080319 000000000000000000000000000000000000000000000000000000000000000a
283 000000000000000000000000000000000000000000000000000000000000000a320 5465737420555249203100000000000000000000000000000000000000000000
284 5465737420555249203100000000000000000000000000000000000000000000321 000000000000000000000000000000000000000000000000000000000000002f
285 000000000000000000000000000000000000000000000000000000000000002f322 2222222222222222222222222222222222222222222222222222222222222222
286 2222222222222222222222222222222222222222222222222222222222222222323 2222222222222222222222222222220000000000000000000000000000000000
287 2222222222222222222222222222220000000000000000000000000000000000324
288325 0000000000000000000000000000000000000000000000000000000000000040
289 0000000000000000000000000000000000000000000000000000000000000040326 0000000000000000000000000000000000000000000000000000000000000080
290 0000000000000000000000000000000000000000000000000000000000000080327 000000000000000000000000000000000000000000000000000000000000000a
291 000000000000000000000000000000000000000000000000000000000000000a328 5465737420555249203200000000000000000000000000000000000000000000
292 5465737420555249203200000000000000000000000000000000000000000000329 0000000000000000000000000000000000000000000000000000000000000002
293 0000000000000000000000000000000000000000000000000000000000000002330 3333000000000000000000000000000000000000000000000000000000000000
294 3333000000000000000000000000000000000000000000000000000000000000331 "
295 "
296 )332 ),
297);333 );
334}
335
336#[test]
337// #[ignore = "reason"]
338fn encode_decode_tuple0_tuple1_uint8_tuple1_string_bytes_tuple1_uint8_bytes() {
339 let int = 0xff;
340 let by = bytes(vec![0x11, 0x22, 0x33]);
341 let string = "some string".to_string();
342
343 test_impl::<((u8,), (String, bytes), (u8, bytes))>(
344 0xdeadbeef,
345 ((int,), (string.clone(), by.clone()), (int, by)),
346 &hex!(
347 "
348 deadbeef
349 0000000000000000000000000000000000000000000000000000000000000020
350 00000000000000000000000000000000000000000000000000000000000000ff
351 0000000000000000000000000000000000000000000000000000000000000060
352 0000000000000000000000000000000000000000000000000000000000000120
353 0000000000000000000000000000000000000000000000000000000000000040
354 0000000000000000000000000000000000000000000000000000000000000080
355 000000000000000000000000000000000000000000000000000000000000000b
356 736f6d6520737472696e67000000000000000000000000000000000000000000
357 0000000000000000000000000000000000000000000000000000000000000003
358 1122330000000000000000000000000000000000000000000000000000000000
359 00000000000000000000000000000000000000000000000000000000000000ff
360 0000000000000000000000000000000000000000000000000000000000000040
361 0000000000000000000000000000000000000000000000000000000000000003
362 1122330000000000000000000000000000000000000000000000000000000000
363 "
364 ),
365 );
366}
367
368#[test]
369fn encode_decode_tuple0_tuple1_uint8_tuple1_uint8_uint8_tuple1_uint8_uint8() {
370 test_impl::<((u8,), (u8, u8), (u8, u8))>(
371 0xdeadbeef,
372 ((43,), (44, 45), (46, 47)),
373 &hex!(
374 "
375 deadbeef
376 000000000000000000000000000000000000000000000000000000000000002b
377 000000000000000000000000000000000000000000000000000000000000002c
378 000000000000000000000000000000000000000000000000000000000000002d
379 000000000000000000000000000000000000000000000000000000000000002e
380 000000000000000000000000000000000000000000000000000000000000002f
381 "
382 ),
383 );
384}
385
386#[test]
387fn encode_decode_tuple0_tuple1_uint8_tuple1_uint8() {
388 test_impl::<((u8,), (u8,))>(
389 0xdeadbeef,
390 ((43,), (44,)),
391 &hex!(
392 "
393 deadbeef
394 000000000000000000000000000000000000000000000000000000000000002b
395 000000000000000000000000000000000000000000000000000000000000002c
396 "
397 ),
398 );
399}
400
401#[test]
402fn encode_decode_tuple0_tuple1_uint8_uint8() {
403 test_impl::<((u8, u8),)>(
404 0xdeadbeef,
405 ((43, 44),),
406 &hex!(
407 "
408 deadbeef
409 000000000000000000000000000000000000000000000000000000000000002b
410 000000000000000000000000000000000000000000000000000000000000002c
411 "
412 ),
413 );
414}
415
416#[test]
417fn encode_decode_tuple_uint8_uint8() {
418 test_impl::<(u8, u8)>(
419 0xdeadbeef,
420 (43, 44),
421 &hex!(
422 "
423 deadbeef
424 000000000000000000000000000000000000000000000000000000000000002b
425 000000000000000000000000000000000000000000000000000000000000002c
426 "
427 ),
428 );
429}
430
431#[test]
432fn encode_decode_tuple0_tuple1_uint8_uint8_tuple1_uint8_uint8_and_uint8() {
433 test_impl::<((u8, u8), (u8, u8), u8)>(
434 0xdeadbeef,
435 ((10, 11), (12, 13), 14),
436 &hex!(
437 "
438 deadbeef
439 000000000000000000000000000000000000000000000000000000000000000a
440 000000000000000000000000000000000000000000000000000000000000000b
441 000000000000000000000000000000000000000000000000000000000000000c
442 000000000000000000000000000000000000000000000000000000000000000d
443 000000000000000000000000000000000000000000000000000000000000000e
444 "
445 ),
446 );
447}
448
449#[test]
450fn encode_decode_tuple0_tuple1_string() {
451 test_impl::<((String,),)>(
452 0xdeadbeef,
453 (("some string".to_string(),),),
454 &hex!(
455 "
456 deadbeef
457 0000000000000000000000000000000000000000000000000000000000000020
458 0000000000000000000000000000000000000000000000000000000000000020
459 0000000000000000000000000000000000000000000000000000000000000020
460 000000000000000000000000000000000000000000000000000000000000000b
461 736f6d6520737472696e67000000000000000000000000000000000000000000
462 "
463 ),
464 );
465}
466
467#[test]
468fn encode_decode_tuple0_tuple1_uint8_string() {
469 test_impl::<((u8, String),)>(
470 0xdeadbeef,
471 ((0xff, "some string".to_string()),),
472 &hex!(
473 "
474 deadbeef
475 0000000000000000000000000000000000000000000000000000000000000020
476 0000000000000000000000000000000000000000000000000000000000000020
477 00000000000000000000000000000000000000000000000000000000000000ff
478 0000000000000000000000000000000000000000000000000000000000000040
479 000000000000000000000000000000000000000000000000000000000000000b
480 736f6d6520737472696e67000000000000000000000000000000000000000000
481 "
482 ),
483 );
484}
485
486#[test]
487fn encode_decode_tuple0_tuple1_string_bytes() {
488 test_impl::<((String, bytes),)>(
489 0xdeadbeef,
490 (("some string".to_string(), bytes(vec![1, 2, 3])),),
491 &hex!(
492 "
493 deadbeef
494 0000000000000000000000000000000000000000000000000000000000000020
495 0000000000000000000000000000000000000000000000000000000000000020
496 0000000000000000000000000000000000000000000000000000000000000040
497 0000000000000000000000000000000000000000000000000000000000000080
498 000000000000000000000000000000000000000000000000000000000000000b
499 736f6d6520737472696e67000000000000000000000000000000000000000000
500 0000000000000000000000000000000000000000000000000000000000000003
501 0102030000000000000000000000000000000000000000000000000000000000
502 "
503 ),
504 );
505}
506
507#[test]
508fn encode_decode_tuple0_tuple1_uint8_tuple1_string() {
509 test_impl::<((u8,), (String,))>(
510 0xdeadbeef,
511 ((0xff,), ("some string".to_string(),)),
512 &hex!(
513 "
514 deadbeef
515 0000000000000000000000000000000000000000000000000000000000000020
516 00000000000000000000000000000000000000000000000000000000000000ff
517 0000000000000000000000000000000000000000000000000000000000000040
518 0000000000000000000000000000000000000000000000000000000000000020
519 000000000000000000000000000000000000000000000000000000000000000b
520 736f6d6520737472696e67000000000000000000000000000000000000000000
521 "
522 ),
523 );
524}
525
526#[test]
527fn parse_multiple_params() {
528 let encoded_data = hex!(
529 "
530 deadbeef
531 000000000000000000000000000000000000000000000000000000000000000a
532 000000000000000000000000000000000000000000000000000000000000000b
533 "
534 );
535 let (_, mut decoder) = AbiReader::new_call(&encoded_data).unwrap();
536 let p1 = <u8>::abi_read(&mut decoder).unwrap();
537 let p2 = <u8>::abi_read(&mut decoder).unwrap();
538 assert_eq!(p1, 0x0a);
539 assert_eq!(p2, 0x0b);
540}
298541
modifiedcrates/evm-coder/src/abi/traits.rsdiffbeforeafterboth
22 fn size() -> usize;22 fn size() -> usize;
23}23}
24
25/// Sealed traits.
26pub mod sealed {
27 /// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead
28 pub trait CanBePlacedInVec {}
29}
3024
31/// [`AbiReader`] implements reading of many types.25/// [`AbiReader`] implements reading of many types.
32pub trait AbiRead {26pub trait AbiRead {
50 }44 }
51}45}
52
53impl<T: AbiWrite> AbiWrite for &T {
54 fn abi_write(&self, writer: &mut AbiWriter) {
55 T::abi_write(self, writer);
56 }
57}
5846
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
93pub use evm_coder_procedural::solidity;93pub use evm_coder_procedural::solidity;
94/// See [`solidity_interface`]94/// See [`solidity_interface`]
95pub use evm_coder_procedural::weight;95pub use evm_coder_procedural::weight;
96pub use evm_coder_procedural::AbiCoder;
96pub use sha3_const;97pub use sha3_const;
9798
98/// Derives [`ToLog`] for enum99/// Derives [`ToLog`] for enum
111#[cfg(feature = "stubgen")]112#[cfg(feature = "stubgen")]
112pub mod solidity;113pub mod solidity;
114
115/// Sealed traits.
116pub mod sealed {
117 /// Not every type should be directly placed in vec.
118 /// Vec encoding is not memory efficient, as every item will be padded
119 /// to 32 bytes.
120 /// Instead you should use specialized types (`bytes` in case of `Vec<u8>`)
121 pub trait CanBePlacedInVec {}
122}
113123
114/// Solidity type definitions (aliases from solidity name to rust type)124/// Solidity type definitions (aliases from solidity name to rust type)
115/// To be used in [`solidity_interface`] definitions, to make sure there is no125/// To be used in [`solidity_interface`] definitions, to make sure there is no
119129
120 #[cfg(not(feature = "std"))]130 #[cfg(not(feature = "std"))]
121 use alloc::{vec::Vec};131 use alloc::{vec::Vec};
122 use pallet_evm::account::CrossAccountId;
123 use primitive_types::{U256, H160, H256};132 use primitive_types::{U256, H160, H256};
124133
125 pub type address = H160;134 pub type address = H160;
137 #[cfg(feature = "std")]146 #[cfg(feature = "std")]
138 pub type string = ::std::string::String;147 pub type string = ::std::string::String;
139148
140 #[derive(Default, Debug, PartialEq)]149 #[derive(Default, Debug, PartialEq, Eq, Clone)]
141 pub struct bytes(pub Vec<u8>);150 pub struct bytes(pub Vec<u8>);
142151
143 /// Solidity doesn't have `void` type, however we have special implementation152 /// Solidity doesn't have `void` type, however we have special implementation
188 }197 }
189 }198 }
190
191 #[derive(Debug, Default)]
192 pub struct EthCrossAccount {
193 pub(crate) eth: address,
194 pub(crate) sub: uint256,
195 }
196
197 impl EthCrossAccount {
198 pub fn from_sub_cross_account<T>(cross_account_id: &T::CrossAccountId) -> Self
199 where
200 T: pallet_evm::Config,
201 T::AccountId: AsRef<[u8; 32]>,
202 {
203 if cross_account_id.is_canonical_substrate() {
204 Self {
205 eth: Default::default(),
206 sub: convert_cross_account_to_uint256::<T>(cross_account_id),
207 }
208 } else {
209 Self {
210 eth: *cross_account_id.as_eth(),
211 sub: Default::default(),
212 }
213 }
214 }
215
216 pub fn into_sub_cross_account<T>(&self) -> crate::execution::Result<T::CrossAccountId>
217 where
218 T: pallet_evm::Config,
219 T::AccountId: From<[u8; 32]>,
220 {
221 if self.eth == Default::default() && self.sub == Default::default() {
222 Err("All fields of cross account is zeroed".into())
223 } else if self.eth == Default::default() {
224 Ok(convert_uint256_to_cross_account::<T>(self.sub))
225 } else if self.sub == Default::default() {
226 Ok(T::CrossAccountId::from_eth(self.eth))
227 } else {
228 Err("All fields of cross account is non zeroed".into())
229 }
230 }
231 }
232
233 /// Convert `CrossAccountId` to `uint256`.
234 pub fn convert_cross_account_to_uint256<T: pallet_evm::Config>(
235 from: &T::CrossAccountId,
236 ) -> uint256
237 where
238 T::AccountId: AsRef<[u8; 32]>,
239 {
240 let slice = from.as_sub().as_ref();
241 uint256::from_big_endian(slice)
242 }
243
244 /// Convert `uint256` to `CrossAccountId`.
245 pub fn convert_uint256_to_cross_account<T: pallet_evm::Config>(
246 from: uint256,
247 ) -> T::CrossAccountId
248 where
249 T::AccountId: From<[u8; 32]>,
250 {
251 let mut new_admin_arr = [0_u8; 32];
252 from.to_big_endian(&mut new_admin_arr);
253 let account_id = T::AccountId::from(new_admin_arr);
254 T::CrossAccountId::from_sub(account_id)
255 }
256199
257 #[derive(Debug, Default)]200 #[derive(Debug, Default)]
258 pub struct Property {201 pub struct Property {
deletedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/src/solidity/traits.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/tests/abi_derive_generation.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/tests/build_failed/abi_derive_enum_generation.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/tests/build_failed/abi_derive_enum_generation.stderrdiffbeforeafterboth

no changes

addedcrates/evm-coder/tests/build_failed/abi_derive_struct_generation.rsdiffbeforeafterboth

no changes

addedcrates/evm-coder/tests/build_failed/abi_derive_struct_generation.stderrdiffbeforeafterboth

no changes

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
1616
17//! This module contains the implementation of pallet methods for evm.17//! This module contains the implementation of pallet methods for evm.
1818
19use evm_coder::{
20 abi::AbiType,
21 solidity_interface, solidity, ToLog,
22 types::*,
23 types::Property as PropertyStruct,
24 execution::{Result, Error},
25 weight,
26};
27pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};19pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};
20use evm_coder::{
21 abi::AbiType,
22 solidity_interface, solidity, ToLog,
23 types::*,
24 types::Property as PropertyStruct,
25 execution::{Result, Error},
26 weight,
27};
28use pallet_evm_coder_substrate::dispatch_to_evm;28use pallet_evm_coder_substrate::dispatch_to_evm;
29use sp_std::vec::Vec;29use sp_std::vec::Vec;
30use up_data_structs::{30use up_data_structs::{
3535
36use crate::{36use crate::{
37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
38 eth::convert_cross_account_to_uint256, weights::WeightInfo,38 eth::{EthCrossAccount, convert_cross_account_to_uint256},
39 weights::WeightInfo,
39};40};
4041
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
1616
17//! The module contains a number of functions for converting and checking ethereum identifiers.17//! The module contains a number of functions for converting and checking ethereum identifiers.
1818
19use evm_coder::types::{uint256, address};19use evm_coder::{
20 AbiCoder,
21 types::{uint256, address},
22};
20pub use pallet_evm::{Config, account::CrossAccountId};23pub use pallet_evm::{Config, account::CrossAccountId};
21use sp_core::H160;24use sp_core::H160;
22use up_data_structs::CollectionId;25use up_data_structs::CollectionId;
110 }113 }
111}114}
115
116/// Cross account struct
117#[derive(Debug, Default, AbiCoder)]
118pub struct EthCrossAccount {
119 pub(crate) eth: address,
120 pub(crate) sub: uint256,
121}
122
123impl EthCrossAccount {
124 pub fn from_sub_cross_account<T>(cross_account_id: &T::CrossAccountId) -> Self
125 where
126 T: pallet_evm::Config,
127 T::AccountId: AsRef<[u8; 32]>,
128 {
129 if cross_account_id.is_canonical_substrate() {
130 Self {
131 eth: Default::default(),
132 sub: convert_cross_account_to_uint256::<T>(cross_account_id),
133 }
134 } else {
135 Self {
136 eth: *cross_account_id.as_eth(),
137 sub: Default::default(),
138 }
139 }
140 }
141
142 pub fn into_sub_cross_account<T>(&self) -> evm_coder::execution::Result<T::CrossAccountId>
143 where
144 T: pallet_evm::Config,
145 T::AccountId: From<[u8; 32]>,
146 {
147 if self.eth == Default::default() && self.sub == Default::default() {
148 Err("All fields of cross account is zeroed".into())
149 } else if self.eth == Default::default() {
150 Ok(convert_uint256_to_cross_account::<T>(self.sub))
151 } else if self.sub == Default::default() {
152 Ok(T::CrossAccountId::from_eth(self.eth))
153 } else {
154 Err("All fields of cross account is non zeroed".into())
155 }
156 }
157}
112158
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
376 type TreasuryAccountId: Get<Self::AccountId>;376 type TreasuryAccountId: Get<Self::AccountId>;
377377
378 /// Address under which the CollectionHelper contract would be available.378 /// Address under which the CollectionHelper contract would be available.
379 #[pallet::constant]
379 type ContractAddress: Get<H160>;380 type ContractAddress: Get<H160>;
380381
381 /// Mapper for token addresses to Ethereum addresses.382 /// Mapper for token addresses to Ethereum addresses.
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
47 type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;47 type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;
4848
49 /// Address, under which magic contract will be available49 /// Address, under which magic contract will be available
50 #[pallet::constant]
50 type ContractAddress: Get<H160>;51 type ContractAddress: Get<H160>;
5152
52 /// In case of enabled sponsoring, but no sponsoring rate limit set,53 /// In case of enabled sponsoring, but no sponsoring rate limit set,
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
24 weight,24 weight,
25};25};
26use up_data_structs::CollectionMode;26use up_data_structs::CollectionMode;
27use pallet_common::erc::{CommonEvmHandler, PrecompileResult};27use pallet_common::{
28 CollectionHandle,
29 erc::{CommonEvmHandler, PrecompileResult, CollectionCall},
30 eth::EthCrossAccount,
31};
28use sp_std::vec::Vec;32use sp_std::vec::Vec;
29use pallet_evm::{account::CrossAccountId, PrecompileHandle};33use pallet_evm::{account::CrossAccountId, PrecompileHandle};
30use pallet_evm_coder_substrate::{call, dispatch_to_evm};34use pallet_evm_coder_substrate::{call, dispatch_to_evm};
31use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};35use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
32use pallet_common::{CollectionHandle, erc::CollectionCall};36use sp_core::Get;
3337
34use crate::{38use crate::{
35 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,39 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,
133 Ok(<Allowance<T>>::get((self.id, owner, spender)).into())137 Ok(<Allowance<T>>::get((self.id, owner, spender)).into())
134 }138 }
139
140 /// @notice Returns collection helper contract address
141 fn collection_helper_address(&self) -> Result<address> {
142 Ok(T::ContractAddress::get())
143 }
135}144}
136145
137#[solidity_interface(name = ERC20Mintable)]146#[solidity_interface(name = ERC20Mintable)]
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
547 event Approval(address indexed owner, address indexed spender, uint256 value);547 event Approval(address indexed owner, address indexed spender, uint256 value);
548}548}
549549
550/// @dev the ERC-165 identifier for this interface is 0x942e8b22550/// @dev the ERC-165 identifier for this interface is 0x8cb847c4
551contract ERC20 is Dummy, ERC165, ERC20Events {551contract ERC20 is Dummy, ERC165, ERC20Events {
552 /// @dev EVM selector for this function is: 0x06fdde03,552 /// @dev EVM selector for this function is: 0x06fdde03,
553 /// or in textual repr: name()553 /// or in textual repr: name()
635 return 0;635 return 0;
636 }636 }
637
638 /// @notice Returns collection helper contract address
639 /// @dev EVM selector for this function is: 0x1896cce6,
640 /// or in textual repr: collectionHelperAddress()
641 function collectionHelperAddress() public view returns (address) {
642 require(false, stub_error);
643 dummy;
644 return 0x0000000000000000000000000000000000000000;
645 }
637}646}
638647
639contract UniqueFungible is Dummy, ERC165, ERC20, ERC20Mintable, ERC20UniqueExtensions, Collection {}648contract UniqueFungible is Dummy, ERC165, ERC20, ERC20Mintable, ERC20UniqueExtensions, Collection {}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
36use pallet_evm_coder_substrate::dispatch_to_evm;36use pallet_evm_coder_substrate::dispatch_to_evm;
37use sp_std::vec::Vec;37use sp_std::vec::Vec;
38use pallet_common::{38use pallet_common::{
39 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
39 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},40 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
40 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,41 eth::EthCrossAccount,
41};42};
42use pallet_evm::{account::CrossAccountId, PrecompileHandle};43use pallet_evm::{account::CrossAccountId, PrecompileHandle};
43use pallet_evm_coder_substrate::call;44use pallet_evm_coder_substrate::call;
44use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};45use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
46use sp_core::Get;
4547
46use crate::{48use crate::{
47 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,49 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
490 Err("not implemented".into())492 Err("not implemented".into())
491 }493 }
494
495 /// @notice Returns collection helper contract address
496 fn collection_helper_address(&self) -> Result<address> {
497 Ok(T::ContractAddress::get())
498 }
492}499}
493500
494/// @title ERC721 Token that can be irreversibly burned (destroyed).501/// @title ERC721 Token that can be irreversibly burned (destroyed).
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
920920
921/// @title ERC-721 Non-Fungible Token Standard921/// @title ERC-721 Non-Fungible Token Standard
922/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md922/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
923/// @dev the ERC-165 identifier for this interface is 0x80ac58cd923/// @dev the ERC-165 identifier for this interface is 0x983a942b
924contract ERC721 is Dummy, ERC165, ERC721Events {924contract ERC721 is Dummy, ERC165, ERC721Events {
925 /// @notice Count all NFTs assigned to an owner925 /// @notice Count all NFTs assigned to an owner
926 /// @dev NFTs assigned to the zero address are considered invalid, and this926 /// @dev NFTs assigned to the zero address are considered invalid, and this
1051 return 0x0000000000000000000000000000000000000000;1051 return 0x0000000000000000000000000000000000000000;
1052 }1052 }
1053
1054 /// @notice Returns collection helper contract address
1055 /// @dev EVM selector for this function is: 0x1896cce6,
1056 /// or in textual repr: collectionHelperAddress()
1057 function collectionHelperAddress() public view returns (address) {
1058 require(false, stub_error);
1059 dummy;
1060 return 0x0000000000000000000000000000000000000000;
1061 }
1053}1062}
10541063
1055contract UniqueNFT is1064contract UniqueNFT is
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
178178
179use RmrkProperty::*;179use RmrkProperty::*;
180180
181/// Maximum number of levels of depth in the token nesting tree.181/// A maximum number of levels of depth in the token nesting tree.
182pub const NESTING_BUDGET: u32 = 5;182pub const NESTING_BUDGET: u32 = 5;
183183
184type PendingTarget = (CollectionId, TokenId);184type PendingTarget = (CollectionId, TokenId);
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
31};31};
32use frame_support::{BoundedBTreeMap, BoundedVec};32use frame_support::{BoundedBTreeMap, BoundedVec};
33use pallet_common::{33use pallet_common::{
34 CollectionHandle, CollectionPropertyPermissions,34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
35 erc::{CommonEvmHandler, CollectionCall, static_property::key},35 erc::{CommonEvmHandler, CollectionCall, static_property::key},
36 CommonCollectionOperations,36 eth::EthCrossAccount,
37};37};
38use pallet_evm::{account::CrossAccountId, PrecompileHandle};38use pallet_evm::{account::CrossAccountId, PrecompileHandle};
39use pallet_evm_coder_substrate::{call, dispatch_to_evm};39use pallet_evm_coder_substrate::{call, dispatch_to_evm};
40use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};40use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
41use sp_core::H160;41use sp_core::{H160, Get};
42use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};42use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};
43use up_data_structs::{43use up_data_structs::{
44 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,44 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,
483 Err("not implemented".into())483 Err("not implemented".into())
484 }484 }
485
486 /// @notice Returns collection helper contract address
487 fn collection_helper_address(&self) -> Result<address> {
488 Ok(T::ContractAddress::get())
489 }
485}490}
486491
487/// Returns amount of pieces of `token` that `owner` have492/// Returns amount of pieces of `token` that `owner` have
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
919919
920/// @title ERC-721 Non-Fungible Token Standard920/// @title ERC-721 Non-Fungible Token Standard
921/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md921/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
922/// @dev the ERC-165 identifier for this interface is 0x58800161922/// @dev the ERC-165 identifier for this interface is 0x4016cd87
923contract ERC721 is Dummy, ERC165, ERC721Events {923contract ERC721 is Dummy, ERC165, ERC721Events {
924 /// @notice Count all RFTs assigned to an owner924 /// @notice Count all RFTs assigned to an owner
925 /// @dev RFTs assigned to the zero address are considered invalid, and this925 /// @dev RFTs assigned to the zero address are considered invalid, and this
1048 return 0x0000000000000000000000000000000000000000;1048 return 0x0000000000000000000000000000000000000000;
1049 }1049 }
1050
1051 /// @notice Returns collection helper contract address
1052 /// @dev EVM selector for this function is: 0x1896cce6,
1053 /// or in textual repr: collectionHelperAddress()
1054 function collectionHelperAddress() public view returns (address) {
1055 require(false, stub_error);
1056 dummy;
1057 return 0x0000000000000000000000000000000000000000;
1058 }
1050}1059}
10511060
1052contract UniqueRefungible is1061contract UniqueRefungible is
modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
28 CollectionById,28 CollectionById,
29 dispatch::CollectionDispatch,29 dispatch::CollectionDispatch,
30 erc::{CollectionHelpersEvents, static_property::key},30 erc::{CollectionHelpersEvents, static_property::key},
31 eth::{map_eth_to_id, collection_id_to_address},
31 Pallet as PalletCommon,32 Pallet as PalletCommon,
32};33};
33use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};34use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
34use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};35use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
35use sp_std::vec;36use sp_std::vec;
36use up_data_structs::{37use up_data_structs::{
37 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,38 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
38 CreateCollectionData,39 CreateCollectionData, CollectionId,
39};40};
4041
41use crate::{weights::WeightInfo, Config, SelfWeightOf};42use crate::{weights::WeightInfo, Config, SelfWeightOf};
362 Ok(price.into())363 Ok(price.into())
363 }364 }
365
366 /// Returns address of a collection.
367 /// @param collectionId - CollectionId of the collection
368 /// @return eth mirror address of the collection
369 fn collection_address(&self, collection_id: uint32) -> Result<address> {
370 Ok(collection_id_to_address(collection_id.into()))
371 }
372
373 /// Returns collectionId of a collection.
374 /// @param collectionAddress - Eth address of the collection
375 /// @return collectionId of the collection
376 fn collection_id(&self, collection_address: address) -> Result<uint32> {
377 map_eth_to_id(&collection_address)
378 .map(|id| id.0)
379 .ok_or(Error::Revert(format!(
380 "failed to convert address {} into collectionId.",
381 collection_address
382 )))
383 }
364}384}
365385
366/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]386/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
24}24}
2525
26/// @title Contract, which allows users to operate with collections26/// @title Contract, which allows users to operate with collections
27/// @dev the ERC-165 identifier for this interface is 0x7dea03b127/// @dev the ERC-165 identifier for this interface is 0xe65011aa
28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
29 /// Create an NFT collection29 /// Create an NFT collection
30 /// @param name Name of the collection30 /// @param name Name of the collection
131 return 0;131 return 0;
132 }132 }
133
134 /// Returns address of a collection.
135 /// @param collectionId - CollectionId of the collection
136 /// @return eth mirror address of the collection
137 /// @dev EVM selector for this function is: 0x2e716683,
138 /// or in textual repr: collectionAddress(uint32)
139 function collectionAddress(uint32 collectionId) public view returns (address) {
140 require(false, stub_error);
141 collectionId;
142 dummy;
143 return 0x0000000000000000000000000000000000000000;
144 }
145
146 /// Returns collectionId of a collection.
147 /// @param collectionAddress - Eth address of the collection
148 /// @return collectionId of the collection
149 /// @dev EVM selector for this function is: 0xb5cb7498,
150 /// or in textual repr: collectionId(address)
151 function collectionId(address collectionAddress) public view returns (uint32) {
152 require(false, stub_error);
153 collectionAddress;
154 dummy;
155 return 0;
156 }
133}157}
134158
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
86use sp_std::{vec, vec::Vec};86use sp_std::{vec, vec::Vec};
87use up_data_structs::{87use up_data_structs::{
88 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,88 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
89 MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,
90 MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,
89 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,91 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,
90 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,92 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
91 PropertyKeyPermission,93 PropertyKeyPermission,
102pub mod weights;104pub mod weights;
103use weights::WeightInfo;105use weights::WeightInfo;
104106
105/// Maximum number of levels of depth in the token nesting tree.107/// A maximum number of levels of depth in the token nesting tree.
106pub const NESTING_BUDGET: u32 = 5;108pub const NESTING_BUDGET: u32 = 5;
107109
108decl_error! {110decl_error! {
277 {279 {
278 type Error = Error<T>;280 type Error = Error<T>;
281
282 #[doc = "A maximum number of levels of depth in the token nesting tree."]
283 const NESTING_BUDGET: u32 = NESTING_BUDGET;
284
285 #[doc = "Maximal length of a collection name."]
286 const MAX_COLLECTION_NAME_LENGTH: u32 = MAX_COLLECTION_NAME_LENGTH;
287
288 #[doc = "Maximal length of a collection description."]
289 const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = MAX_COLLECTION_DESCRIPTION_LENGTH;
290
291 #[doc = "Maximal length of a token prefix."]
292 const MAX_TOKEN_PREFIX_LENGTH: u32 = MAX_TOKEN_PREFIX_LENGTH;
293
294 #[doc = "Maximum admins per collection."]
295 const COLLECTION_ADMINS_LIMIT: u32 = COLLECTION_ADMINS_LIMIT;
296
297 #[doc = "Maximal length of a property key."]
298 const MAX_PROPERTY_KEY_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH;
299
300 #[doc = "Maximal length of a property value."]
301 const MAX_PROPERTY_VALUE_LENGTH: u32 = MAX_PROPERTY_VALUE_LENGTH;
302
303 #[doc = "A maximum number of token properties."]
304 const MAX_PROPERTIES_PER_ITEM: u32 = MAX_PROPERTIES_PER_ITEM;
305
306 #[doc = "Maximum size for all collection properties."]
307 const MAX_COLLECTION_PROPERTIES_SIZE: u32 = MAX_COLLECTION_PROPERTIES_SIZE;
308
309 #[doc = "Maximum size of all token properties."]
310 const MAX_TOKEN_PROPERTIES_SIZE: u32 = MAX_TOKEN_PROPERTIES_SIZE;
311
312 #[doc = "Default NFT collection limit."]
313 const NFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::NFT);
314
315 #[doc = "Default RFT collection limit."]
316 const RFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::ReFungible);
317
318 #[doc = "Default FT collection limit."]
319 const FT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::Fungible(0));
320
279321
280 pub fn deposit_event() = default;322 pub fn deposit_event() = default;
modifiedprimitives/data-structs/CHANGELOG.mddiffbeforeafterboth
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->
6
6## [v0.2.2] 2022-08-167## [v0.2.2] 2022-08-16
78
8### Other changes9### Other changes
28multiple users into `RefungibleMultipleItems` call.29multiple users into `RefungibleMultipleItems` call.
2930
30## [v0.2.0] - 2022-08-0131## [v0.2.0] - 2022-08-01
32
31### Deprecated33### Deprecated
34
32- `CreateReFungibleData::const_data`35- `CreateReFungibleData::const_data`
3336
34## [v0.1.2] - 2022-07-2537## [v0.1.2] - 2022-07-25
38
35### Added39### Added
40
36- Type aliases `CollectionName`, `CollectionDescription`, `CollectionTokenPrefix`41- Type aliases `CollectionName`, `CollectionDescription`, `CollectionTokenPrefix`
42
37## [v0.1.1] - 2022-07-2243## [v0.1.1] - 2022-07-22
44
38### Added45### Added
46
39- Аields with properties to `CreateReFungibleData` and `CreateRefungibleExData`.47- Fields with properties to `CreateReFungibleData` and `CreateRefungibleExData`.
48
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
120// TODO: not used. Delete?120// TODO: not used. Delete?
121pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;121pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;
122122
123/// Maximum length for collection name.123/// Maximal length of a collection name.
124pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;124pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;
125125
126/// Maximum length for collection description.126/// Maximal length of a collection description.
127pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;127pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;
128128
129/// Maximal token prefix length.129/// Maximal length of a token prefix.
130pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;130pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;
131131
132/// Maximal lenght of property key.132/// Maximal length of a property key.
133pub const MAX_PROPERTY_KEY_LENGTH: u32 = 256;133pub const MAX_PROPERTY_KEY_LENGTH: u32 = 256;
134134
135/// Maximal lenght of property value.135/// Maximal length of a property value.
136pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;136pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;
137137
138/// Maximum properties that can be assigned to token.138/// A maximum number of token properties.
139pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;139pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;
140140
141/// Maximal lenght of extended property value.141/// Maximal lenght of extended property value.
144/// Maximum size for all collection properties.144/// Maximum size for all collection properties.
145pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;145pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;
146146
147/// Maximum size for all token properties.147/// Maximum size of all token properties.
148pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;148pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;
149149
150/// How much items can be created per single150/// How much items can be created per single
609}609}
610610
611impl CollectionLimits {611impl CollectionLimits {
612 pub fn with_default_limits(collection_type: CollectionMode) -> Self {
613 CollectionLimits {
614 account_token_ownership_limit: Some(ACCOUNT_TOKEN_OWNERSHIP_LIMIT),
615 sponsored_data_size: Some(CUSTOM_DATA_LIMIT),
616 sponsored_data_rate_limit: Some(SponsoringRateLimit::SponsoringDisabled),
617 token_limit: Some(COLLECTION_TOKEN_LIMIT),
618 sponsor_transfer_timeout: match collection_type {
619 CollectionMode::NFT => Some(NFT_SPONSOR_TRANSFER_TIMEOUT),
620 CollectionMode::ReFungible => Some(REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT),
621 CollectionMode::Fungible(_) => Some(FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT),
622 },
623 sponsor_approve_timeout: Some(SPONSOR_APPROVE_TIMEOUT),
624 owner_can_transfer: Some(false),
625 owner_can_destroy: Some(true),
626 transfers_enabled: Some(true),
627 }
628 }
629
612 /// Get effective value for [`account_token_ownership_limit`](self.account_token_ownership_limit).630 /// Get effective value for [`account_token_ownership_limit`](self.account_token_ownership_limit).
613 pub fn account_token_ownership_limit(&self) -> u32 {631 pub fn account_token_ownership_limit(&self) -> u32 {
modifiedtests/package.jsondiffbeforeafterboth
102 "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",102 "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
103 "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",103 "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
104 "benchMintingFee": "ts-node src/benchmarks/mintFee/benchmark.ts",104 "benchMintingFee": "ts-node src/benchmarks/mintFee/benchmark.ts",
105 "testApiConsts": "mocha --timeout 9999999 -r ts-node/register ./**/apiConsts.test.ts",
105 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",106 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
106 "loadTransfer": "ts-node src/transfer.nload.ts",107 "loadTransfer": "ts-node src/transfer.nload.ts",
107 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",108 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",
addedtests/src/apiConsts.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
31 "name": "CollectionDestroyed",31 "name": "CollectionDestroyed",
32 "type": "event"32 "type": "event"
33 },33 },
34 {
35 "inputs": [
36 { "internalType": "uint32", "name": "collectionId", "type": "uint32" }
37 ],
38 "name": "collectionAddress",
39 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
40 "stateMutability": "view",
41 "type": "function"
42 },
34 {43 {
35 "inputs": [],44 "inputs": [],
36 "name": "collectionCreationFee",45 "name": "collectionCreationFee",
37 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],46 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
38 "stateMutability": "view",47 "stateMutability": "view",
39 "type": "function"48 "type": "function"
40 },49 },
50 {
51 "inputs": [
52 {
53 "internalType": "address",
54 "name": "collectionAddress",
55 "type": "address"
56 }
57 ],
58 "name": "collectionId",
59 "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
60 "stateMutability": "view",
61 "type": "function"
62 },
41 {63 {
42 "inputs": [64 "inputs": [
43 { "internalType": "string", "name": "name", "type": "string" },65 { "internalType": "string", "name": "name", "type": "string" },
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
199 "stateMutability": "view",199 "stateMutability": "view",
200 "type": "function"200 "type": "function"
201 },201 },
202 {
203 "inputs": [],
204 "name": "collectionHelperAddress",
205 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
206 "stateMutability": "view",
207 "type": "function"
208 },
202 {209 {
203 "inputs": [],210 "inputs": [],
204 "name": "collectionOwner",211 "name": "collectionOwner",
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
229 "stateMutability": "view",229 "stateMutability": "view",
230 "type": "function"230 "type": "function"
231 },231 },
232 {
233 "inputs": [],
234 "name": "collectionHelperAddress",
235 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
236 "stateMutability": "view",
237 "type": "function"
238 },
232 {239 {
233 "inputs": [],240 "inputs": [],
234 "name": "collectionOwner",241 "name": "collectionOwner",
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
211 "stateMutability": "view",211 "stateMutability": "view",
212 "type": "function"212 "type": "function"
213 },213 },
214 {
215 "inputs": [],
216 "name": "collectionHelperAddress",
217 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
218 "stateMutability": "view",
219 "type": "function"
220 },
214 {221 {
215 "inputs": [],222 "inputs": [],
216 "name": "collectionOwner",223 "name": "collectionOwner",
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
19}19}
2020
21/// @title Contract, which allows users to operate with collections21/// @title Contract, which allows users to operate with collections
22/// @dev the ERC-165 identifier for this interface is 0x7dea03b122/// @dev the ERC-165 identifier for this interface is 0xe65011aa
23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
24 /// Create an NFT collection24 /// Create an NFT collection
25 /// @param name Name of the collection25 /// @param name Name of the collection
79 /// or in textual repr: collectionCreationFee()79 /// or in textual repr: collectionCreationFee()
80 function collectionCreationFee() external view returns (uint256);80 function collectionCreationFee() external view returns (uint256);
81
82 /// Returns address of a collection.
83 /// @param collectionId - CollectionId of the collection
84 /// @return eth mirror address of the collection
85 /// @dev EVM selector for this function is: 0x2e716683,
86 /// or in textual repr: collectionAddress(uint32)
87 function collectionAddress(uint32 collectionId) external view returns (address);
88
89 /// Returns collectionId of a collection.
90 /// @param collectionAddress - Eth address of the collection
91 /// @return collectionId of the collection
92 /// @dev EVM selector for this function is: 0xb5cb7498,
93 /// or in textual repr: collectionId(address)
94 function collectionId(address collectionAddress) external view returns (uint32);
81}95}
8296
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
354 event Approval(address indexed owner, address indexed spender, uint256 value);354 event Approval(address indexed owner, address indexed spender, uint256 value);
355}355}
356356
357/// @dev the ERC-165 identifier for this interface is 0x942e8b22357/// @dev the ERC-165 identifier for this interface is 0x8cb847c4
358interface ERC20 is Dummy, ERC165, ERC20Events {358interface ERC20 is Dummy, ERC165, ERC20Events {
359 /// @dev EVM selector for this function is: 0x06fdde03,359 /// @dev EVM selector for this function is: 0x06fdde03,
360 /// or in textual repr: name()360 /// or in textual repr: name()
396 /// or in textual repr: allowance(address,address)396 /// or in textual repr: allowance(address,address)
397 function allowance(address owner, address spender) external view returns (uint256);397 function allowance(address owner, address spender) external view returns (uint256);
398
399 /// @notice Returns collection helper contract address
400 /// @dev EVM selector for this function is: 0x1896cce6,
401 /// or in textual repr: collectionHelperAddress()
402 function collectionHelperAddress() external view returns (address);
398}403}
399404
400interface UniqueFungible is Dummy, ERC165, ERC20, ERC20Mintable, ERC20UniqueExtensions, Collection {}405interface UniqueFungible is Dummy, ERC165, ERC20, ERC20Mintable, ERC20UniqueExtensions, Collection {}
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
605605
606/// @title ERC-721 Non-Fungible Token Standard606/// @title ERC-721 Non-Fungible Token Standard
607/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md607/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
608/// @dev the ERC-165 identifier for this interface is 0x80ac58cd608/// @dev the ERC-165 identifier for this interface is 0x983a942b
609interface ERC721 is Dummy, ERC165, ERC721Events {609interface ERC721 is Dummy, ERC165, ERC721Events {
610 /// @notice Count all NFTs assigned to an owner610 /// @notice Count all NFTs assigned to an owner
611 /// @dev NFTs assigned to the zero address are considered invalid, and this611 /// @dev NFTs assigned to the zero address are considered invalid, and this
686 /// or in textual repr: isApprovedForAll(address,address)686 /// or in textual repr: isApprovedForAll(address,address)
687 function isApprovedForAll(address owner, address operator) external view returns (address);687 function isApprovedForAll(address owner, address operator) external view returns (address);
688
689 /// @notice Returns collection helper contract address
690 /// @dev EVM selector for this function is: 0x1896cce6,
691 /// or in textual repr: collectionHelperAddress()
692 function collectionHelperAddress() external view returns (address);
688}693}
689694
690interface UniqueNFT is695interface UniqueNFT is
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
604604
605/// @title ERC-721 Non-Fungible Token Standard605/// @title ERC-721 Non-Fungible Token Standard
606/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md606/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
607/// @dev the ERC-165 identifier for this interface is 0x58800161607/// @dev the ERC-165 identifier for this interface is 0x4016cd87
608interface ERC721 is Dummy, ERC165, ERC721Events {608interface ERC721 is Dummy, ERC165, ERC721Events {
609 /// @notice Count all RFTs assigned to an owner609 /// @notice Count all RFTs assigned to an owner
610 /// @dev RFTs assigned to the zero address are considered invalid, and this610 /// @dev RFTs assigned to the zero address are considered invalid, and this
683 /// or in textual repr: isApprovedForAll(address,address)683 /// or in textual repr: isApprovedForAll(address,address)
684 function isApprovedForAll(address owner, address operator) external view returns (address);684 function isApprovedForAll(address owner, address operator) external view returns (address);
685
686 /// @notice Returns collection helper contract address
687 /// @dev EVM selector for this function is: 0x1896cce6,
688 /// or in textual repr: collectionHelperAddress()
689 function collectionHelperAddress() external view returns (address);
685}690}
686691
687interface UniqueRefungible is692interface UniqueRefungible is
addedtests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
103103
104 contractHelpers(caller: string): Contract {104 contractHelpers(caller: string): Contract {
105 const web3 = this.helper.getWeb3();105 const web3 = this.helper.getWeb3();
106 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, gas: this.helper.eth.DEFAULT_GAS});106 return new web3.eth.Contract(contractHelpersAbi as any, this.helper.getApi().consts.evmContractHelpers.contractAddress.toString(), {from: caller, gas: this.helper.eth.DEFAULT_GAS});
107 }107 }
108108
109 collectionHelpers(caller: string) {109 collectionHelpers(caller: string) {
110 const web3 = this.helper.getWeb3();110 const web3 = this.helper.getWeb3();
111 return new web3.eth.Contract(collectionHelpersAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, gas: this.helper.eth.DEFAULT_GAS});111 return new web3.eth.Contract(collectionHelpersAbi as any, this.helper.getApi().consts.common.contractAddress.toString(), {from: caller, gas: this.helper.eth.DEFAULT_GAS});
112 }112 }
113113
114 collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false): Contract {114 collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false): Contract {
modifiedtests/src/interfaces/augment-api-consts.tsdiffbeforeafterboth
8import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';8import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';
9import type { Option, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';9import type { Option, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
10import type { Codec } from '@polkadot/types-codec/types';10import type { Codec } from '@polkadot/types-codec/types';
11import type { Perbill, Permill, Weight } from '@polkadot/types/interfaces/runtime';11import type { H160, Perbill, Permill, Weight } from '@polkadot/types/interfaces/runtime';
12import type { FrameSupportPalletId, FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight, XcmV1MultiLocation } from '@polkadot/types/lookup';12import type { FrameSupportPalletId, FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight, UpDataStructsCollectionLimits, XcmV1MultiLocation } from '@polkadot/types/lookup';
1313
14export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;14export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;
1515
69 * Set price to create a collection.69 * Set price to create a collection.
70 **/70 **/
71 collectionCreationPrice: u128 & AugmentedConst<ApiType>;71 collectionCreationPrice: u128 & AugmentedConst<ApiType>;
72 /**
73 * Address under which the CollectionHelper contract would be available.
74 **/
75 contractAddress: H160 & AugmentedConst<ApiType>;
72 /**76 /**
73 * Generic const77 * Generic const
74 **/78 **/
82 **/86 **/
83 [key: string]: Codec;87 [key: string]: Codec;
84 };88 };
89 evmContractHelpers: {
90 /**
91 * Address, under which magic contract will be available
92 **/
93 contractAddress: H160 & AugmentedConst<ApiType>;
94 /**
95 * Generic const
96 **/
97 [key: string]: Codec;
98 };
85 inflation: {99 inflation: {
86 /**100 /**
87 * Number of blocks that pass between treasury balance updates due to inflation101 * Number of blocks that pass between treasury balance updates due to inflation
231 **/245 **/
232 [key: string]: Codec;246 [key: string]: Codec;
233 };247 };
248 unique: {
249 /**
250 * Maximum admins per collection.
251 **/
252 collectionAdminsLimit: u32 & AugmentedConst<ApiType>;
253 /**
254 * Default FT collection limit.
255 **/
256 ftDefaultCollectionLimits: UpDataStructsCollectionLimits & AugmentedConst<ApiType>;
257 /**
258 * Maximal length of a collection description.
259 **/
260 maxCollectionDescriptionLength: u32 & AugmentedConst<ApiType>;
261 /**
262 * Maximal length of a collection name.
263 **/
264 maxCollectionNameLength: u32 & AugmentedConst<ApiType>;
265 /**
266 * Maximum size for all collection properties.
267 **/
268 maxCollectionPropertiesSize: u32 & AugmentedConst<ApiType>;
269 /**
270 * A maximum number of token properties.
271 **/
272 maxPropertiesPerItem: u32 & AugmentedConst<ApiType>;
273 /**
274 * Maximal length of a property key.
275 **/
276 maxPropertyKeyLength: u32 & AugmentedConst<ApiType>;
277 /**
278 * Maximal length of a property value.
279 **/
280 maxPropertyValueLength: u32 & AugmentedConst<ApiType>;
281 /**
282 * Maximal length of a token prefix.
283 **/
284 maxTokenPrefixLength: u32 & AugmentedConst<ApiType>;
285 /**
286 * Maximum size of all token properties.
287 **/
288 maxTokenPropertiesSize: u32 & AugmentedConst<ApiType>;
289 /**
290 * A maximum number of levels of depth in the token nesting tree.
291 **/
292 nestingBudget: u32 & AugmentedConst<ApiType>;
293 /**
294 * Default NFT collection limit.
295 **/
296 nftDefaultCollectionLimits: UpDataStructsCollectionLimits & AugmentedConst<ApiType>;
297 /**
298 * Default RFT collection limit.
299 **/
300 rftDefaultCollectionLimits: UpDataStructsCollectionLimits & AugmentedConst<ApiType>;
301 /**
302 * Generic const
303 **/
304 [key: string]: Codec;
305 };
234 vesting: {306 vesting: {
235 /**307 /**
236 * The minimum amount transferred to call `vested_transfer`.308 * The minimum amount transferred to call `vested_transfer`.