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
- func Sort(fs []Function)
- type Context
- func (ic *Context) AddNotification(hash util.Uint160, name string, item *stackitem.Array)
- func (ic *Context) BaseExecFee() int64
- func (ic *Context) BaseStorageFee() int64
- func (ic *Context) BlockHeight() uint32
- func (ic *Context) CurrentBlockHash() util.Uint256
- func (ic *Context) Exec() error
- func (ic *Context) Finalize()
- func (ic *Context) GetBlock(hash util.Uint256) (*block.Block, error)
- func (ic *Context) GetContract(hash util.Uint160) (*state.Contract, error)
- func (ic *Context) GetFunction(id uint32) *Function
- func (ic *Context) GetPrice(op opcode.Opcode, parameter []byte) int64
- func (ic *Context) InitNonceData()
- func (ic *Context) IsHardforkEnabled(hf config.Hardfork) bool
- func (ic *Context) LoadToken(id int32) error
- func (ic *Context) RegisterCancelFunc(f context.CancelFunc)
- func (ic *Context) ReuseVM(v *vm.VM)
- func (ic *Context) Signers() []transaction.Signer
- func (ic *Context) SpawnVM() *vm.VM
- func (ic *Context) SyscallHandler(_ *vm.VM, id uint32) error
- func (ic *Context) UseSigners(s []transaction.Signer)
- type Contract
- type ContractMD
- func (c *ContractMD) AddEvent(name string, ps ...manifest.Parameter)
- func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method)
- func (c *ContractMD) GetMethod(name string, paramCount int) (MethodAndPrice, bool)
- func (c *ContractMD) GetMethodByOffset(offset int) (MethodAndPrice, bool)
- func (c *ContractMD) IsActive(height uint32) bool
- func (c *ContractMD) UpdateHash()
- type Function
- type Ledger
- type Method
- type MethodAndPrice
Constants ¶
const (
// DefaultBaseExecFee specifies the default multiplier for opcode and syscall prices.
DefaultBaseExecFee = 30
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct { Chain Ledger Container hash.Hashable Network uint32 Hardforks map[string]uint32 Natives []Contract Trigger trigger.Type Block *block.Block NonceData [16]byte Tx *transaction.Transaction DAO *dao.Simple Notifications []state.NotificationEvent Log *zap.Logger VM *vm.VM Functions []Function Invocations map[util.Uint160]int GetRandomCounter uint32 // contains filtered or unexported fields }
Context represents context in which interops are executed.
func NewContext ¶
func NewContext(trigger trigger.Type, bc Ledger, d *dao.Simple, baseExecFee, baseStorageFee int64, getContract func(*dao.Simple, util.Uint160) (*state.Contract, error), natives []Contract, loadTokenFunc func(ic *Context, id int32) error, block *block.Block, tx *transaction.Transaction, log *zap.Logger) *Context
NewContext returns new interop context.
func (*Context) AddNotification ¶ added in v0.99.0
AddNotification creates notification event and appends it to the notification list.
func (*Context) BaseExecFee ¶ added in v0.92.0
BaseExecFee represents factor to multiply syscall prices with.
func (*Context) BaseStorageFee ¶ added in v0.99.0
BaseStorageFee represents price for storing one byte of data in the contract storage.
func (*Context) BlockHeight ¶ added in v0.99.0
BlockHeight returns current block height got from Context's block if it's set.
func (*Context) CurrentBlockHash ¶ added in v0.99.0
CurrentBlockHash returns current block hash got from Context's block if it's set.
func (*Context) Exec ¶ added in v0.98.0
Exec executes loaded VM script and calls registered finalizers to release the occupied resources.
func (*Context) Finalize ¶ added in v0.98.0
func (ic *Context) Finalize()
Finalize calls all registered cancel functions to release the occupied resources.
func (*Context) GetBlock ¶ added in v0.99.0
GetBlock returns block if it exists and available at the current Context's height.
func (*Context) GetContract ¶ added in v0.92.0
GetContract returns a contract by its hash in the current interop context.
func (*Context) GetFunction ¶ added in v0.91.0
GetFunction returns metadata for interop with the specified id.
func (*Context) GetPrice ¶ added in v0.93.0
GetPrice returns a price for executing op with the provided parameter.
func (*Context) InitNonceData ¶ added in v0.96.0
func (ic *Context) InitNonceData()
InitNonceData initializes nonce to be used in `GetRandom` calculations.
func (*Context) IsHardforkEnabled ¶ added in v0.99.0
IsHardforkEnabled tells whether specified hard-fork enabled at the current context height.
func (*Context) LoadToken ¶ added in v0.99.1
LoadToken wraps externally provided load-token loading function providing it with context, this function can then be easily used by VM.
func (*Context) RegisterCancelFunc ¶ added in v0.98.0
func (ic *Context) RegisterCancelFunc(f context.CancelFunc)
RegisterCancelFunc adds the given function to the list of functions to be called after the VM finishes script execution.
func (*Context) ReuseVM ¶ added in v0.99.1
ReuseVM resets given VM and allows to reuse it in the current context.
func (*Context) Signers ¶ added in v0.98.0
func (ic *Context) Signers() []transaction.Signer
Signers returns signers witnessing the current execution context.
func (*Context) SpawnVM ¶ added in v0.91.0
SpawnVM spawns a new VM with the specified gas limit and set context.VM field.
func (*Context) SyscallHandler ¶ added in v0.91.0
SyscallHandler handles syscall with id.
func (*Context) UseSigners ¶ added in v0.98.0
func (ic *Context) UseSigners(s []transaction.Signer)
UseSigners allows overriding signers used in this context.
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 a 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 a new event to the native contract.
func (*ContractMD) AddMethod ¶
func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method)
AddMethod adds a 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 the specified number of parameters.
func (*ContractMD) GetMethodByOffset ¶ added in v0.94.0
func (c *ContractMD) GetMethodByOffset(offset int) (MethodAndPrice, bool)
GetMethodByOffset returns method 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 if the contract was deployed by the specified height.
func (*ContractMD) UpdateHash ¶ added in v0.94.0
func (c *ContractMD) UpdateHash()
UpdateHash creates a 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 the price, it's supposed to be inited once for all interopContexts, so it doesn't use vm.InteropFuncPrice directly.
type Ledger ¶ added in v0.98.1
type Ledger interface { BlockHeight() uint32 CurrentBlockHash() util.Uint256 GetBlock(hash util.Uint256) (*block.Block, error) GetConfig() config.ProtocolConfiguration GetHeaderHash(int) util.Uint256 }
Ledger is the interface to Blockchain required for Context functionality.