Skip to content

Commit 43a7758

Browse files
committed
fix: supports for event with the string "event" in name
1 parent 9083807 commit 43a7758

4 files changed

Lines changed: 42 additions & 18 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
all: test
2+
3+
test:
4+
go test -v ./...

encoding/json/trace_test_data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"to": "0x3f3af6ecc90d04e5261b1740c411b0f3018d3e6b",
1010
"ids": ["0","1","3","4"],
1111
"amounts": ["1000","1000","200","200"],
12-
"data": "AA=="
12+
"data": "0x00"
1313
},
1414
"outputs":{}
1515
}

fullsig/fullsig_test_data.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,26 @@
278278
]
279279
}
280280
]
281+
},
282+
{
283+
"fullsig": "event event_withdraw(address,uint256)",
284+
"field": [
285+
{
286+
"type": "event",
287+
"name": "event_withdraw",
288+
"inputs": [
289+
{
290+
"name": "arg0",
291+
"type": "address",
292+
"indexed": false
293+
},
294+
{
295+
"name": "arg1",
296+
"type": "uint256",
297+
"indexed": false
298+
}
299+
]
300+
}
301+
]
281302
}
282303
]

fullsig/parse.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ import (
1111
)
1212

1313
const (
14-
TokenOpenParens = 1
15-
TokenCloseParens = 2
16-
TokenOpenBracket = 3
17-
TokenCloseBracket = 4
18-
TokenComma = 5
19-
TokenEvent = 6
20-
TokenFunction = 7
21-
TokenIndexed = 8
22-
TokenScalarTypeName = 9
14+
TokenOpenParens = 1
15+
TokenCloseParens = 2
16+
TokenOpenBracket = 3
17+
TokenCloseBracket = 4
18+
TokenComma = 5
2319
)
2420

2521
var (
@@ -49,18 +45,21 @@ var (
4945
DefineTokens(TokenOpenBracket, []string{"["}).
5046
DefineTokens(TokenCloseBracket, []string{"]"}).
5147
DefineTokens(TokenComma, []string{","}).
52-
DefineTokens(TokenEvent, []string{"event"}).
53-
DefineTokens(TokenFunction, []string{"function"}).
54-
DefineTokens(TokenIndexed, []string{"indexed"}).
55-
DefineTokens(TokenScalarTypeName, SCALAR_TYPENAMES).
5648
AllowKeywordSymbols([]rune{'_'}, []rune{'$', '_', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})
5749
)
5850

51+
func isEventToken(t *tokenizer.Token) bool { return t.IsKeyword() && t.ValueString() == "event" }
52+
func isFunctionToken(t *tokenizer.Token) bool { return t.IsKeyword() && t.ValueString() == "function" }
53+
func isIndexedToken(t *tokenizer.Token) bool { return t.IsKeyword() && t.ValueString() == "indexed" }
54+
func isScalarTypeName(t *tokenizer.Token) bool {
55+
return lo.Contains(SCALAR_TYPENAMES, t.ValueString())
56+
}
57+
5958
func ParseEvent(s string) (eth_abi.Event, error) {
6059
var stream = tknz.ParseString(s)
6160
defer stream.Close()
6261

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

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

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

@@ -160,7 +159,7 @@ func parseArgument(stream *tokenizer.Stream) (eth_abi.ArgumentMarshaling, error)
160159
)
161160

162161
switch {
163-
case stream.CurrentToken().Is(TokenScalarTypeName):
162+
case isScalarTypeName(stream.CurrentToken()):
164163
res.Type = stream.CurrentToken().ValueString()
165164
stream.GoNext()
166165
case stream.CurrentToken().Is(TokenOpenParens):
@@ -184,7 +183,7 @@ func parseArgument(stream *tokenizer.Stream) (eth_abi.ArgumentMarshaling, error)
184183
res.Type = res.Type + s
185184
}
186185

187-
if stream.CurrentToken().Is(TokenIndexed) {
186+
if isIndexedToken(stream.CurrentToken()) {
188187
res.Indexed = true
189188
stream.GoNext()
190189
}

0 commit comments

Comments
 (0)