mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2025-02-22 16:00:37 +01:00
feat: add within network check for approve events
This commit is contained in:
parent
0b5af2f938
commit
5962c26659
@ -25,7 +25,7 @@ func bootstrapEventRouter(cacheProvider cache.Cache, pubCB router.Callback) *rou
|
|||||||
router.RegisterLogRoute(w3.H("0xab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f8"), handler.HandleTokenMintLog())
|
router.RegisterLogRoute(w3.H("0xab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f8"), handler.HandleTokenMintLog())
|
||||||
router.RegisterLogRoute(w3.H("0x894e56e1dac400b4475c83d8af0f0aa44de17c62764bd82f6e768a504e242461"), handler.HandleCustodialRegistrationLog())
|
router.RegisterLogRoute(w3.H("0x894e56e1dac400b4475c83d8af0f0aa44de17c62764bd82f6e768a504e242461"), handler.HandleCustodialRegistrationLog())
|
||||||
router.RegisterLogRoute(w3.H("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), handler.HandleTokenTransferLog(handlerContainer))
|
router.RegisterLogRoute(w3.H("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), handler.HandleTokenTransferLog(handlerContainer))
|
||||||
router.RegisterLogRoute(w3.H("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"), handler.HandleTokenApproveLog())
|
router.RegisterLogRoute(w3.H("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"), handler.HandleTokenApproveLog(handlerContainer))
|
||||||
|
|
||||||
router.RegisterInputDataRoute("63e4bff4", handler.HandleFaucetGiveInputData())
|
router.RegisterInputDataRoute("63e4bff4", handler.HandleFaucetGiveInputData())
|
||||||
router.RegisterInputDataRoute("de82efb4", handler.HandleFaucetGiveInputData())
|
router.RegisterInputDataRoute("de82efb4", handler.HandleFaucetGiveInputData())
|
||||||
@ -42,7 +42,7 @@ func bootstrapEventRouter(cacheProvider cache.Cache, pubCB router.Callback) *rou
|
|||||||
router.RegisterInputDataRoute("4420e486", handler.HandleCustodialRegistrationInputData())
|
router.RegisterInputDataRoute("4420e486", handler.HandleCustodialRegistrationInputData())
|
||||||
router.RegisterInputDataRoute("a9059cbb", handler.HandleTokenTransferInputData(handlerContainer))
|
router.RegisterInputDataRoute("a9059cbb", handler.HandleTokenTransferInputData(handlerContainer))
|
||||||
router.RegisterInputDataRoute("23b872dd", handler.HandleTokenTransferInputData(handlerContainer))
|
router.RegisterInputDataRoute("23b872dd", handler.HandleTokenTransferInputData(handlerContainer))
|
||||||
router.RegisterInputDataRoute("095ea7b3", handler.HandleTokenApproveInputData())
|
router.RegisterInputDataRoute("095ea7b3", handler.HandleTokenApproveInputData(handlerContainer))
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ var (
|
|||||||
tokenApproveToSig = w3.MustNewFunc("approve(address, uint256)", "bool")
|
tokenApproveToSig = w3.MustNewFunc("approve(address, uint256)", "bool")
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleTokenApproveLog() router.LogHandlerFunc {
|
func HandleTokenApproveLog(hc *HandlerContainer) router.LogHandlerFunc {
|
||||||
return func(ctx context.Context, lp router.LogPayload, c router.Callback) error {
|
return func(ctx context.Context, lp router.LogPayload, c router.Callback) error {
|
||||||
var (
|
var (
|
||||||
owner common.Address
|
owner common.Address
|
||||||
@ -29,6 +29,14 @@ func HandleTokenApproveLog() router.LogHandlerFunc {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proceed, err := hc.checkWithinNetwork(ctx, lp.Log.Address.Hex(), owner.Hex(), spender.Hex())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !proceed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
tokenApproveEvent := event.Event{
|
tokenApproveEvent := event.Event{
|
||||||
Index: lp.Log.Index,
|
Index: lp.Log.Index,
|
||||||
Block: lp.Log.BlockNumber,
|
Block: lp.Log.BlockNumber,
|
||||||
@ -48,7 +56,7 @@ func HandleTokenApproveLog() router.LogHandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleTokenApproveInputData() router.InputDataHandlerFunc {
|
func HandleTokenApproveInputData(hc *HandlerContainer) router.InputDataHandlerFunc {
|
||||||
return func(ctx context.Context, idp router.InputDataPayload, c router.Callback) error {
|
return func(ctx context.Context, idp router.InputDataPayload, c router.Callback) error {
|
||||||
var (
|
var (
|
||||||
spender common.Address
|
spender common.Address
|
||||||
@ -59,6 +67,14 @@ func HandleTokenApproveInputData() router.InputDataHandlerFunc {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proceed, err := hc.checkWithinNetwork(ctx, idp.ContractAddress, idp.From, spender.Hex())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !proceed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
tokenApproveEvent := event.Event{
|
tokenApproveEvent := event.Event{
|
||||||
Block: idp.Block,
|
Block: idp.Block,
|
||||||
ContractAddress: idp.ContractAddress,
|
ContractAddress: idp.ContractAddress,
|
||||||
|
@ -30,7 +30,7 @@ func HandleTokenTransferLog(hc *HandlerContainer) router.LogHandlerFunc {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
proceed, err := hc.checkTransferWithinNetwork(ctx, lp.Log.Address.Hex(), from.Hex(), to.Hex())
|
proceed, err := hc.checkWithinNetwork(ctx, lp.Log.Address.Hex(), from.Hex(), to.Hex())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func HandleTokenTransferInputData(hc *HandlerContainer) router.InputDataHandlerF
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
proceed, err := hc.checkTransferWithinNetwork(ctx, idp.ContractAddress, idp.From, to.Hex())
|
proceed, err := hc.checkWithinNetwork(ctx, idp.ContractAddress, idp.From, to.Hex())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ func HandleTokenTransferInputData(hc *HandlerContainer) router.InputDataHandlerF
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
proceed, err := hc.checkTransferWithinNetwork(ctx, idp.ContractAddress, from.Hex(), to.Hex())
|
proceed, err := hc.checkWithinNetwork(ctx, idp.ContractAddress, from.Hex(), to.Hex())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -125,12 +125,3 @@ func HandleTokenTransferInputData(hc *HandlerContainer) router.InputDataHandlerF
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *HandlerContainer) checkTransferWithinNetwork(ctx context.Context, contractAddress string, from string, to string) (bool, error) {
|
|
||||||
exists, err := hc.cache.ExistsNetwork(ctx, contractAddress, from, to)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return exists, nil
|
|
||||||
}
|
|
||||||
|
12
internal/handler/within_network.go
Normal file
12
internal/handler/within_network.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
func (hc *HandlerContainer) checkWithinNetwork(ctx context.Context, contractAddress string, from string, to string) (bool, error) {
|
||||||
|
exists, err := hc.cache.ExistsNetwork(ctx, contractAddress, from, to)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return exists, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user