git.delta.rocks / unique-network / refs/commits / 64d0cdb0c53e

difftreelog

refac: rename bytes -> Bytes

Trubnikov Sergey2023-01-18parent: #7d542e4.patch.diff
in: master

9 files changed

modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
6767
68impl_abi_writeable!(&str, string);68impl_abi_writeable!(&str, string);
6969
70impl_abi_type!(bytes, bytes, true);70impl_abi_type!(Bytes, bytes, true);
7171
72impl AbiRead for bytes {72impl AbiRead for Bytes {
73 fn abi_read(reader: &mut AbiReader) -> Result<bytes> {73 fn abi_read(reader: &mut AbiReader) -> Result<Bytes> {
74 Ok(bytes(reader.bytes()?))74 Ok(Bytes(reader.bytes()?))
75 }75 }
76}76}
7777
78impl AbiWrite for bytes {78impl AbiWrite for Bytes {
79 fn abi_write(&self, writer: &mut AbiWriter) {79 fn abi_write(&self, writer: &mut AbiWriter) {
80 writer.bytes(self.0.as_slice())80 writer.bytes(self.0.as_slice())
81 }81 }
modifiedcrates/evm-coder/src/abi/test.rsdiffbeforeafterboth
273273
274#[test]274#[test]
275fn encode_decode_vec_tuple_string_bytes() {275fn encode_decode_vec_tuple_string_bytes() {
276 test_impl::<Vec<(String, bytes)>>(276 test_impl::<Vec<(String, Bytes)>>(
277 0xdeadbeef,277 0xdeadbeef,
278 vec![278 vec![
279 (279 (
280 "Test URI 0".to_string(),280 "Test URI 0".to_string(),
281 bytes(vec![281 Bytes(vec![
282 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,282 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
283 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,283 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
284 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,284 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
287 ),287 ),
288 (288 (
289 "Test URI 1".to_string(),289 "Test URI 1".to_string(),
290 bytes(vec![290 Bytes(vec![
291 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,291 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
292 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,292 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
293 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,293 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
294 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,294 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
295 ]),295 ]),
296 ),296 ),
297 ("Test URI 2".to_string(), bytes(vec![0x33, 0x33])),297 ("Test URI 2".to_string(), Bytes(vec![0x33, 0x33])),
298 ],298 ],
299 &hex!(299 &hex!(
300 "300 "
337// #[ignore = "reason"]337// #[ignore = "reason"]
338fn encode_decode_tuple0_tuple1_uint8_tuple1_string_bytes_tuple1_uint8_bytes() {338fn encode_decode_tuple0_tuple1_uint8_tuple1_string_bytes_tuple1_uint8_bytes() {
339 let int = 0xff;339 let int = 0xff;
340 let by = bytes(vec![0x11, 0x22, 0x33]);340 let by = Bytes(vec![0x11, 0x22, 0x33]);
341 let string = "some string".to_string();341 let string = "some string".to_string();
342342
343 test_impl::<((u8,), (String, bytes), (u8, bytes))>(343 test_impl::<((u8,), (String, Bytes), (u8, Bytes))>(
344 0xdeadbeef,344 0xdeadbeef,
345 ((int,), (string.clone(), by.clone()), (int, by)),345 ((int,), (string.clone(), by.clone()), (int, by)),
346 &hex!(346 &hex!(
485485
486#[test]486#[test]
487fn encode_decode_tuple0_tuple1_string_bytes() {487fn encode_decode_tuple0_tuple1_string_bytes() {
488 test_impl::<((String, bytes),)>(488 test_impl::<((String, Bytes),)>(
489 0xdeadbeef,489 0xdeadbeef,
490 (("some string".to_string(), bytes(vec![1, 2, 3])),),490 (("some string".to_string(), Bytes(vec![1, 2, 3])),),
491 &hex!(491 &hex!(
492 "492 "
493 deadbeef493 deadbeef
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
141 pub type String = ::std::string::String;141 pub type String = ::std::string::String;
142142
143 #[derive(Default, Debug, PartialEq, Eq, Clone)]143 #[derive(Default, Debug, PartialEq, Eq, Clone)]
144 pub struct bytes(pub Vec<u8>);144 pub struct Bytes(pub Vec<u8>);
145145
146 //#region Special types146 //#region Special types
147 /// Makes function payable147 /// Makes function payable
162 pub value: U256,162 pub value: U256,
163 }163 }
164164
165 impl From<Vec<u8>> for bytes {165 impl From<Vec<u8>> for Bytes {
166 fn from(src: Vec<u8>) -> Self {166 fn from(src: Vec<u8>) -> Self {
167 Self(src)167 Self(src)
168 }168 }
169 }169 }
170170
171 #[allow(clippy::from_over_into)]171 #[allow(clippy::from_over_into)]
172 impl Into<Vec<u8>> for bytes {172 impl Into<Vec<u8>> for Bytes {
173 fn into(self) -> Vec<u8> {173 fn into(self) -> Vec<u8> {
174 self.0174 self.0
175 }175 }
176 }176 }
177177
178 impl bytes {178 impl Bytes {
179 #[must_use]179 #[must_use]
180 pub fn len(&self) -> usize {180 pub fn len(&self) -> usize {
181 self.0.len()181 self.0.len()
modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
30 Bytes4 => "bytes4" true = "bytes4(0)",30 Bytes4 => "bytes4" true = "bytes4(0)",
31 H160 => "address" true = "0x0000000000000000000000000000000000000000",31 H160 => "address" true = "0x0000000000000000000000000000000000000000",
32 String => "string" false = "\"\"",32 String => "string" false = "\"\"",
33 bytes => "bytes" false = "hex\"\"",33 Bytes => "bytes" false = "hex\"\"",
34 bool => "bool" true = "false",34 bool => "bool" true = "false",
35}35}
3636
modifiedcrates/evm-coder/tests/abi_derive_generation.rsdiffbeforeafterboth
1mod test_struct {1mod test_struct {
2 use evm_coder_procedural::AbiCoder;2 use evm_coder_procedural::AbiCoder;
3 use evm_coder::types::bytes;3 use evm_coder::types::Bytes;
44
5 #[test]5 #[test]
6 fn empty_struct() {6 fn empty_struct() {
27 #[derive(AbiCoder, PartialEq, Debug)]27 #[derive(AbiCoder, PartialEq, Debug)]
28 struct TypeStruct2DynamicParam {28 struct TypeStruct2DynamicParam {
29 _a: String,29 _a: String,
30 _b: bytes,30 _b: Bytes,
31 }31 }
3232
33 #[derive(AbiCoder, PartialEq, Debug)]33 #[derive(AbiCoder, PartialEq, Debug)]
34 struct TypeStruct2MixedParam {34 struct TypeStruct2MixedParam {
35 _a: u8,35 _a: u8,
36 _b: bytes,36 _b: Bytes,
37 }37 }
3838
39 #[derive(AbiCoder, PartialEq, Debug)]39 #[derive(AbiCoder, PartialEq, Debug)]
236 struct TupleStruct2SimpleParam(u8, u32);236 struct TupleStruct2SimpleParam(u8, u32);
237237
238 #[derive(AbiCoder, PartialEq, Debug)]238 #[derive(AbiCoder, PartialEq, Debug)]
239 struct TupleStruct2DynamicParam(String, bytes);239 struct TupleStruct2DynamicParam(String, Bytes);
240240
241 #[derive(AbiCoder, PartialEq, Debug)]241 #[derive(AbiCoder, PartialEq, Debug)]
242 struct TupleStruct2MixedParam(u8, bytes);242 struct TupleStruct2MixedParam(u8, Bytes);
243243
244 #[derive(AbiCoder, PartialEq, Debug)]244 #[derive(AbiCoder, PartialEq, Debug)]
245 struct TupleStruct1DerivedSimpleParam(TupleStruct1SimpleParam);245 struct TupleStruct1DerivedSimpleParam(TupleStruct1SimpleParam);
562 #[test]562 #[test]
563 fn codec_struct_2_dynamic() {563 fn codec_struct_2_dynamic() {
564 let _a: String = "some string".into();564 let _a: String = "some string".into();
565 let _b: bytes = bytes(vec![0x11, 0x22, 0x33]);565 let _b: Bytes = Bytes(vec![0x11, 0x22, 0x33]);
566 test_impl::<(String, bytes), TupleStruct2DynamicParam, TypeStruct2DynamicParam>(566 test_impl::<(String, Bytes), TupleStruct2DynamicParam, TypeStruct2DynamicParam>(
567 (_a.clone(), _b.clone()),567 (_a.clone(), _b.clone()),
568 TupleStruct2DynamicParam(_a.clone(), _b.clone()),568 TupleStruct2DynamicParam(_a.clone(), _b.clone()),
569 TypeStruct2DynamicParam { _a, _b },569 TypeStruct2DynamicParam { _a, _b },
573 #[test]573 #[test]
574 fn codec_struct_2_mixed() {574 fn codec_struct_2_mixed() {
575 let _a: u8 = 0xff;575 let _a: u8 = 0xff;
576 let _b: bytes = bytes(vec![0x11, 0x22, 0x33]);576 let _b: Bytes = Bytes(vec![0x11, 0x22, 0x33]);
577 test_impl::<(u8, bytes), TupleStruct2MixedParam, TypeStruct2MixedParam>(577 test_impl::<(u8, Bytes), TupleStruct2MixedParam, TypeStruct2MixedParam>(
578 (_a.clone(), _b.clone()),578 (_a.clone(), _b.clone()),
579 TupleStruct2MixedParam(_a.clone(), _b.clone()),579 TupleStruct2MixedParam(_a.clone(), _b.clone()),
580 TypeStruct2MixedParam { _a, _b },580 TypeStruct2MixedParam { _a, _b },
605 #[test]605 #[test]
606 fn codec_struct_2_derived_dynamic() {606 fn codec_struct_2_derived_dynamic() {
607 let _a = "some string".to_string();607 let _a = "some string".to_string();
608 let _b = bytes(vec![0x11, 0x22, 0x33]);608 let _b = Bytes(vec![0x11, 0x22, 0x33]);
609 test_impl::<609 test_impl::<
610 ((String,), (String, bytes)),610 ((String,), (String, Bytes)),
611 TupleStruct2DerivedDynamicParam,611 TupleStruct2DerivedDynamicParam,
612 TypeStruct2DerivedDynamicParam,612 TypeStruct2DerivedDynamicParam,
613 >(613 >(
626 #[test]626 #[test]
627 fn codec_struct_3_derived_mixed() {627 fn codec_struct_3_derived_mixed() {
628 let int = 0xff;628 let int = 0xff;
629 let by = bytes(vec![0x11, 0x22, 0x33]);629 let by = Bytes(vec![0x11, 0x22, 0x33]);
630 let string = "some string".to_string();630 let string = "some string".to_string();
631 test_impl::<631 test_impl::<
632 ((u8,), (String, bytes), (u8, bytes)),632 ((u8,), (String, Bytes), (u8, Bytes)),
633 TupleStruct3DerivedMixedParam,633 TupleStruct3DerivedMixedParam,
634 TypeStruct3DerivedMixedParam,634 TypeStruct3DerivedMixedParam,
635 >(635 >(
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
94 /// @param value Propery value.94 /// @param value Propery value.
95 #[solidity(hide)]95 #[solidity(hide)]
96 #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]96 #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
97 fn set_collection_property(&mut self, caller: caller, key: String, value: bytes) -> Result<()> {97 fn set_collection_property(&mut self, caller: caller, key: String, value: Bytes) -> Result<()> {
98 let caller = T::CrossAccountId::from_eth(caller);98 let caller = T::CrossAccountId::from_eth(caller);
99 let key = <Vec<u8>>::from(key)99 let key = <Vec<u8>>::from(key)
100 .try_into()100 .try_into()
164 ///164 ///
165 /// @param key Property key.165 /// @param key Property key.
166 /// @return bytes The property corresponding to the key.166 /// @return bytes The property corresponding to the key.
167 fn collection_property(&self, key: String) -> Result<bytes> {167 fn collection_property(&self, key: String) -> Result<Bytes> {
168 let key = <Vec<u8>>::from(key)168 let key = <Vec<u8>>::from(key)
169 .try_into()169 .try_into()
170 .map_err(|_| "key too large")?;170 .map_err(|_| "key too large")?;
171171
172 let props = CollectionProperties::<T>::get(self.id);172 let props = CollectionProperties::<T>::get(self.id);
173 let prop = props.get(&key).ok_or("key not found")?;173 let prop = props.get(&key).ok_or("key not found")?;
174174
175 Ok(bytes(prop.to_vec()))175 Ok(Bytes(prop.to_vec()))
176 }176 }
177177
178 /// Get collection properties.178 /// Get collection properties.
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
119#[derive(Debug, Default, AbiCoder)]119#[derive(Debug, Default, AbiCoder)]
120pub struct Property {120pub struct Property {
121 key: evm_coder::types::String,121 key: evm_coder::types::String,
122 value: evm_coder::types::bytes,122 value: evm_coder::types::Bytes,
123}123}
124124
125impl TryFrom<up_data_structs::Property> for Property {125impl TryFrom<up_data_structs::Property> for Property {
128 fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {128 fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {
129 let key = evm_coder::types::String::from_utf8(from.key.into())129 let key = evm_coder::types::String::from_utf8(from.key.into())
130 .map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;130 .map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;
131 let value = evm_coder::types::bytes(from.value.to_vec());131 let value = evm_coder::types::Bytes(from.value.to_vec());
132 Ok(Property { key, value })132 Ok(Property { key, value })
133 }133 }
134}134}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
124 caller: caller,124 caller: caller,
125 token_id: U256,125 token_id: U256,
126 key: String,126 key: String,
127 value: bytes,127 value: Bytes,
128 ) -> Result<()> {128 ) -> Result<()> {
129 let caller = T::CrossAccountId::from_eth(caller);129 let caller = T::CrossAccountId::from_eth(caller);
130 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;130 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
239 /// @param tokenId ID of the token.239 /// @param tokenId ID of the token.
240 /// @param key Property key.240 /// @param key Property key.
241 /// @return Property value bytes241 /// @return Property value bytes
242 fn property(&self, token_id: U256, key: String) -> Result<bytes> {242 fn property(&self, token_id: U256, key: String) -> Result<Bytes> {
243 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;243 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
244 let key = <Vec<u8>>::from(key)244 let key = <Vec<u8>>::from(key)
245 .try_into()245 .try_into()
422 _from: Address,422 _from: Address,
423 _to: Address,423 _to: Address,
424 _token_id: U256,424 _token_id: U256,
425 _data: bytes,425 _data: Bytes,
426 ) -> Result<()> {426 ) -> Result<()> {
427 // TODO: Not implemetable427 // TODO: Not implemetable
428 Err("not implemented".into())428 Err("not implemented".into())
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
127 caller: caller,127 caller: caller,
128 token_id: U256,128 token_id: U256,
129 key: String,129 key: String,
130 value: bytes,130 value: Bytes,
131 ) -> Result<()> {131 ) -> Result<()> {
132 let caller = T::CrossAccountId::from_eth(caller);132 let caller = T::CrossAccountId::from_eth(caller);
133 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;133 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
242 /// @param tokenId ID of the token.242 /// @param tokenId ID of the token.
243 /// @param key Property key.243 /// @param key Property key.
244 /// @return Property value bytes244 /// @return Property value bytes
245 fn property(&self, token_id: U256, key: String) -> Result<bytes> {245 fn property(&self, token_id: U256, key: String) -> Result<Bytes> {
246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
247 let key = <Vec<u8>>::from(key)247 let key = <Vec<u8>>::from(key)
248 .try_into()248 .try_into()
423 _from: Address,423 _from: Address,
424 _to: Address,424 _to: Address,
425 _token_id: U256,425 _token_id: U256,
426 _data: bytes,426 _data: Bytes,
427 ) -> Result<()> {427 ) -> Result<()> {
428 // TODO: Not implemetable428 // TODO: Not implemetable
429 Err("not implemented".into())429 Err("not implemented".into())