diff --git a/pkg/core/contract_state.go b/pkg/core/contract_state.go index b5e736b7a..e3efdce27 100644 --- a/pkg/core/contract_state.go +++ b/pkg/core/contract_state.go @@ -39,11 +39,7 @@ func (a Contracts) commit(store storage.Store) error { // DecodeBinary implements Serializable interface. func (cs *ContractState) DecodeBinary(br *io.BinReader) { cs.Script = br.ReadBytes() - paramBytes := br.ReadBytes() - cs.ParamList = make([]smartcontract.ParamType, len(paramBytes)) - for k := range paramBytes { - cs.ParamList[k] = smartcontract.ParamType(paramBytes[k]) - } + br.ReadArray(&cs.ParamList) br.ReadLE(&cs.ReturnType) br.ReadLE(&cs.Properties) cs.Name = br.ReadString() @@ -57,10 +53,7 @@ func (cs *ContractState) DecodeBinary(br *io.BinReader) { // EncodeBinary implements Serializable interface. func (cs *ContractState) EncodeBinary(bw *io.BinWriter) { bw.WriteBytes(cs.Script) - bw.WriteVarUint(uint64(len(cs.ParamList))) - for k := range cs.ParamList { - bw.WriteLE(cs.ParamList[k]) - } + bw.WriteArray(cs.ParamList) bw.WriteLE(cs.ReturnType) bw.WriteLE(cs.Properties) bw.WriteString(cs.Name) diff --git a/pkg/smartcontract/param_context.go b/pkg/smartcontract/param_context.go index f7414f6a0..98d32a1f9 100644 --- a/pkg/smartcontract/param_context.go +++ b/pkg/smartcontract/param_context.go @@ -1,6 +1,9 @@ package smartcontract -import "github.com/CityOfZion/neo-go/pkg/util" +import ( + "github.com/CityOfZion/neo-go/pkg/io" + "github.com/CityOfZion/neo-go/pkg/util" +) // ParamType represents the Type of the contract parameter. type ParamType byte @@ -67,6 +70,16 @@ func (pt ParamType) MarshalJSON() ([]byte, error) { return []byte(`"` + pt.String() + `"`), nil } +// EncodeBinary implements io.Serializable interface. +func (pt ParamType) EncodeBinary(w *io.BinWriter) { + w.WriteLE(pt) +} + +// DecodeBinary implements io.Serializable interface. +func (pt *ParamType) DecodeBinary(r *io.BinReader) { + r.ReadLE(pt) +} + // NewParameter returns a Parameter with proper initialized Value // of the given ParamType. func NewParameter(t ParamType) Parameter {