bridge

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultCap define default cap of NewIterator
	DefaultCap = 1000
	// MaxContractCallDepth define max contract call depth
	MaxContractCallDepth = 10
)

Variables

View Source
var (
	// ErrOutOfDiskLimit define OutOfDiskLimit Error
	ErrOutOfDiskLimit    = errors.New("out of disk limit")
	ErrNotImplementation = errors.New("not implementation")
)

Functions

func AmountBytesToString

func AmountBytesToString(buf []byte) string

AmountBytesToString conver amount bytes to string

func ContractCodeDescKey

func ContractCodeDescKey(contractName string) []byte

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
}

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

func (*Context) GetAuthRequire

func (c *Context) GetAuthRequire() []string

GetAuthRequire return initiator

func (*Context) GetInitiator

func (c *Context) GetInitiator() string

GetInitiator return initiator

func (*Context) ResourceUsed

func (c *Context) ResourceUsed() contract.Limits

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

ContractCodeProvider provides source code and desc of contract

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 ContractType

type ContractType string
const (
	TypeWasm   ContractType = "wasm"
	TypeNative ContractType = "native"
	TypeEvm    ContractType = "evm"
	TypeKernel ContractType = "xkernel"
)

type Instance

type Instance interface {
	Exec() error
	ResourceUsed() contract.Limits
	Release()
	Abort(msg string)
}

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

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

ContractCall implements Syscall interface

func (*SyscallService) CrossContractQuery

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

PostLog handle log entry from contract

func (*SyscallService) GetAccountAddresses

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

NewIterator implements Syscall interface

func (*SyscallService) Ping

Ping implements Syscall interface

func (*SyscallService) PostLog

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

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 VMConfig

type VMConfig interface {
	DriverName() string
	IsEnable() bool
}

type XBridge

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

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

func New

func New(cfg *XBridgeConfig) (*XBridge, error)

New instances a new XBridge

func (XBridge) DeployContract

func (c XBridge) DeployContract(kctx contract.KContext) (*contract.Response, contract.Limits, error)

DeployContract deploy contract and initialize contract

func (*XBridge) NewContext

func (v *XBridge) NewContext(ctxCfg *contract.ContextConfig) (contract.Context, error)

func (XBridge) UpgradeContract

func (c XBridge) UpgradeContract(kctx contract.KContext) (*contract.Response, contract.Limits, error)

UpgradeContract deploy contract and initialize contract

type XBridgeConfig

type XBridgeConfig struct {
	Basedir   string
	VMConfigs map[ContractType]VMConfig
	XModel    ledger.XMReader
	Config    contract.ContractConfig
	LogDriver logs.Logger
	Core      contract.ChainCore
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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