smartcontract: implement json.Unmarshaler for ParamType

This commit is contained in:
Evgenii Stratonikov 2020-02-20 13:25:01 +03:00
parent ea30122a09
commit eacea8bff5

View file

@ -2,6 +2,7 @@ package smartcontract
import (
"encoding/hex"
"encoding/json"
"errors"
"strconv"
"strings"
@ -78,6 +79,22 @@ func (pt ParamType) MarshalJSON() ([]byte, error) {
return []byte(`"` + pt.String() + `"`), nil
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (pt *ParamType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
p, err := parseParamType(s)
if err != nil {
return err
}
*pt = p
return nil
}
// EncodeBinary implements io.Serializable interface.
func (pt ParamType) EncodeBinary(w *io.BinWriter) {
w.WriteB(byte(pt))