difftreelog
refac: rename bytes -> Bytes
in: master
9 files changed
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -67,15 +67,15 @@
impl_abi_writeable!(&str, string);
-impl_abi_type!(bytes, bytes, true);
+impl_abi_type!(Bytes, bytes, true);
-impl AbiRead for bytes {
- fn abi_read(reader: &mut AbiReader) -> Result<bytes> {
- Ok(bytes(reader.bytes()?))
+impl AbiRead for Bytes {
+ fn abi_read(reader: &mut AbiReader) -> Result<Bytes> {
+ Ok(Bytes(reader.bytes()?))
}
}
-impl AbiWrite for bytes {
+impl AbiWrite for Bytes {
fn abi_write(&self, writer: &mut AbiWriter) {
writer.bytes(self.0.as_slice())
}
crates/evm-coder/src/abi/test.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/test.rs
+++ b/crates/evm-coder/src/abi/test.rs
@@ -273,12 +273,12 @@
#[test]
fn encode_decode_vec_tuple_string_bytes() {
- test_impl::<Vec<(String, bytes)>>(
+ test_impl::<Vec<(String, Bytes)>>(
0xdeadbeef,
vec![
(
"Test URI 0".to_string(),
- bytes(vec![
+ Bytes(vec![
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
@@ -287,14 +287,14 @@
),
(
"Test URI 1".to_string(),
- bytes(vec![
+ Bytes(vec![
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
]),
),
- ("Test URI 2".to_string(), bytes(vec![0x33, 0x33])),
+ ("Test URI 2".to_string(), Bytes(vec![0x33, 0x33])),
],
&hex!(
"
@@ -337,10 +337,10 @@
// #[ignore = "reason"]
fn encode_decode_tuple0_tuple1_uint8_tuple1_string_bytes_tuple1_uint8_bytes() {
let int = 0xff;
- let by = bytes(vec![0x11, 0x22, 0x33]);
+ let by = Bytes(vec![0x11, 0x22, 0x33]);
let string = "some string".to_string();
- test_impl::<((u8,), (String, bytes), (u8, bytes))>(
+ test_impl::<((u8,), (String, Bytes), (u8, Bytes))>(
0xdeadbeef,
((int,), (string.clone(), by.clone()), (int, by)),
&hex!(
@@ -485,9 +485,9 @@
#[test]
fn encode_decode_tuple0_tuple1_string_bytes() {
- test_impl::<((String, bytes),)>(
+ test_impl::<((String, Bytes),)>(
0xdeadbeef,
- (("some string".to_string(), bytes(vec![1, 2, 3])),),
+ (("some string".to_string(), Bytes(vec![1, 2, 3])),),
&hex!(
"
deadbeef
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -141,7 +141,7 @@
pub type String = ::std::string::String;
#[derive(Default, Debug, PartialEq, Eq, Clone)]
- pub struct bytes(pub Vec<u8>);
+ pub struct Bytes(pub Vec<u8>);
//#region Special types
/// Makes function payable
@@ -162,20 +162,20 @@
pub value: U256,
}
- impl From<Vec<u8>> for bytes {
+ impl From<Vec<u8>> for Bytes {
fn from(src: Vec<u8>) -> Self {
Self(src)
}
}
#[allow(clippy::from_over_into)]
- impl Into<Vec<u8>> for bytes {
+ impl Into<Vec<u8>> for Bytes {
fn into(self) -> Vec<u8> {
self.0
}
}
- impl bytes {
+ impl Bytes {
#[must_use]
pub fn len(&self) -> usize {
self.0.len()
crates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth1use super::{TypeCollector, SolidityTypeName, SolidityTupleTy};2use crate::{sealed, types::*};3use core::fmt;4use primitive_types::{U256, H160};56macro_rules! solidity_type_name {7 ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => {8 $(9 impl SolidityTypeName for $ty {10 fn solidity_name(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {11 write!(writer, $name)12 }13 fn is_simple() -> bool {14 $simple15 }16 fn solidity_default(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {17 write!(writer, $default)18 }19 }20 )*21 };22}2324solidity_type_name! {25 u8 => "uint8" true = "0",26 u32 => "uint32" true = "0",27 u64 => "uint64" true = "0",28 u128 => "uint128" true = "0",29 U256 => "uint256" true = "0",30 Bytes4 => "bytes4" true = "bytes4(0)",31 H160 => "address" true = "0x0000000000000000000000000000000000000000",32 String => "string" false = "\"\"",33 bytes => "bytes" false = "hex\"\"",34 bool => "bool" true = "false",35}3637impl SolidityTypeName for () {38 fn solidity_name(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {39 Ok(())40 }41 fn is_simple() -> bool {42 true43 }44 fn solidity_default(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {45 Ok(())46 }47 fn is_void() -> bool {48 true49 }50}5152impl<T: SolidityTypeName + sealed::CanBePlacedInVec> SolidityTypeName for Vec<T> {53 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {54 T::solidity_name(writer, tc)?;55 write!(writer, "[]")56 }57 fn is_simple() -> bool {58 false59 }60 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {61 write!(writer, "new ")?;62 T::solidity_name(writer, tc)?;63 write!(writer, "[](0)")64 }65}6667macro_rules! count {68 () => (0usize);69 ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));70}7172macro_rules! impl_tuples {73 ($($ident:ident)+) => {74 impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {75 fn fields(tc: &TypeCollector) -> Vec<String> {76 let mut collected = Vec::with_capacity(Self::len());77 $({78 let mut out = String::new();79 $ident::solidity_name(&mut out, tc).expect("no fmt error");80 collected.push(out);81 })*;82 collected83 }8485 fn len() -> usize {86 count!($($ident)*)87 }88 }89 impl<$($ident: SolidityTypeName + 'static),+> SolidityTypeName for ($($ident,)+) {90 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {91 write!(writer, "{}", tc.collect_tuple::<Self>())92 }93 fn is_simple() -> bool {94 false95 }96 #[allow(unused_assignments)]97 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {98 write!(writer, "{}(", tc.collect_tuple::<Self>())?;99 let mut first = true;100 $(101 if !first {102 write!(writer, ",")?;103 } else {104 first = false;105 }106 <$ident>::solidity_default(writer, tc)?;107 )*108 write!(writer, ")")109 }110 }111 };112}113114impl_tuples! {A}115impl_tuples! {A B}116impl_tuples! {A B C}117impl_tuples! {A B C D}118impl_tuples! {A B C D E}119impl_tuples! {A B C D E F}120impl_tuples! {A B C D E F G}121impl_tuples! {A B C D E F G H}122impl_tuples! {A B C D E F G H I}123impl_tuples! {A B C D E F G H I J}124125//----- impls for Option -----126impl<T: SolidityTypeName + 'static> SolidityTypeName for Option<T> {127 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {128 write!(writer, "{}", tc.collect_struct::<Self>())129 }130 fn is_simple() -> bool {131 false132 }133 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {134 write!(writer, "{}(", tc.collect_struct::<Self>())?;135 bool::solidity_default(writer, tc)?;136 write!(writer, ", ");137 T::solidity_default(writer, tc)?;138 write!(writer, ")")139 }140}141142impl<T: SolidityTypeName> super::SolidityStructTy for Option<T> {143 fn generate_solidity_interface(tc: &TypeCollector) -> String {144 let mut solidity_name = "Option".to_string();145 let mut generic_name = String::new();146 T::solidity_name(&mut generic_name, tc);147 solidity_name.push(148 generic_name149 .chars()150 .next()151 .expect("Generic name is empty")152 .to_ascii_uppercase(),153 );154 solidity_name.push_str(&generic_name[1..]);155156 let interface = super::SolidityStruct {157 docs: &[" Optional value"],158 name: solidity_name.as_str(),159 fields: (160 super::SolidityStructField::<bool> {161 docs: &[" Shows the status of accessibility of value"],162 name: "status",163 ty: ::core::marker::PhantomData,164 },165 super::SolidityStructField::<T> {166 docs: &[" Actual value if `status` is true"],167 name: "value",168 ty: ::core::marker::PhantomData,169 },170 ),171 };172173 let mut out = String::new();174 let _ = interface.format(&mut out, tc);175 tc.collect(out);176177 solidity_name.to_string()178 }179}1use super::{TypeCollector, SolidityTypeName, SolidityTupleTy};2use crate::{sealed, types::*};3use core::fmt;4use primitive_types::{U256, H160};56macro_rules! solidity_type_name {7 ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => {8 $(9 impl SolidityTypeName for $ty {10 fn solidity_name(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {11 write!(writer, $name)12 }13 fn is_simple() -> bool {14 $simple15 }16 fn solidity_default(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {17 write!(writer, $default)18 }19 }20 )*21 };22}2324solidity_type_name! {25 u8 => "uint8" true = "0",26 u32 => "uint32" true = "0",27 u64 => "uint64" true = "0",28 u128 => "uint128" true = "0",29 U256 => "uint256" true = "0",30 Bytes4 => "bytes4" true = "bytes4(0)",31 H160 => "address" true = "0x0000000000000000000000000000000000000000",32 String => "string" false = "\"\"",33 Bytes => "bytes" false = "hex\"\"",34 bool => "bool" true = "false",35}3637impl SolidityTypeName for () {38 fn solidity_name(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {39 Ok(())40 }41 fn is_simple() -> bool {42 true43 }44 fn solidity_default(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {45 Ok(())46 }47 fn is_void() -> bool {48 true49 }50}5152impl<T: SolidityTypeName + sealed::CanBePlacedInVec> SolidityTypeName for Vec<T> {53 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {54 T::solidity_name(writer, tc)?;55 write!(writer, "[]")56 }57 fn is_simple() -> bool {58 false59 }60 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {61 write!(writer, "new ")?;62 T::solidity_name(writer, tc)?;63 write!(writer, "[](0)")64 }65}6667macro_rules! count {68 () => (0usize);69 ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));70}7172macro_rules! impl_tuples {73 ($($ident:ident)+) => {74 impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {75 fn fields(tc: &TypeCollector) -> Vec<String> {76 let mut collected = Vec::with_capacity(Self::len());77 $({78 let mut out = String::new();79 $ident::solidity_name(&mut out, tc).expect("no fmt error");80 collected.push(out);81 })*;82 collected83 }8485 fn len() -> usize {86 count!($($ident)*)87 }88 }89 impl<$($ident: SolidityTypeName + 'static),+> SolidityTypeName for ($($ident,)+) {90 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {91 write!(writer, "{}", tc.collect_tuple::<Self>())92 }93 fn is_simple() -> bool {94 false95 }96 #[allow(unused_assignments)]97 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {98 write!(writer, "{}(", tc.collect_tuple::<Self>())?;99 let mut first = true;100 $(101 if !first {102 write!(writer, ",")?;103 } else {104 first = false;105 }106 <$ident>::solidity_default(writer, tc)?;107 )*108 write!(writer, ")")109 }110 }111 };112}113114impl_tuples! {A}115impl_tuples! {A B}116impl_tuples! {A B C}117impl_tuples! {A B C D}118impl_tuples! {A B C D E}119impl_tuples! {A B C D E F}120impl_tuples! {A B C D E F G}121impl_tuples! {A B C D E F G H}122impl_tuples! {A B C D E F G H I}123impl_tuples! {A B C D E F G H I J}124125//----- impls for Option -----126impl<T: SolidityTypeName + 'static> SolidityTypeName for Option<T> {127 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {128 write!(writer, "{}", tc.collect_struct::<Self>())129 }130 fn is_simple() -> bool {131 false132 }133 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {134 write!(writer, "{}(", tc.collect_struct::<Self>())?;135 bool::solidity_default(writer, tc)?;136 write!(writer, ", ");137 T::solidity_default(writer, tc)?;138 write!(writer, ")")139 }140}141142impl<T: SolidityTypeName> super::SolidityStructTy for Option<T> {143 fn generate_solidity_interface(tc: &TypeCollector) -> String {144 let mut solidity_name = "Option".to_string();145 let mut generic_name = String::new();146 T::solidity_name(&mut generic_name, tc);147 solidity_name.push(148 generic_name149 .chars()150 .next()151 .expect("Generic name is empty")152 .to_ascii_uppercase(),153 );154 solidity_name.push_str(&generic_name[1..]);155156 let interface = super::SolidityStruct {157 docs: &[" Optional value"],158 name: solidity_name.as_str(),159 fields: (160 super::SolidityStructField::<bool> {161 docs: &[" Shows the status of accessibility of value"],162 name: "status",163 ty: ::core::marker::PhantomData,164 },165 super::SolidityStructField::<T> {166 docs: &[" Actual value if `status` is true"],167 name: "value",168 ty: ::core::marker::PhantomData,169 },170 ),171 };172173 let mut out = String::new();174 let _ = interface.format(&mut out, tc);175 tc.collect(out);176177 solidity_name.to_string()178 }179}crates/evm-coder/tests/abi_derive_generation.rsdiffbeforeafterboth--- a/crates/evm-coder/tests/abi_derive_generation.rs
+++ b/crates/evm-coder/tests/abi_derive_generation.rs
@@ -1,6 +1,6 @@
mod test_struct {
use evm_coder_procedural::AbiCoder;
- use evm_coder::types::bytes;
+ use evm_coder::types::Bytes;
#[test]
fn empty_struct() {
@@ -27,13 +27,13 @@
#[derive(AbiCoder, PartialEq, Debug)]
struct TypeStruct2DynamicParam {
_a: String,
- _b: bytes,
+ _b: Bytes,
}
#[derive(AbiCoder, PartialEq, Debug)]
struct TypeStruct2MixedParam {
_a: u8,
- _b: bytes,
+ _b: Bytes,
}
#[derive(AbiCoder, PartialEq, Debug)]
@@ -236,10 +236,10 @@
struct TupleStruct2SimpleParam(u8, u32);
#[derive(AbiCoder, PartialEq, Debug)]
- struct TupleStruct2DynamicParam(String, bytes);
+ struct TupleStruct2DynamicParam(String, Bytes);
#[derive(AbiCoder, PartialEq, Debug)]
- struct TupleStruct2MixedParam(u8, bytes);
+ struct TupleStruct2MixedParam(u8, Bytes);
#[derive(AbiCoder, PartialEq, Debug)]
struct TupleStruct1DerivedSimpleParam(TupleStruct1SimpleParam);
@@ -562,8 +562,8 @@
#[test]
fn codec_struct_2_dynamic() {
let _a: String = "some string".into();
- let _b: bytes = bytes(vec![0x11, 0x22, 0x33]);
- test_impl::<(String, bytes), TupleStruct2DynamicParam, TypeStruct2DynamicParam>(
+ let _b: Bytes = Bytes(vec![0x11, 0x22, 0x33]);
+ test_impl::<(String, Bytes), TupleStruct2DynamicParam, TypeStruct2DynamicParam>(
(_a.clone(), _b.clone()),
TupleStruct2DynamicParam(_a.clone(), _b.clone()),
TypeStruct2DynamicParam { _a, _b },
@@ -573,8 +573,8 @@
#[test]
fn codec_struct_2_mixed() {
let _a: u8 = 0xff;
- let _b: bytes = bytes(vec![0x11, 0x22, 0x33]);
- test_impl::<(u8, bytes), TupleStruct2MixedParam, TypeStruct2MixedParam>(
+ let _b: Bytes = Bytes(vec![0x11, 0x22, 0x33]);
+ test_impl::<(u8, Bytes), TupleStruct2MixedParam, TypeStruct2MixedParam>(
(_a.clone(), _b.clone()),
TupleStruct2MixedParam(_a.clone(), _b.clone()),
TypeStruct2MixedParam { _a, _b },
@@ -605,9 +605,9 @@
#[test]
fn codec_struct_2_derived_dynamic() {
let _a = "some string".to_string();
- let _b = bytes(vec![0x11, 0x22, 0x33]);
+ let _b = Bytes(vec![0x11, 0x22, 0x33]);
test_impl::<
- ((String,), (String, bytes)),
+ ((String,), (String, Bytes)),
TupleStruct2DerivedDynamicParam,
TypeStruct2DerivedDynamicParam,
>(
@@ -626,10 +626,10 @@
#[test]
fn codec_struct_3_derived_mixed() {
let int = 0xff;
- let by = bytes(vec![0x11, 0x22, 0x33]);
+ let by = Bytes(vec![0x11, 0x22, 0x33]);
let string = "some string".to_string();
test_impl::<
- ((u8,), (String, bytes), (u8, bytes)),
+ ((u8,), (String, Bytes), (u8, Bytes)),
TupleStruct3DerivedMixedParam,
TypeStruct3DerivedMixedParam,
>(
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -94,7 +94,7 @@
/// @param value Propery value.
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
- fn set_collection_property(&mut self, caller: caller, key: String, value: bytes) -> Result<()> {
+ fn set_collection_property(&mut self, caller: caller, key: String, value: Bytes) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let key = <Vec<u8>>::from(key)
.try_into()
@@ -164,7 +164,7 @@
///
/// @param key Property key.
/// @return bytes The property corresponding to the key.
- fn collection_property(&self, key: String) -> Result<bytes> {
+ fn collection_property(&self, key: String) -> Result<Bytes> {
let key = <Vec<u8>>::from(key)
.try_into()
.map_err(|_| "key too large")?;
@@ -172,7 +172,7 @@
let props = CollectionProperties::<T>::get(self.id);
let prop = props.get(&key).ok_or("key not found")?;
- Ok(bytes(prop.to_vec()))
+ Ok(Bytes(prop.to_vec()))
}
/// Get collection properties.
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -119,7 +119,7 @@
#[derive(Debug, Default, AbiCoder)]
pub struct Property {
key: evm_coder::types::String,
- value: evm_coder::types::bytes,
+ value: evm_coder::types::Bytes,
}
impl TryFrom<up_data_structs::Property> for Property {
@@ -128,7 +128,7 @@
fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {
let key = evm_coder::types::String::from_utf8(from.key.into())
.map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;
- let value = evm_coder::types::bytes(from.value.to_vec());
+ let value = evm_coder::types::Bytes(from.value.to_vec());
Ok(Property { key, value })
}
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -124,7 +124,7 @@
caller: caller,
token_id: U256,
key: String,
- value: bytes,
+ value: Bytes,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -239,7 +239,7 @@
/// @param tokenId ID of the token.
/// @param key Property key.
/// @return Property value bytes
- fn property(&self, token_id: U256, key: String) -> Result<bytes> {
+ fn property(&self, token_id: U256, key: String) -> Result<Bytes> {
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
let key = <Vec<u8>>::from(key)
.try_into()
@@ -422,7 +422,7 @@
_from: Address,
_to: Address,
_token_id: U256,
- _data: bytes,
+ _data: Bytes,
) -> Result<()> {
// TODO: Not implemetable
Err("not implemented".into())
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -127,7 +127,7 @@
caller: caller,
token_id: U256,
key: String,
- value: bytes,
+ value: Bytes,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -242,7 +242,7 @@
/// @param tokenId ID of the token.
/// @param key Property key.
/// @return Property value bytes
- fn property(&self, token_id: U256, key: String) -> Result<bytes> {
+ fn property(&self, token_id: U256, key: String) -> Result<Bytes> {
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
let key = <Vec<u8>>::from(key)
.try_into()
@@ -423,7 +423,7 @@
_from: Address,
_to: Address,
_token_id: U256,
- _data: bytes,
+ _data: Bytes,
) -> Result<()> {
// TODO: Not implemetable
Err("not implemented".into())