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 NewInterpreterRuntime() runtime.Runtime
- 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 WithStorageMBPerFLOW(ratio cadence.UFix64) BootstrapProcedureOption
- func WithTransactionFee(fee cadence.UFix64) BootstrapProcedureOption
- type Context
- type DefaultSignatureVerifier
- type MetricsCollector
- type Option
- func WithAccountFreezeAvailable(accountFreezeAvailable bool) 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 WithExtensiveTracing() 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 WithServiceEventCollectionEnabled() Option
- func WithTracer(tr module.Tracer) Option
- func WithTransactionFeesEnabled(enabled bool) Option
- func WithTransactionProcessors(processors ...TransactionProcessor) Option
- type Procedure
- type ScriptInvocator
- type ScriptProcedure
- type ScriptProcessor
- type SetValueHandler
- type SignatureVerifier
- type TransactionAccountFrozenChecker
- type TransactionAccountFrozenEnabler
- type TransactionContractFunctionInvocator
- 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.00100000") 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.00100000") if err != nil { panic(fmt.Errorf("invalid default minimum storage reservation: %w", err)) } return value }()
var DefaultStorageMBPerFLOW = func() cadence.UFix64 { value, err := cadence.NewUFix64("10.00000000") 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.
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 NewInterpreterRuntime ¶ added in v0.15.1
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
NewBlockFinder constructs a new block finder
type BlocksFinder ¶ added in v0.13.0
type BlocksFinder struct {
// contains filtered or unexported fields
}
BlocksFinder finds blocks and return block headers
func (*BlocksFinder) ByHeightFrom ¶ added in v0.13.0
ByHeightFrom returns the block header by height.
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 WithStorageMBPerFLOW ¶ added in v0.16.1
func WithStorageMBPerFLOW(ratio 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 TransactionFeesEnabled bool CadenceLoggingEnabled bool EventCollectionEnabled bool ServiceEventCollectionEnabled bool AccountFreezeAvailable bool ExtensiveTracing bool 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 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 Option ¶
An Option sets a configuration parameter for a virtual machine context.
func WithAccountFreezeAvailable ¶ added in v0.15.1
WithAccountFreezeAvailable sets availability of account freeze function for a virtual machine context.
With this option set to true, a setAccountFreeze function will be enabled for transactions processed by the VM
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 WithExtensiveTracing ¶ added in v0.16.0
func WithExtensiveTracing() Option
WithExtensiveTracing sets the extensive tracing
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 WithServiceEventCollectionEnabled ¶ added in v0.17.1
func WithServiceEventCollectionEnabled() Option
WithServiceEventCollectionEnabled enables service event collection
func WithTracer ¶ added in v0.14.5
WithTracer sets the tracer for a virtual machine context.
func WithTransactionFeesEnabled ¶ added in v0.17.1
WithTransactionFeesEnabled enables or disables deduction of transaction fees
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 GasUsed uint64 Err errors.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 TransactionAccountFrozenChecker ¶ added in v0.15.1
type TransactionAccountFrozenChecker struct{}
func NewTransactionAccountFrozenChecker ¶ added in v0.15.1
func NewTransactionAccountFrozenChecker() *TransactionAccountFrozenChecker
func (*TransactionAccountFrozenChecker) Process ¶ added in v0.15.1
func (c *TransactionAccountFrozenChecker) Process( _ *VirtualMachine, _ *Context, proc *TransactionProcedure, sth *state.StateHolder, _ *programs.Programs, ) error
type TransactionAccountFrozenEnabler ¶ added in v0.15.1
type TransactionAccountFrozenEnabler struct{}
func NewTransactionAccountFrozenEnabler ¶ added in v0.15.1
func NewTransactionAccountFrozenEnabler() *TransactionAccountFrozenEnabler
func (*TransactionAccountFrozenEnabler) Process ¶ added in v0.15.1
func (c *TransactionAccountFrozenEnabler) Process( _ *VirtualMachine, ctx *Context, proc *TransactionProcedure, _ *state.StateHolder, _ *programs.Programs, ) error
type TransactionContractFunctionInvocator ¶ added in v0.17.1
type TransactionContractFunctionInvocator struct {
// contains filtered or unexported fields
}
func NewTransactionContractFunctionInvocator ¶ added in v0.17.1
func NewTransactionContractFunctionInvocator( contractLocation common.AddressLocation, functionName string, arguments []interpreter.Value, argumentTypes []sema.Type, logger zerolog.Logger) *TransactionContractFunctionInvocator
func (*TransactionContractFunctionInvocator) Invoke ¶ added in v0.17.1
func (i *TransactionContractFunctionInvocator) Invoke(env *hostEnv, proc *TransactionProcedure) (cadence.Value, 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, ) (processErr error)
type TransactionProcedure ¶
type TransactionProcedure struct { ID flow.Identifier Transaction *flow.TransactionBody TxIndex uint32 Logs []string Events []flow.Event ServiceEvents []flow.Event GasUsed uint64 Err errors.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( _ *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( _ *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 NewVirtualMachine ¶ added in v0.15.1
func NewVirtualMachine(rt runtime.Runtime) *VirtualMachine
NewVirtualMachine creates a new virtual machine instance with the provided runtime.