Documentation
¶
Overview ¶
package present processor interface. It must be implemented by VM
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterVMType ¶
func RegisterVMType(vmtype string, constructor VMConstructor) error
RegisterVMType registers new VM type by providing a constructor function to construct an instance of the processor. The constructor is a closure which also may encompass configuration params for the VM The function is normally called from the init code
func SetDefaultVMType ¶
func SetDefaultVMType(vmtype string)
Types ¶
type AccountAccess ¶
type AccountAccess interface {
// access to total available outputs/balances
AvailableBalance(col *balance.Color) int64
MoveTokens(targetAddr *address.Address, col *balance.Color, amount int64) bool
EraseColor(targetAddr *address.Address, col *balance.Color, amount int64) bool
// part of the outputs/balances which are coming from the current request transaction
AvailableBalanceFromRequest(col *balance.Color) int64
MoveTokensFromRequest(targetAddr *address.Address, col *balance.Color, amount int64) bool
EraseColorFromRequest(targetAddr *address.Address, col *balance.Color, amount int64) bool
// send iotas to the smart contract owner
HarvestFees(amount int64) int64
HarvestFeesFromRequest(amount int64) bool
}
access to token operations (txbuilder) mint (create new color) is not here on purpose: ColorNew is used for request tokens
type EntryPoint ¶
type EntryPoint interface {
WithGasLimit(int) EntryPoint
Run(ctx Sandbox)
}
EntryPoint is an abstract interface by which VM is run by passing the Sandbox interface to it VM is expected to be fully deterministic and it result is 100% reflected as a side effect on the Sandbox interface
type NewRequestParams ¶
type NewRequestParams struct {
TargetAddress *address.Address
RequestCode sctransaction.RequestCode
Timelock uint32
Args kv.Map
IncludeReward int64
}
type Processor ¶
type Processor interface {
// returns true if processor can process specific request code. Valid only for not reserved codes
// to return true for reserved codes is ignored
GetEntryPoint(code sctransaction.RequestCode) (EntryPoint, bool)
GetDescription() string
}
Processor is a abstract interface to the VM processor instance. It can be called via exported entry points Each entry point is uniquely identified by the request code (uint16). The request code contains information if it requires authentication to run (protected) and also if it represents built in processor or user-defined processor.
type RequestAccess ¶
type RequestAccess interface {
//request id
ID() sctransaction.RequestId
// request code
Code() sctransaction.RequestCode
// sender address (exactly 1)
Sender() address.Address
// arguments
Args() kv.RCodec // TODO must return MustCodec
// number of free minted tokens in the request transaction
// it is equal to total minted tokens minus number of requests
NumFreeMintedTokens() int64
}
access to request parameters (arguments)
type Sandbox ¶
type Sandbox interface {
// general function
IsOriginState() bool
GetSCAddress() *address.Address
GetOwnerAddress() *address.Address
GetTimestamp() int64
GetEntropy() hashing.HashValue // 32 bytes of deterministic and unpredictably random data
// Same as panic(), but added as a Sandbox method to emphasize that it's ok to panic from a SC.
// A panic will be recovered, and Rollback() will be automatically called after.
Panic(v interface{})
// clear all updates, restore same context as in the beginning of the VM call
Rollback()
// sub interfaces
// access to the request block
AccessRequest() RequestAccess
// base level of virtual state access
AccessState() kv.MustCodec
// AccessSCAccount
AccessSCAccount() AccountAccess
// Send request
SendRequest(par NewRequestParams) bool
// Send request to itself
SendRequestToSelf(reqCode sctransaction.RequestCode, args kv.Map) bool
// Send request to itself with timelock for some seconds after the current timestamp
SendRequestToSelfWithDelay(reqCode sctransaction.RequestCode, args kv.Map, deferForSec uint32) bool
// for testing
// Publish "vmmsg" message through Publisher
Publish(msg string)
Publishf(format string, args ...interface{})
GetWaspLog() *logger.Logger
DumpAccount() string
}
Sandbox is an interface given to the processor to access the VMContext and virtual state, transaction builder and request parameters through it.