mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2026-05-17 10:15:21 +02:00
refactor: Decouple router and handlers (#31)
* refactor: decouple router to allow adding custom log and input data handlers * feat: refactor handlers * devops: update service build args * chore: cleanup unecessary files/code
This commit is contained in:
78
internal/handler/token_mint.go
Normal file
78
internal/handler/token_mint.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/pkg/router"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
const mintEventName = "TOKEN_MINT"
|
||||
|
||||
var (
|
||||
tokenMintEvent = w3.MustNewEvent("Mint(address indexed _tokenMinter, address indexed _beneficiary, uint256 _value)")
|
||||
tokenMintToSig = w3.MustNewFunc("mintTo(address, uint256)", "bool")
|
||||
)
|
||||
|
||||
func HandleTokenMintLog() router.LogHandlerFunc {
|
||||
return func(ctx context.Context, lp router.LogPayload, c router.Callback) error {
|
||||
var (
|
||||
tokenMinter common.Address
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenMintEvent.DecodeArgs(lp.Log, &tokenMinter, &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenMintEvent := event.Event{
|
||||
Index: lp.Log.Index,
|
||||
Block: lp.Log.BlockNumber,
|
||||
ContractAddress: lp.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: lp.Timestamp,
|
||||
TxHash: lp.Log.TxHash.Hex(),
|
||||
TxType: mintEventName,
|
||||
Payload: map[string]any{
|
||||
"tokenMinter": tokenMinter.Hex(),
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return c(ctx, tokenMintEvent)
|
||||
}
|
||||
}
|
||||
|
||||
func HandleTokenMintInputData() router.InputDataHandlerFunc {
|
||||
return func(ctx context.Context, idp router.InputDataPayload, c router.Callback) error {
|
||||
var (
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenMintToSig.DecodeArgs(w3.B(idp.InputData), &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenMintEvent := event.Event{
|
||||
Block: idp.Block,
|
||||
ContractAddress: idp.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: idp.Timestamp,
|
||||
TxHash: idp.TxHash,
|
||||
TxType: mintEventName,
|
||||
Payload: map[string]any{
|
||||
"tokenMinter": idp.From,
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return c(ctx, tokenMintEvent)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user