@@ -7,8 +7,11 @@ use std::num::{
77 ParseIntError ,
88} ;
99
10+ use crate :: FunctionAttributes ;
1011use num_bigint:: BigInt ;
1112
13+ const ADDRESS_BYTE_LENGTH : usize = 20 ;
14+
1215pub fn u256_max ( ) -> BigInt {
1316 BigInt :: from ( 2 ) . pow ( 256 ) - 1
1417}
@@ -99,6 +102,7 @@ pub enum Type {
99102 Map ( Map ) ,
100103 Tuple ( Tuple ) ,
101104 String ( FeString ) ,
105+ Contract ( Contract ) ,
102106}
103107
104108#[ derive( Clone , Debug , PartialEq , PartialOrd , Ord , Eq ) ]
@@ -107,6 +111,7 @@ pub enum FixedSize {
107111 Array ( Array ) ,
108112 Tuple ( Tuple ) ,
109113 String ( FeString ) ,
114+ Contract ( Contract ) ,
110115}
111116
112117#[ derive( Clone , Debug , PartialEq , PartialOrd , Ord , Eq ) ]
@@ -157,6 +162,12 @@ pub struct FeString {
157162 pub max_size : usize ,
158163}
159164
165+ #[ derive( Clone , Debug , PartialEq , PartialOrd , Ord , Eq ) ]
166+ pub struct Contract {
167+ pub name : String ,
168+ pub functions : Vec < FunctionAttributes > ,
169+ }
170+
160171impl TryFrom < & str > for FeString {
161172 type Error = String ;
162173
@@ -246,6 +257,7 @@ impl From<FixedSize> for Type {
246257 FixedSize :: Base ( base) => Type :: Base ( base) ,
247258 FixedSize :: Tuple ( tuple) => Type :: Tuple ( tuple) ,
248259 FixedSize :: String ( string) => Type :: String ( string) ,
260+ FixedSize :: Contract ( contract) => Type :: Contract ( contract) ,
249261 }
250262 }
251263}
@@ -257,6 +269,7 @@ impl FeSized for FixedSize {
257269 FixedSize :: Array ( array) => array. size ( ) ,
258270 FixedSize :: Tuple ( tuple) => tuple. size ( ) ,
259271 FixedSize :: String ( string) => string. size ( ) ,
272+ FixedSize :: Contract ( contract) => contract. size ( ) ,
260273 }
261274 }
262275}
@@ -287,6 +300,7 @@ impl AbiEncoding for FixedSize {
287300 FixedSize :: Base ( base) => base. abi_name ( ) ,
288301 FixedSize :: Tuple ( tuple) => tuple. abi_name ( ) ,
289302 FixedSize :: String ( string) => string. abi_name ( ) ,
303+ FixedSize :: Contract ( contract) => contract. abi_name ( ) ,
290304 }
291305 }
292306
@@ -296,6 +310,7 @@ impl AbiEncoding for FixedSize {
296310 FixedSize :: Base ( base) => base. abi_safe_name ( ) ,
297311 FixedSize :: Tuple ( tuple) => tuple. abi_safe_name ( ) ,
298312 FixedSize :: String ( string) => string. abi_safe_name ( ) ,
313+ FixedSize :: Contract ( contract) => contract. abi_safe_name ( ) ,
299314 }
300315 }
301316
@@ -305,6 +320,7 @@ impl AbiEncoding for FixedSize {
305320 FixedSize :: Array ( array) => array. abi_type ( ) ,
306321 FixedSize :: Tuple ( tuple) => tuple. abi_type ( ) ,
307322 FixedSize :: String ( string) => string. abi_type ( ) ,
323+ FixedSize :: Contract ( contract) => contract. abi_type ( ) ,
308324 }
309325 }
310326}
@@ -333,6 +349,7 @@ impl TryFrom<Type> for FixedSize {
333349 Type :: Tuple ( tuple) => Ok ( FixedSize :: Tuple ( tuple) ) ,
334350 Type :: String ( string) => Ok ( FixedSize :: String ( string) ) ,
335351 Type :: Map ( _) => Err ( SemanticError :: type_error ( ) ) ,
352+ Type :: Contract ( contract) => Ok ( FixedSize :: Contract ( contract) ) ,
336353 }
337354 }
338355}
@@ -343,7 +360,7 @@ impl FeSized for Base {
343360 Base :: Numeric ( integer) => integer. size ( ) ,
344361 Base :: Bool => 1 ,
345362 Base :: Byte => 1 ,
346- Base :: Address => 20 ,
363+ Base :: Address => ADDRESS_BYTE_LENGTH ,
347364 }
348365 }
349366}
@@ -457,7 +474,7 @@ impl AbiEncoding for Base {
457474 } ,
458475 Base :: Address => AbiType :: Uint {
459476 size : AbiUintSize {
460- data_size : 20 ,
477+ data_size : ADDRESS_BYTE_LENGTH ,
461478 padded_size : 32 ,
462479 } ,
463480 } ,
@@ -568,17 +585,31 @@ impl AbiEncoding for FeString {
568585 }
569586}
570587
588+ impl FeSized for Contract {
589+ fn size ( & self ) -> usize {
590+ ADDRESS_BYTE_LENGTH
591+ }
592+ }
593+
594+ impl AbiEncoding for Contract {
595+ fn abi_name ( & self ) -> String {
596+ unimplemented ! ( ) ;
597+ }
598+
599+ fn abi_safe_name ( & self ) -> String {
600+ unimplemented ! ( ) ;
601+ }
602+
603+ fn abi_type ( & self ) -> AbiType {
604+ unimplemented ! ( ) ;
605+ }
606+ }
607+
571608pub fn type_desc_fixed_size (
572609 defs : & HashMap < String , Type > ,
573610 typ : & fe:: TypeDesc ,
574611) -> Result < FixedSize , SemanticError > {
575- match type_desc ( defs, typ) ? {
576- Type :: Base ( base) => Ok ( FixedSize :: Base ( base) ) ,
577- Type :: Array ( array) => Ok ( FixedSize :: Array ( array) ) ,
578- Type :: Tuple ( tuple) => Ok ( FixedSize :: Tuple ( tuple) ) ,
579- Type :: String ( string) => Ok ( FixedSize :: String ( string) ) ,
580- Type :: Map ( _) => Err ( SemanticError :: type_error ( ) ) ,
581- }
612+ FixedSize :: try_from ( type_desc ( defs, typ) ?)
582613}
583614
584615pub fn type_desc_base (
0 commit comments