mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 13:58:05 +00:00
ec17654986
add dao which takes care about all CRUD operations on storage remove blockchain state since everything is stored on change remove storage operations from structs(entities) move structs to entities package
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package entities
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
|
"github.com/CityOfZion/neo-go/pkg/smartcontract"
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
)
|
|
|
|
// ContractState holds information about a smart contract in the NEO blockchain.
|
|
type ContractState struct {
|
|
Script []byte
|
|
ParamList []smartcontract.ParamType
|
|
ReturnType smartcontract.ParamType
|
|
Properties smartcontract.PropertyState
|
|
Name string
|
|
CodeVersion string
|
|
Author string
|
|
Email string
|
|
Description string
|
|
|
|
scriptHash util.Uint160
|
|
}
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
func (cs *ContractState) DecodeBinary(br *io.BinReader) {
|
|
cs.Script = br.ReadVarBytes()
|
|
br.ReadArray(&cs.ParamList)
|
|
br.ReadLE(&cs.ReturnType)
|
|
br.ReadLE(&cs.Properties)
|
|
cs.Name = br.ReadString()
|
|
cs.CodeVersion = br.ReadString()
|
|
cs.Author = br.ReadString()
|
|
cs.Email = br.ReadString()
|
|
cs.Description = br.ReadString()
|
|
cs.createHash()
|
|
}
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
func (cs *ContractState) EncodeBinary(bw *io.BinWriter) {
|
|
bw.WriteVarBytes(cs.Script)
|
|
bw.WriteArray(cs.ParamList)
|
|
bw.WriteLE(cs.ReturnType)
|
|
bw.WriteLE(cs.Properties)
|
|
bw.WriteString(cs.Name)
|
|
bw.WriteString(cs.CodeVersion)
|
|
bw.WriteString(cs.Author)
|
|
bw.WriteString(cs.Email)
|
|
bw.WriteString(cs.Description)
|
|
}
|
|
|
|
// ScriptHash returns a contract script hash.
|
|
func (cs *ContractState) ScriptHash() util.Uint160 {
|
|
if cs.scriptHash.Equals(util.Uint160{}) {
|
|
cs.createHash()
|
|
}
|
|
return cs.scriptHash
|
|
}
|
|
|
|
// createHash creates contract script hash.
|
|
func (cs *ContractState) createHash() {
|
|
cs.scriptHash = hash.Hash160(cs.Script)
|
|
}
|
|
|
|
// HasStorage checks whether the contract has storage property set.
|
|
func (cs *ContractState) HasStorage() bool {
|
|
return (cs.Properties & smartcontract.HasStorage) != 0
|
|
}
|
|
|
|
// HasDynamicInvoke checks whether the contract has dynamic invoke property set.
|
|
func (cs *ContractState) HasDynamicInvoke() bool {
|
|
return (cs.Properties & smartcontract.HasDynamicInvoke) != 0
|
|
}
|
|
|
|
// IsPayable checks whether the contract has payable property set.
|
|
func (cs *ContractState) IsPayable() bool {
|
|
return (cs.Properties & smartcontract.IsPayable) != 0
|
|
}
|