forked from TrueCloudLab/neoneo-go
sc: implement io.Serializable for ParamType
This commit is contained in:
parent
2be18f91df
commit
1a08ad19aa
2 changed files with 16 additions and 10 deletions
|
@ -39,11 +39,7 @@ func (a Contracts) commit(store storage.Store) error {
|
||||||
// DecodeBinary implements Serializable interface.
|
// DecodeBinary implements Serializable interface.
|
||||||
func (cs *ContractState) DecodeBinary(br *io.BinReader) {
|
func (cs *ContractState) DecodeBinary(br *io.BinReader) {
|
||||||
cs.Script = br.ReadBytes()
|
cs.Script = br.ReadBytes()
|
||||||
paramBytes := br.ReadBytes()
|
br.ReadArray(&cs.ParamList)
|
||||||
cs.ParamList = make([]smartcontract.ParamType, len(paramBytes))
|
|
||||||
for k := range paramBytes {
|
|
||||||
cs.ParamList[k] = smartcontract.ParamType(paramBytes[k])
|
|
||||||
}
|
|
||||||
br.ReadLE(&cs.ReturnType)
|
br.ReadLE(&cs.ReturnType)
|
||||||
br.ReadLE(&cs.Properties)
|
br.ReadLE(&cs.Properties)
|
||||||
cs.Name = br.ReadString()
|
cs.Name = br.ReadString()
|
||||||
|
@ -57,10 +53,7 @@ func (cs *ContractState) DecodeBinary(br *io.BinReader) {
|
||||||
// EncodeBinary implements Serializable interface.
|
// EncodeBinary implements Serializable interface.
|
||||||
func (cs *ContractState) EncodeBinary(bw *io.BinWriter) {
|
func (cs *ContractState) EncodeBinary(bw *io.BinWriter) {
|
||||||
bw.WriteBytes(cs.Script)
|
bw.WriteBytes(cs.Script)
|
||||||
bw.WriteVarUint(uint64(len(cs.ParamList)))
|
bw.WriteArray(cs.ParamList)
|
||||||
for k := range cs.ParamList {
|
|
||||||
bw.WriteLE(cs.ParamList[k])
|
|
||||||
}
|
|
||||||
bw.WriteLE(cs.ReturnType)
|
bw.WriteLE(cs.ReturnType)
|
||||||
bw.WriteLE(cs.Properties)
|
bw.WriteLE(cs.Properties)
|
||||||
bw.WriteString(cs.Name)
|
bw.WriteString(cs.Name)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package smartcontract
|
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.
|
// ParamType represents the Type of the contract parameter.
|
||||||
type ParamType byte
|
type ParamType byte
|
||||||
|
@ -67,6 +70,16 @@ func (pt ParamType) MarshalJSON() ([]byte, error) {
|
||||||
return []byte(`"` + pt.String() + `"`), nil
|
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
|
// NewParameter returns a Parameter with proper initialized Value
|
||||||
// of the given ParamType.
|
// of the given ParamType.
|
||||||
func NewParameter(t ParamType) Parameter {
|
func NewParameter(t ParamType) Parameter {
|
||||||
|
|
Loading…
Reference in a new issue