fix: early ack on handler not found

This commit is contained in:
2024-10-30 14:08:09 +03:00
parent b305d4814a
commit d8bb140f94
8 changed files with 41 additions and 16 deletions

View File

@@ -2,9 +2,11 @@ package handler
import (
"context"
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/grassrootseconomics/eth-tracker/pkg/event"
"github.com/grassrootseconomics/ethutils"
"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
)
@@ -13,7 +15,7 @@ var (
nameGetter = w3.MustNewFunc("name()", "string")
symbolGetter = w3.MustNewFunc("symbol()", "string")
decimalsGetter = w3.MustNewFunc("decimals()", "uint8")
sinkAddressGetter = w3.MustNewFunc("sinkAddress", "address")
sinkAddressGetter = w3.MustNewFunc("sinkAddress()", "address")
)
func (h *Handler) AddToken(ctx context.Context, event event.Event) error {
@@ -26,6 +28,8 @@ func (h *Handler) AddToken(ctx context.Context, event event.Event) error {
tokenSymbol string
tokenDecimals uint8
sinkAddress common.Address
batchErr w3.CallErrors
)
contractAddress := w3.A(event.ContractAddress)
@@ -35,11 +39,21 @@ func (h *Handler) AddToken(ctx context.Context, event event.Event) error {
eth.CallFunc(contractAddress, nameGetter).Returns(&tokenName),
eth.CallFunc(contractAddress, symbolGetter).Returns(&tokenSymbol),
eth.CallFunc(contractAddress, decimalsGetter).Returns(&tokenDecimals),
eth.CallFunc(contractAddress, sinkAddressGetter).Returns(&sinkAddress),
); err != nil {
); errors.As(err, &batchErr) {
return batchErr
} else if err != nil {
return err
}
if err := h.chainProvider.Client.CallCtx(
ctx,
eth.CallFunc(contractAddress, decimalsGetter).Returns(&tokenDecimals),
); err != nil {
// This will most likely revert if the contract does not have a sinkAddress
// Instead of handling the error we just ignore it and set the value to 0
sinkAddress = ethutils.ZeroAddress
}
return h.store.InsertToken(ctx, event.ContractAddress, tokenName, tokenSymbol, tokenDecimals, sinkAddress.Hex())
}

View File

@@ -11,7 +11,7 @@ import (
"github.com/lmittmann/w3/module/eth"
)
const balanceThreshold = 50
const balanceThreshold = 5
func (h *Handler) IndexFaucetGive(ctx context.Context, event event.Event) error {
return h.store.InsertFaucetGive(ctx, event)
@@ -28,7 +28,7 @@ func (h *Handler) FaucetHealthCheck(ctx context.Context, event event.Event) erro
}
if balance.Cmp(new(big.Int).Mul(w3.BigEther, big.NewInt(balanceThreshold))) < 0 {
return h.telegram.Notify(ctx, fmt.Sprintf("%s: %s", event.ContractAddress, telegram.NOTIFY_LOW_BALANCE_ON_GAS_FAUCET))
return h.telegram.Notify(ctx, fmt.Sprintf("%s:\n\n %s", event.ContractAddress, telegram.NOTIFY_LOW_BALANCE_ON_GAS_FAUCET))
}
return nil