mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
accounts/abi: add support for anonymous events
This commit is contained in:
parent
38827dd9ca
commit
bcfa8136be
3 changed files with 31 additions and 15 deletions
|
|
@ -349,6 +349,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
||||||
Name string
|
Name string
|
||||||
Constant bool
|
Constant bool
|
||||||
Indexed bool
|
Indexed bool
|
||||||
|
Anonymous bool
|
||||||
Inputs []Argument
|
Inputs []Argument
|
||||||
Outputs []Argument
|
Outputs []Argument
|
||||||
}
|
}
|
||||||
|
|
@ -376,6 +377,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
||||||
case "event":
|
case "event":
|
||||||
abi.Events[field.Name] = Event{
|
abi.Events[field.Name] = Event{
|
||||||
Name: field.Name,
|
Name: field.Name,
|
||||||
|
Anonymous: field.Anonymous,
|
||||||
Inputs: field.Inputs,
|
Inputs: field.Inputs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -752,23 +752,35 @@ func TestDefaultFunctionParsing(t *testing.T) {
|
||||||
func TestBareEvents(t *testing.T) {
|
func TestBareEvents(t *testing.T) {
|
||||||
const definition = `[
|
const definition = `[
|
||||||
{ "type" : "event", "name" : "balance" },
|
{ "type" : "event", "name" : "balance" },
|
||||||
{ "type" : "event", "name" : "name" }]`
|
{ "type" : "event", "name" : "name" },
|
||||||
|
{ "type" : "event", "name" : "anon", "anonymous" : true}]`
|
||||||
|
|
||||||
abi, err := JSON(strings.NewReader(definition))
|
abi, err := JSON(strings.NewReader(definition))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(abi.Events) != 2 {
|
if len(abi.Events) != 3 {
|
||||||
t.Error("expected 2 events")
|
t.Error("expected 3 events")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := abi.Events["balance"]; !ok {
|
if _, ok := abi.Events["balance"]; !ok {
|
||||||
t.Error("expected 'balance' event to be present")
|
t.Error("expected 'balance' event to be present")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := abi.Events["name"]; !ok {
|
if ev, ok := abi.Events["name"]; !ok {
|
||||||
t.Error("expected 'name' event to be present")
|
t.Error("expected 'name' event to be present")
|
||||||
|
} else if ev.Anonymous {
|
||||||
|
t.Errorf("expected 'name' to have the Anonymous field set to false")
|
||||||
|
}
|
||||||
|
|
||||||
|
anonEvent, ok := abi.Events["anon"]
|
||||||
|
if ok {
|
||||||
|
if !anonEvent.Anonymous {
|
||||||
|
t.Errorf("expected anon event to have the Anonymous field set to true")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Errorf("expected 'anon' event to be present")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Event is an event potentially triggered by the EVM's LOG mechanism. The Event
|
// Event is an event potentially triggered by the EVM's LOG mechanism. The Event
|
||||||
// holds type information (inputs) about the yielded output
|
// holds type information (inputs) about the yielded output. Anonymous events
|
||||||
|
// don't get the signature canonical representation as the first LOG topic.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Name string
|
Name string
|
||||||
|
Anonymous bool
|
||||||
Inputs []Argument
|
Inputs []Argument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue