neoneo-go/pkg/rpc/response/result/contract_state.go
2020-03-03 17:21:42 +03:00

56 lines
1.7 KiB
Go

package result
import (
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
)
// ContractState wrapper used for the representation of
// state.Contract on the RPC Server.
type ContractState struct {
Version byte `json:"version"`
ScriptHash util.Uint160 `json:"hash"`
Script []byte `json:"script"`
ParamList []smartcontract.ParamType `json:"parameters"`
ReturnType smartcontract.ParamType `json:"returntype"`
Name string `json:"name"`
CodeVersion string `json:"code_version"`
Author string `json:"author"`
Email string `json:"email"`
Description string `json:"description"`
Properties Properties `json:"properties"`
}
// Properties response wrapper.
type Properties struct {
HasStorage bool `json:"storage"`
HasDynamicInvoke bool `json:"dynamic_invoke"`
IsPayable bool `json:"is_payable"`
}
// NewContractState creates a new Contract wrapper.
func NewContractState(c *state.Contract) ContractState {
// reverse scriptHash to be consistent with other client
scriptHash := c.ScriptHash().Reverse()
properties := Properties{
HasStorage: c.HasStorage(),
HasDynamicInvoke: c.HasDynamicInvoke(),
IsPayable: c.IsPayable(),
}
return ContractState{
Version: 0,
ScriptHash: scriptHash,
Script: c.Script,
ParamList: c.ParamList,
ReturnType: c.ReturnType,
Properties: properties,
Name: c.Name,
CodeVersion: c.CodeVersion,
Author: c.Author,
Email: c.Email,
Description: c.Description,
}
}