@@ -656,30 +656,30 @@ const extractInkAbiEvents = function (
656
656
contractAbi : IInkAbi ,
657
657
) : IAbiEventsOutputContractEvent [ ] {
658
658
// Extract events
659
- const events : IAbiEventsOutputContractEvent [ ] = contractAbi . spec . events . map (
660
- ( event : IInkAbiEvent ) => ( {
659
+ const events : IAbiEventsOutputContractEvent [ ] =
660
+ contractAbi . spec . events . map ( ( event : IInkAbiEvent ) => ( {
661
661
name : event . label ,
662
662
args : event . args . map ( ( arg : IInkAbiArg ) => ( {
663
663
name : arg . label ,
664
664
type : resolveInkType ( arg . type . type , contractAbi . types ) ,
665
665
} ) ) ,
666
- } ) ,
667
- ) ;
666
+ } ) ) || [ ] ;
668
667
return events ;
669
668
} ;
670
669
671
670
const extractEvmAbiEvents = function (
672
671
abi : IEvmAbi ,
673
672
) : IAbiEventsOutputContractEvent [ ] {
674
- const events : IAbiEventsOutputContractEvent [ ] = abi
675
- . filter ( ( item ) => item . type === 'event' )
676
- . map ( ( event : IEvmEventAbiItem ) => ( {
677
- name : event . name ! ,
678
- args : event . inputs ! . map ( ( input ) => ( {
679
- name : input . name ,
680
- type : resolveEvmType ( input . type ) ,
681
- } ) ) ,
682
- } ) ) ;
673
+ const events : IAbiEventsOutputContractEvent [ ] =
674
+ abi
675
+ . filter ( ( item ) => item . type === 'event' )
676
+ . map ( ( event : IEvmEventAbiItem ) => ( {
677
+ name : event . name ! ,
678
+ args : event . inputs ! . map ( ( input ) => ( {
679
+ name : input . name ,
680
+ type : resolveEvmType ( input . type ) ,
681
+ } ) ) ,
682
+ } ) ) || [ ] ;
683
683
684
684
return events ;
685
685
} ;
@@ -688,46 +688,48 @@ const extractInkAbiFunctions = function (
688
688
contractAbi : IInkAbi ,
689
689
) : IAbiCallsOutputContractCall [ ] {
690
690
// Extract messages (calls) that mutate the blockchain state
691
- const calls : IAbiCallsOutputContractCall [ ] = contractAbi . spec . messages
692
- . filter ( ( message : IInkAbiMessage ) => message . mutates )
693
- . map ( ( message : IInkAbiMessage ) => ( {
694
- name : message . label ,
695
- selector : message . selector ,
696
- args : message . args . map ( ( arg : IInkAbiArg ) => ( {
697
- name : arg . label ,
698
- type : resolveInkType ( arg . type . type , contractAbi . types ) ,
699
- } ) ) ,
700
- } ) ) ;
691
+ const calls : IAbiCallsOutputContractCall [ ] =
692
+ contractAbi . spec . messages
693
+ . filter ( ( message : IInkAbiMessage ) => message . mutates )
694
+ . map ( ( message : IInkAbiMessage ) => ( {
695
+ name : message . label ,
696
+ selector : message . selector ,
697
+ args : message . args . map ( ( arg : IInkAbiArg ) => ( {
698
+ name : arg . label ,
699
+ type : resolveInkType ( arg . type . type , contractAbi . types ) ,
700
+ } ) ) ,
701
+ } ) ) || [ ] ;
701
702
return calls ;
702
703
} ;
703
704
704
705
const extractEvmAbiFunctions = function (
705
706
abi : IEvmAbi ,
706
707
) : IAbiCallsOutputContractCall [ ] {
707
- const calls : IAbiCallsOutputContractCall [ ] = abi
708
- . filter (
709
- ( item ) =>
710
- item . type === 'function' &&
711
- item . stateMutability !== 'view' &&
712
- item . stateMutability !== 'pure' ,
713
- )
714
- . map ( ( func : IEvmFunctionAbiItem ) => {
715
- const functionSignature = `${ func . name } (${ func
716
- . inputs ! . map ( ( input ) => input . type )
717
- . join ( ',' ) } )`;
718
- const selector = ethers
719
- . keccak256 ( ethers . toUtf8Bytes ( functionSignature ) )
720
- . slice ( 0 , 10 ) ;
721
- // TODO: jrojek, prevent selector calculation every time the method is called
722
- return {
723
- name : func . name ! ,
724
- selector : selector ,
725
- args : func . inputs ! . map ( ( input ) => ( {
726
- name : input . name ,
727
- type : resolveEvmType ( input . type ) ,
728
- } ) ) ,
729
- } ;
730
- } ) ;
708
+ const calls : IAbiCallsOutputContractCall [ ] =
709
+ abi
710
+ . filter (
711
+ ( item ) =>
712
+ item . type === 'function' &&
713
+ item . stateMutability !== 'view' &&
714
+ item . stateMutability !== 'pure' ,
715
+ )
716
+ . map ( ( func : IEvmFunctionAbiItem ) => {
717
+ const functionSignature = `${ func . name } (${ func
718
+ . inputs ! . map ( ( input ) => input . type )
719
+ . join ( ',' ) } )`;
720
+ const selector = ethers
721
+ . keccak256 ( ethers . toUtf8Bytes ( functionSignature ) )
722
+ . slice ( 0 , 10 ) ;
723
+ // TODO: jrojek, prevent selector calculation every time the method is called
724
+ return {
725
+ name : func . name ! ,
726
+ selector : selector ,
727
+ args : func . inputs ! . map ( ( input ) => ( {
728
+ name : input . name ,
729
+ type : resolveEvmType ( input . type ) ,
730
+ } ) ) ,
731
+ } ;
732
+ } ) || [ ] ;
731
733
732
734
return calls ;
733
735
} ;
0 commit comments