2017-11-27 15:39:53 +00:00
|
|
|
package geth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrInvalidAbiFile = errors.New("invalid abi")
|
|
|
|
ErrMissingAbiFile = errors.New("missing abi")
|
|
|
|
)
|
|
|
|
|
|
|
|
func ParseAbiFile(abiFilePath string) (abi.ABI, error) {
|
2017-12-04 21:12:27 +00:00
|
|
|
abiString, err := ReadAbiFile(abiFilePath)
|
2017-11-27 15:39:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return abi.ABI{}, ErrMissingAbiFile
|
|
|
|
}
|
2017-12-04 22:35:41 +00:00
|
|
|
return ParseAbi(abiString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseAbi(abiString string) (abi.ABI, error) {
|
2017-11-27 15:39:53 +00:00
|
|
|
parsedAbi, err := abi.JSON(strings.NewReader(abiString))
|
|
|
|
if err != nil {
|
|
|
|
return abi.ABI{}, ErrInvalidAbiFile
|
|
|
|
}
|
|
|
|
return parsedAbi, nil
|
|
|
|
}
|
2017-12-04 21:12:27 +00:00
|
|
|
|
|
|
|
func ReadAbiFile(abiFilePath string) (string, error) {
|
|
|
|
filesBytes, err := ioutil.ReadFile(abiFilePath)
|
|
|
|
if err != nil {
|
|
|
|
return "", ErrMissingAbiFile
|
|
|
|
}
|
|
|
|
return string(filesBytes), nil
|
|
|
|
}
|