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

difftreelog

feat impls SolidityTypeName & SolidityStructTy for Option<T>

Trubnikov Sergey2023-01-10parent: #50ff12a.patch.diff
in: master

2 files changed

modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
122impl_tuples! {A B C D E F G H I}122impl_tuples! {A B C D E F G H I}
123impl_tuples! {A B C D E F G H I J}123impl_tuples! {A B C D E F G H I J}
124
125//----- 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 false
132 }
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}
141
142impl<T: SolidityTypeName> super::SolidityStructTy for Option<T> {
143 fn generate_solidity_interface(tc: &TypeCollector) -> String {
144 // use super::solidity::*;
145
146 let mut solidity_name = "Option_".to_string();
147 T::solidity_name(&mut solidity_name, tc);
148 let solidity_name_str = solidity_name.as_str();
149 let interface = super::SolidityStruct {
150 docs: &[" Optional value"],
151 name: solidity_name_str,
152 fields: (
153 super::SolidityStructField::<bool> {
154 docs: &[" Shows the status of accessibility of value"],
155 name: "status",
156 ty: ::core::marker::PhantomData,
157 },
158 super::SolidityStructField::<T> {
159 docs: &[" Actual value if `status` is true"],
160 name: "value",
161 ty: ::core::marker::PhantomData,
162 },
163 ),
164 };
165
166 let mut out = String::new();
167 let _ = interface.format(&mut out, tc);
168 tc.collect(out);
169
170 solidity_name.to_string()
171 }
172}
124173
modifiedcrates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity/mod.rs
+++ b/crates/evm-coder/src/solidity/mod.rs
@@ -456,13 +456,13 @@
 		Ok(())
 	}
 }
-pub struct SolidityStruct<F> {
-	pub docs: &'static [&'static str],
+pub struct SolidityStruct<'a, F> {
+	pub docs: &'a [&'a str],
 	// pub generics:
-	pub name: &'static str,
+	pub name: &'a str,
 	pub fields: F,
 }
-impl<F> SolidityStruct<F>
+impl<F> SolidityStruct<'_, F>
 where
 	F: SolidityItems,
 {