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
|
|
@ -345,12 +345,13 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) error {
|
|||
|
||||
func (abi *ABI) UnmarshalJSON(data []byte) error {
|
||||
var fields []struct {
|
||||
Type string
|
||||
Name string
|
||||
Constant bool
|
||||
Indexed bool
|
||||
Inputs []Argument
|
||||
Outputs []Argument
|
||||
Type string
|
||||
Name string
|
||||
Constant bool
|
||||
Indexed bool
|
||||
Anonymous bool
|
||||
Inputs []Argument
|
||||
Outputs []Argument
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &fields); err != nil {
|
||||
|
|
@ -375,8 +376,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
case "event":
|
||||
abi.Events[field.Name] = Event{
|
||||
Name: field.Name,
|
||||
Inputs: field.Inputs,
|
||||
Name: field.Name,
|
||||
Anonymous: field.Anonymous,
|
||||
Inputs: field.Inputs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -752,23 +752,35 @@ func TestDefaultFunctionParsing(t *testing.T) {
|
|||
func TestBareEvents(t *testing.T) {
|
||||
const definition = `[
|
||||
{ "type" : "event", "name" : "balance" },
|
||||
{ "type" : "event", "name" : "name" }]`
|
||||
{ "type" : "event", "name" : "name" },
|
||||
{ "type" : "event", "name" : "anon", "anonymous" : true}]`
|
||||
|
||||
abi, err := JSON(strings.NewReader(definition))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(abi.Events) != 2 {
|
||||
t.Error("expected 2 events")
|
||||
if len(abi.Events) != 3 {
|
||||
t.Error("expected 3 events")
|
||||
}
|
||||
|
||||
if _, ok := abi.Events["balance"]; !ok {
|
||||
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")
|
||||
} 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,10 +25,12 @@ import (
|
|||
)
|
||||
|
||||
// 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 {
|
||||
Name string
|
||||
Inputs []Argument
|
||||
Name string
|
||||
Anonymous bool
|
||||
Inputs []Argument
|
||||
}
|
||||
|
||||
// Id returns the canonical representation of the event's signature used by the
|
||||
|
|
|
|||
Loading…
Reference in a new issue