bridge

package
v0.0.0-...-d9e9996 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfDiskLimit = errors.New("out of disk limit")
)

Functions

func ConvertTxToSDKTx

func ConvertTxToSDKTx(tx *AmpChainpb.Transaction) *pb.Transaction

Types

type Context

type Context struct {
	ID int64
	// 合约名字
	ContractName string

	ResourceLimits contract.Limits

	Cache *xmodel.XMCache

	Args map[string][]byte

	Method string

	Initiator string

	AuthRequire []string

	// Write by contract
	Output *pb.Response
}

Context 保存了合约执行的内核状态, 所有的系统调用产生的状态保存在这里

func (*Context) DiskUsed

func (c *Context) DiskUsed() int64

DiskUsed returns the bytes written to xmodel

func (*Context) ExceedDiskLimit

func (c *Context) ExceedDiskLimit() bool

ExceedDiskLimit check whether disk usage exceeds limit

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 ContractError

type ContractError struct {
	Status  int
	Message string
}

ContractError indicates the error of the contract running result

func (*ContractError) Error

func (c *ContractError) Error() string

Error implements error interface

type Executor

type Executor interface {
	// RegisterSyscallService 用于虚拟机把系统调用链接到合约代码上,类似vdso
	// 注册到Registry的时候被调用一次
	RegisterSyscallService(*SyscallService)
	// NewInstance 根据合约Context返回合约虚拟机的一个实例
	NewInstance(ctx *Context) (Instance, error)
}

Executor 为用户态虚拟机工厂类

type Instance

type Instance interface {
	// Exec根据ctx里面的参数执行合约代码
	Exec() error
	// ResourceUsed returns the resource used by contract
	ResourceUsed() contract.Limits
	// Release releases contract instance
	Release()
}

Instance is an instance of a contract run

type SyscallService

type SyscallService struct {
	// contains filtered or unexported fields
}

SyscallService is the handler of contract syscalls

func NewSyscallService

func NewSyscallService(ctxmgr *ContextManager) *SyscallService

NewSyscallService instances a new SyscallService

func (*SyscallService) ContractCall

ContractCall 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) 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

NewIterator implements Syscall interface

func (*SyscallService) Ping

Ping 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) QueryBlock

QueryBlock implements Syscall interface

func (*SyscallService) QueryTx

QueryTx implements Syscall interface

func (*SyscallService) SetOutput

SetOutput implements Syscall interface

func (*SyscallService) Transfer

Transfer implements Syscall interface

type XBridge

type XBridge struct {
	// contains filtered or unexported fields
}

XBridge 用于注册用户虚拟机以及向AChain Core注册可被识别的vm.VirtualMachine

func New

func New() *XBridge

New instances a new XBridge

func (*XBridge) GetVirtualMachine

func (v *XBridge) GetVirtualMachine(name string) (contract.VirtualMachine, bool)

GetVirtualMachine returns a contract.VirtualMachine from the given name

func (*XBridge) RegisterExecutor

func (v *XBridge) RegisterExecutor(name string, exec Executor) contract.VirtualMachine

RegisterExecutor register a Executor to XBridge

func (*XBridge) RegisterToXCore

func (v *XBridge) RegisterToXCore(regfunc func(name string, vm contract.VirtualMachine) error)

RegisterToXCore register VirtualMachines to AmpChain core

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL