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.
|
||||
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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue