/
helpers.go
44 lines (33 loc) · 925 Bytes
/
helpers.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
package eth
import (
"encoding/hex"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/pkg/errors"
"github.com/barnbridge/meminero/utils"
)
func DecodeString(output string) ([]byte, error) {
output = utils.Trim0x(output)
data, err := hex.DecodeString(output)
if err != nil {
return nil, errors.Wrap(err, "could not decode log data")
}
return data, nil
}
func DecodeFunctionOutputToInterface(a abi.ABI, methodName string, output string, result interface{}) error {
data, err := DecodeString(output)
if err != nil {
return err
}
err = a.UnpackIntoInterface(result, methodName, data)
if err != nil {
return errors.Wrap(err, "could not unpack log data")
}
return nil
}
func ABIGenerateInput(a abi.ABI, methodName string, args ...interface{}) (string, error) {
input, err := a.Pack(methodName, args...)
if err != nil {
return "", nil
}
return "0x" + hex.EncodeToString(input), nil
}