Documentation ¶
Index ¶
- Constants
- Variables
- func ToPbLimits(limits Limits) []*pb.ResourceLimit
- type Context
- type ContextConfig
- type ContractExtInterface
- type ContractInterface
- type ContractOutputInterface
- type Limits
- type SmartContract
- func (s *SmartContract) Finalize(blockid []byte) error
- func (s *SmartContract) Get(name string) (ContractInterface, bool)
- func (s *SmartContract) GetAll() map[string]ContractInterface
- func (s *SmartContract) RegisterHandler(moduleName string, handler ContractInterface, priv int) bool
- func (s *SmartContract) Remove(name string, priv int)
- func (s *SmartContract) Rollback(desc *TxDesc) error
- func (s *SmartContract) Run(desc *TxDesc) error
- func (s *SmartContract) SetContext(ctx *TxContext)
- func (s *SmartContract) Stop()
- type TriggerDesc
- type TxContext
- type TxDesc
- type VMManager
- type VirtualMachine
Constants ¶
const ConsensusModueName = "consensus"
ConsensusModueName is the name of consensus contract
const (
// ContractPluginName is the name of contract plugin
ContractPluginName = "contract"
)
const KernelModuleName = "kernel"
KernelModuleName is the name of kernel contract
Variables ¶
var AutoGenWhiteList = map[string]bool{ "consensus.update_consensus": true, "kernel.UpdateMaxBlockSize": true, }
AutoGenWhiteList 为必须通过提案机制才能触发调用的智能合约名单
var ( // ErrVMNotExist is returned when found vm not exist ErrVMNotExist = errors.New("Vm not exist in vm manager") )
var MaxLimits = Limits{
Cpu: maxResourceLimit,
Memory: maxResourceLimit,
Disk: maxResourceLimit,
XFee: maxResourceLimit,
}
MaxLimits describes the maximum limit of resources
Functions ¶
func ToPbLimits ¶
func ToPbLimits(limits Limits) []*pb.ResourceLimit
FromPbLimits converts Limits to []*pb.ResourceLimit
Types ¶
type Context ¶
type Context interface { Invoke(method string, args map[string][]byte) ([]byte, error) ResourceUsed() Limits Release() error }
Context define context interface
type ContextConfig ¶
type ContextConfig struct { XMCache *xmodel.XMCache Initiator string AuthRequire []string ContractName string ResourceLimits Limits }
ContextConfig define the config of context
type ContractExtInterface ¶
ContractExtInterface is used to initialize contract plugin
type ContractInterface ¶
type ContractInterface interface { //TX界别的接口 Run(desc *TxDesc) error Rollback(desc *TxDesc) error //获取执行合约的结果 ReadOutput(desc *TxDesc) (ContractOutputInterface, error) //block级别的接口 //区块生成之后,用来更新各个合约的状态 Finalize(blockid []byte) error //用于被设置上下文 SetContext(context *TxContext) error Stop() }
ContractInterface is the interface to implement a contract driver
func CreateContractInstance ¶
func CreateContractInstance(subtype string, extParams map[string]interface{}) (ContractInterface, error)
CreateContractInstance create contract driver from plugin manager
type ContractOutputInterface ¶
type ContractOutputInterface interface { Decode(data []byte) error Encode() ([]byte, error) GetGasUsed() uint64 Digest() ([]byte, error) }
ContractOutputInterface used to read output of a contract
type Limits ¶
Limits describes the usage or limit of resources
func FromPbLimits ¶
func FromPbLimits(rlimits []*pb.ResourceLimit) Limits
FromPbLimits converts []*pb.ResourceLimit to Limits
type SmartContract ¶
type SmartContract struct {
// contains filtered or unexported fields
}
SmartContract manage smart contracts
func NewSmartContract ¶
func NewSmartContract() *SmartContract
NewSmartContract instances a new SmartContract instance
func (*SmartContract) Finalize ¶
func (s *SmartContract) Finalize(blockid []byte) error
Finalize 在一个块的合约执行完毕之后调用。这里必须在run 之后调用,这里有可能提交之前没有提交过的合约结果
func (*SmartContract) Get ¶
func (s *SmartContract) Get(name string) (ContractInterface, bool)
Get returns ContractInterface from contract driver name
func (*SmartContract) GetAll ¶
func (s *SmartContract) GetAll() map[string]ContractInterface
GetAll returns all the contract drivers
func (*SmartContract) RegisterHandler ¶
func (s *SmartContract) RegisterHandler(moduleName string, handler ContractInterface, priv int) bool
RegisterHandler 注册module对应的handler
func (*SmartContract) Remove ¶
func (s *SmartContract) Remove(name string, priv int)
Remove remove contract driver
func (*SmartContract) SetContext ¶
func (s *SmartContract) SetContext(ctx *TxContext)
SetContext 设置所有注册合约的上下文。这里必须在run之前设置,后设置会覆盖前面设置的
type TriggerDesc ¶
type TriggerDesc struct { TxDesc Height int64 `json:"height"` RefTxid []byte `json:"refTxid"` //创建trigger的txid,系统自动回填的 }
TriggerDesc is the description to trigger a event used by proposal
type TxContext ¶
type TxContext struct { UtxoBatch kvdb.Batch //如果合约机和UtxoVM共用DB, 可以将修改打包到这个batch确保原子性 //... 其他的需要UtxoVM与合约机共享的也可以放到这里 Block *pb.InternalBlock LedgerObj *ledger.Ledger IsUndo bool }
TxContext 合约的上下文,通常生命周期是Block范围
type TxDesc ¶
type TxDesc struct { Module string `json:"module"` Method string `json:"method"` Args map[string]interface{} `json:"args"` //纯文本注释 Tag []byte `json:"tag"` //表示当前合约执行到期时间, 只有大于0的时候才有效, 否则应该被认为是不限制到期时间 Deadline int64 `json:"deadline"` Tx *pb.Transaction `json:"tx"` Trigger *TriggerDesc `json:"trigger"` }
TxDesc is the description to running a contract
type VMManager ¶
type VMManager struct {
// contains filtered or unexported fields
}
VMManager define VMManager type
func NewVMManager ¶
NewVMManager new an instance of VMManager
func (*VMManager) GetVM ¶
func (vmMgr *VMManager) GetVM(module string) (VirtualMachine, error)
GetVM return specific virtual machine instance
func (*VMManager) RegisterVM ¶
func (vmMgr *VMManager) RegisterVM(module string, vm VirtualMachine) error
RegisterVM register an instance of VM into VMManager
type VirtualMachine ¶
type VirtualMachine interface { GetName() string NewContext(*ContextConfig) (Context, error) }
VirtualMachine define virtual machine interface