feat: cache contracts created by other cached accounts for instant indexing

This commit is contained in:
Mohamed Sohail 2025-07-03 11:52:35 +03:00
parent ef28ec1298
commit 679d7f9927
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
2 changed files with 6 additions and 2 deletions

View File

@ -11,7 +11,7 @@ func bootstrapEventRouter(cacheProvider cache.Cache, pubCB router.Callback) *rou
handlerContainer := handler.New(cacheProvider)
router := router.New(pubCB)
router.RegisterContractCreationHandler(handler.HandleContractCreation())
router.RegisterContractCreationHandler(handler.HandleContractCreation(handlerContainer))
router.RegisterLogRoute(w3.H("0x26162814817e23ec5035d6a2edc6c422da2da2119e27cfca6be65cc2dc55ca4c"), handler.HandleFaucetGiveLog())
router.RegisterLogRoute(w3.H("0xa226db3f664042183ee0281230bba26cbf7b5057e50aee7f25a175ff45ce4d7f"), handler.HandleIndexAddLog(handlerContainer))

View File

@ -9,7 +9,7 @@ import (
const contractCreationEventName = "CONTRACT_CREATION"
func HandleContractCreation() router.ContractCreationHandlerFunc {
func HandleContractCreation(hc *HandlerContainer) router.ContractCreationHandlerFunc {
return func(ctx context.Context, ccp router.ContractCreationPayload, c router.Callback) error {
contractCreationEvent := event.Event{
Block: ccp.Block,
@ -23,6 +23,10 @@ func HandleContractCreation() router.ContractCreationHandlerFunc {
},
}
if err := hc.cache.Add(ctx, ccp.ContractAddress); err != nil {
return err
}
return c(ctx, contractCreationEvent)
}
}