Documentation ¶
Index ¶
- Constants
- Variables
- func CryptoToRuntimeHashingAlgorithm(h hash.HashingAlgorithm) runtime.HashAlgorithm
- func CryptoToRuntimeSigningAlgorithm(s crypto.SigningAlgorithm) runtime.SignatureAlgorithm
- func FlowFeesAddress(chain flow.Chain) flow.Address
- func FlowTokenAddress(chain flow.Chain) flow.Address
- func FungibleTokenAddress(chain flow.Chain) flow.Address
- func RuntimeToCryptoHashingAlgorithm(s runtime.HashAlgorithm) hash.HashingAlgorithm
- func RuntimeToCryptoSigningAlgorithm(s runtime.SignatureAlgorithm) crypto.SigningAlgorithm
- func SystemChunkTransaction(serviceAddress flow.Address) *flow.TransactionBody
- type Blocks
- type BlocksFinder
- type BootstrapProcedure
- type BootstrapProcedureOption
- func WithAccountCreationFee(fee cadence.UFix64) BootstrapProcedureOption
- func WithInitialTokenSupply(supply cadence.UFix64) BootstrapProcedureOption
- func WithMinimumStorageReservation(reservation cadence.UFix64) BootstrapProcedureOption
- func WithTransactionFee(fee cadence.UFix64) BootstrapProcedureOption
- type Context
- type DefaultSignatureVerifier
- type EncodingUnsupportedValueError
- type Error
- type EventLimitExceededError
- type ExecutionError
- type InvalidHashAlgorithmError
- type InvalidProposalKeyMissingSignatureError
- type InvalidProposalKeyPublicKeyDoesNotExistError
- type InvalidProposalKeyPublicKeyRevokedError
- type InvalidProposalKeySequenceNumberError
- type InvalidSignaturePublicKeyDoesNotExistError
- type InvalidSignaturePublicKeyRevokedError
- type InvalidSignatureVerificationError
- type MetricsCollector
- type MissingPayerError
- type MissingSignatureError
- type Option
- func WithAccountStorageLimit(enabled bool) 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 WithMaxStateInteractionSize(limit uint64) Option
- func WithMaxStateKeySize(limit uint64) Option
- func WithMaxStateValueSize(limit uint64) Option
- func WithMetricsCollector(mc *MetricsCollector) Option
- func WithRestrictedAccountCreation(enabled bool) Option
- func WithRestrictedDeployment(enabled bool) Option
- func WithServiceAccount(enabled bool) Option
- func WithSetValueHandler(handler SetValueHandler) Option
- func WithTracer(tr module.Tracer) Option
- func WithTransactionProcessors(processors ...TransactionProcessor) Option
- type Procedure
- type ScriptInvocator
- type ScriptProcedure
- type ScriptProcessor
- type SetValueHandler
- type SignatureVerifier
- type StorageCapacityExceededError
- type TransactionFeeDeductor
- type TransactionInvocator
- type TransactionProcedure
- type TransactionProcessor
- type TransactionSequenceNumberChecker
- type TransactionSignatureVerifier
- type TransactionStorageLimiter
- type VirtualMachine
Constants ¶
const ( DefaultGasLimit = 100_000 // 100K DefaultEventCollectionByteSizeLimit = 256_000 // 256KB DefaultMaxNumOfTxRetries = 3 )
const AccountKeyWeightThreshold = 1000
Variables ¶
var DefaultAccountCreationFee = func() cadence.UFix64 { value, err := cadence.NewUFix64("0.10000000") if err != nil { panic(fmt.Errorf("invalid default account creation fee: %w", err)) } return value }()
var DefaultMinimumStorageReservation = func() cadence.UFix64 { value, err := cadence.NewUFix64("0.10000000") if err != nil { panic(fmt.Errorf("invalid default minimum storage reservation: %w", err)) } return value }()
var DefaultTransactionFees = func() cadence.UFix64 { value, err := cadence.NewUFix64("0.0001") if err != nil { panic(fmt.Errorf("invalid default transaction fees: %w", err)) } return value }()
DefaultTransactionFees are the default transaction fees if transaction fees are on. If they are off (which is the default behaviour) that means the transaction fees are 0.0.
var ErrAccountNotFound = errors.New("account not found")
var ErrInvalidHashAlgorithm = errors.New("invalid hash algorithm")
Functions ¶
func CryptoToRuntimeHashingAlgorithm ¶ added in v0.15.0
func CryptoToRuntimeHashingAlgorithm(h hash.HashingAlgorithm) runtime.HashAlgorithm
CryptoToRuntimeHashingAlgorithm converts a crypto hashing algorithm to a runtime hash algorithm.
func CryptoToRuntimeSigningAlgorithm ¶ added in v0.15.0
func CryptoToRuntimeSigningAlgorithm(s crypto.SigningAlgorithm) runtime.SignatureAlgorithm
CryptoToRuntimeSigningAlgorithm converts a crypto signature algorithm to a runtime signature algorithm.
func RuntimeToCryptoHashingAlgorithm ¶ added in v0.15.0
func RuntimeToCryptoHashingAlgorithm(s runtime.HashAlgorithm) hash.HashingAlgorithm
RuntimeToCryptoHashingAlgorithm converts a runtime hash algorithm to a crypto hashing algorithm.
func RuntimeToCryptoSigningAlgorithm ¶ added in v0.15.0
func RuntimeToCryptoSigningAlgorithm(s runtime.SignatureAlgorithm) crypto.SigningAlgorithm
RuntimeToCryptoSigningAlgorithm converts a runtime signature algorithm to a crypto signature algorithm.
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 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( serviceAccountPublicKey flow.AccountPublicKey, opts ...BootstrapProcedureOption, ) *BootstrapProcedure
Bootstrap returns a new BootstrapProcedure instance configured with the provided genesis parameters.
func (*BootstrapProcedure) Run ¶
func (b *BootstrapProcedure) Run(vm *VirtualMachine, ctx Context, sth *state.StateHolder, programs *programs.Programs) error
type BootstrapProcedureOption ¶ added in v0.14.0
type BootstrapProcedureOption func(*BootstrapProcedure) *BootstrapProcedure
func WithAccountCreationFee ¶ added in v0.14.0
func WithAccountCreationFee(fee cadence.UFix64) BootstrapProcedureOption
func WithInitialTokenSupply ¶ added in v0.14.0
func WithInitialTokenSupply(supply cadence.UFix64) BootstrapProcedureOption
func WithMinimumStorageReservation ¶ added in v0.14.0
func WithMinimumStorageReservation(reservation cadence.UFix64) BootstrapProcedureOption
func WithTransactionFee ¶ added in v0.14.0
func WithTransactionFee(fee cadence.UFix64) BootstrapProcedureOption
type Context ¶
type Context struct { Chain flow.Chain Blocks Blocks Metrics *MetricsCollector Tracer module.Tracer GasLimit uint64 MaxStateKeySize uint64 MaxStateValueSize uint64 MaxStateInteractionSize uint64 EventCollectionByteSizeLimit uint64 MaxNumOfTxRetries uint8 BlockHeader *flow.Header ServiceAccountEnabled bool RestrictedAccountCreationEnabled bool RestrictedDeploymentEnabled bool LimitAccountStorage 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 EncodingUnsupportedValueError ¶ added in v0.14.1
type EncodingUnsupportedValueError struct { Value interpreter.Value Path []string }
EncodingUnsupportedValueError indicates that Cadence attempted to encode a value that is not supported.
func (*EncodingUnsupportedValueError) Code ¶ added in v0.14.1
func (e *EncodingUnsupportedValueError) Code() uint32
func (*EncodingUnsupportedValueError) Error ¶ added in v0.14.1
func (e *EncodingUnsupportedValueError) Error() string
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 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
func (*MetricsCollector) ValueDecoded ¶ added in v0.14.0
func (m *MetricsCollector) ValueDecoded() time.Duration
func (*MetricsCollector) ValueEncoded ¶ added in v0.14.0
func (m *MetricsCollector) ValueEncoded() 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 WithAccountStorageLimit ¶ added in v0.14.0
WithAccountStorageLimit enables or disables checking if account storage used is over its storage capacity
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 WithMaxStateInteractionSize ¶ added in v0.14.0
WithMaxStateInteractionSize sets the byte size limit for total interaction with ledger. this prevents attacks such as reading all large registers
func WithMaxStateKeySize ¶ added in v0.14.0
WithMaxStateKeySize sets the byte size limit for ledger keys
func WithMaxStateValueSize ¶ added in v0.14.0
WithMaxStateValueSize sets the byte size limit for ledger values
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 WithRestrictedDeployment ¶
WithRestrictedDeployment 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 WithTracer ¶ added in v0.14.5
WithTracer sets the tracer for a virtual machine context.
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, sth *state.StateHolder, programs *programs.Programs) 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, sth *state.StateHolder, programs *programs.Programs, ) 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, sth *state.StateHolder, programs *programs.Programs) error
func (*ScriptProcedure) WithArguments ¶
func (proc *ScriptProcedure) WithArguments(args ...[]byte) *ScriptProcedure
type ScriptProcessor ¶
type ScriptProcessor interface {
Process(*VirtualMachine, Context, *ScriptProcedure, *state.StateHolder, *programs.Programs) error
}
type SetValueHandler ¶
SetValueHandler receives a value written by the Cadence runtime.
type SignatureVerifier ¶
type StorageCapacityExceededError ¶ added in v0.14.0
type StorageCapacityExceededError struct { Address flow.Address StorageUsed uint64 StorageCapacity uint64 }
An StorageCapacityExceededError indicates that an account used more storage than it has storage capacity.
func (*StorageCapacityExceededError) Code ¶ added in v0.14.0
func (e *StorageCapacityExceededError) Code() uint32
func (*StorageCapacityExceededError) Error ¶ added in v0.14.0
func (e *StorageCapacityExceededError) Error() string
type TransactionFeeDeductor ¶
type TransactionFeeDeductor struct{}
func NewTransactionFeeDeductor ¶
func NewTransactionFeeDeductor() *TransactionFeeDeductor
func (*TransactionFeeDeductor) Process ¶
func (d *TransactionFeeDeductor) Process( vm *VirtualMachine, ctx Context, proc *TransactionProcedure, sth *state.StateHolder, programs *programs.Programs, ) 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, sth *state.StateHolder, programs *programs.Programs, ) error
type TransactionProcedure ¶
type TransactionProcedure struct { ID flow.Identifier Transaction *flow.TransactionBody TxIndex uint32 Logs []string Events []flow.Event ServiceEvents []flow.Event // TODO: report gas consumption: https://github.com/dapperlabs/flow-go/issues/4139 GasUsed uint64 Err Error Retried int TraceSpan opentracing.Span }
func Transaction ¶
func Transaction(tx *flow.TransactionBody, txIndex uint32) *TransactionProcedure
func (*TransactionProcedure) Run ¶
func (proc *TransactionProcedure) Run(vm *VirtualMachine, ctx Context, st *state.StateHolder, programs *programs.Programs) error
func (*TransactionProcedure) SetTraceSpan ¶ added in v0.14.5
func (proc *TransactionProcedure) SetTraceSpan(traceSpan opentracing.Span)
type TransactionProcessor ¶
type TransactionProcessor interface {
Process(*VirtualMachine, Context, *TransactionProcedure, *state.StateHolder, *programs.Programs) error
}
type TransactionSequenceNumberChecker ¶
type TransactionSequenceNumberChecker struct{}
func NewTransactionSequenceNumberChecker ¶
func NewTransactionSequenceNumberChecker() *TransactionSequenceNumberChecker
func (*TransactionSequenceNumberChecker) Process ¶
func (c *TransactionSequenceNumberChecker) Process( vm *VirtualMachine, ctx Context, proc *TransactionProcedure, sth *state.StateHolder, programs *programs.Programs, ) 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, sth *state.StateHolder, programs *programs.Programs, ) error
type TransactionStorageLimiter ¶ added in v0.14.0
type TransactionStorageLimiter struct { // A function to create a function to get storage capacity from an address. This is to make this easily testable. GetStorageCapacityFuncFactory func( vm *VirtualMachine, ctx Context, tp *TransactionProcedure, sth *state.StateHolder, programs *programs.Programs, ) (func(address common.Address) (value uint64, err error), error) }
func NewTransactionStorageLimiter ¶ added in v0.14.0
func NewTransactionStorageLimiter() *TransactionStorageLimiter
func (*TransactionStorageLimiter) Process ¶ added in v0.14.0
func (d *TransactionStorageLimiter) Process( vm *VirtualMachine, ctx Context, tp *TransactionProcedure, sth *state.StateHolder, programs *programs.Programs, ) 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.