-
Notifications
You must be signed in to change notification settings - Fork 248
/
event.go
52 lines (43 loc) · 1.19 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2018 The VeChainThor developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package abi
import (
ethabi "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/vechain/thor/v2/thor"
)
// Event see abi.Event in go-ethereum.
type Event struct {
id thor.Bytes32
event *ethabi.Event
argsWithoutIndexed ethabi.Arguments
}
func newEvent(event *ethabi.Event) *Event {
var argsWithoutIndexed ethabi.Arguments
for _, arg := range event.Inputs {
if !arg.Indexed {
argsWithoutIndexed = append(argsWithoutIndexed, arg)
}
}
return &Event{
thor.Bytes32(event.Id()),
event,
argsWithoutIndexed,
}
}
// ID returns event id.
func (e *Event) ID() thor.Bytes32 {
return e.id
}
// Name returns event name.
func (e *Event) Name() string {
return e.event.Name
}
// Encode encodes args to data.
func (e *Event) Encode(args ...interface{}) ([]byte, error) {
return e.argsWithoutIndexed.Pack(args...)
}
// Decode decodes event data.
func (e *Event) Decode(data []byte, v interface{}) error {
return e.argsWithoutIndexed.Unpack(v, data)
}