From 36b9280ad5f91cbb7c9d9daceeb318c6e897ec39 Mon Sep 17 00:00:00 2001 From: hopeyen <60078528+hopeyen@users.noreply.github.com> Date: Fri, 3 Jan 2025 04:52:51 +0000 Subject: [PATCH] fix: properly read filtered logs for params --- core/eth/state.go | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/core/eth/state.go b/core/eth/state.go index bdf6144de..542cdf792 100644 --- a/core/eth/state.go +++ b/core/eth/state.go @@ -148,7 +148,7 @@ func (cs *ChainState) indexSocketMap(ctx context.Context) error { return nil } - var socketUpdates []*socketUpdateInput + var socketUpdates []*socketUpdateParams // logs are in order of block number, so we can just iterate through them for _, log := range logs { @@ -174,15 +174,36 @@ func (cs *ChainState) indexSocketMap(ctx context.Context) error { if err != nil { return err } - input := inputs[0].(socketUpdateInput) - socketUpdates = append(socketUpdates, &input) + var socket string + if method.Name == "registerOperator" { + socket = inputs[1].(string) + } else if method.Name == "updateOperatorSocket" { + socket = inputs[0].(string) + } else { + return fmt.Errorf("unknown method filtered for socket update event: %s", method.Name) + } + // operatorAddr := gcommon.BytesToAddress(log.Topics[1].Bytes()) + operatorID := core.OperatorID(log.Topics[1].Bytes()) + // fmt.Println("operator id", operatorID) + // fmt.Println("operator addr", operatorAddr) + // fmt.Println("operator addr hex", operatorAddr.Hex()) + // operatorId, err := core.OperatorIDFromHex(operatorAddr.Hex()) + // if err != nil { + // fmt.Println(err) + // return err + // } + + socketUpdates = append(socketUpdates, &socketUpdateParams{ + Socket: socket, + OperatorID: operatorID, + }) } cs.socketMu.Lock() defer cs.socketMu.Unlock() for _, socketUpdate := range socketUpdates { - cs.SocketMap[core.OperatorID(socketUpdate.OperatorID.Bytes())] = &socketUpdate.Socket + cs.SocketMap[core.OperatorID(socketUpdate.OperatorID)] = &socketUpdate.Socket } cs.socketPrevBlockNumber = uint32(currentBlockNumber) @@ -224,7 +245,7 @@ func getOperatorState(operatorsByQuorum core.OperatorStakes, blockNumber uint32, return state, nil } -type socketUpdateInput struct { - OperatorID gcommon.Address "json:\"operatorId\"" - Socket string "json:\"socket\"" +type socketUpdateParams struct { + OperatorID core.OperatorID + Socket string }