@@ -70,6 +70,13 @@ type TypeInfo =
70
70
length : number ;
71
71
} ;
72
72
73
+ type Event = {
74
+ name : string ;
75
+ args : { name : string ; type : TypeInfo ; desc : string } [ ] ;
76
+ desc : string ;
77
+ argTupleType : TypeInfo ;
78
+ } ;
79
+
73
80
function getConstantInitializer ( node : ts . Node ) : ts . Node | undefined {
74
81
if ( ! node . isKind ( ts . SyntaxKind . Identifier ) ) return undefined ;
75
82
const definitionNode = node . getDefinitionNodes ( ) . at ( - 1 ) ;
@@ -1719,7 +1726,7 @@ export default class Compiler {
1719
1726
1720
1727
private disableTypeScript : boolean ;
1721
1728
1722
- private events : Record < string , TypeInfo [ ] > = { } ;
1729
+ private events : Record < string , Event > = { } ;
1723
1730
1724
1731
constructor ( content : string , className : string , project : Project , options ?: CompilerOptions ) {
1725
1732
this . project = project ;
@@ -4720,11 +4727,32 @@ export default class Compiler {
4720
4727
}
4721
4728
4722
4729
const initTypeArgs = init . getTypeArguments ( ) ;
4723
- if ( ! initTypeArgs [ 0 ] . isKind ( ts . SyntaxKind . TupleType ) )
4724
- throw Error ( 'EventLogger type argument must be a tuple of types' ) ;
4730
+ if ( ! initTypeArgs [ 0 ] . isKind ( ts . SyntaxKind . TypeLiteral ) ) {
4731
+ throw Error ( `EventLogger type argument must be a type literal` ) ;
4732
+ }
4725
4733
4726
- this . events [ node . getNameNode ( ) . getText ( ) ] =
4727
- initTypeArgs [ 0 ] . getElements ( ) . map ( ( t ) => getTypeInfo ( t . getType ( ) ) ) || [ ] ;
4734
+ this . events [ node . getNameNode ( ) . getText ( ) ] = {
4735
+ name : node . getNameNode ( ) . getText ( ) ,
4736
+ args : [ ] ,
4737
+ desc : node
4738
+ . getJsDocs ( )
4739
+ . map ( ( d ) => d . getCommentText ( ) )
4740
+ . join ( '' ) ,
4741
+ argTupleType : getTypeInfo ( initTypeArgs [ 0 ] . getType ( ) ) ,
4742
+ } ;
4743
+
4744
+ const event = this . events [ node . getNameNode ( ) . getText ( ) ] ;
4745
+
4746
+ initTypeArgs [ 0 ] . getProperties ( ) . forEach ( ( p ) => {
4747
+ const desc = p
4748
+ . getJsDocs ( )
4749
+ . map ( ( d ) => d . getCommentText ( ) )
4750
+ . join ( ) ;
4751
+
4752
+ const name = p . getName ( ) ;
4753
+ const type = getTypeInfo ( p . getType ( ) ) ;
4754
+ event . args . push ( { name, type, desc } ) ;
4755
+ } ) ;
4728
4756
} else if ( init . isKind ( ts . SyntaxKind . CallExpression ) && init . getExpression ( ) . getText ( ) === 'ScratchSlot' ) {
4729
4757
if ( init . getTypeArguments ( ) ?. length !== 1 ) throw Error ( 'ScratchSlot must have one type argument ' ) ;
4730
4758
@@ -4913,16 +4941,15 @@ export default class Compiler {
4913
4941
// If this is an event
4914
4942
if ( chain [ 0 ] . isKind ( ts . SyntaxKind . PropertyAccessExpression ) && this . events [ chain [ 0 ] . getNameNode ( ) . getText ( ) ] ) {
4915
4943
const name = chain [ 0 ] . getNameNode ( ) . getText ( ) ;
4916
- const types = this . events [ name ] ;
4917
- const typesTuple : TypeInfo = { kind : 'tuple' , elements : types } ;
4944
+ const { argTupleType } = this . events [ name ] ;
4918
4945
4919
4946
if ( ! chain [ 1 ] . isKind ( ts . SyntaxKind . PropertyAccessExpression ) || ! chain [ 2 ] . isKind ( ts . SyntaxKind . CallExpression ) )
4920
4947
throw Error ( `Unsupported ${ chain [ 1 ] . getKindName ( ) } ${ chain [ 1 ] . getText ( ) } ` ) ;
4921
4948
4922
4949
if ( chain [ 1 ] . getNameNode ( ) . getText ( ) !== 'log' )
4923
4950
throw Error ( `Unsupported event method ${ chain [ 1 ] . getNameNode ( ) . getText ( ) } ` ) ;
4924
4951
4925
- const argTypes = typeInfoToABIString ( typesTuple )
4952
+ const argTypes = typeInfoToABIString ( argTupleType )
4926
4953
. replace ( / a s s e t / g, 'uint64' )
4927
4954
. replace ( / a c c o u n t / g, 'address' )
4928
4955
. replace ( / a p p l i c a t i o n / g, 'uint64' ) ;
@@ -4931,9 +4958,9 @@ export default class Compiler {
4931
4958
4932
4959
const selector = sha512_256 ( Buffer . from ( signature ) ) . slice ( 0 , 8 ) ;
4933
4960
4934
- this . typeHint = typesTuple ;
4961
+ this . typeHint = argTupleType ;
4935
4962
this . pushVoid ( chain [ 2 ] , `byte 0x${ selector } // ${ signature } ` ) ;
4936
- this . processArrayElements ( chain [ 2 ] . getArguments ( ) , chain [ 2 ] ) ;
4963
+ this . processNode ( chain [ 2 ] . getArguments ( ) [ 0 ] ) ;
4937
4964
this . pushVoid ( chain [ 2 ] , 'concat' ) ;
4938
4965
4939
4966
this . pushVoid ( chain [ 2 ] , 'log' ) ;
0 commit comments