Documentation ¶
Index ¶
- Constants
- Variables
- func FlowTokenAddress(chain flow.Chain) flow.Address
- func FungibleTokenAddress(chain flow.Chain) flow.Address
- func StringToHashingAlgorithm(s string) hash.HashingAlgorithm
- func StringToSigningAlgorithm(s string) crypto.SigningAlgorithm
- func SystemChunkTransaction(serviceAddress flow.Address) *flow.TransactionBody
- type ASTCache
- type Blocks
- type BlocksFinder
- type BootstrapProcedure
- type Context
- type DefaultSignatureVerifier
- type Error
- type EventLimitExceededError
- type ExecutionError
- type InvalidHashAlgorithmError
- type InvalidProposalKeyMissingSignatureError
- type InvalidProposalKeyPublicKeyDoesNotExistError
- type InvalidProposalKeyPublicKeyRevokedError
- type InvalidProposalKeySequenceNumberError
- type InvalidSignaturePublicKeyDoesNotExistError
- type InvalidSignaturePublicKeyRevokedError
- type InvalidSignatureVerificationError
- type LRUASTCache
- type MetricsCollector
- type MissingPayerError
- type MissingSignatureError
- type Option
- func WithASTCache(cache ASTCache) Option
- func WithBlockHeader(header *flow.Header) Option
- func WithBlocks(blocks Blocks) Option
- func WithCadenceLogging(enabled bool) Option
- func WithChain(chain flow.Chain) Option
- func WithEventCollectionSizeLimit(limit uint64) Option
- func WithGasLimit(limit uint64) Option
- func WithMetricsCollector(mc *MetricsCollector) Option
- func WithRestrictedAccountCreation(enabled bool) Option
- func WithRestrictedContractDeployment(enabled bool) Option
- func WithRestrictedContractUpdate(enabled bool) Option
- func WithServiceAccount(enabled bool) Option
- func WithSetValueHandler(handler SetValueHandler) Option
- func WithTransactionProcessors(processors ...TransactionProcessor) Option
- type Procedure
- type ScriptInvocator
- type ScriptProcedure
- type ScriptProcessor
- type SetValueHandler
- type SignatureVerifier
- type TransactionFeeDeductor
- type TransactionInvocator
- type TransactionProcedure
- type TransactionProcessor
- type TransactionSequenceNumberChecker
- type TransactionSignatureVerifier
- type UUIDGenerator
- type VirtualMachine
Constants ¶
const AccountKeyWeightThreshold = 1000
Variables ¶
var ErrAccountNotFound = errors.New("account not found")
var ErrInvalidHashAlgorithm = errors.New("invalid hash algorithm")
Functions ¶
func StringToHashingAlgorithm ¶
func StringToHashingAlgorithm(s string) hash.HashingAlgorithm
StringToHashingAlgorithm converts a string to a HashingAlgorithm.
func StringToSigningAlgorithm ¶
func StringToSigningAlgorithm(s string) crypto.SigningAlgorithm
StringToSigningAlgorithm converts a string to a SigningAlgorithm.
func SystemChunkTransaction ¶
func SystemChunkTransaction(serviceAddress flow.Address) *flow.TransactionBody
SystemChunkTransaction creates and returns the transaction corresponding to the system chunk at the specified service address.
Types ¶
type ASTCache ¶
type ASTCache interface { GetProgram(ast.Location) (*ast.Program, error) SetProgram(ast.Location, *ast.Program) error }
ASTCache is an interface to a cache for parsed program ASTs.
type Blocks ¶
type Blocks interface { // ByHeight returns the block at the given height in the chain ending in `header` (or finalized // if `header` is nil). This enables querying un-finalized blocks by height with respect to the // chain defined by the block we are executing. ByHeightFrom(height uint64, header *flow.Header) (*flow.Header, error) }
func NewBlockFinder ¶ added in v0.13.0
type BlocksFinder ¶ added in v0.13.0
type BlocksFinder struct {
// contains filtered or unexported fields
}
func (*BlocksFinder) ByHeightFrom ¶ added in v0.13.0
type BootstrapProcedure ¶
type BootstrapProcedure struct {
// contains filtered or unexported fields
}
A BootstrapProcedure is an invokable that can be used to bootstrap the ledger state with the default accounts and contracts required by the Flow virtual machine.
func Bootstrap ¶
func Bootstrap( servicePublicKey flow.AccountPublicKey, initialTokenSupply cadence.UFix64, ) *BootstrapProcedure
Bootstrap returns a new BootstrapProcedure instance configured with the provided genesis parameters.
func (*BootstrapProcedure) Run ¶
func (b *BootstrapProcedure) Run(vm *VirtualMachine, ctx Context, ledger state.Ledger) error
type Context ¶
type Context struct { Chain flow.Chain ASTCache ASTCache Blocks Blocks Metrics *MetricsCollector GasLimit uint64 EventCollectionByteSizeLimit uint64 BlockHeader *flow.Header ServiceAccountEnabled bool RestrictedAccountCreationEnabled bool RestrictedContractDeploymentEnabled bool RestrictedContractUpdateEnabled bool CadenceLoggingEnabled bool SetValueHandler SetValueHandler SignatureVerifier SignatureVerifier TransactionProcessors []TransactionProcessor ScriptProcessors []ScriptProcessor Logger zerolog.Logger }
A Context defines a set of execution parameters used by the virtual machine.
func NewContext ¶
NewContext initializes a new execution context with the provided options.
func NewContextFromParent ¶
NewContextFromParent spawns a child execution context with the provided options.
type DefaultSignatureVerifier ¶
type DefaultSignatureVerifier struct{}
func NewDefaultSignatureVerifier ¶
func NewDefaultSignatureVerifier() DefaultSignatureVerifier
type Error ¶
An Error represents a non-fatal error that is expected during normal operation of the virtual machine.
VM errors are distinct from fatal errors, which indicate an unexpected failure in the VM (i.e. storage, stack overflow).
Each VM error is identified by a unique error code that is returned to the user.
type EventLimitExceededError ¶ added in v0.13.1
EventLimitExceededError indicates that the transaction has produced events with size more than limit.
func (*EventLimitExceededError) Code ¶ added in v0.13.1
func (e *EventLimitExceededError) Code() uint32
Code returns the error code for this error
func (*EventLimitExceededError) Error ¶ added in v0.13.1
func (e *EventLimitExceededError) Error() string
type ExecutionError ¶
func (*ExecutionError) Code ¶
func (e *ExecutionError) Code() uint32
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
type InvalidHashAlgorithmError ¶
type InvalidHashAlgorithmError struct { Address flow.Address KeyIndex uint64 HashAlgo hash.HashingAlgorithm }
An InvalidHashAlgorithmError indicates that a given key has an invalid hash algorithm.
func (*InvalidHashAlgorithmError) Code ¶
func (e *InvalidHashAlgorithmError) Code() uint32
func (*InvalidHashAlgorithmError) Error ¶
func (e *InvalidHashAlgorithmError) Error() string
type InvalidProposalKeyMissingSignatureError ¶
A InvalidProposalKeyMissingSignatureError indicates that a proposal key does not have a valid signature.
func (*InvalidProposalKeyMissingSignatureError) Code ¶
func (e *InvalidProposalKeyMissingSignatureError) Code() uint32
func (*InvalidProposalKeyMissingSignatureError) Error ¶
func (e *InvalidProposalKeyMissingSignatureError) Error() string
type InvalidProposalKeyPublicKeyDoesNotExistError ¶
A InvalidProposalKeyPublicKeyDoesNotExistError indicates that proposal key specifies a nonexistent public key.
func (*InvalidProposalKeyPublicKeyDoesNotExistError) Code ¶
func (e *InvalidProposalKeyPublicKeyDoesNotExistError) Code() uint32
func (*InvalidProposalKeyPublicKeyDoesNotExistError) Error ¶
func (e *InvalidProposalKeyPublicKeyDoesNotExistError) Error() string
type InvalidProposalKeyPublicKeyRevokedError ¶
An InvalidProposalKeyPublicKeyRevokedError indicates that proposal key sequence number does not match the on-chain value.
func (*InvalidProposalKeyPublicKeyRevokedError) Code ¶
func (e *InvalidProposalKeyPublicKeyRevokedError) Code() uint32
func (*InvalidProposalKeyPublicKeyRevokedError) Error ¶
func (e *InvalidProposalKeyPublicKeyRevokedError) Error() string
type InvalidProposalKeySequenceNumberError ¶
type InvalidProposalKeySequenceNumberError struct { Address flow.Address KeyIndex uint64 CurrentSeqNumber uint64 ProvidedSeqNumber uint64 }
An InvalidProposalKeySequenceNumberError indicates that proposal key sequence number does not match the on-chain value.
func (*InvalidProposalKeySequenceNumberError) Code ¶
func (e *InvalidProposalKeySequenceNumberError) Code() uint32
func (*InvalidProposalKeySequenceNumberError) Error ¶
func (e *InvalidProposalKeySequenceNumberError) Error() string
type InvalidSignaturePublicKeyDoesNotExistError ¶
An InvalidSignaturePublicKeyDoesNotExistError indicates that a signature specifies a public key that does not exist.
func (*InvalidSignaturePublicKeyDoesNotExistError) Code ¶
func (e *InvalidSignaturePublicKeyDoesNotExistError) Code() uint32
func (*InvalidSignaturePublicKeyDoesNotExistError) Error ¶
func (e *InvalidSignaturePublicKeyDoesNotExistError) Error() string
type InvalidSignaturePublicKeyRevokedError ¶
An InvalidSignaturePublicKeyRevokedError indicates that a signature specifies a public key that has been revoked.
func (*InvalidSignaturePublicKeyRevokedError) Code ¶
func (e *InvalidSignaturePublicKeyRevokedError) Code() uint32
func (*InvalidSignaturePublicKeyRevokedError) Error ¶
func (e *InvalidSignaturePublicKeyRevokedError) Error() string
type InvalidSignatureVerificationError ¶
An InvalidSignatureVerificationError indicates that a signature could not be verified using its specified public key.
func (*InvalidSignatureVerificationError) Code ¶
func (e *InvalidSignatureVerificationError) Code() uint32
func (*InvalidSignatureVerificationError) Error ¶
func (e *InvalidSignatureVerificationError) Error() string
type LRUASTCache ¶
type LRUASTCache struct {
// contains filtered or unexported fields
}
LRUASTCache implements a program AST cache with a LRU cache.
func NewLRUASTCache ¶
func NewLRUASTCache(size int) (*LRUASTCache, error)
NewLRUASTCache creates a new LRU cache that implements the ASTCache interface.
func (*LRUASTCache) GetProgram ¶
GetProgram retrieves a program AST from the LRU cache.
func (*LRUASTCache) SetProgram ¶
SetProgram adds a program AST to the LRU cache.
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
A MetricsCollector accumulates performance metrics reported by the Cadence runtime.
A single collector instance will sum all reported values. For example, the "parsed" field will be incremented each time a program is parsed.
func NewMetricsCollector ¶
func NewMetricsCollector() *MetricsCollector
NewMetricsCollectors returns a new runtime metrics collector.
func (*MetricsCollector) Checked ¶
func (m *MetricsCollector) Checked() time.Duration
func (*MetricsCollector) Interpreted ¶
func (m *MetricsCollector) Interpreted() time.Duration
func (*MetricsCollector) Parsed ¶
func (m *MetricsCollector) Parsed() time.Duration
type MissingPayerError ¶
type MissingPayerError struct{}
A MissingPayerError indicates that a transaction is missing a payer.
func (*MissingPayerError) Code ¶
func (e *MissingPayerError) Code() uint32
func (*MissingPayerError) Error ¶
func (e *MissingPayerError) Error() string
type MissingSignatureError ¶
A MissingSignatureError indicates that a transaction is missing a required signature.
func (*MissingSignatureError) Code ¶
func (e *MissingSignatureError) Code() uint32
func (*MissingSignatureError) Error ¶
func (e *MissingSignatureError) Error() string
type Option ¶
An Option sets a configuration parameter for a virtual machine context.
func WithASTCache ¶
WithASTCache sets the AST cache for a virtual machine context.
func WithBlockHeader ¶
WithBlockHeader sets the block header for a virtual machine context.
The VM uses the header to provide current block information to the Cadence runtime, as well as to seed the pseudorandom number generator.
func WithBlocks ¶
WithBlocks sets the block storage provider for a virtual machine context.
The VM uses the block storage provider to provide historical block information to the Cadence runtime.
func WithCadenceLogging ¶ added in v0.13.1
WithCadenceLogging enables or disables Cadence logging for a virtual machine context.
func WithEventCollectionSizeLimit ¶ added in v0.13.1
WithEventCollectionSizeLimit sets the event collection byte size limit for a virtual machine context.
func WithGasLimit ¶
WithGasLimit sets the gas limit for a virtual machine context.
func WithMetricsCollector ¶
func WithMetricsCollector(mc *MetricsCollector) Option
WithMetricsCollector sets the metrics collector for a virtual machine context.
A metrics collector is used to gather metrics reported by the Cadence runtime.
func WithRestrictedAccountCreation ¶
WithRestrictedAccountCreation enables or disables restricted account creation for a virtual machine context
func WithRestrictedContractDeployment ¶ added in v0.26.0
WithRestrictedContractDeployment enables or disables restricted contract deployment for a virtual machine context.
func WithRestrictedContractUpdate ¶
WithRestrictedContractUpdate enables or disables restricted contract deployment for a virtual machine context.
func WithServiceAccount ¶
WithServiceAccount enables or disables calls to the Flow service account.
func WithSetValueHandler ¶
func WithSetValueHandler(handler SetValueHandler) Option
WithSetValueHandler sets a handler that is called when a value is written by the Cadence runtime.
func WithTransactionProcessors ¶
func WithTransactionProcessors(processors ...TransactionProcessor) Option
WithTransactionProcessors sets the transaction processors for a virtual machine context.
type Procedure ¶
type Procedure interface {
Run(vm *VirtualMachine, ctx Context, ledger state.Ledger) error
}
An Procedure is an operation (or set of operations) that reads or writes ledger state.
type ScriptInvocator ¶
type ScriptInvocator struct{}
func NewScriptInvocator ¶
func NewScriptInvocator() ScriptInvocator
func (ScriptInvocator) Process ¶
func (i ScriptInvocator) Process( vm *VirtualMachine, ctx Context, proc *ScriptProcedure, ledger state.Ledger, ) error
type ScriptProcedure ¶
type ScriptProcedure struct { ID flow.Identifier Script []byte Arguments [][]byte Value cadence.Value Logs []string Events []flow.Event // TODO: report gas consumption: https://github.com/dapperlabs/flow-go/issues/4139 GasUsed uint64 Err Error }
func Script ¶
func Script(code []byte) *ScriptProcedure
func (*ScriptProcedure) Run ¶
func (proc *ScriptProcedure) Run(vm *VirtualMachine, ctx Context, ledger state.Ledger) error
func (*ScriptProcedure) WithArguments ¶
func (proc *ScriptProcedure) WithArguments(args ...[]byte) *ScriptProcedure
type ScriptProcessor ¶
type ScriptProcessor interface {
Process(*VirtualMachine, Context, *ScriptProcedure, state.Ledger) error
}
type SetValueHandler ¶
SetValueHandler receives a value written by the Cadence runtime.
type SignatureVerifier ¶
type TransactionFeeDeductor ¶
type TransactionFeeDeductor struct{}
func NewTransactionFeeDeductor ¶
func NewTransactionFeeDeductor() *TransactionFeeDeductor
func (*TransactionFeeDeductor) Process ¶
func (d *TransactionFeeDeductor) Process( vm *VirtualMachine, ctx Context, proc *TransactionProcedure, ledger state.Ledger, ) error
type TransactionInvocator ¶
type TransactionInvocator struct {
// contains filtered or unexported fields
}
func NewTransactionInvocator ¶
func NewTransactionInvocator(logger zerolog.Logger) *TransactionInvocator
func (*TransactionInvocator) Process ¶
func (i *TransactionInvocator) Process( vm *VirtualMachine, ctx Context, proc *TransactionProcedure, ledger state.Ledger, ) error
type TransactionProcedure ¶
type TransactionProcedure struct { ID flow.Identifier Transaction *flow.TransactionBody TxIndex uint32 Logs []string Events []flow.Event // TODO: report gas consumption: https://github.com/dapperlabs/flow-go/issues/4139 GasUsed uint64 Err Error }
func Transaction ¶
func Transaction(tx *flow.TransactionBody, txIndex uint32) *TransactionProcedure
func (*TransactionProcedure) Run ¶
func (proc *TransactionProcedure) Run(vm *VirtualMachine, ctx Context, ledger state.Ledger) error
type TransactionProcessor ¶
type TransactionProcessor interface {
Process(*VirtualMachine, Context, *TransactionProcedure, state.Ledger) error
}
type TransactionSequenceNumberChecker ¶
type TransactionSequenceNumberChecker struct{}
func NewTransactionSequenceNumberChecker ¶
func NewTransactionSequenceNumberChecker() *TransactionSequenceNumberChecker
func (*TransactionSequenceNumberChecker) Process ¶
func (c *TransactionSequenceNumberChecker) Process( vm *VirtualMachine, ctx Context, proc *TransactionProcedure, ledger state.Ledger, ) error
type TransactionSignatureVerifier ¶
type TransactionSignatureVerifier struct { SignatureVerifier SignatureVerifier KeyWeightThreshold int }
func NewTransactionSignatureVerifier ¶
func NewTransactionSignatureVerifier(keyWeightThreshold int) *TransactionSignatureVerifier
func (*TransactionSignatureVerifier) Process ¶
func (v *TransactionSignatureVerifier) Process( vm *VirtualMachine, ctx Context, proc *TransactionProcedure, ledger state.Ledger, ) error
type UUIDGenerator ¶
type UUIDGenerator struct {
// contains filtered or unexported fields
}
func NewUUIDGenerator ¶
func NewUUIDGenerator(uuids *state.UUIDs) *UUIDGenerator
func (*UUIDGenerator) GenerateUUID ¶
func (u *UUIDGenerator) GenerateUUID() (uint64, error)
type VirtualMachine ¶
A VirtualMachine augments the Cadence runtime with Flow host functionality.
func New ¶
func New(rt runtime.Runtime) *VirtualMachine
New creates a new virtual machine instance with the provided runtime.