git.delta.rocks / unique-network / refs/commits / ce58d45f1913

difftreelog

misc: Use PascalCase in OptionGeneric name

Trubnikov Sergey2023-01-11parent: #3006d97.patch.diff
in: master

17 files changed

modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
after · crates/evm-coder/src/solidity/impls.rs
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 void {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		const option_name: &str = "Option";145		const option_name_len: usize = option_name.len();146147		let to_upper_case_generic_type_name = |s: &mut String| {148			let c = s149				.chars()150				.skip(option_name_len)151				.next()152				.expect("Ethereum name must be presented");153			if c.is_ascii_uppercase() {154				return;155			}156			let uc = String::from(c.to_ascii_uppercase());157			s.replace_range(option_name_len..option_name_len + 1, uc.as_str());158		};159160		let mut solidity_name = option_name.to_string();161		T::solidity_name(&mut solidity_name, tc);162		to_upper_case_generic_type_name(&mut solidity_name);163164		let interface = super::SolidityStruct {165			docs: &[" Optional value"],166			name: solidity_name.as_str(),167			fields: (168				super::SolidityStructField::<bool> {169					docs: &[" Shows the status of accessibility of value"],170					name: "status",171					ty: ::core::marker::PhantomData,172				},173				super::SolidityStructField::<T> {174					docs: &[" Actual value if `status` is true"],175					name: "value",176					ty: ::core::marker::PhantomData,177				},178			),179		};180181		let mut out = String::new();182		let _ = interface.format(&mut out, tc);183		tc.collect(out);184185		solidity_name.to_string()186	}187}
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -96,11 +96,11 @@
 	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
 	/// @dev EVM selector for this function is: 0x766c4f37,
 	///  or in textual repr: sponsor(address)
-	function sponsor(address contractAddress) public view returns (Option_CrossAddress memory) {
+	function sponsor(address contractAddress) public view returns (OptionCrossAddress memory) {
 		require(false, stub_error);
 		contractAddress;
 		dummy;
-		return Option_CrossAddress(false, CrossAddress(0x0000000000000000000000000000000000000000, 0));
+		return OptionCrossAddress(false, CrossAddress(0x0000000000000000000000000000000000000000, 0));
 	}
 
 	/// Check tat contract has confirmed sponsor.
@@ -282,7 +282,7 @@
 }
 
 /// Optional value
-struct Option_CrossAddress {
+struct OptionCrossAddress {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -466,11 +466,11 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	Option_uint256 value;
+	OptionUint256 value;
 }
 
 /// Optional value
-struct Option_uint256 {
+struct OptionUint256 {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -608,11 +608,11 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	Option_uint256 value;
+	OptionUint256 value;
 }
 
 /// Optional value
-struct Option_uint256 {
+struct OptionUint256 {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -608,11 +608,11 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	Option_uint256 value;
+	OptionUint256 value;
 }
 
 /// Optional value
-struct Option_uint256 {
+struct OptionUint256 {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedtests/src/eth/abi/contractHelpers.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/contractHelpers.json
+++ b/tests/src/eth/abi/contractHelpers.json
@@ -238,7 +238,7 @@
             "type": "tuple"
           }
         ],
-        "internalType": "struct Option_CrossAddress",
+        "internalType": "struct OptionCrossAddress",
         "name": "",
         "type": "tuple"
       }
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/fungible.json
+++ b/tests/src/eth/abi/fungible.json
@@ -222,7 +222,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct Option_uint256",
+            "internalType": "struct OptionUint256",
             "name": "value",
             "type": "tuple"
           }
@@ -508,7 +508,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct Option_uint256",
+            "internalType": "struct OptionUint256",
             "name": "value",
             "type": "tuple"
           }
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -252,7 +252,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct Option_uint256",
+            "internalType": "struct OptionUint256",
             "name": "value",
             "type": "tuple"
           }
@@ -670,7 +670,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct Option_uint256",
+            "internalType": "struct OptionUint256",
             "name": "value",
             "type": "tuple"
           }
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -234,7 +234,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct Option_uint256",
+            "internalType": "struct OptionUint256",
             "name": "value",
             "type": "tuple"
           }
@@ -652,7 +652,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct Option_uint256",
+            "internalType": "struct OptionUint256",
             "name": "value",
             "type": "tuple"
           }
modifiedtests/src/eth/api/ContractHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -69,7 +69,7 @@
 	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
 	/// @dev EVM selector for this function is: 0x766c4f37,
 	///  or in textual repr: sponsor(address)
-	function sponsor(address contractAddress) external view returns (Option_CrossAddress memory);
+	function sponsor(address contractAddress) external view returns (OptionCrossAddress memory);
 
 	/// Check tat contract has confirmed sponsor.
 	///
@@ -182,7 +182,7 @@
 }
 
 /// Optional value
-struct Option_CrossAddress {
+struct OptionCrossAddress {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -308,11 +308,11 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	Option_uint256 value;
+	OptionUint256 value;
 }
 
 /// Optional value
-struct Option_uint256 {
+struct OptionUint256 {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -408,11 +408,11 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	Option_uint256 value;
+	OptionUint256 value;
 }
 
 /// Optional value
-struct Option_uint256 {
+struct OptionUint256 {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -408,11 +408,11 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	Option_uint256 value;
+	OptionUint256 value;
 }
 
 /// Optional value
-struct Option_uint256 {
+struct OptionUint256 {
 	/// Shows the status of accessibility of value
 	bool status;
 	/// Actual value if `status` is true