owasm

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const UnknownGasCost = 10000000

Variables

This section is empty.

Functions

func Execute

func Execute(
	env ExecutionEnvironment,
	code []byte,
	entry string,
	calldata []byte,
	gasLimit uint64,
) (result []byte, gasUsed uint64, err error)

Execute runs an Owasm script code by via the script's entryID. Note that both result and err can be nil concurrently if the function terminates successfully without `saveReturnData` getting called.

func GetLocalInt64

func GetLocalInt64(vm *exec.VirtualMachine, index int) int64

func NewResolver

func NewResolver(env ExecutionEnvironment, calldata []byte) *resolver

Types

type BandChainGasPolicy

type BandChainGasPolicy struct{}

func (*BandChainGasPolicy) GetCost

func (p *BandChainGasPolicy) GetCost(key compiler.Instr) int64

type ExecutionEnvironment

type ExecutionEnvironment interface {
	// GetCurrentRequestID returns the unique identifier that is the reference
	// to the current data request.
	GetCurrentRequestID() int64

	// GetRequestedValidatorCount returns the number of validators that the current
	// data request specifies for the oracle query.
	GetRequestedValidatorCount() int64

	// GetSufficientValidatorCount returns the number of validators
	// that is enough to push this data request into the aggregation phase.
	GetSufficientValidatorCount() int64

	// GetReceivedValidatorCount returns the number of validators among the
	// requested ones that replied with raw data reports. Return zero during the
	// *preparation* phase.
	GetReceivedValidatorCount() int64

	// GetPrepareBlockTime returns the time at which the *preparation* phase of
	// this data request was being run.
	GetPrepareBlockTime() int64

	// GetAggregateBlockTime returns the time at which the *aggregation* phase of
	// this data request was being run. Return zero during the *preparation* phase.
	GetAggregateBlockTime() int64

	// GetValidatorPublic returns the 20-byte address of the block validator
	// at the specified index.
	GetValidatorAddress(validatorIndex int64) ([]byte, error)

	// GetMaximumResultSize returns the maxixmum size of result data that returns from
	// execute function.
	GetMaximumResultSize() int64

	// GetMaximumCalldataOfDataSourceSize returns the maximum size of call data using in
	// data source execution.
	GetMaximumCalldataOfDataSourceSize() int64

	// RequestExternalData performs a request to the specified data source
	// with and assigns the request with the external data ID. The function must
	// only be called during the *preparation* phase of an oracle script.
	RequestExternalData(
		dataSourceID int64,
		externalDataID int64,
		calldata []byte,
	) error

	// GetExternalData reads from the execution environment state for a raw
	// data report for the specified external data ID from the specified validator.
	// The function must only be called during the *aggregation* phase.
	GetExternalData(
		externalDataID int64,
		validatorIndex int64,
	) ([]byte, uint8, error)
}

ExecutionEnvironment encapsulates the operations that an Owasm script can call to interact with the external world. An operation can fail and when that occurs, the whole function call will fail.

Jump to

Keyboard shortcuts

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