-
Notifications
You must be signed in to change notification settings - Fork 13
/
precompiles.go
39 lines (34 loc) · 1.01 KB
/
precompiles.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
package types
import (
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
var (
TypeAddress, _ = abi.NewType("address", "", nil)
TypeUint256, _ = abi.NewType("uint256", "", nil)
TypeString, _ = abi.NewType("string", "", nil)
TypeBool, _ = abi.NewType("bool", "", nil)
TypeBytes32, _ = abi.NewType("bytes32", "", nil)
)
func ParseMethodArgs(method abi.Method, v MethodArgs, data []byte) error {
unpacked, err := method.Inputs.Unpack(data)
if err != nil {
return err
}
if err = method.Inputs.Copy(v, unpacked); err != nil {
return err
}
return v.Validate()
}
func PackTopicData(event abi.Event, topics []common.Hash, args ...interface{}) ([]byte, []common.Hash, error) {
data, err := event.Inputs.NonIndexed().Pack(args...)
if err != nil {
return nil, nil, fmt.Errorf("pack %s event error: %s", event.Name, err.Error())
}
newTopic := []common.Hash{event.ID}
if len(topics) > 0 {
newTopic = append(newTopic, topics...)
}
return data, newTopic, nil
}