interop

package
v0.95.2-pre Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package interop contains implementations of Neo interop functions.

This is not the package you use from smart contracts, refer to pkg/interop for that.

Index

Constants

View Source
const (
	// DefaultBaseExecFee specifies default multiplier for opcode and syscall prices.
	DefaultBaseExecFee = 30
)

Variables

This section is empty.

Functions

func Sort added in v0.91.0

func Sort(fs []Function)

Sort sorts interop functions by id.

Types

type Context

type Context struct {
	Chain         blockchainer.Blockchainer
	Container     hash.Hashable
	Network       uint32
	Natives       []Contract
	Trigger       trigger.Type
	Block         *block.Block
	Tx            *transaction.Transaction
	DAO           *dao.Cached
	Notifications []state.NotificationEvent
	Log           *zap.Logger
	VM            *vm.VM
	Functions     []Function
	// contains filtered or unexported fields
}

Context represents context in which interops are executed.

func NewContext

func NewContext(trigger trigger.Type, bc blockchainer.Blockchainer, d dao.DAO,
	getContract func(dao.DAO, util.Uint160) (*state.Contract, error), natives []Contract,
	block *block.Block, tx *transaction.Transaction, log *zap.Logger) *Context

NewContext returns new interop context.

func (*Context) BaseExecFee added in v0.92.0

func (ic *Context) BaseExecFee() int64

BaseExecFee represents factor to multiply syscall prices with.

func (*Context) GetContract added in v0.92.0

func (ic *Context) GetContract(hash util.Uint160) (*state.Contract, error)

GetContract returns contract by its hash in current interop context.

func (*Context) GetFunction added in v0.91.0

func (ic *Context) GetFunction(id uint32) *Function

GetFunction returns metadata for interop with the specified id.

func (*Context) GetPrice added in v0.93.0

func (ic *Context) GetPrice(op opcode.Opcode, parameter []byte) int64

GetPrice returns a price for executing op with the provided parameter.

func (*Context) SpawnVM added in v0.91.0

func (ic *Context) SpawnVM() *vm.VM

SpawnVM spawns new VM with the specified gas limit and set context.VM field.

func (*Context) SyscallHandler added in v0.91.0

func (ic *Context) SyscallHandler(_ *vm.VM, id uint32) error

SyscallHandler handles syscall with id.

type Contract

type Contract interface {
	Initialize(*Context) error
	Metadata() *ContractMD
	OnPersist(*Context) error
	PostPersist(*Context) error
}

Contract is an interface for all native contracts.

type ContractMD

type ContractMD struct {
	state.NativeContract
	Name    string
	Methods []MethodAndPrice
}

ContractMD represents native contract instance.

func NewContractMD

func NewContractMD(name string, id int32) *ContractMD

NewContractMD returns Contract with the specified list of methods.

func (*ContractMD) AddEvent

func (c *ContractMD) AddEvent(name string, ps ...manifest.Parameter)

AddEvent adds new event to a native contract.

func (*ContractMD) AddMethod

func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method)

AddMethod adds new method to a native contract.

func (*ContractMD) GetMethod added in v0.93.0

func (c *ContractMD) GetMethod(name string, paramCount int) (MethodAndPrice, bool)

GetMethod returns method `name` with specified number of parameters.

func (*ContractMD) GetMethodByOffset added in v0.94.0

func (c *ContractMD) GetMethodByOffset(offset int) (MethodAndPrice, bool)

GetMethodByOffset returns with the provided offset. Offset is offset of `System.Contract.CallNative` syscall.

func (*ContractMD) IsActive added in v0.94.0

func (c *ContractMD) IsActive(height uint32) bool

IsActive returns true iff the contract was deployed by the specified height.

func (*ContractMD) UpdateHash added in v0.94.0

func (c *ContractMD) UpdateHash()

UpdateHash creates native contract script and updates hash.

type Function

type Function struct {
	ID   uint32
	Name string
	Func func(*Context) error
	// ParamCount is a number of function parameters.
	ParamCount int
	Price      int64
	// RequiredFlags is a set of flags which must be set during script invocations.
	// Default value is NoneFlag i.e. no flags are required.
	RequiredFlags callflag.CallFlag
}

Function binds function name, id with the function itself and price, it's supposed to be inited once for all interopContexts, so it doesn't use vm.InteropFuncPrice directly.

type Method

type Method = func(ic *Context, args []stackitem.Item) stackitem.Item

Method is a signature for a native method.

type MethodAndPrice

type MethodAndPrice struct {
	Func          Method
	MD            *manifest.Method
	CPUFee        int64
	StorageFee    int64
	SyscallOffset int
	RequiredFlags callflag.CallFlag
}

MethodAndPrice is a native-contract method descriptor.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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