Documentation ¶
Index ¶
- type Bridge
- type CallContract
- type Contract
- type ContractError
- type ContractState
- type Executor
- type Instance
- type StateManager
- type SyscallService
- func (c *SyscallService) DeleteObject(ctx context.Context, in *pb.DeleteRequest) (*pb.DeleteResponse, error)
- func (c *SyscallService) GetCallArgs(ctx context.Context, in *pb.GetCallArgsRequest) (*pb.CallArgs, error)
- func (c *SyscallService) GetObject(ctx context.Context, in *pb.GetRequest) (*pb.GetResponse, error)
- func (c *SyscallService) PutObject(ctx context.Context, in *pb.PutRequest) (*pb.PutResponse, error)
- func (c *SyscallService) SetOutput(ctx context.Context, in *pb.SetOutputRequest) (*pb.SetOutputResponse, error)
- type VirtualMachine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge 用于注册用户虚拟机以及向Xchain Core注册可被识别的vm.VirtualMachine
func (*Bridge) GetVirtualMachine ¶
func (v *Bridge) GetVirtualMachine(name string) (VirtualMachine, bool)
GetVirtualMachine returns a contract.VirtualMachine from the given name
func (*Bridge) RegisterExecutor ¶
func (v *Bridge) RegisterExecutor(name string, exec Executor) VirtualMachine
RegisterExecutor register a Executor to Bridge
type CallContract ¶
type ContractError ¶
ContractError indicates the error of the contract running result
func (*ContractError) Error ¶
func (c *ContractError) Error() string
Error implements error interface
type ContractState ¶
type ContractState struct { ID int64 // 合约名字 ContractName string Method string Args map[string][]byte Language string Caller string Output *pb.Response }
ContractState 保存了合约执行的内核状态, 所有的系统调用产生的状态保存在这里
type Executor ¶
type Executor interface { // RegisterSyscallService 用于虚拟机把系统调用链接到合约代码上,类似vdso // 注册到Registry的时候被调用一次 RegisterSyscallService(*SyscallService) // NewCreatorInstance 根据合约Context返回合约虚拟机的一个实例 NewCreatorInstance(ctx *ContractState) (Instance, error) CallContract }
Executor 为用户态虚拟机工厂类
type Instance ¶
type Instance interface { // Exec根据ctx里面的参数执行合约代码 Exec(function string) error // ResourceUsed returns the resource used by contract ResourceUsed() gas.Limits // ReleaseCache releases contract instance Release() // Abort terminates running contract with error message Abort(msg string) }
Instance is an instance of a contract run
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager 用于管理产生和销毁ContractState
func NewStateManager ¶
func NewStateManager() *StateManager
NewStateManager instances a new StateManager
func (*StateManager) CreateContractState ¶
func (n *StateManager) CreateContractState() *ContractState
CreateContractState allocates a ContractState with unique context id
func (*StateManager) DestroyContractState ¶
func (n *StateManager) DestroyContractState(ctx *ContractState)
DestroyContractState 一定要在合约执行完毕(成功或失败)进行销毁
func (*StateManager) GetContractState ¶
func (n *StateManager) GetContractState(id int64) (*ContractState, bool)
ContractState 根据ContractState的id返回当前运行当前合约的上下文
type SyscallService ¶
type SyscallService struct {
// contains filtered or unexported fields
}
SyscallService is the handler of contract syscalls
func NewSyscallService ¶
func NewSyscallService(state *StateManager, db db.Database) *SyscallService
NewSyscallService instances a new SyscallService
func (*SyscallService) DeleteObject ¶
func (c *SyscallService) DeleteObject(ctx context.Context, in *pb.DeleteRequest) (*pb.DeleteResponse, error)
DeleteObject implements Syscall interface
func (*SyscallService) GetCallArgs ¶
func (c *SyscallService) GetCallArgs(ctx context.Context, in *pb.GetCallArgsRequest) (*pb.CallArgs, error)
GetCallArgs implements Syscall interface
func (*SyscallService) GetObject ¶
func (c *SyscallService) GetObject(ctx context.Context, in *pb.GetRequest) (*pb.GetResponse, error)
GetObject implements Syscall interface
func (*SyscallService) PutObject ¶
func (c *SyscallService) PutObject(ctx context.Context, in *pb.PutRequest) (*pb.PutResponse, error)
PutObject implements Syscall interface
func (*SyscallService) SetOutput ¶
func (c *SyscallService) SetOutput(ctx context.Context, in *pb.SetOutputRequest) (*pb.SetOutputResponse, error)
SetOutput implements Syscall interface
type VirtualMachine ¶
type VirtualMachine interface { GetName() string NewVM(state *ContractState) (Contract, error) CallContract }
VirtualMachine define virtual machine interface