@@ -3,7 +3,6 @@ import { requiredEnv } from "./utils/envs";
33import {
44 GetTransactionReceiptResponse ,
55 ParsedEvent ,
6- ParsedEvents ,
76} from "starknet" ;
87import { Event } from "./entity/event" ;
98import { Transaction } from "./entity/transaction" ;
@@ -18,6 +17,7 @@ import {
1817} from "./utils/contract" ;
1918import { IsNull , Not } from "typeorm" ;
2019import assert from "assert" ;
20+ import { eventNameMap } from "./utils/const" ;
2121
2222type ReturnedTransactionStatus = {
2323 tx_status : string ;
@@ -30,19 +30,31 @@ const contractAddress = requiredEnv("CONTRACT_ADDRESS");
3030
3131function parseEvent ( emittedEvent : EMITTED_EVENT ) : ParsedEvent {
3232 let parsedEvent : ParsedEvent | undefined = undefined ;
33+ const shouldUseNewContract = emittedEvent . block_number == null || emittedEvent . block_number > OLD_CONTRACT_BLOCK_END ;
3334
34- if ( emittedEvent . block_number == null || emittedEvent . block_number >= OLD_CONTRACT_BLOCK_END ) {
35- parsedEvent = contract
36- . parseEvents ( {
37- events : [ emittedEvent ] ,
38- } as GetTransactionReceiptResponse )
39- . at ( 0 ) ;
40- } else {
41- parsedEvent = oldContract
35+ try {
36+ const parsingContract = shouldUseNewContract ? contract : oldContract ;
37+ parsedEvent = parsingContract
4238 . parseEvents ( {
4339 events : [ emittedEvent ] ,
4440 } as GetTransactionReceiptResponse )
4541 . at ( 0 ) ;
42+ } catch ( e ) {
43+ console . error ( "Error parsing event with default parser" , e ) ;
44+ }
45+
46+ if ( parsedEvent == undefined ) {
47+ console . debug ( "Parsing with fallback parser" ) ;
48+ const parsingContract = shouldUseNewContract ? oldContract : contract ;
49+ try {
50+ parsedEvent = parsingContract
51+ . parseEvents ( {
52+ events : [ emittedEvent ] ,
53+ } as GetTransactionReceiptResponse )
54+ . at ( 0 ) ;
55+ } catch ( e ) {
56+ console . error ( "Error parsing event with fallback parser" , e ) ;
57+ }
4658 }
4759
4860 assert ( parsedEvent != null , "Parsed event is null." ) ;
@@ -178,12 +190,6 @@ async function pullEvents() {
178190 }
179191}
180192
181- const eventNameMap = {
182- GameCreated : "game_created" ,
183- GameEvolved : "game_evolved" ,
184- CellRevived : "cell_revived" ,
185- } as { [ key : string ] : string } ;
186-
187193type MaterializedViewName = "balance" | "creator" | "infinite" ;
188194
189195async function refreshMaterializedView ( name : MaterializedViewName ) {
0 commit comments