runtime

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 38 Imported by: 60

Documentation

Index

Constants

View Source
const (
	// Supported signing algorithms
	SignatureAlgorithmUnknown         = sema.SignatureAlgorithmUnknown
	SignatureAlgorithmECDSA_P256      = sema.SignatureAlgorithmECDSA_P256
	SignatureAlgorithmECDSA_secp256k1 = sema.SignatureAlgorithmECDSA_secp256k1
	SignatureAlgorithmBLS_BLS12_381   = sema.SignatureAlgorithmBLS_BLS12_381
)
View Source
const (
	// Supported hashing algorithms
	HashAlgorithmUnknown               = sema.HashAlgorithmUnknown
	HashAlgorithmSHA2_256              = sema.HashAlgorithmSHA2_256
	HashAlgorithmSHA2_384              = sema.HashAlgorithmSHA2_384
	HashAlgorithmSHA3_256              = sema.HashAlgorithmSHA3_256
	HashAlgorithmSHA3_384              = sema.HashAlgorithmSHA3_384
	HashAlgorithmKMAC128_BLS_BLS12_381 = sema.HashAlgorithmKMAC128_BLS_BLS12_381
	HashAlgorithmKECCAK_256            = sema.HashAlgorithmKECCAK_256
)
View Source
const (
	AccountStorageKey = "stored"
)

Variables

View Source
var InvalidLiteralError = parser.NewSyntaxError(
	ast.Position{Line: 1},
	"invalid literal",
)
View Source
var LiteralExpressionTypeError = parser.NewSyntaxError(
	ast.Position{Line: 1},
	"input is not a literal",
)
View Source
var UnsupportedLiteralError = parser.NewSyntaxError(
	ast.Position{Line: 1},
	"unsupported literal",
)

Functions

func CommitStorage added in v1.4.0

func CommitStorage(context interpreter.ValueTransferContext, storage *Storage, checkStorageHealth bool) error

func EmitEventFields added in v1.0.0

func EmitEventFields(
	context interpreter.ValueExportContext,
	eventType *sema.CompositeType,
	eventFields []interpreter.Value,
	emitEvent func(cadence.Event) error,
)

func ExportMeteredType added in v0.24.0

func ExportMeteredType(
	gauge common.MemoryGauge,
	t sema.Type,
	results map[sema.TypeID]cadence.Type,
) cadence.Type

ExportMeteredType converts a runtime type to its corresponding Go representation.

func ExportType added in v0.11.0

func ExportType(t sema.Type, results map[sema.TypeID]cadence.Type) cadence.Type

ExportType converts a runtime type to its corresponding Go representation.

func ExportValue added in v0.12.0

func ExportValue(
	value interpreter.Value,
	context interpreter.ValueExportContext,
) (cadence.Value, error)

ExportValue converts a runtime value to its native Go representation.

func ImportType added in v0.24.0

func ImportType(memoryGauge common.MemoryGauge, t cadence.Type) interpreter.StaticType

func ImportValue added in v0.27.0

func ImportValue(
	context ValueImportContext,
	standardLibraryHandler stdlib.StandardLibraryHandler,
	resolveLocation sema.LocationHandlerFunc,
	value cadence.Value,
	expectedType sema.Type,
) (interpreter.Value, error)

ImportValue converts a Cadence value to a runtime value.

func LiteralValue added in v0.12.0

func LiteralValue(
	context interpreter.ValueExportContext,
	expression ast.Expression,
	ty sema.Type,
) (cadence.Value, error)

func NewBaseVMEnvironment added in v1.7.0

func NewBaseVMEnvironment(config Config) *vmEnvironment

func NewPersistentSlabStorage added in v1.3.0

func NewPersistentSlabStorage(
	ledger atree.Ledger,
	memoryGauge common.MemoryGauge,
) *atree.PersistentSlabStorage

func ParseLiteral added in v0.12.0

func ParseLiteral(
	literal string,
	ty sema.Type,
	context interpreter.ValueExportContext,
) (
	cadence.Value,
	error,
)

ParseLiteral parses a single literal string, that should have the given type.

Returns an error if the literal string is not a literal (e.g. it does not have valid syntax, or does not parse to a literal).

func ParseLiteralArgumentList added in v0.12.4

func ParseLiteralArgumentList(
	argumentList string,
	parameterTypes []sema.Type,
	context interpreter.ValueExportContext,
) (
	[]cadence.Value,
	error,
)

ParseLiteralArgumentList parses an argument list with literals, that should have the given types. Returns an error if the code is not a valid argument list, or the arguments are not literals.

Note: This method is not used directly within Cadence, but used by downstream dependencies such as CLI, playground, etc. Hence, shouldn't be moved to test.

func Recover added in v1.4.0

func Recover(onError func(Error), location Location, codesAndPrograms CodesAndPrograms)

func SortContractUpdates added in v0.23.0

func SortContractUpdates(updates []ContractUpdate)

func UserPanicToError added in v1.0.0

func UserPanicToError(f func()) (returnedError error)

UserPanicToError Executes `f` and gracefully handle `UserError` panics. All on-user panics (including `InternalError` and `ExternalError`) are propagated up.

Types

type AccountKey added in v0.14.0

type AccountKey = stdlib.AccountKey

type AccountStorage added in v1.4.0

type AccountStorage struct {
	// contains filtered or unexported fields
}

func NewAccountStorage added in v1.4.0

func NewAccountStorage(
	ledger atree.Ledger,
	slabStorage atree.SlabStorage,
	memoryGauge common.MemoryGauge,
	computationGauge common.ComputationGauge,
) *AccountStorage

func (*AccountStorage) GetDomainStorageMap added in v1.4.0

func (s *AccountStorage) GetDomainStorageMap(
	storageMutationTracker interpreter.StorageMutationTracker,
	address common.Address,
	domain common.StorageDomain,
	createIfNotExists bool,
) (
	domainStorageMap *interpreter.DomainStorageMap,
)

func (*AccountStorage) SetNewAccountStorageMapSlabIndex added in v1.4.0

func (s *AccountStorage) SetNewAccountStorageMapSlabIndex(
	address common.Address,
	slabIndex atree.SlabIndex,
)

type Address

type Address = common.Address

type ArgumentConversionContext added in v1.4.0

type ArgumentConversionContext interface {
	interpreter.AccountCreationContext
}

type ArgumentDecoder added in v0.30.0

type ArgumentDecoder interface {
	stdlib.StandardLibraryHandler
	LocationResolver

	// DecodeArgument decodes a transaction/script argument against the given type.
	DecodeArgument(argument []byte, argumentType cadence.Type) (cadence.Value, error)
}

type ArgumentNotImportableError added in v0.18.0

type ArgumentNotImportableError struct {
	Type interpreter.StaticType
}

ArgumentNotImportableError is an error that is reported for script arguments that belongs to non-importable types.

func (*ArgumentNotImportableError) Error added in v0.18.0

func (*ArgumentNotImportableError) IsUserError added in v0.25.0

func (*ArgumentNotImportableError) IsUserError()

type Block added in v0.9.0

type Block = stdlib.Block

type CheckingEnvironment added in v1.6.2

type CheckingEnvironment struct {
	Config *sema.Config
	// contains filtered or unexported fields
}

func (*CheckingEnvironment) GetProgram added in v1.6.2

func (e *CheckingEnvironment) GetProgram(
	location Location,
	storeProgram bool,
	checkedImports importResolutionResults,
) (
	*Program,
	error,
)

func (*CheckingEnvironment) ParseAndCheckProgram added in v1.6.2

func (e *CheckingEnvironment) ParseAndCheckProgram(
	code []byte,
	location common.Location,
	getAndSetProgram bool,
) (
	*interpreter.Program,
	error,
)

type CodesAndPrograms added in v0.41.0

type CodesAndPrograms struct {
	// contains filtered or unexported fields
}

CodesAndPrograms collects the source code and AST for each location. It is purely used for debugging: Both the codes and the programs are provided in runtime errors.

func NewCodesAndPrograms added in v0.41.0

func NewCodesAndPrograms() CodesAndPrograms

type ComputationProfile added in v1.8.0

type ComputationProfile struct {

	// DelegatedComputationGauge is the computation gauge to which
	// delegated computation metering is reported.
	// It may be nil, in which case no delegation occurs.
	DelegatedComputationGauge common.ComputationGauge
	// contains filtered or unexported fields
}

ComputationProfile collects computation profiling information per location.

func NewComputationProfile added in v1.8.0

func NewComputationProfile() *ComputationProfile

NewComputationProfile creates and returns a *ComputationProfile.

func (*ComputationProfile) InspectProgram added in v1.8.0

func (p *ComputationProfile) InspectProgram(location Location, program *ast.Program)

InspectProgram inspects the elements of the given *ast.Program, and determines the ranges of functions.

func (*ComputationProfile) MeterComputation added in v1.8.0

func (p *ComputationProfile) MeterComputation(computationUsage common.ComputationUsage) error

func (*ComputationProfile) Reset added in v1.8.0

func (p *ComputationProfile) Reset()

Reset clears the collected profiling information for all locations and inspected locations.

func (*ComputationProfile) WithComputationWeights added in v1.8.0

func (p *ComputationProfile) WithComputationWeights(
	weights map[common.ComputationKind]uint64,
)

WithComputationWeights sets the computation weights for this profile.

func (*ComputationProfile) WithLocationMappings added in v1.8.0

func (p *ComputationProfile) WithLocationMappings(
	locationMappings map[string]string,
)

WithLocationMappings sets the location mappings for this profile.

type Config added in v0.26.0

type Config struct {
	Debugger *interpreter.Debugger
	// StackDepthLimit specifies the maximum depth for call stacks
	StackDepthLimit uint64
	// AtreeValidationEnabled configures if atree validation is enabled
	AtreeValidationEnabled bool
	// ResourceOwnerChangeCallbackEnabled configures if the resource owner change callback is enabled
	ResourceOwnerChangeHandlerEnabled bool
	// CoverageReport enables and collects coverage reporting metrics
	CoverageReport *CoverageReport
	// ComputationProfile enables and collects computation profiling metrics
	ComputationProfile *ComputationProfile
}

Config is a constant/read-only configuration of an environment.

type Context added in v0.12.0

type Context struct {
	Interface        Interface
	Location         Location
	Environment      Environment
	MemoryGauge      common.MemoryGauge
	ComputationGauge common.ComputationGauge

	// UseVM configures if the VM should be used
	UseVM bool
}

type ContractUpdate added in v0.13.2

type ContractUpdate struct {
	ContractValue *interpreter.CompositeValue
	Key           interpreter.StorageKey
}

type CoverageReport added in v0.12.0

type CoverageReport struct {
	// Contains a *LocationCoverage per location.
	Coverage map[common.Location]*LocationCoverage
	// Contains locations whose programs are already inspected.
	Locations map[common.Location]struct{}
	// Contains locations excluded from coverage collection.
	ExcludedLocations map[common.Location]struct{}
	// contains filtered or unexported fields
}

CoverageReport collects coverage information per location. It keeps track of inspected locations, and can also exclude locations from coverage collection.

func NewCoverageReport added in v0.12.0

func NewCoverageReport() *CoverageReport

NewCoverageReport creates and returns a *CoverageReport.

func (*CoverageReport) AddLineHit added in v0.12.0

func (r *CoverageReport) AddLineHit(location Location, line int)

AddLineHit increments the hit count for the given line, on the given location. The method call is a NO-OP in two cases: - If the location is excluded from coverage collection - If the location has not been inspected for its statements

func (*CoverageReport) Diff added in v0.38.0

Diff computes the incremental diff between the calling object and a new CoverageReport. The returned result is a CoverageReportSummary object.

CoverageReportSummary{
	Locations:  0,
	Statements: 0,
	Hits:       2,
	Misses:     -2,
	Coverage:   "100.0%",
}

The above diff is interpreted as follows: - No diff in locations, - No diff in statements, - Hits increased by 2, - Misses decreased by 2, - Coverage Δ increased by 100.0%.

func (*CoverageReport) ExcludeLocation added in v0.33.1

func (r *CoverageReport) ExcludeLocation(location Location)

ExcludeLocation adds the given location to the map of excluded locations.

func (*CoverageReport) ExcludedLocationIDs added in v0.38.0

func (r *CoverageReport) ExcludedLocationIDs() []string

ExcludedLocationIDs returns the ID of each excluded location. This is helpful in order to marshal/unmarshal a CoverageReport, without losing any valuable information.

func (*CoverageReport) Hits added in v0.38.0

func (r *CoverageReport) Hits() int

Hits returns the total count of covered lines, for all the locations included in the CoverageReport.

func (*CoverageReport) InspectProgram added in v0.33.1

func (r *CoverageReport) InspectProgram(location Location, program *ast.Program)

InspectProgram inspects the elements of the given *ast.Program, and counts its statements. If inspection is successful, the location is marked as inspected. If the given location is excluded from coverage collection, the method call results in a NO-OP. If the CoverageReport.LocationFilter is present, and calling it with the given location results to false, the method call also results in a NO-OP.

func (*CoverageReport) IsLocationExcluded added in v0.33.1

func (r *CoverageReport) IsLocationExcluded(location Location) bool

IsLocationExcluded checks whether the given location is excluded or not, from coverage collection.

func (*CoverageReport) IsLocationInspected added in v0.38.0

func (r *CoverageReport) IsLocationInspected(location Location) bool

IsLocationInspected checks whether the given location, has been inspected or not.

func (*CoverageReport) MarshalJSON added in v0.27.0

func (r *CoverageReport) MarshalJSON() ([]byte, error)

MarshalJSON serializes each common.Location/*LocationCoverage key/value pair on the *CoverageReport.Coverage map, as well as the IDs on the *CoverageReport.ExcludedLocations map.

func (*CoverageReport) MarshalLCOV added in v0.39.10

func (r *CoverageReport) MarshalLCOV() ([]byte, error)

MarshalLCOV serializes each common.Location/*LocationCoverage key/value pair on the *CoverageReport.Coverage map, to the LCOV format. Currently supports only line coverage, function and branch coverage are not yet available. Description for the LCOV file format, can be found here https://github.com/linux-test-project/lcov/blob/master/man/geninfo.1#L948.

func (*CoverageReport) Merge added in v0.38.0

func (r *CoverageReport) Merge(other CoverageReport)

Merge adds all the collected coverage information to the calling object. Excluded locations are also taken into account.

func (*CoverageReport) Misses added in v0.38.0

func (r *CoverageReport) Misses() int

Misses returns the total count of non-covered lines, for all the locations included in the CoverageReport.

func (*CoverageReport) Percentage added in v0.38.0

func (r *CoverageReport) Percentage() string

Percentage returns a string representation of the covered statements percentage. It is defined as the ratio of total covered lines over total statements, for all locations.

func (*CoverageReport) Reset added in v0.37.0

func (r *CoverageReport) Reset()

Reset clears the collected coverage information for all locations and inspected locations. Excluded locations remain intact.

func (*CoverageReport) Statements added in v0.38.0

func (r *CoverageReport) Statements() int

Statements returns the total count of statements, for all the locations included in the CoverageReport.

func (*CoverageReport) String added in v0.38.0

func (r *CoverageReport) String() string

String returns a human-friendly message for the covered statements percentage.

func (*CoverageReport) Summary added in v0.38.0

Summary returns a CoverageReportSummary object, containing key metrics for a CoverageReport, such as: - Total Locations, - Total Statements, - Total Hits, - Total Misses, - Overall Coverage Percentage.

func (*CoverageReport) TotalLocations added in v0.38.0

func (r *CoverageReport) TotalLocations() int

TotalLocations returns the count of locations included in the CoverageReport. This implies that these locations are: - inspected, - not marked as exlucded.

func (*CoverageReport) UnmarshalJSON added in v0.38.0

func (r *CoverageReport) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes a JSON structure and populates the calling object with the respective *CoverageReport.Coverage & *CoverageReport.ExcludedLocations maps.

func (*CoverageReport) WithLocationFilter added in v0.39.0

func (r *CoverageReport) WithLocationFilter(
	locationFilter LocationFilter,
)

WithLocationFilter sets the LocationFilter for the current CoverageReport.

func (*CoverageReport) WithLocationMappings added in v0.42.1

func (r *CoverageReport) WithLocationMappings(
	locationMappings map[string]string,
)

WithLocationMappings sets the LocationMappings for the current CoverageReport.

type CoverageReportSummary added in v0.38.0

type CoverageReportSummary struct {
	Locations  int    `json:"locations"`
	Statements int    `json:"statements"`
	Hits       int    `json:"hits"`
	Misses     int    `json:"misses"`
	Coverage   string `json:"coverage"`
}

CoverageReportSummary contains key metrics that are derived from a CoverageReport object, such as: - Total Locations, - Total Statements, - Total Hits, - Total Misses, - Overall Coverage Percentage. This metrics can be utilized in various ways, such as a CI plugin/app.

type EmptyRuntimeInterface

type EmptyRuntimeInterface struct{}

EmptyRuntimeInterface is an empty implementation of runtime.Interface. It can be embedded in other types implementing runtime.Interface to avoid having to implement all methods.

func (EmptyRuntimeInterface) AccountKeysCount added in v1.0.0

func (EmptyRuntimeInterface) AccountKeysCount(_ Address) (uint32, error)

func (EmptyRuntimeInterface) AddAccountKey

func (EmptyRuntimeInterface) AddAccountKey(
	_ Address,
	_ *PublicKey,
	_ HashAlgorithm,
	_ int,
) (*AccountKey, error)

func (EmptyRuntimeInterface) AllocateSlabIndex added in v1.0.0

func (EmptyRuntimeInterface) AllocateSlabIndex(_ []byte) (atree.SlabIndex, error)

func (EmptyRuntimeInterface) BLSAggregatePublicKeys added in v1.0.0

func (EmptyRuntimeInterface) BLSAggregatePublicKeys(_ []*PublicKey) (*PublicKey, error)

func (EmptyRuntimeInterface) BLSAggregateSignatures added in v1.0.0

func (EmptyRuntimeInterface) BLSAggregateSignatures(_ [][]byte) ([]byte, error)

func (EmptyRuntimeInterface) BLSVerifyPOP added in v1.0.0

func (EmptyRuntimeInterface) BLSVerifyPOP(_ *PublicKey, _ []byte) (bool, error)

func (EmptyRuntimeInterface) CreateAccount

func (EmptyRuntimeInterface) CreateAccount(_ Address) (address Address, err error)

func (EmptyRuntimeInterface) DecodeArgument added in v0.2.0

func (EmptyRuntimeInterface) DecodeArgument(_ []byte, _ cadence.Type) (cadence.Value, error)

func (EmptyRuntimeInterface) EmitEvent

func (EmptyRuntimeInterface) GenerateAccountID added in v1.0.0

func (EmptyRuntimeInterface) GenerateAccountID(_ common.Address) (uint64, error)

func (EmptyRuntimeInterface) GenerateUUID

func (EmptyRuntimeInterface) GenerateUUID() (uint64, error)

func (EmptyRuntimeInterface) GetAccountAvailableBalance added in v1.0.0

func (EmptyRuntimeInterface) GetAccountAvailableBalance(_ common.Address) (value uint64, err error)

func (EmptyRuntimeInterface) GetAccountBalance added in v1.0.0

func (EmptyRuntimeInterface) GetAccountBalance(_ common.Address) (value uint64, err error)

func (EmptyRuntimeInterface) GetAccountContractCode added in v0.10.0

func (EmptyRuntimeInterface) GetAccountContractCode(_ common.AddressLocation) (code []byte, err error)

func (EmptyRuntimeInterface) GetAccountContractNames added in v1.0.0

func (EmptyRuntimeInterface) GetAccountContractNames(_ Address) ([]string, error)

func (EmptyRuntimeInterface) GetAccountKey added in v1.0.0

func (EmptyRuntimeInterface) GetAccountKey(_ Address, _ uint32) (*AccountKey, error)

func (EmptyRuntimeInterface) GetBlockAtHeight added in v0.3.0

func (EmptyRuntimeInterface) GetBlockAtHeight(_ uint64) (block Block, exists bool, err error)

func (EmptyRuntimeInterface) GetCode added in v0.10.0

func (EmptyRuntimeInterface) GetCode(_ Location) ([]byte, error)

func (EmptyRuntimeInterface) GetCurrentBlockHeight added in v0.3.0

func (EmptyRuntimeInterface) GetCurrentBlockHeight() (uint64, error)

func (EmptyRuntimeInterface) GetOrLoadProgram added in v1.0.0

func (EmptyRuntimeInterface) GetOrLoadProgram(_ Location, _ func() (*Program, error)) (*Program, error)

func (EmptyRuntimeInterface) GetSigningAccounts

func (EmptyRuntimeInterface) GetSigningAccounts() ([]Address, error)

func (EmptyRuntimeInterface) GetStorageCapacity added in v0.10.3

func (EmptyRuntimeInterface) GetStorageCapacity(_ Address) (value uint64, err error)

func (EmptyRuntimeInterface) GetStorageUsed added in v0.10.3

func (EmptyRuntimeInterface) GetStorageUsed(_ Address) (value uint64, err error)

func (EmptyRuntimeInterface) GetValue

func (EmptyRuntimeInterface) GetValue(_, _ []byte) (value []byte, err error)

func (EmptyRuntimeInterface) Hash added in v0.10.0

func (EmptyRuntimeInterface) ImplementationDebugLog added in v0.12.8

func (EmptyRuntimeInterface) ImplementationDebugLog(_ string) error

func (EmptyRuntimeInterface) MinimumRequiredVersion added in v1.0.2

func (EmptyRuntimeInterface) MinimumRequiredVersion() (string, error)

func (EmptyRuntimeInterface) ProgramLog added in v0.12.8

func (EmptyRuntimeInterface) ProgramLog(_ string) error

func (EmptyRuntimeInterface) ReadRandom added in v1.0.0

func (EmptyRuntimeInterface) ReadRandom(_ []byte) error

func (EmptyRuntimeInterface) RecordTrace added in v1.0.0

func (EmptyRuntimeInterface) RecoverProgram added in v1.0.0

func (EmptyRuntimeInterface) RecoverProgram(_ *ast.Program, _ common.Location) ([]byte, error)

func (EmptyRuntimeInterface) RemoveAccountContractCode added in v0.10.0

func (EmptyRuntimeInterface) RemoveAccountContractCode(_ common.AddressLocation) (err error)

func (EmptyRuntimeInterface) ResolveLocation added in v0.10.0

func (EmptyRuntimeInterface) ResolveLocation(_ []Identifier, _ Location) ([]ResolvedLocation, error)

func (EmptyRuntimeInterface) ResourceOwnerChanged added in v1.0.0

func (EmptyRuntimeInterface) RevokeAccountKey added in v1.0.0

func (EmptyRuntimeInterface) RevokeAccountKey(_ Address, _ uint32) (*AccountKey, error)

func (EmptyRuntimeInterface) SetValue

func (EmptyRuntimeInterface) SetValue(_, _, _ []byte) (err error)

func (EmptyRuntimeInterface) UpdateAccountContractCode added in v0.10.0

func (EmptyRuntimeInterface) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) (err error)

func (EmptyRuntimeInterface) ValidatePublicKey added in v1.0.0

func (EmptyRuntimeInterface) ValidatePublicKey(_ *PublicKey) error

func (EmptyRuntimeInterface) ValueExists

func (EmptyRuntimeInterface) ValueExists(_, _ []byte) (exists bool, err error)

func (EmptyRuntimeInterface) VerifySignature added in v0.5.0

func (EmptyRuntimeInterface) VerifySignature(
	_ []byte,
	_ string,
	_ []byte,
	_ []byte,
	_ SignatureAlgorithm,
	_ HashAlgorithm,
) (bool, error)

type Environment added in v0.26.0

type Environment interface {
	ArgumentDecoder

	DeclareValue(
		valueDeclaration stdlib.StandardLibraryValue,
		location common.Location,
	)
	DeclareType(
		typeDeclaration stdlib.StandardLibraryType,
		location common.Location,
	)
	Configure(
		runtimeInterface Interface,
		codesAndPrograms CodesAndPrograms,
		storage *Storage,
		memoryGauge common.MemoryGauge,
		computationGauge common.ComputationGauge,
	)
	ParseAndCheckProgram(
		code []byte,
		location common.Location,
		getAndSetProgram bool,
	) (
		*interpreter.Program,
		error,
	)
	// contains filtered or unexported methods
}

func NewScriptVMEnvironment added in v1.7.0

func NewScriptVMEnvironment(config Config) Environment

type Error

type Error struct {
	Err      error
	Location Location
	Codes    map[Location][]byte
	Programs map[Location]*ast.Program
}

Error is the containing type for all errors produced by the runtime.

func GetWrappedError added in v1.4.0

func GetWrappedError(recovered any, location Location, codesAndPrograms CodesAndPrograms) Error

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Executor added in v0.25.0

type Executor interface {
	// Preprocess prepares the transaction/script for execution.
	//
	// This function returns an error if the program has errors (e.g., syntax
	// errors, type errors).
	//
	// This method may be called multiple times.  Only the first call will
	// trigger meaningful work; subsequent calls will return the cached return
	// value from the original call (i.e., an Executor implementation must
	// guard this method with sync.Once).
	Preprocess() error

	// Execute executes the transaction/script.
	//
	// This function returns an error if Preprocess failed or if the execution
	// fails.
	//
	// This method may be called multiple times.  Only the first call will
	// trigger meaningful work; subsequent calls will return the cached return
	// value from the original call (i.e., an Executor implementation must
	// guard this method with sync.Once).
	//
	// Note: Execute will invoke Preprocess to ensure Preprocess was called at
	// least once.
	Execute() error

	// Result returns the transaction/scipt's execution result.
	//
	// This function returns an error if Preproces or Execute fails.  The
	// cadence.Value is always nil for transaction.
	//
	// This method may be called multiple times.  Only the first call will
	// trigger meaningful work; subsequent calls will return the cached return
	// value from the original call (i.e., an Executor implementation must
	// guard this method with sync.Once).
	//
	// Note: Result will invoke Execute to ensure Execute was called at least
	// once.
	Result() (cadence.Value, error)
}

Executor is a continuation which represents a full unit of transaction/script execution.

The full unit of execution is divided into stages:

  1. Preprocess() initializes the executor in preparation for the actual transaction execution (e.g., parse / type check the input). Note that the work done by Preprocess() should be embrassingly parallel.
  2. Execute() performs the actual transaction execution (e.g., run the interpreter to produce the transaction result).
  3. Result() returns the result of the full unit of execution.

TODO: maybe add Cleanup/Postprocess in the future

type ExternalInterface added in v1.5.0

type ExternalInterface struct {
	Interface Interface
}

ExternalInterface is an implementation of runtime.Interface which forwards all calls to the embedded Interface. All calls' panics and errors are wrapped.

func (ExternalInterface) AccountKeysCount added in v1.5.0

func (e ExternalInterface) AccountKeysCount(address Address) (count uint32, err error)

func (ExternalInterface) AddAccountKey added in v1.5.0

func (e ExternalInterface) AddAccountKey(
	address Address,
	publicKey *PublicKey,
	hashAlgo HashAlgorithm,
	weight int,
) (
	key *AccountKey,
	err error,
)

func (ExternalInterface) AllocateSlabIndex added in v1.5.0

func (e ExternalInterface) AllocateSlabIndex(owner []byte) (index atree.SlabIndex, err error)

func (ExternalInterface) BLSAggregatePublicKeys added in v1.5.0

func (e ExternalInterface) BLSAggregatePublicKeys(publicKeys []*PublicKey) (publicKey *PublicKey, err error)

func (ExternalInterface) BLSAggregateSignatures added in v1.5.0

func (e ExternalInterface) BLSAggregateSignatures(signatures [][]byte) (signature []byte, err error)

func (ExternalInterface) BLSVerifyPOP added in v1.5.0

func (e ExternalInterface) BLSVerifyPOP(publicKey *PublicKey, signature []byte) (valid bool, err error)

func (ExternalInterface) CreateAccount added in v1.5.0

func (e ExternalInterface) CreateAccount(payer Address) (address Address, err error)

func (ExternalInterface) DecodeArgument added in v1.5.0

func (e ExternalInterface) DecodeArgument(argument []byte, argumentType cadence.Type) (value cadence.Value, err error)

func (ExternalInterface) EmitEvent added in v1.5.0

func (e ExternalInterface) EmitEvent(event cadence.Event) (err error)

func (ExternalInterface) GenerateAccountID added in v1.5.0

func (e ExternalInterface) GenerateAccountID(address common.Address) (id uint64, err error)

func (ExternalInterface) GenerateUUID added in v1.5.0

func (e ExternalInterface) GenerateUUID() (uuid uint64, err error)

func (ExternalInterface) GetAccountAvailableBalance added in v1.5.0

func (e ExternalInterface) GetAccountAvailableBalance(address common.Address) (value uint64, err error)

func (ExternalInterface) GetAccountBalance added in v1.5.0

func (e ExternalInterface) GetAccountBalance(address common.Address) (value uint64, err error)

func (ExternalInterface) GetAccountContractCode added in v1.5.0

func (e ExternalInterface) GetAccountContractCode(location common.AddressLocation) (code []byte, err error)

func (ExternalInterface) GetAccountContractNames added in v1.5.0

func (e ExternalInterface) GetAccountContractNames(address Address) (names []string, err error)

func (ExternalInterface) GetAccountKey added in v1.5.0

func (e ExternalInterface) GetAccountKey(address Address, index uint32) (key *AccountKey, err error)

func (ExternalInterface) GetBlockAtHeight added in v1.5.0

func (e ExternalInterface) GetBlockAtHeight(height uint64) (block Block, exists bool, err error)

func (ExternalInterface) GetCode added in v1.5.0

func (e ExternalInterface) GetCode(location Location) (code []byte, err error)

func (ExternalInterface) GetCurrentBlockHeight added in v1.5.0

func (e ExternalInterface) GetCurrentBlockHeight() (height uint64, err error)

func (ExternalInterface) GetOrLoadProgram added in v1.5.0

func (e ExternalInterface) GetOrLoadProgram(
	location Location,
	load func() (*Program, error),
) (
	program *Program,
	err error,
)

func (ExternalInterface) GetSigningAccounts added in v1.5.0

func (e ExternalInterface) GetSigningAccounts() (addresses []Address, err error)

func (ExternalInterface) GetStorageCapacity added in v1.5.0

func (e ExternalInterface) GetStorageCapacity(address Address) (capacity uint64, err error)

func (ExternalInterface) GetStorageUsed added in v1.5.0

func (e ExternalInterface) GetStorageUsed(address Address) (usage uint64, err error)

func (ExternalInterface) GetValue added in v1.5.0

func (e ExternalInterface) GetValue(owner, key []byte) (value []byte, err error)

func (ExternalInterface) Hash added in v1.5.0

func (e ExternalInterface) Hash(data []byte, tag string, hashAlgorithm HashAlgorithm) (hash []byte, err error)

func (ExternalInterface) ImplementationDebugLog added in v1.5.0

func (e ExternalInterface) ImplementationDebugLog(message string) (err error)

func (ExternalInterface) MinimumRequiredVersion added in v1.5.0

func (e ExternalInterface) MinimumRequiredVersion() (version string, err error)

func (ExternalInterface) ProgramChecked added in v1.5.0

func (e ExternalInterface) ProgramChecked(location Location, duration time.Duration)

func (ExternalInterface) ProgramInterpreted added in v1.5.0

func (e ExternalInterface) ProgramInterpreted(location Location, duration time.Duration)

func (ExternalInterface) ProgramLog added in v1.5.0

func (e ExternalInterface) ProgramLog(message string) (err error)

func (ExternalInterface) ProgramParsed added in v1.5.0

func (e ExternalInterface) ProgramParsed(location Location, duration time.Duration)

func (ExternalInterface) ReadRandom added in v1.5.0

func (e ExternalInterface) ReadRandom(bytes []byte) (err error)

func (ExternalInterface) RecordTrace added in v1.5.0

func (e ExternalInterface) RecordTrace(
	operation string,
	duration time.Duration,
	attrs []attribute.KeyValue,
)

func (ExternalInterface) RecoverProgram added in v1.5.0

func (e ExternalInterface) RecoverProgram(program *ast.Program, location common.Location) (code []byte, err error)

func (ExternalInterface) RemoveAccountContractCode added in v1.5.0

func (e ExternalInterface) RemoveAccountContractCode(location common.AddressLocation) (err error)

func (ExternalInterface) ResolveLocation added in v1.5.0

func (e ExternalInterface) ResolveLocation(
	identifiers []Identifier,
	location Location,
) (
	locations []ResolvedLocation,
	err error,
)

func (ExternalInterface) ResourceOwnerChanged added in v1.5.0

func (e ExternalInterface) ResourceOwnerChanged(
	interpreter *interpreter.Interpreter,
	resource *interpreter.CompositeValue,
	oldOwner common.Address,
	newOwner common.Address,
)

func (ExternalInterface) RevokeAccountKey added in v1.5.0

func (e ExternalInterface) RevokeAccountKey(address Address, index uint32) (key *AccountKey, err error)

func (ExternalInterface) SetValue added in v1.5.0

func (e ExternalInterface) SetValue(owner, key, value []byte) (err error)

func (ExternalInterface) UpdateAccountContractCode added in v1.5.0

func (e ExternalInterface) UpdateAccountContractCode(location common.AddressLocation, code []byte) (err error)

func (ExternalInterface) ValidateAccountCapabilitiesGet added in v1.5.0

func (e ExternalInterface) ValidateAccountCapabilitiesGet(
	context interpreter.AccountCapabilityGetValidationContext,
	address interpreter.AddressValue,
	path interpreter.PathValue,
	wantedBorrowType *sema.ReferenceType,
	capabilityBorrowType *sema.ReferenceType,
) (
	valid bool,
	err error,
)

func (ExternalInterface) ValidateAccountCapabilitiesPublish added in v1.5.0

func (e ExternalInterface) ValidateAccountCapabilitiesPublish(
	context interpreter.AccountCapabilityPublishValidationContext,
	address interpreter.AddressValue,
	path interpreter.PathValue,
	capabilityBorrowType *interpreter.ReferenceStaticType,
) (
	ok bool,
	err error,
)

func (ExternalInterface) ValidatePublicKey added in v1.5.0

func (e ExternalInterface) ValidatePublicKey(key *PublicKey) (err error)

func (ExternalInterface) ValueExists added in v1.5.0

func (e ExternalInterface) ValueExists(owner, key []byte) (exists bool, err error)

func (ExternalInterface) VerifySignature added in v1.5.0

func (e ExternalInterface) VerifySignature(
	signature []byte,
	tag string,
	signedData []byte,
	publicKey []byte,
	signatureAlgorithm SignatureAlgorithm,
	hashAlgorithm HashAlgorithm,
) (
	valid bool,
	err error,
)

type HashAlgorithm added in v0.14.0

type HashAlgorithm = sema.HashAlgorithm

type Identifier added in v0.10.0

type Identifier = ast.Identifier

type ImportResolver

type ImportResolver = func(location Location) (program *ast.Program, e error)

type Interface

type Interface interface {
	// ResolveLocation resolves an import location.
	ResolveLocation(identifiers []Identifier, location Location) ([]ResolvedLocation, error)
	// GetCode returns the code at a given location
	GetCode(location Location) ([]byte, error)
	// GetOrLoadProgram returns the program for the given location, if available,
	// or sets the program by calling the given load function.
	//
	// For implementations:
	// - Perform a lookup for the location and return the program if it exists.
	// - If the program does not exist, call load, and store the result,
	//   *EVEN IF loading failed* (program is nil / error is non-nil)!
	// - During execution of a high-level program (e.g. script, transaction, etc.),
	//   this function MUST always return the *same* program,
	//   i.e. it may NOT return a different program,
	//   an elaboration in the program that is not annotating the AST in the program;
	//   or a program/elaboration and then nothing in a subsequent call.
	// - This function MUST also return exactly what was previously returned from load,
	//   *EVEN IF loading failed* (program is nil / error is non-nil),
	//   and it may NOT return something different
	// - Do NOT implement this as a cache!
	GetOrLoadProgram(
		location Location,
		load func() (*Program, error),
	) (*Program, error)
	// GetValue gets a value for the given key in the storage, owned by the given account.
	GetValue(owner, key []byte) (value []byte, err error)
	// SetValue sets a value for the given key in the storage, owned by the given account.
	SetValue(owner, key, value []byte) (err error)
	// ValueExists returns true if the given key exists in the storage, owned by the given account.
	ValueExists(owner, key []byte) (exists bool, err error)
	// AllocateSlabIndex allocates a new slab index under the given account.
	AllocateSlabIndex(owner []byte) (atree.SlabIndex, error)
	// CreateAccount creates a new account.
	CreateAccount(payer Address) (address Address, err error)
	// AddAccountKey appends a key to an account.
	AddAccountKey(address Address, publicKey *PublicKey, hashAlgo HashAlgorithm, weight int) (*AccountKey, error)
	// GetAccountKey retrieves a key from an account by index.
	GetAccountKey(address Address, index uint32) (*AccountKey, error)
	AccountKeysCount(address Address) (uint32, error)
	// RevokeAccountKey removes a key from an account by index.
	RevokeAccountKey(address Address, index uint32) (*AccountKey, error)
	// UpdateAccountContractCode updates the code associated with an account contract.
	UpdateAccountContractCode(location common.AddressLocation, code []byte) (err error)
	// GetAccountContractCode returns the code associated with an account contract.
	GetAccountContractCode(location common.AddressLocation) (code []byte, err error)
	// RemoveAccountContractCode removes the code associated with an account contract.
	RemoveAccountContractCode(location common.AddressLocation) (err error)
	// GetSigningAccounts returns the signing accounts.
	GetSigningAccounts() ([]Address, error)
	// ProgramLog logs program logs.
	ProgramLog(string) error
	// EmitEvent is called when an event is emitted by the runtime.
	EmitEvent(cadence.Event) error
	// GenerateUUID is called to generate a UUID.
	GenerateUUID() (uint64, error)
	// DecodeArgument decodes a transaction/script argument against the given type.
	DecodeArgument(argument []byte, argumentType cadence.Type) (cadence.Value, error)
	// GetCurrentBlockHeight returns the current block height.
	GetCurrentBlockHeight() (uint64, error)
	// GetBlockAtHeight returns the block at the given height.
	GetBlockAtHeight(height uint64) (block Block, exists bool, err error)
	// ReadRandom reads pseudo-random bytes into the input slice, using distributed randomness.
	ReadRandom([]byte) error
	// VerifySignature returns true if the given signature was produced by signing the given tag + data
	// using the given public key, signature algorithm, and hash algorithm.
	VerifySignature(
		signature []byte,
		tag string,
		signedData []byte,
		publicKey []byte,
		signatureAlgorithm SignatureAlgorithm,
		hashAlgorithm HashAlgorithm,
	) (bool, error)
	// Hash returns the digest of hashing the given data with using the given hash algorithm
	Hash(data []byte, tag string, hashAlgorithm HashAlgorithm) ([]byte, error)
	// GetAccountBalance gets accounts default flow token balance.
	GetAccountBalance(address common.Address) (value uint64, err error)
	// GetAccountAvailableBalance gets accounts default flow token balance - balance that is reserved for storage.
	GetAccountAvailableBalance(address common.Address) (value uint64, err error)
	// GetStorageUsed gets storage used in bytes by the address at the moment of the function call.
	GetStorageUsed(address Address) (value uint64, err error)
	// GetStorageCapacity gets storage capacity in bytes on the address.
	GetStorageCapacity(address Address) (value uint64, err error)
	// ImplementationDebugLog logs implementation log statements on a debug-level
	ImplementationDebugLog(message string) error
	// ValidatePublicKey verifies the validity of a public key.
	ValidatePublicKey(key *PublicKey) error
	// GetAccountContractNames returns the names of all contracts deployed in an account.
	GetAccountContractNames(address Address) ([]string, error)
	// RecordTrace records an OpenTelemetry trace.
	RecordTrace(operation string, duration time.Duration, attrs []attribute.KeyValue)
	// BLSVerifyPOP verifies a proof of possession (PoP) for the receiver public key.
	BLSVerifyPOP(publicKey *PublicKey, signature []byte) (bool, error)
	// BLSAggregateSignatures aggregate multiple BLS signatures into one.
	BLSAggregateSignatures(signatures [][]byte) ([]byte, error)
	// BLSAggregatePublicKeys aggregate multiple BLS public keys into one.
	BLSAggregatePublicKeys(publicKeys []*PublicKey) (*PublicKey, error)
	// ResourceOwnerChanged gets called when a resource's owner changed (if enabled)
	ResourceOwnerChanged(
		interpreter *interpreter.Interpreter,
		resource *interpreter.CompositeValue,
		oldOwner common.Address,
		newOwner common.Address,
	)
	// GenerateAccountID generates a new, *non-zero*, unique ID for the given account.
	GenerateAccountID(address common.Address) (uint64, error)
	RecoverProgram(program *ast.Program, location common.Location) ([]byte, error)
	ValidateAccountCapabilitiesGet(
		context interpreter.AccountCapabilityGetValidationContext,
		address interpreter.AddressValue,
		path interpreter.PathValue,
		wantedBorrowType *sema.ReferenceType,
		capabilityBorrowType *sema.ReferenceType,
	) (bool, error)
	ValidateAccountCapabilitiesPublish(
		context interpreter.AccountCapabilityPublishValidationContext,
		address interpreter.AddressValue,
		path interpreter.PathValue,
		capabilityBorrowType *interpreter.ReferenceStaticType,
	) (bool, error)

	MinimumRequiredVersion() (string, error)
}

type InterpreterEnvironment added in v1.6.2

type InterpreterEnvironment struct {
	CheckingEnvironment *CheckingEnvironment

	InterpreterConfig *interpreter.Config

	*stdlib.SimpleContractAdditionTracker
	// contains filtered or unexported fields
}

func NewBaseInterpreterEnvironment added in v0.26.0

func NewBaseInterpreterEnvironment(config Config) *InterpreterEnvironment

func NewInterpreterEnvironment added in v1.4.0

func NewInterpreterEnvironment(config Config) *InterpreterEnvironment

func NewScriptInterpreterEnvironment added in v0.26.0

func NewScriptInterpreterEnvironment(config Config) *InterpreterEnvironment

func (*InterpreterEnvironment) CommitStorageTemporarily added in v1.6.2

func (e *InterpreterEnvironment) CommitStorageTemporarily(context interpreter.ValueTransferContext) error

func (*InterpreterEnvironment) Configure added in v1.6.2

func (e *InterpreterEnvironment) Configure(
	runtimeInterface Interface,
	codesAndPrograms CodesAndPrograms,
	storage *Storage,
	memoryGauge common.MemoryGauge,
	computationGauge common.ComputationGauge,
)

func (*InterpreterEnvironment) ContractUpdateRecorded added in v1.6.2

func (e *InterpreterEnvironment) ContractUpdateRecorded(location common.AddressLocation) bool

func (*InterpreterEnvironment) DeclareType added in v1.6.2

func (e *InterpreterEnvironment) DeclareType(typeDeclaration stdlib.StandardLibraryType, location common.Location)

func (*InterpreterEnvironment) DeclareValue added in v1.6.2

func (e *InterpreterEnvironment) DeclareValue(valueDeclaration stdlib.StandardLibraryValue, location common.Location)

func (*InterpreterEnvironment) EmitEvent added in v1.6.2

func (e *InterpreterEnvironment) EmitEvent(
	context interpreter.ValueExportContext,
	eventType *sema.CompositeType,
	values []interpreter.Value,
)

func (*InterpreterEnvironment) Interpret added in v1.6.2

func (e *InterpreterEnvironment) Interpret(
	location common.Location,
	program *interpreter.Program,
	f interpretFunc,
) (
	interpreter.Value,
	*interpreter.Interpreter,
	error,
)

func (*InterpreterEnvironment) LoadContractValue added in v1.6.2

func (e *InterpreterEnvironment) LoadContractValue(
	location common.AddressLocation,
	program *interpreter.Program,
	name string,
	invocation stdlib.DeployedContractConstructorInvocation,
) (
	contract *interpreter.CompositeValue,
	err error,
)

func (*InterpreterEnvironment) NewInterpreterConfig added in v1.6.2

func (e *InterpreterEnvironment) NewInterpreterConfig() *interpreter.Config

func (*InterpreterEnvironment) ParseAndCheckProgram added in v1.6.2

func (e *InterpreterEnvironment) ParseAndCheckProgram(
	code []byte,
	location common.Location,
	getAndSetProgram bool,
) (
	*interpreter.Program,
	error,
)

func (*InterpreterEnvironment) ProgramLog added in v1.6.2

func (e *InterpreterEnvironment) ProgramLog(message string) error

func (*InterpreterEnvironment) RecordContractRemoval added in v1.6.2

func (e *InterpreterEnvironment) RecordContractRemoval(location common.AddressLocation)

func (*InterpreterEnvironment) RecordContractUpdate added in v1.6.2

func (e *InterpreterEnvironment) RecordContractUpdate(
	location common.AddressLocation,
	contractValue *interpreter.CompositeValue,
)

func (*InterpreterEnvironment) ResolveLocation added in v1.6.2

func (e *InterpreterEnvironment) ResolveLocation(
	identifiers []Identifier,
	location Location,
) (
	res []ResolvedLocation,
	err error,
)

func (*InterpreterEnvironment) SetCompositeValueFunctionsHandler added in v1.6.2

func (e *InterpreterEnvironment) SetCompositeValueFunctionsHandler(
	typeID common.TypeID,
	handler stdlib.CompositeValueFunctionsHandler,
)

func (*InterpreterEnvironment) TemporarilyRecordCode added in v1.6.2

func (e *InterpreterEnvironment) TemporarilyRecordCode(location common.AddressLocation, code []byte)

type InvalidEntryPointArgumentError added in v0.5.0

type InvalidEntryPointArgumentError struct {
	Err   error
	Index int
}

InvalidEntryPointArgumentError

func (*InvalidEntryPointArgumentError) Error added in v0.5.0

func (*InvalidEntryPointArgumentError) IsUserError added in v0.25.0

func (*InvalidEntryPointArgumentError) IsUserError()

func (*InvalidEntryPointArgumentError) Unwrap added in v0.5.0

type InvalidEntryPointParameterCountError added in v0.5.0

type InvalidEntryPointParameterCountError struct {
	Expected int
	Actual   int
}

func (InvalidEntryPointParameterCountError) Error added in v0.5.0

func (InvalidEntryPointParameterCountError) IsUserError added in v0.25.0

type InvalidScriptReturnTypeError added in v0.11.0

type InvalidScriptReturnTypeError struct {
	Type sema.Type
}

InvalidScriptReturnTypeError is an error that is reported for invalid script return types.

A type is invalid if it cannot be exported / returned externally.

func (*InvalidScriptReturnTypeError) Error added in v0.11.0

func (*InvalidScriptReturnTypeError) IsUserError added in v0.25.0

func (*InvalidScriptReturnTypeError) IsUserError()

type InvalidTransactionAuthorizerCountError added in v0.2.0

type InvalidTransactionAuthorizerCountError struct {
	Expected int
	Actual   int
}

func (InvalidTransactionAuthorizerCountError) Error added in v0.2.0

func (InvalidTransactionAuthorizerCountError) IsUserError added in v0.25.0

type InvalidTransactionCountError

type InvalidTransactionCountError struct {
	Count int
}

func (InvalidTransactionCountError) Error

func (InvalidTransactionCountError) IsUserError added in v0.25.0

func (InvalidTransactionCountError) IsUserError()

type InvalidValueTypeError added in v0.15.0

type InvalidValueTypeError struct {
	ExpectedType sema.Type
}

InvalidValueTypeError

func (*InvalidValueTypeError) Error added in v0.15.0

func (e *InvalidValueTypeError) Error() string

func (*InvalidValueTypeError) IsUserError added in v0.25.0

func (*InvalidValueTypeError) IsUserError()

type LimitingMemoryGauge added in v1.7.0

type LimitingMemoryGauge struct {
	Weights map[common.MemoryKind]uint64
	Usage   uint64
	Limit   uint64
}

func NewLimitingMemoryGauge added in v1.7.0

func NewLimitingMemoryGauge(
	weights map[common.MemoryKind]uint64,
	limit uint64,
) *LimitingMemoryGauge

func (*LimitingMemoryGauge) MeterMemory added in v1.7.0

func (g *LimitingMemoryGauge) MeterMemory(usage common.MemoryUsage) error

type Location

type Location = common.Location

type LocationCoverage added in v0.12.0

type LocationCoverage struct {
	// Contains hit count for each line on a given location.
	// A hit count of 0 means the line was not covered.
	LineHits map[int]int
	// Total number of statements on a given location.
	Statements int
}

LocationCoverage records coverage information for a location.

func NewLocationCoverage added in v0.12.0

func NewLocationCoverage(lineHits map[int]int) *LocationCoverage

NewLocationCoverage creates and returns a *LocationCoverage with the given lineHits map.

func (*LocationCoverage) AddLineHit added in v0.12.0

func (c *LocationCoverage) AddLineHit(line int)

AddLineHit increments the hit count for the given line.

func (*LocationCoverage) CoveredLines added in v0.33.1

func (c *LocationCoverage) CoveredLines() int

CoveredLines returns the count of covered lines for a given location. This is the number of lines with a hit count > 0.

func (*LocationCoverage) MissedLines added in v0.33.1

func (c *LocationCoverage) MissedLines() []int

MissedLines returns an array with the missed lines for a given location. These are all the lines with a hit count == 0. The resulting array is sorted in ascending order.

func (*LocationCoverage) Percentage added in v0.33.1

func (c *LocationCoverage) Percentage() string

Percentage returns a string representation of the covered statements percentage. It is defined as the ratio of covered lines over the total statements for a given location.

type LocationFilter added in v0.39.0

type LocationFilter func(location Location) bool

type LocationLine added in v1.8.0

type LocationLine struct {
	Location common.Location
	Line     int
}

type LocationResolver added in v1.4.0

type LocationResolver interface {
	ResolveLocation(identifiers []ast.Identifier, location common.Location) ([]ResolvedLocation, error)
}

type MalformedValueError added in v0.15.0

type MalformedValueError struct {
	ExpectedType sema.Type
}

func (*MalformedValueError) Error added in v0.15.0

func (e *MalformedValueError) Error() string

func (*MalformedValueError) IsUserError added in v0.25.0

func (*MalformedValueError) IsUserError()

type MemoryLimitExceededError added in v1.7.0

type MemoryLimitExceededError struct {
	Limit uint64
	Usage uint64
}

func (MemoryLimitExceededError) Error added in v1.7.0

func (e MemoryLimitExceededError) Error() string

func (MemoryLimitExceededError) IsUserError added in v1.7.0

func (MemoryLimitExceededError) IsUserError()

type Metrics added in v0.2.0

type Metrics interface {
	ProgramParsed(location Location, duration time.Duration)
	ProgramChecked(location Location, duration time.Duration)
	ProgramInterpreted(location Location, duration time.Duration)
}

type PProfExporter added in v1.8.0

type PProfExporter struct {
	ComputationProfile *ComputationProfile
	// contains filtered or unexported fields
}

func NewPProfExporter added in v1.8.0

func NewPProfExporter(computationProfile *ComputationProfile) *PProfExporter

func (*PProfExporter) Export added in v1.8.0

func (e *PProfExporter) Export() (*pprof.Profile, error)

type ParsingCheckingError added in v0.9.3

type ParsingCheckingError struct {
	Err      error
	Location Location
}

ParsingCheckingError is an error wrapper for a parsing or a checking error at a specific location

func (*ParsingCheckingError) ChildErrors added in v0.9.3

func (e *ParsingCheckingError) ChildErrors() []error

func (*ParsingCheckingError) Error added in v0.9.3

func (e *ParsingCheckingError) Error() string

func (*ParsingCheckingError) ImportLocation added in v0.12.1

func (e *ParsingCheckingError) ImportLocation() Location

func (*ParsingCheckingError) IsUserError added in v0.25.0

func (*ParsingCheckingError) IsUserError()

func (*ParsingCheckingError) Unwrap added in v0.9.3

func (e *ParsingCheckingError) Unwrap() error

type Program added in v1.5.0

type Program struct {
	// contains filtered or unexported fields
}

type PublicKey added in v0.14.0

type PublicKey = stdlib.PublicKey

type REPL

type REPL struct {
	OnError          func(err error, location Location, codes map[Location][]byte)
	OnExpressionType func(sema.Type)
	OnResult         func(interpreter.Value)
	// contains filtered or unexported fields
}

func NewREPL

func NewREPL() (*REPL, error)

func (*REPL) Accept

func (r *REPL) Accept(code []byte, eval bool) (inputIsComplete bool, err error)

func (*REPL) ExportValue added in v0.30.0

func (r *REPL) ExportValue(value interpreter.Value) (cadence.Value, error)

func (*REPL) GetGlobal added in v0.30.0

func (r *REPL) GetGlobal(name string) interpreter.Value

func (*REPL) Suggestions

func (r *REPL) Suggestions() (result []REPLSuggestion)

type REPLSuggestion added in v0.2.0

type REPLSuggestion struct {
	Name, Description string
}

type ResolvedLocation added in v0.10.0

type ResolvedLocation = sema.ResolvedLocation

func ResolveLocationWithInterface added in v1.4.0

func ResolveLocationWithInterface(
	i Interface,
	identifiers []Identifier,
	location Location,
) (
	res []ResolvedLocation,
	err error,
)

type Runtime

type Runtime interface {
	// Config returns the runtime.Config this Runtime was instantiated with.
	Config() Config

	// NewScriptExecutor returns an executor which executes the given script.
	NewScriptExecutor(Script, Context) Executor

	// ExecuteScript executes the given script.
	//
	// This function returns an error if the program has errors (e.g syntax errors, type errors),
	// or if the execution fails.
	ExecuteScript(Script, Context) (cadence.Value, error)

	// NewTransactionExecutor returns an executor which executes the given
	// transaction.
	NewTransactionExecutor(Script, Context) Executor

	// ExecuteTransaction executes the given transaction.
	//
	// This function returns an error if the program has errors (e.g syntax errors, type errors),
	// or if the execution fails.
	ExecuteTransaction(Script, Context) error

	// NewContractFunctionExecutor returns an executor which invokes a contract
	// function with the given arguments.
	NewContractFunctionExecutor(
		contractLocation common.AddressLocation,
		functionName string,
		arguments []cadence.Value,
		argumentTypes []sema.Type,
		context Context,
	) Executor

	// InvokeContractFunction invokes a contract function with the given arguments.
	//
	// This function returns an error if the execution fails.
	// If the contract function accepts an &Account as a parameter,
	// the corresponding argument can be an interpreter.Address.
	// Returns a cadence.Value
	InvokeContractFunction(
		contractLocation common.AddressLocation,
		functionName string,
		arguments []cadence.Value,
		argumentTypes []sema.Type,
		context Context,
	) (cadence.Value, error)

	// ParseAndCheckProgram parses and checks the given code without executing the program.
	//
	// This function returns an error if the program contains any syntax or semantic errors.
	ParseAndCheckProgram(source []byte, context Context) (*interpreter.Program, error)

	// ReadStored reads the value stored at the given path
	//
	ReadStored(address common.Address, path cadence.Path, context Context) (cadence.Value, error)

	// Storage returns the storage system and an interpreter which can be used for
	// accessing values in storage.
	//
	// NOTE: only use the interpreter for storage operations,
	// do *NOT* use the interpreter for any other purposes,
	// such as executing a program.
	//
	Storage(context Context) (*Storage, *interpreter.Interpreter, error)

	SetDebugger(debugger *interpreter.Debugger)
}

Runtime is a runtime capable of executing Cadence.

func NewRuntime added in v1.4.0

func NewRuntime(defaultConfig Config) Runtime

NewRuntime returns an interpreter-based version of the Flow runtime.

type Script added in v0.12.0

type Script struct {
	Source    []byte
	Arguments [][]byte
}

type ScriptParameterTypeNotImportableError added in v0.17.0

type ScriptParameterTypeNotImportableError struct {
	Type sema.Type
}

ScriptParameterTypeNotImportableError is an error that is reported for script parameter types that are not importable.

For example, the type `Int` is an importable type, whereas a function-type is not.

func (*ScriptParameterTypeNotImportableError) Error added in v0.17.0

func (*ScriptParameterTypeNotImportableError) IsUserError added in v0.25.0

type ScriptParameterTypeNotStorableError added in v0.8.0

type ScriptParameterTypeNotStorableError struct {
	Type sema.Type
}

ScriptParameterTypeNotStorableError is an error that is reported for script parameter types that are not storable.

For example, the type `Int` is a storable type, whereas a function type is not.

func (*ScriptParameterTypeNotStorableError) Error added in v0.8.0

func (*ScriptParameterTypeNotStorableError) IsUserError added in v0.25.0

func (*ScriptParameterTypeNotStorableError) IsUserError()

type SignatureAlgorithm added in v0.14.0

type SignatureAlgorithm = sema.SignatureAlgorithm

type Storage added in v0.20.0

type Storage struct {
	*atree.PersistentSlabStorage

	Ledger atree.Ledger

	Config StorageConfig

	AccountStorage *AccountStorage
	// contains filtered or unexported fields
}

func NewStorage added in v0.20.0

func NewStorage(
	ledger atree.Ledger,
	memoryGauge common.MemoryGauge,
	computationGauge common.ComputationGauge,
	config StorageConfig,
) *Storage

func (*Storage) CheckHealth added in v0.20.0

func (s *Storage) CheckHealth() error

func (*Storage) Commit added in v0.20.0

func (s *Storage) Commit(context interpreter.ValueTransferContext, commitContractUpdates bool) error

Commit serializes/saves all values in the readCache in storage (through the runtime interface).

func (*Storage) GetDomainStorageMap added in v1.3.0

func (s *Storage) GetDomainStorageMap(
	storageMutationTracker interpreter.StorageMutationTracker,
	address common.Address,
	domain common.StorageDomain,
	createIfNotExists bool,
) (
	domainStorageMap *interpreter.DomainStorageMap,
)

GetDomainStorageMap returns existing or new domain storage map for the given account and domain.

func (*Storage) NondeterministicCommit deprecated added in v1.0.0

func (s *Storage) NondeterministicCommit(inter *interpreter.Interpreter, commitContractUpdates bool) error

Deprecated: NondeterministicCommit serializes and commits all values in the deltas storage in nondeterministic order. This function is used when commit ordering isn't required (e.g. migration programs).

type StorageConfig added in v1.3.0

type StorageConfig struct {
}

type UnreferencedRootSlabsError added in v0.42.10

type UnreferencedRootSlabsError struct {
	UnreferencedRootSlabIDs []atree.SlabID
}

func (UnreferencedRootSlabsError) Error added in v0.42.10

func (UnreferencedRootSlabsError) IsInternalError added in v0.42.10

func (UnreferencedRootSlabsError) IsInternalError()

type ValueImportContext added in v1.4.0

type ValueNotExportableError added in v0.30.0

type ValueNotExportableError struct {
	Type interpreter.StaticType
}

ValueNotExportableError is an error that is reported for values that cannot be exported.

func (*ValueNotExportableError) Error added in v0.30.0

func (e *ValueNotExportableError) Error() string

func (*ValueNotExportableError) IsUserError added in v0.30.0

func (*ValueNotExportableError) IsUserError()

Jump to

Keyboard shortcuts

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