Documentation ¶
Index ¶
- Constants
- Variables
- func AmountBytesToString(buf []byte) string
- func ContractCodeDescKey(contractName string) []byte
- func Register(tp ContractType, name string, driver NewInstanceCreatorFunc)
- type Context
- type ContextManager
- type ContractCodeProvider
- type ContractError
- type ContractType
- type Instance
- type InstanceCreator
- type InstanceCreatorConfig
- type NewInstanceCreatorFunc
- type SyscallService
- func (c *SyscallService) ContractCall(ctx context.Context, in *pb.ContractCallRequest) (*pb.ContractCallResponse, error)
- func (c *SyscallService) CrossContractQuery(ctx context.Context, in *pb.CrossContractQueryRequest) (*pb.CrossContractQueryResponse, error)
- func (c *SyscallService) DeleteObject(ctx context.Context, in *pb.DeleteRequest) (*pb.DeleteResponse, error)
- func (c *SyscallService) EmitEvent(ctx context.Context, in *pb.EmitEventRequest) (*pb.EmitEventResponse, error)
- func (c *SyscallService) GetAccountAddresses(ctx context.Context, in *pb.GetAccountAddressesRequest) (*pb.GetAccountAddressesResponse, 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) NewIterator(ctx context.Context, in *pb.IteratorRequest) (*pb.IteratorResponse, error)
- func (c *SyscallService) Ping(ctx context.Context, in *pb.PingRequest) (*pb.PingResponse, error)
- func (c *SyscallService) PostLog(ctx context.Context, in *pb.PostLogRequest) (*pb.PostLogResponse, error)
- func (c *SyscallService) PutObject(ctx context.Context, in *pb.PutRequest) (*pb.PutResponse, error)
- func (c *SyscallService) QueryBlock(ctx context.Context, in *pb.QueryBlockRequest) (*pb.QueryBlockResponse, error)
- func (c *SyscallService) QueryTx(ctx context.Context, in *pb.QueryTxRequest) (*pb.QueryTxResponse, error)
- func (c *SyscallService) SetOutput(ctx context.Context, in *pb.SetOutputRequest) (*pb.SetOutputResponse, error)
- func (c *SyscallService) Transfer(ctx context.Context, in *pb.TransferRequest) (*pb.TransferResponse, error)
- type VMConfig
- type XBridge
- type XBridgeConfig
Constants ¶
const ( // DefaultCap define default cap of NewIterator DefaultCap = 1000 // MaxContractCallDepth define max contract call depth MaxContractCallDepth = 10 )
Variables ¶
var ( // ErrOutOfDiskLimit define OutOfDiskLimit Error ErrOutOfDiskLimit = errors.New("out of disk limit") ErrNotImplementation = errors.New("not implementation") )
Functions ¶
func AmountBytesToString ¶
AmountBytesToString conver amount bytes to string
func ContractCodeDescKey ¶
func Register ¶
func Register(tp ContractType, name string, driver NewInstanceCreatorFunc)
Register makes a contract driver available by the provided type and name
Types ¶
type Context ¶
type Context struct { ID int64 Module string // 合约名字 ContractName string ResourceLimits contract.Limits State contract.StateSandbox Args map[string][]byte Method string Initiator string Caller string AuthRequire []string CanInitialize bool Core contract.ChainCore TransferAmount string Instance Instance Logger logs.Logger // resource used by sub contract call SubResourceUsed contract.Limits // Contract being called // set by bridge to check recursive contract call ContractSet map[string]bool // The events generated by contract Events []*protos.ContractEvent // Write by contract Output *pb.Response // Read from cache ReadFromCache bool ChainName string }
Context 保存了合约执行的内核状态, 所有的系统调用产生的状态保存在这里
func (*Context) ExceedDiskLimit ¶
ExceedDiskLimit check whether disk usage exceeds limit
func (*Context) GetAuthRequire ¶
GetAuthRequire return initiator
func (*Context) GetInitiator ¶
GetInitiator return initiator
func (*Context) ResourceUsed ¶
ResourceUsed returns the resource used by context
type ContextManager ¶
type ContextManager struct {
// contains filtered or unexported fields
}
ContextManager 用于管理产生和销毁Context
func NewContextManager ¶
func NewContextManager() *ContextManager
NewContextManager instances a new ContextManager
func (*ContextManager) Context ¶
func (n *ContextManager) Context(id int64) (*Context, bool)
Context 根据context的id返回当前运行当前合约的上下文
func (*ContextManager) DestroyContext ¶
func (n *ContextManager) DestroyContext(ctx *Context)
DestroyContext 一定要在合约执行完毕(成功或失败)进行销毁
func (*ContextManager) MakeContext ¶
func (n *ContextManager) MakeContext() *Context
MakeContext allocates a Context with unique context id
type ContractCodeProvider ¶
type ContractCodeProvider interface { GetContractCodeDesc(name string) (*protos.WasmCodeDesc, error) GetContractCode(name string) ([]byte, error) GetContractAbi(name string) ([]byte, error) GetContractCodeFromCache(name string) ([]byte, error) GetContractAbiFromCache(name string) ([]byte, error) }
ContractCodeProvider provides source code and desc of contract
type ContractError ¶
ContractError indicates the error of the contract running result
func (*ContractError) Error ¶
func (c *ContractError) Error() string
Error implements error interface
type ContractType ¶
type ContractType string
const ( TypeWasm ContractType = "wasm" TypeNative ContractType = "native" TypeEvm ContractType = "evm" TypeKernel ContractType = "xkernel" )
type Instance ¶
Instance is a contract virtual machine instance which can run a single contract call
type InstanceCreator ¶
type InstanceCreator interface { // CreateInstance instances a wasm virtual machine instance which can run a single contract call CreateInstance(ctx *Context, cp ContractCodeProvider) (Instance, error) RemoveCache(name string) }
InstanceCreator is the creator of contract virtual machine instance
func Open ¶
func Open(tp ContractType, name string, config *InstanceCreatorConfig) (InstanceCreator, error)
Open opens a contract virtual machine specified by its driver type and name
type InstanceCreatorConfig ¶
type InstanceCreatorConfig struct { Basedir string SyscallService *SyscallService // VMConfig is the config of vm driver VMConfig VMConfig }
InstanceCreatorConfig configures InstanceCreator
type NewInstanceCreatorFunc ¶
type NewInstanceCreatorFunc func(config *InstanceCreatorConfig) (InstanceCreator, error)
NewInstanceCreatorFunc instances a new InstanceCreator from InstanceCreatorConfig
type SyscallService ¶
type SyscallService struct {
// contains filtered or unexported fields
}
SyscallService is the handler of contract syscalls
func NewSyscallService ¶
func NewSyscallService(ctxmgr *ContextManager, bridge *XBridge) *SyscallService
NewSyscallService instances a new SyscallService
func (*SyscallService) ContractCall ¶
func (c *SyscallService) ContractCall(ctx context.Context, in *pb.ContractCallRequest) (*pb.ContractCallResponse, error)
ContractCall implements Syscall interface
func (*SyscallService) CrossContractQuery ¶
func (c *SyscallService) CrossContractQuery(ctx context.Context, in *pb.CrossContractQueryRequest) (*pb.CrossContractQueryResponse, error)
CrossContractQuery implements Syscall interface
func (*SyscallService) DeleteObject ¶
func (c *SyscallService) DeleteObject(ctx context.Context, in *pb.DeleteRequest) (*pb.DeleteResponse, error)
DeleteObject implements Syscall interface
func (*SyscallService) EmitEvent ¶
func (c *SyscallService) EmitEvent(ctx context.Context, in *pb.EmitEventRequest) (*pb.EmitEventResponse, error)
PostLog handle log entry from contract
func (*SyscallService) GetAccountAddresses ¶
func (c *SyscallService) GetAccountAddresses(ctx context.Context, in *pb.GetAccountAddressesRequest) (*pb.GetAccountAddressesResponse, error)
GetAccountAddresses mplements 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) NewIterator ¶
func (c *SyscallService) NewIterator(ctx context.Context, in *pb.IteratorRequest) (*pb.IteratorResponse, error)
NewIterator implements Syscall interface
func (*SyscallService) Ping ¶
func (c *SyscallService) Ping(ctx context.Context, in *pb.PingRequest) (*pb.PingResponse, error)
Ping implements Syscall interface
func (*SyscallService) PostLog ¶
func (c *SyscallService) PostLog(ctx context.Context, in *pb.PostLogRequest) (*pb.PostLogResponse, error)
PostLog handle log entry from contract
func (*SyscallService) PutObject ¶
func (c *SyscallService) PutObject(ctx context.Context, in *pb.PutRequest) (*pb.PutResponse, error)
PutObject implements Syscall interface
func (*SyscallService) QueryBlock ¶
func (c *SyscallService) QueryBlock(ctx context.Context, in *pb.QueryBlockRequest) (*pb.QueryBlockResponse, error)
QueryBlock implements Syscall interface
func (*SyscallService) QueryTx ¶
func (c *SyscallService) QueryTx(ctx context.Context, in *pb.QueryTxRequest) (*pb.QueryTxResponse, error)
QueryTx implements Syscall interface
func (*SyscallService) SetOutput ¶
func (c *SyscallService) SetOutput(ctx context.Context, in *pb.SetOutputRequest) (*pb.SetOutputResponse, error)
SetOutput implements Syscall interface
func (*SyscallService) Transfer ¶
func (c *SyscallService) Transfer(ctx context.Context, in *pb.TransferRequest) (*pb.TransferResponse, error)
Transfer implements Syscall interface
type XBridge ¶
type XBridge struct {
// contains filtered or unexported fields
}
XBridge 用于注册用户虚拟机以及向Xchain Core注册可被识别的vm.VirtualMachine
func (XBridge) DeployContract ¶
func (c XBridge) DeployContract(kctx contract.KContext) (*contract.Response, contract.Limits, error)
DeployContract deploy contract and initialize contract