Skip to content

Commit

Permalink
fix: supports for event with the string "event" in name
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbriche committed Jan 10, 2025
1 parent 9083807 commit 43a7758
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all: test

test:
go test -v ./...
2 changes: 1 addition & 1 deletion encoding/json/trace_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"to": "0x3f3af6ecc90d04e5261b1740c411b0f3018d3e6b",
"ids": ["0","1","3","4"],
"amounts": ["1000","1000","200","200"],
"data": "AA=="
"data": "0x00"
},
"outputs":{}
}
Expand Down
21 changes: 21 additions & 0 deletions fullsig/fullsig_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,26 @@
]
}
]
},
{
"fullsig": "event event_withdraw(address,uint256)",
"field": [
{
"type": "event",
"name": "event_withdraw",
"inputs": [
{
"name": "arg0",
"type": "address",
"indexed": false
},
{
"name": "arg1",
"type": "uint256",
"indexed": false
}
]
}
]
}
]
33 changes: 16 additions & 17 deletions fullsig/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import (
)

const (
TokenOpenParens = 1
TokenCloseParens = 2
TokenOpenBracket = 3
TokenCloseBracket = 4
TokenComma = 5
TokenEvent = 6
TokenFunction = 7
TokenIndexed = 8
TokenScalarTypeName = 9
TokenOpenParens = 1
TokenCloseParens = 2
TokenOpenBracket = 3
TokenCloseBracket = 4
TokenComma = 5
)

var (
Expand Down Expand Up @@ -49,18 +45,21 @@ var (
DefineTokens(TokenOpenBracket, []string{"["}).
DefineTokens(TokenCloseBracket, []string{"]"}).
DefineTokens(TokenComma, []string{","}).
DefineTokens(TokenEvent, []string{"event"}).
DefineTokens(TokenFunction, []string{"function"}).
DefineTokens(TokenIndexed, []string{"indexed"}).
DefineTokens(TokenScalarTypeName, SCALAR_TYPENAMES).
AllowKeywordSymbols([]rune{'_'}, []rune{'$', '_', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})
)

func isEventToken(t *tokenizer.Token) bool { return t.IsKeyword() && t.ValueString() == "event" }
func isFunctionToken(t *tokenizer.Token) bool { return t.IsKeyword() && t.ValueString() == "function" }
func isIndexedToken(t *tokenizer.Token) bool { return t.IsKeyword() && t.ValueString() == "indexed" }
func isScalarTypeName(t *tokenizer.Token) bool {
return lo.Contains(SCALAR_TYPENAMES, t.ValueString())
}

func ParseEvent(s string) (eth_abi.Event, error) {
var stream = tknz.ParseString(s)
defer stream.Close()

if !stream.CurrentToken().Is(TokenEvent) {
if !isEventToken(stream.CurrentToken()) {
return eth_abi.Event{}, fmt.Errorf("event fullsig must start with keyword 'event': %s", s)
}

Expand All @@ -87,7 +86,7 @@ func ParseMethod(s string) (eth_abi.Method, error) {
var stream = tknz.ParseString(s)
defer stream.Close()

if !stream.CurrentToken().Is(TokenFunction) {
if !isFunctionToken(stream.CurrentToken()) {
return eth_abi.Method{}, fmt.Errorf("function fullsig must start with keyword 'function': %s", s)
}

Expand Down Expand Up @@ -160,7 +159,7 @@ func parseArgument(stream *tokenizer.Stream) (eth_abi.ArgumentMarshaling, error)
)

switch {
case stream.CurrentToken().Is(TokenScalarTypeName):
case isScalarTypeName(stream.CurrentToken()):
res.Type = stream.CurrentToken().ValueString()
stream.GoNext()
case stream.CurrentToken().Is(TokenOpenParens):
Expand All @@ -184,7 +183,7 @@ func parseArgument(stream *tokenizer.Stream) (eth_abi.ArgumentMarshaling, error)
res.Type = res.Type + s
}

if stream.CurrentToken().Is(TokenIndexed) {
if isIndexedToken(stream.CurrentToken()) {
res.Indexed = true
stream.GoNext()
}
Expand Down

0 comments on commit 43a7758

Please sign in to comment.