Skip to content

Commit

Permalink
chore: change DecodeLog signature to ensure topics are always 32 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbriche committed Jan 29, 2025
1 parent 43a7758 commit 4c2b4d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions encoding/json/decode_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
eth_abi "github.com/ethereum/go-ethereum/accounts/abi"
)

func DecodeLog(topics [][]byte, input []byte, event eth_abi.Event) (ast.Node, error) {
func DecodeLog(topics [][32]byte, input []byte, event eth_abi.Event) (ast.Node, error) {
var indexed, unindexed = SplitInputs(event.Inputs)

// mismatch btw num of indexed fields and num of topics
Expand Down Expand Up @@ -37,7 +37,7 @@ func DecodeLog(topics [][]byte, input []byte, event eth_abi.Event) (ast.Node, er
}

for i, input := range indexed {
v, err := DecodeValue(topics[i+1], input.Type)
v, err := DecodeValue(topics[i+1][:], input.Type)

if err != nil {
return ast.Node{}, err
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestDecodeLog(t *testing.T) {
var (
event = _abi.Events[log.EventName]
input = hexutil.MustDecode(log.Input)
topics = lo.Map(log.Topics, func(topic string, _ int) []byte { return hexutil.MustDecode(topic) })
topics = lo.Map(log.Topics, func(topic string, _ int) [32]byte { return [32]byte(hexutil.MustDecode(topic)) })
)

node, err := DecodeLog(topics, input, event)
Expand Down

0 comments on commit 4c2b4d0

Please sign in to comment.