smartcontract: implement json.Unmarshaler for ParamType
This commit is contained in:
parent
ea30122a09
commit
eacea8bff5
1 changed files with 17 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue