@@ -225,13 +225,35 @@ export class TypeRegistry {
225
225
decodeEvent < T > ( event : Event ) : TypedEventInstance < T > | undefined {
226
226
return this . decodedInternal < T > ( event ) as TypedEventInstance < T >
227
227
}
228
+ filterAndDecodeEvents < T > ( typePrefix : string , resources : Event [ ] ) : TypedEventInstance < T > [ ] {
229
+ return this . filterAndDecodeInternal ( typePrefix , resources ) as TypedEventInstance < T > [ ]
230
+ }
231
+ decodeResource < T > ( res : MoveResource ) : TypedMoveResource < T > | undefined {
232
+ return this . decodedInternal < T > ( res )
233
+ }
234
+ filterAndDecodeResources < T > ( typePrefix : string , resources : MoveResource [ ] ) : TypedMoveResource < T > [ ] {
235
+ return this . filterAndDecodeInternal ( typePrefix , resources )
236
+ }
228
237
229
- decodeResource < T > ( event : MoveResource ) : TypedMoveResource < T > | undefined {
230
- return this . decodedInternal < T > ( event )
238
+ private filterAndDecodeInternal < T > ( typePrefix : string , structs : StructWithTag [ ] ) : StructWithType < T > [ ] {
239
+ if ( ! structs ) {
240
+ return [ ]
241
+ }
242
+ const results : StructWithType < T > [ ] = [ ]
243
+ for ( const resource of structs ) {
244
+ if ( ! resource . type . startsWith ( typePrefix ) ) {
245
+ continue
246
+ }
247
+ const result = this . decodedInternal ( resource )
248
+ if ( result ) {
249
+ results . push ( result as StructWithType < T > )
250
+ }
251
+ }
252
+ return results
231
253
}
232
254
233
255
private decodedInternal < T > ( typeStruct : StructWithTag ) : StructWithType < T > | undefined {
234
- const registry = DEFAULT_TYPE_REGISTRY
256
+ const registry = TYPE_REGISTRY
235
257
// this.loadTypes(registry)
236
258
// TODO check if module is not loaded
237
259
@@ -249,7 +271,7 @@ export class TypeRegistry {
249
271
}
250
272
251
273
decodeFunctionPayload ( payload : TransactionPayload_EntryFunctionPayload ) : TransactionPayload_EntryFunctionPayload {
252
- const registry = DEFAULT_TYPE_REGISTRY
274
+ const registry = TYPE_REGISTRY
253
275
// this.loadTypes(registry)
254
276
const argumentsTyped : any [ ] = [ ]
255
277
@@ -269,4 +291,4 @@ export class TypeRegistry {
269
291
}
270
292
}
271
293
272
- export const DEFAULT_TYPE_REGISTRY = new TypeRegistry ( )
294
+ export const TYPE_REGISTRY = new TypeRegistry ( )
0 commit comments