@@ -53,22 +53,25 @@ function getLatestMeta (registry: Registry, json: Record<string, unknown>): Cont
53
53
return converter [ 1 ] ( registry , metadata [ `as${ converter [ 0 ] } ` ] ) ;
54
54
}
55
55
56
- function getEnvTypes ( env : ContractEnvironment , lookup : PortableRegistry ) {
57
- const keys = Object . keys ( env ) ;
56
+ function getEnvTypes ( env : ContractEnvironment | undefined , lookup : PortableRegistry ) {
57
+ if ( env ) {
58
+ const keys = Object . keys ( env ) ;
58
59
59
- return Object . values ( env ) . map ( ( t : unknown , i ) => {
60
- if ( typeof t === 'object' && t !== null && 'type' in t ) {
61
- return { [ keys [ i ] ] : lookup . getTypeDef ( t . type as number ) } ;
62
- }
60
+ return Object . values ( env ) . map ( ( t : unknown , i ) => {
61
+ if ( typeof t === 'object' && t !== null && 'type' in t ) {
62
+ return { [ keys [ i ] ] : lookup . getTypeDef ( t . type as number ) } ;
63
+ }
64
+
65
+ return { [ keys [ i ] ] : t } ;
66
+ } ) ;
67
+ }
63
68
64
- return { [ keys [ i ] ] : t } ;
65
- } ) ;
69
+ return [ ] ;
66
70
}
67
71
68
72
function parseJson ( json : Record < string , unknown > , chainProperties ?: ChainProperties ) : [ Record < string , unknown > , Registry , ContractMetadataLatest , ContractProjectInfo , { [ x : string ] : unknown } [ ] ] {
69
73
const registry = new TypeRegistry ( ) ;
70
74
const info = registry . createType ( 'ContractProjectInfo' , json ) as unknown as ContractProjectInfo ;
71
- const { spec : { environment } } = json as { spec : { environment ?: ContractEnvironment } } ;
72
75
const latest = getLatestMeta ( registry , json ) ;
73
76
const lookup = registry . createType ( 'PortableRegistry' , { types : latest . types } , true ) ;
74
77
@@ -84,9 +87,15 @@ function parseJson (json: Record<string, unknown>, chainProperties?: ChainProper
84
87
lookup . getTypeDef ( id )
85
88
) ;
86
89
87
- const env = environment
88
- ? getEnvTypes ( environment , lookup )
89
- : [ ] ;
90
+ let env : { [ x : string ] : unknown } [ ] = [ ] ;
91
+
92
+ try {
93
+ const { spec : { environment } } = json as unknown as ContractMetadataLatest ;
94
+
95
+ env = getEnvTypes ( environment , lookup ) ;
96
+ } catch ( e ) {
97
+ console . error ( e ) ;
98
+ }
90
99
91
100
return [ json , registry , latest , info , env ] ;
92
101
}
@@ -110,7 +119,7 @@ export class Abi {
110
119
) ;
111
120
this . constructors = this . metadata . spec . constructors . map ( ( spec : ContractConstructorSpecLatest , index ) => {
112
121
const isDefault = 'default' in spec ? spec . default . isTrue : undefined ;
113
- const typeSpec = spec . returnType . unwrapOr ( null ) ;
122
+ const typeSpec = 'returnType' in spec ? spec . returnType . unwrapOr ( null ) : null ;
114
123
115
124
return this . #createMessage( spec , index , {
116
125
isConstructor : true ,
0 commit comments