@@ -11,8 +11,12 @@ import {
1111 RpcClient ,
1212 TypeID ,
1313} from 'casper-js-sdk' ;
14- import { Event , parseEventDataFromBytes , parseEventNameWithRemainder , } from './event' ;
15- import { parseSchemasFromBytes , Schemas } from './schema' ;
14+ import {
15+ Event ,
16+ parseEventDataFromBytes ,
17+ parseEventNameWithRemainder ,
18+ } from './event' ;
19+ import { parseSchemasFromBytes , Schemas } from './schema' ;
1620
1721export interface ContractMetadata {
1822 schemas : Schemas ;
@@ -23,9 +27,9 @@ export interface ContractMetadata {
2327}
2428
2529interface Dictionary {
26- uref : string ,
27- key : string ,
28- value : Uint8Array ,
30+ uref : string ;
31+ key : string ;
32+ value : Uint8Array ;
2933}
3034
3135export const EVENTS_SCHEMA_NAMED_KEY = '__events_schema' ;
@@ -64,7 +68,11 @@ export class Parser {
6468
6569 for ( const contractHash of contractHashes ) {
6670 const contractData = (
67- await rpcClient . getStateItem ( stateRootHash . stateRootHash . toHex ( ) , `hash-${ contractHash } ` , [ ] )
71+ await rpcClient . getStateItem (
72+ stateRootHash . stateRootHash . toHex ( ) ,
73+ `hash-${ contractHash } ` ,
74+ [ ] ,
75+ )
6876 ) . storedValue . contract ;
6977
7078 const namedKeys = Object . values ( contractData ! . namedKeys ) ;
@@ -73,8 +81,8 @@ export class Parser {
7381 throw new Error ( 'contract data not found' ) ;
7482 }
7583
76- let eventsSchemaUref = "" ;
77- let eventsUref = "" ;
84+ let eventsSchemaUref = '' ;
85+ let eventsUref = '' ;
7886
7987 for ( const namedKey of namedKeys ) {
8088 if ( namedKey . name === EVENTS_SCHEMA_NAMED_KEY ) {
@@ -83,7 +91,7 @@ export class Parser {
8391 eventsUref = namedKey . key ;
8492 }
8593
86- if ( eventsSchemaUref !== "" && eventsUref !== "" ) {
94+ if ( eventsSchemaUref !== '' && eventsUref !== '' ) {
8795 break ;
8896 }
8997 }
@@ -96,12 +104,20 @@ export class Parser {
96104 throw new Error ( `no '${ EVENTS_NAMED_KEY } ' uref found` ) ;
97105 }
98106
99- const schemaResponse = await rpcClient . getStateItem ( stateRootHash . stateRootHash . toHex ( ) , eventsSchemaUref . toString ( ) , [ ] ) ;
107+ const schemaResponse = await rpcClient . getStateItem (
108+ stateRootHash . stateRootHash . toHex ( ) ,
109+ eventsSchemaUref . toString ( ) ,
110+ [ ] ,
111+ ) ;
100112 if ( ! schemaResponse . storedValue . clValue ) {
101113 throw new Error ( `no schema uref for ${ eventsSchemaUref } ` ) ;
102114 }
103115
104- const schemas = parseSchemasFromBytes ( Conversions . decodeBase16 ( schemaResponse . rawJSON . stored_value . CLValue . bytes ) ) ;
116+ const schemas = parseSchemasFromBytes (
117+ Conversions . decodeBase16 (
118+ schemaResponse . rawJSON . stored_value . CLValue . bytes ,
119+ ) ,
120+ ) ;
105121
106122 contractsSchemas [ eventsUref . toString ( ) ] = {
107123 schemas,
@@ -142,9 +158,7 @@ export class Parser {
142158 try {
143159 dictionary = this . newDictionaryFromBytes ( clValue . any . bytes ( ) ) ;
144160
145- eventNameWithRemainder = parseEventNameWithRemainder (
146- dictionary . value ,
147- ) ;
161+ eventNameWithRemainder = parseEventNameWithRemainder ( dictionary . value ) ;
148162 } catch ( err ) {
149163 continue ;
150164 }
@@ -170,7 +184,8 @@ export class Parser {
170184 parsedEvent . contractHash = contractMetadata . contractHash ;
171185 parsedEvent . contractPackageHash = contractMetadata . contractPackageHash ;
172186
173- const eventSchema = contractMetadata . schemas [ eventNameWithRemainder . result ] ;
187+ const eventSchema =
188+ contractMetadata . schemas [ eventNameWithRemainder . result ] ;
174189 if ( ! eventSchema ) {
175190 results . push ( {
176191 event : parsedEvent ,
@@ -213,28 +228,41 @@ export class Parser {
213228
214229 const clValue = CLValueParser . fromBytesWithType ( u32 . bytes ) ;
215230
216- if ( ! ( clValue . result . type instanceof CLTypeList ) || clValue . result . type . elementsType . getTypeID ( ) !== TypeID . U8 ) {
231+ if (
232+ ! ( clValue . result . type instanceof CLTypeList ) ||
233+ clValue . result . type . elementsType . getTypeID ( ) !== TypeID . U8
234+ ) {
217235 throw new Error ( 'failed to parse CLList(CLU8) from bytes' ) ;
218236 }
219237
220238 const clValueByteSize = CLValueUInt32 . fromBytes ( clValue . bytes ) ;
221239
222- const clByteArrayAsUref = CLValueParser . fromBytesByType ( clValueByteSize . bytes , new CLTypeByteArray ( clValueByteSize . result . toNumber ( ) ) ) ;
240+ const clByteArrayAsUref = CLValueParser . fromBytesByType (
241+ clValueByteSize . bytes ,
242+ new CLTypeByteArray ( clValueByteSize . result . toNumber ( ) ) ,
243+ ) ;
223244 if ( ! clByteArrayAsUref . result . byteArray ) {
224245 throw new Error ( 'failed to parse CLByteArray from bytes' ) ;
225246 }
226247
227- const uref = `uref-${ Conversions . encodeBase16 ( clByteArrayAsUref . result . byteArray . bytes ( ) ) } -007` ;
248+ const uref = `uref-${ Conversions . encodeBase16 (
249+ clByteArrayAsUref . result . byteArray . bytes ( ) ,
250+ ) } -007`;
228251
229- const clStringAsDictKey = CLValueParser . fromBytesByType ( clByteArrayAsUref . bytes , CLTypeString ) ;
252+ const clStringAsDictKey = CLValueParser . fromBytesByType (
253+ clByteArrayAsUref . bytes ,
254+ CLTypeString ,
255+ ) ;
230256 if ( ! clStringAsDictKey . result . stringVal ) {
231257 throw new Error ( 'failed to parse CLString from bytes' ) ;
232258 }
233259
234260 return {
235261 uref : uref ,
236262 key : clStringAsDictKey . result . stringVal . toString ( ) ,
237- value : new Uint8Array ( clValue . result . list ! . elements . map ( el => el . ui8 ! . toNumber ( ) ) ) ,
263+ value : new Uint8Array (
264+ clValue . result . list ! . elements . map ( el => el . ui8 ! . toNumber ( ) ) ,
265+ ) ,
238266 } ;
239267 }
240268}
@@ -244,7 +272,11 @@ export async function fetchContractSchemasBytes(
244272 contractHash : string ,
245273 stateRootHash : string ,
246274) : Promise < Uint8Array > {
247- const schemaResponse = await rpcClient . getStateItem ( stateRootHash , `hash-${ contractHash } ` , [ EVENTS_SCHEMA_NAMED_KEY ] ) ;
275+ const schemaResponse = await rpcClient . getStateItem (
276+ stateRootHash ,
277+ `hash-${ contractHash } ` ,
278+ [ EVENTS_SCHEMA_NAMED_KEY ] ,
279+ ) ;
248280
249281 if ( ! schemaResponse . storedValue . clValue ) {
250282 throw new Error ( 'no clvalue for contract schema' ) ;
0 commit comments