environment

package
v0.33.33-pebble-chunk-... Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: AGPL-3.0 Imports: 46 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// [2_000, 3_000) reserved for the FVM
	ComputationKindHash = 2001 + iota
	ComputationKindVerifySignature
	ComputationKindAddAccountKey
	ComputationKindAddEncodedAccountKey
	ComputationKindAllocateStorageIndex
	ComputationKindCreateAccount
	ComputationKindEmitEvent
	ComputationKindGenerateUUID
	ComputationKindGetAccountAvailableBalance
	ComputationKindGetAccountBalance
	ComputationKindGetAccountContractCode
	ComputationKindGetAccountContractNames
	ComputationKindGetAccountKey
	ComputationKindGetBlockAtHeight
	ComputationKindGetCode
	ComputationKindGetCurrentBlockHeight

	ComputationKindGetStorageCapacity
	ComputationKindGetStorageUsed
	ComputationKindGetValue
	ComputationKindRemoveAccountContractCode
	ComputationKindResolveLocation
	ComputationKindRevokeAccountKey
	ComputationKindRevokeEncodedAccountKey

	ComputationKindSetValue
	ComputationKindUpdateAccountContractCode
	ComputationKindValidatePublicKey
	ComputationKindValueExists
	ComputationKindAccountKeysCount
	ComputationKindBLSVerifyPOP
	ComputationKindBLSAggregateSignatures
	ComputationKindBLSAggregatePublicKeys
	ComputationKindGetOrLoadProgram
	ComputationKindGenerateAccountLocalID
	ComputationKindGetRandomSourceHistory
	ComputationKindEVMGasUsage
	ComputationKindRLPEncoding
	ComputationKindRLPDecoding
	ComputationKindEncodeEvent

	ComputationKindEVMEncodeABI
	ComputationKindEVMDecodeABI
)
View Source
const (
	// The max value for any is uuid partition is MaxUint56, since one byte
	// in the uuid is used for partitioning.
	MaxUint56 = (uint64(1) << 56) - 1

	// Start warning when there's only a single high bit left.  This should give
	// us plenty of time to migrate to larger counters.
	Uint56OverflowWarningThreshold = (uint64(1) << 55) - 1
)
View Source
const (
	DefaultEventCollectionByteSizeLimit = 256_000 // 256KB
)
View Source
const (
	MaxPublicKeyCount = math.MaxUint64
)

Variables

This section is empty.

Functions

func FlowFeesAddress

func FlowFeesAddress(chain flow.Chain) flow.Address

func FlowToRuntimeAccountKey added in v0.29.0

func FlowToRuntimeAccountKey(
	flowKey flow.AccountPublicKey,
) (
	*runtime.AccountKey,
	error,
)

func IsServiceEvent

func IsServiceEvent(eventType flow.EventType, chain flow.ChainID) (bool, error)

IsServiceEvent determines whether or not an emitted Cadence event is considered a service event for the given chain.

func IsValidAccountKeyHashAlgo

func IsValidAccountKeyHashAlgo(algo hash.HashingAlgorithm) bool

func IsValidAccountKeySignAlgo

func IsValidAccountKeySignAlgo(algo crypto.SigningAlgorithm) bool

func NewAccountKeyUpdater

func NewAccountKeyUpdater(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
	txnState state.NestedTransactionPreparer,
	env Environment,
) *accountKeyUpdater

func NewAccountPublicKey

func NewAccountPublicKey(publicKey *runtime.PublicKey,
	hashAlgo sema.HashAlgorithm,
	keyIndex int,
	weight int,
) (
	*flow.AccountPublicKey,
	error,
)

NewAccountPublicKey construct an account public key given a runtime public key.

func NewScriptEnv added in v0.30.0

func NewScriptEnv(
	ctx context.Context,
	tracer tracing.TracerSpan,
	params EnvironmentParams,
	txnState storage.TransactionPreparer,
) *facadeEnvironment

func NewScriptEnvironmentFromStorageSnapshot added in v0.30.0

func NewScriptEnvironmentFromStorageSnapshot(
	params EnvironmentParams,
	storageSnapshot snapshot.StorageSnapshot,
) *facadeEnvironment

This is mainly used by command line tools, the emulator, and cadence tools testing.

func NewTransactionEnvironment

func NewTransactionEnvironment(
	tracer tracing.TracerSpan,
	params EnvironmentParams,
	txnState storage.TransactionPreparer,
) *facadeEnvironment

func NewUUIDGenerator

func NewUUIDGenerator(
	tracer tracing.TracerSpan,
	log zerolog.Logger,
	meter Meter,
	txnState state.NestedTransactionPreparer,
	blockHeader *flow.Header,
	txnIndex uint32,
) *uUIDGenerator

func RegisterSize

func RegisterSize(id flow.RegisterID, value flow.RegisterValue) int

func ServiceAddress

func ServiceAddress(chain flow.Chain) flow.Address

func StorageMBUFixToBytesUInt

func StorageMBUFixToBytesUInt(result cadence.Value) uint64

StorageMBUFixToBytesUInt converts the return type of storage capacity which is a UFix64 with the unit of megabytes to UInt with the unit of bytes

Types

type AccountCreator

type AccountCreator interface {
	CreateAccount(runtimePayer common.Address) (common.Address, error)
}

func NewAccountCreator

func NewAccountCreator(
	txnState state.NestedTransactionPreparer,
	chain flow.Chain,
	accounts Accounts,
	isServiceAccountEnabled bool,
	tracer tracing.TracerSpan,
	meter Meter,
	metrics MetricsReporter,
	systemContracts *SystemContracts,
) AccountCreator

func NewParseRestrictedAccountCreator

func NewParseRestrictedAccountCreator(
	txnState state.NestedTransactionPreparer,
	creator AccountCreator,
) AccountCreator

type AccountInfo

type AccountInfo interface {
	// Cadence's runtime APIs.
	GetStorageUsed(runtimeaddress common.Address) (uint64, error)
	GetStorageCapacity(runtimeAddress common.Address) (uint64, error)
	GetAccountBalance(runtimeAddress common.Address) (uint64, error)
	GetAccountAvailableBalance(runtimeAddress common.Address) (uint64, error)

	GetAccount(address flow.Address) (*flow.Account, error)
}

AccountInfo exposes various account balance and storage statistics.

func NewAccountInfo

func NewAccountInfo(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
	systemContracts *SystemContracts,
	serviceAccountEnabled bool,
) AccountInfo

func NewParseRestrictedAccountInfo

func NewParseRestrictedAccountInfo(
	txnState state.NestedTransactionPreparer,
	impl AccountInfo,
) AccountInfo

type AccountKeyReader

type AccountKeyReader interface {
	// GetAccountKey retrieves a public key by index from an existing account.
	//
	// This function returns a nil key with no errors, if a key doesn't exist at
	// the given index. An error is returned if the specified account does not
	// exist, the provided index is not valid, or if the key retrieval fails.
	GetAccountKey(
		runtimeAddress common.Address,
		keyIndex int,
	) (
		*runtime.AccountKey,
		error,
	)
	AccountKeysCount(runtimeAddress common.Address) (uint64, error)
}

AccountKeyReader provide read access to account keys.

func NewAccountKeyReader

func NewAccountKeyReader(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
) AccountKeyReader

func NewParseRestrictedAccountKeyReader added in v0.28.1

func NewParseRestrictedAccountKeyReader(
	txnState state.NestedTransactionPreparer,
	impl AccountKeyReader,
) AccountKeyReader

type AccountKeyUpdater

type AccountKeyUpdater interface {
	// AddEncodedAccountKey adds an encoded public key to an existing account.
	//
	// This function returns an error if the specified account does not exist or
	// if the key insertion fails.
	//
	// Note that the script variant will return OperationNotSupportedError.
	AddEncodedAccountKey(runtimeAddress common.Address, publicKey []byte) error

	// RevokeEncodedAccountKey revokes a public key by index from an existing
	// account.
	//
	// This function returns an error if the specified account does not exist,
	// the provided key is invalid, or if key revoking fails.
	//
	// Note that the script variant will return OperationNotSupportedError.
	RevokeEncodedAccountKey(
		runtimeAddress common.Address,
		index int,
	) (
		[]byte,
		error,
	)

	// AddAccountKey adds a public key to an existing account.
	//
	// This function returns an error if the specified account does not exist or
	// if the key insertion fails.
	//
	// Note that the script variant will return OperationNotSupportedError.
	AddAccountKey(
		runtimeAddress common.Address,
		publicKey *runtime.PublicKey,
		hashAlgo runtime.HashAlgorithm,
		weight int,
	) (
		*runtime.AccountKey,
		error,
	)

	// RevokeAccountKey revokes a public key by index from an existing account,
	// and returns the revoked key.
	//
	// This function returns a nil key with no errors, if a key doesn't exist
	// at the given index.  An error is returned if the specified account does
	// not exist, the provided index is not valid, or if the key revoking
	// fails.
	//
	// Note that the script variant will return OperationNotSupportedError.
	RevokeAccountKey(
		runtimeAddress common.Address,
		keyIndex int,
	) (
		*runtime.AccountKey,
		error,
	)
}

AccountKeyUpdater handles all account keys modification.

Note that scripts cannot modify account keys, but must expose the API in compliance with the runtime environment interface.

type AccountLocalIDGenerator added in v0.31.0

type AccountLocalIDGenerator interface {
	GenerateAccountID(address common.Address) (uint64, error)
}

func NewAccountLocalIDGenerator added in v0.31.0

func NewAccountLocalIDGenerator(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
) AccountLocalIDGenerator

func NewParseRestrictedAccountLocalIDGenerator added in v0.31.0

func NewParseRestrictedAccountLocalIDGenerator(
	txnState state.NestedTransactionPreparer,
	impl AccountLocalIDGenerator,
) AccountLocalIDGenerator

type AccountStatus

type AccountStatus [accountStatusSize]byte

AccountStatus holds meta information about an account

currently modelled as a byte array with on-demand encoding/decoding of sub arrays the first byte captures flags the next 8 bytes (big-endian) captures storage used by an account the next 8 bytes (big-endian) captures the storage index of an account the next 8 bytes (big-endian) captures the number of public keys stored on this account the next 8 bytes (big-endian) captures the current address id counter

func AccountStatusFromBytes

func AccountStatusFromBytes(inp []byte) (*AccountStatus, error)

AccountStatusFromBytes constructs an AccountStatus from the given byte slice

func NewAccountStatus

func NewAccountStatus() *AccountStatus

NewAccountStatus returns a new AccountStatus sets the storage index to the init value

func (*AccountStatus) AccountIdCounter added in v0.31.0

func (a *AccountStatus) AccountIdCounter() uint64

AccountIdCounter returns id counter of the account

func (*AccountStatus) PublicKeyCount

func (a *AccountStatus) PublicKeyCount() uint64

PublicKeyCount returns the public key count of the account

func (*AccountStatus) SetAccountIdCounter added in v0.31.0

func (a *AccountStatus) SetAccountIdCounter(id uint64)

SetAccountIdCounter updates id counter of the account

func (*AccountStatus) SetPublicKeyCount

func (a *AccountStatus) SetPublicKeyCount(count uint64)

SetPublicKeyCount updates the public key count of the account

func (*AccountStatus) SetStorageIndex

func (a *AccountStatus) SetStorageIndex(index atree.StorageIndex)

SetStorageIndex updates the storage index of the account

func (*AccountStatus) SetStorageUsed

func (a *AccountStatus) SetStorageUsed(used uint64)

SetStorageUsed updates the storage used by the account

func (*AccountStatus) StorageIndex

func (a *AccountStatus) StorageIndex() atree.StorageIndex

StorageIndex returns the storage index of the account

func (*AccountStatus) StorageUsed

func (a *AccountStatus) StorageUsed() uint64

StorageUsed returns the storage used by the account

func (*AccountStatus) ToBytes

func (a *AccountStatus) ToBytes() []byte

ToBytes converts AccountStatus to a byte slice

this has been kept this way in case one day we decided to move on to use a struct to represent account status.

type Accounts

type Accounts interface {
	Exists(address flow.Address) (bool, error)
	Get(address flow.Address) (*flow.Account, error)
	GetPublicKeyCount(address flow.Address) (uint64, error)
	AppendPublicKey(address flow.Address, key flow.AccountPublicKey) error
	GetPublicKey(address flow.Address, keyIndex uint64) (flow.AccountPublicKey, error)
	SetPublicKey(address flow.Address, keyIndex uint64, publicKey flow.AccountPublicKey) ([]byte, error)
	GetContractNames(address flow.Address) ([]string, error)
	GetContract(contractName string, address flow.Address) ([]byte, error)
	ContractExists(contractName string, address flow.Address) (bool, error)
	SetContract(contractName string, address flow.Address, contract []byte) error
	DeleteContract(contractName string, address flow.Address) error
	Create(publicKeys []flow.AccountPublicKey, newAddress flow.Address) error
	GetValue(id flow.RegisterID) (flow.RegisterValue, error)
	GetStorageUsed(address flow.Address) (uint64, error)
	SetValue(id flow.RegisterID, value flow.RegisterValue) error
	AllocateStorageIndex(address flow.Address) (atree.StorageIndex, error)
	GenerateAccountLocalID(address flow.Address) (uint64, error)
}

type AddressGenerator

type AddressGenerator interface {
	Bytes() []byte
	NextAddress() (flow.Address, error)
	CurrentAddress() flow.Address
	AddressCount() uint64
}

func NewAddressGenerator

func NewAddressGenerator(
	txnState state.NestedTransactionPreparer,
	chain flow.Chain,
) AddressGenerator

type BlockInfo

type BlockInfo interface {
	// GetCurrentBlockHeight returns the current block height.
	GetCurrentBlockHeight() (uint64, error)

	// GetBlockAtHeight returns the block at the given height.
	GetBlockAtHeight(
		height uint64,
	) (
		runtime.Block,
		bool,
		error,
	)
}

func NewBlockInfo

func NewBlockInfo(
	tracer tracing.TracerSpan,
	meter Meter,
	blockHeader *flow.Header,
	blocks Blocks,
) BlockInfo

func NewParseRestrictedBlockInfo added in v0.28.1

func NewParseRestrictedBlockInfo(
	txnState storage.TransactionPreparer,
	impl BlockInfo,
) BlockInfo

type BlockInfoParams

type BlockInfoParams struct {
	Blocks      Blocks
	BlockHeader *flow.Header
}

func DefaultBlockInfoParams

func DefaultBlockInfoParams() BlockInfoParams

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

func NewBlockFinder(storage storage.Headers) Blocks

NewBlockFinder constructs a new block finder

type BlocksFinder

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

BlocksFinder finds blocks and return block headers

func (*BlocksFinder) ByHeightFrom

func (finder *BlocksFinder) ByHeightFrom(height uint64, header *flow.Header) (*flow.Header, error)

ByHeightFrom returns the block header by height.

type BootstrapAccountCreator

type BootstrapAccountCreator interface {
	CreateBootstrapAccount(
		publicKeys []flow.AccountPublicKey,
	) (
		flow.Address,
		error,
	)
}

func NewBootstrapAccountCreator

func NewBootstrapAccountCreator(
	txnState state.NestedTransactionPreparer,
	chain flow.Chain,
	accounts Accounts,
) BootstrapAccountCreator

type CadenceEventEncoder added in v0.29.0

type CadenceEventEncoder struct{}

func NewCadenceEventEncoder added in v0.29.0

func NewCadenceEventEncoder() *CadenceEventEncoder

func (*CadenceEventEncoder) Encode added in v0.29.0

func (e *CadenceEventEncoder) Encode(event cadence.Event) ([]byte, error)

type ContractFunctionSpec

type ContractFunctionSpec struct {
	AddressFromChain func(flow.Chain) flow.Address
	LocationName     string
	FunctionName     string
	ArgumentTypes    []sema.Type
}

ContractFunctionSpec specify all the information, except the function's address and arguments, needed to invoke the contract function.

type ContractReader

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

ContractReader provide read access to contracts.

func NewContractReader

func NewContractReader(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
) *ContractReader

func (*ContractReader) GetAccountContractCode

func (reader *ContractReader) GetAccountContractCode(
	location common.AddressLocation,
) (
	[]byte,
	error,
)

func (*ContractReader) GetAccountContractNames

func (reader *ContractReader) GetAccountContractNames(
	runtimeAddress common.Address,
) (
	[]string,
	error,
)

func (*ContractReader) GetCode

func (reader *ContractReader) GetCode(
	location runtime.Location,
) (
	[]byte,
	error,
)

func (*ContractReader) ResolveLocation

func (reader *ContractReader) ResolveLocation(
	identifiers []runtime.Identifier,
	location runtime.Location,
) (
	[]runtime.ResolvedLocation,
	error,
)

type ContractUpdate added in v0.29.0

type ContractUpdate struct {
	Location common.AddressLocation
	Code     []byte
}

type ContractUpdater

type ContractUpdater interface {
	// Cadence's runtime API.  Note that the script variant will return
	// OperationNotSupportedError.
	UpdateAccountContractCode(
		location common.AddressLocation,
		code []byte,
	) error

	// Cadence's runtime API.  Note that the script variant will return
	// OperationNotSupportedError.
	RemoveAccountContractCode(location common.AddressLocation) error

	Commit() (ContractUpdates, error)

	Reset()
}

ContractUpdater handles all smart contracts modification. It captures contract updates and defer the updates to the end of the txn execution.

Note that scripts cannot modify smart contracts, but must expose the API in compliance with the runtime environment interface.

type ContractUpdaterImpl added in v0.29.0

type ContractUpdaterImpl struct {
	ContractUpdaterStubs
	// contains filtered or unexported fields
}

func NewContractUpdater

func NewContractUpdater(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
	signingAccounts []flow.Address,
	chain flow.Chain,
	params ContractUpdaterParams,
	logger *ProgramLogger,
	systemContracts *SystemContracts,
	runtime *Runtime,
) *ContractUpdaterImpl

func NewContractUpdaterForTesting

func NewContractUpdaterForTesting(
	accounts Accounts,
	stubs ContractUpdaterStubs,
) *ContractUpdaterImpl

func (*ContractUpdaterImpl) Commit added in v0.29.0

func (updater *ContractUpdaterImpl) Commit() (ContractUpdates, error)

func (*ContractUpdaterImpl) HasUpdates added in v0.29.0

func (updater *ContractUpdaterImpl) HasUpdates() bool

func (*ContractUpdaterImpl) RemoveAccountContractCode added in v0.29.0

func (updater *ContractUpdaterImpl) RemoveAccountContractCode(
	location common.AddressLocation,
) error

func (*ContractUpdaterImpl) RemoveContract added in v0.29.0

func (updater *ContractUpdaterImpl) RemoveContract(
	location common.AddressLocation,
	signingAccounts []flow.Address,
) (err error)

func (*ContractUpdaterImpl) Reset added in v0.29.0

func (updater *ContractUpdaterImpl) Reset()

func (*ContractUpdaterImpl) SetContract added in v0.29.0

func (updater *ContractUpdaterImpl) SetContract(
	location common.AddressLocation,
	code []byte,
	signingAccounts []flow.Address,
) error

func (*ContractUpdaterImpl) UpdateAccountContractCode added in v0.29.0

func (updater *ContractUpdaterImpl) UpdateAccountContractCode(
	location common.AddressLocation,
	code []byte,
) error

type ContractUpdaterParams

type ContractUpdaterParams struct {
	// Depricated: RestrictedDeploymentEnabled is deprecated use
	// SetIsContractDeploymentRestrictedTransaction instead.
	// Can be removed after all networks are migrated to
	// SetIsContractDeploymentRestrictedTransaction
	RestrictContractDeployment bool
	RestrictContractRemoval    bool
}

func DefaultContractUpdaterParams

func DefaultContractUpdaterParams() ContractUpdaterParams

type ContractUpdaterStubs

type ContractUpdaterStubs interface {
	RestrictedDeploymentEnabled() bool
	RestrictedRemovalEnabled() bool

	GetAuthorizedAccounts(path cadence.Path) []flow.Address
}

Expose stub interface for testing.

type ContractUpdates added in v0.30.0

type ContractUpdates struct {
	Updates   []common.AddressLocation
	Deploys   []common.AddressLocation
	Deletions []common.AddressLocation
}

func (ContractUpdates) Any added in v0.30.0

func (u ContractUpdates) Any() bool

type CryptoLibrary

type CryptoLibrary interface {
	Hash(
		data []byte,
		tag string,
		hashAlgorithm runtime.HashAlgorithm,
	) (
		[]byte,
		error,
	)

	VerifySignature(
		signature []byte,
		tag string,
		signedData []byte,
		publicKey []byte,
		signatureAlgorithm runtime.SignatureAlgorithm,
		hashAlgorithm runtime.HashAlgorithm,
	) (
		bool,
		error,
	)

	ValidatePublicKey(pk *runtime.PublicKey) error

	BLSVerifyPOP(
		pk *runtime.PublicKey,
		sig []byte,
	) (
		bool,
		error,
	)

	BLSAggregateSignatures(sigs [][]byte) ([]byte, error)

	BLSAggregatePublicKeys(
		keys []*runtime.PublicKey,
	) (
		*runtime.PublicKey,
		error,
	)
}

func NewCryptoLibrary

func NewCryptoLibrary(tracer tracing.TracerSpan, meter Meter) CryptoLibrary

func NewParseRestrictedCryptoLibrary added in v0.28.1

func NewParseRestrictedCryptoLibrary(
	txnState state.NestedTransactionPreparer,
	impl CryptoLibrary,
) CryptoLibrary

type DerivedDataInvalidator added in v0.29.0

type DerivedDataInvalidator struct {
	ContractUpdates

	MeterParamOverridesUpdated bool
}

func NewDerivedDataInvalidator added in v0.29.0

func NewDerivedDataInvalidator(
	contractUpdates ContractUpdates,
	serviceAddress flow.Address,
	executionSnapshot *snapshot.ExecutionSnapshot,
) DerivedDataInvalidator

func (DerivedDataInvalidator) MeterParamOverridesInvalidator added in v0.29.0

func (invalidator DerivedDataInvalidator) MeterParamOverridesInvalidator() derived.MeterParamOverridesInvalidator

func (DerivedDataInvalidator) ProgramInvalidator added in v0.29.0

func (invalidator DerivedDataInvalidator) ProgramInvalidator() derived.ProgramInvalidator

type EntropyProvider added in v0.32.0

type EntropyProvider interface {
	// RandomSource provides a source of entropy that can be
	// expanded into randoms (using a pseudo-random generator).
	// The returned slice should have at least 128 bits of entropy.
	// The function doesn't error in normal operations, any
	// error should be treated as an exception.
	RandomSource() ([]byte, error)
}

EntropyProvider represents an entropy (source of randomness) provider

type Environment

type Environment interface {
	runtime.Interface

	// Tracer
	StartChildSpan(
		name trace.SpanName,
		options ...otelTrace.SpanStartOption,
	) tracing.TracerSpan

	Meter

	// Runtime
	BorrowCadenceRuntime() *reusableRuntime.ReusableCadenceRuntime
	ReturnCadenceRuntime(*reusableRuntime.ReusableCadenceRuntime)

	TransactionInfo

	// ProgramLogger
	Logger() zerolog.Logger
	Logs() []string

	// EventEmitter
	Events() flow.EventsList
	ServiceEvents() flow.EventsList
	ConvertedServiceEvents() flow.ServiceEventList

	// SystemContracts
	AccountsStorageCapacity(
		addresses []flow.Address,
		payer flow.Address,
		maxTxFees uint64,
	) (
		cadence.Value,
		error,
	)
	CheckPayerBalanceAndGetMaxTxFees(
		payer flow.Address,
		inclusionEffort uint64,
		executionEffort uint64,
	) (
		cadence.Value,
		error,
	)
	DeductTransactionFees(
		payer flow.Address,
		inclusionEffort uint64,
		executionEffort uint64,
	) (
		cadence.Value,
		error,
	)

	// AccountInfo
	GetAccount(address flow.Address) (*flow.Account, error)

	// RandomSourceHistory is the current block's derived random source.
	// This source is only used by the core-contract that tracks the random source
	// history for commit-reveal schemes.
	RandomSourceHistory() ([]byte, error)

	// FlushPendingUpdates flushes pending updates from the stateful environment
	// modules (i.e., ContractUpdater) to the state transaction, and return
	// the updated contract keys.
	FlushPendingUpdates() (
		ContractUpdates,
		error,
	)

	// Reset resets all stateful environment modules (e.g., ContractUpdater,
	// EventEmitter) to initial state.
	Reset()

	GetProgramDependencies() (derived.ProgramDependencies, error)

	CheckDependencies(dependencies []common.AddressLocation, auths []flow.Address) (cadence.Value, error)
}

Environment implements the accounts business logic and exposes cadence runtime interface methods for the runtime.

type EnvironmentParams

func DefaultEnvironmentParams

func DefaultEnvironmentParams() EnvironmentParams

func (*EnvironmentParams) SetScriptInfoParams added in v0.32.0

func (env *EnvironmentParams) SetScriptInfoParams(info *ScriptInfoParams)

type EventCollection

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

func NewEventCollection

func NewEventCollection(meter Meter) *EventCollection

func (*EventCollection) AppendEvent

func (collection *EventCollection) AppendEvent(event flow.Event, size uint64) error

func (*EventCollection) AppendServiceEvent

func (collection *EventCollection) AppendServiceEvent(
	chain flow.Chain,
	event flow.Event,
	size uint64,
) error

func (*EventCollection) ConvertedServiceEvents added in v0.30.0

func (collection *EventCollection) ConvertedServiceEvents() flow.ServiceEventList

func (*EventCollection) Events

func (collection *EventCollection) Events() flow.EventsList

func (*EventCollection) ServiceEvents

func (collection *EventCollection) ServiceEvents() flow.EventsList

func (*EventCollection) TotalByteSize

func (collection *EventCollection) TotalByteSize() uint64

func (*EventCollection) TotalEventCounter

func (collection *EventCollection) TotalEventCounter() uint32

type EventEmitter

type EventEmitter interface {
	// EmitEvent satisfies Cadence's runtime API.
	// This will encode the cadence event
	//
	// Note that the script variant will return OperationNotSupportedError.
	EmitEvent(event cadence.Event) error

	Events() flow.EventsList
	ServiceEvents() flow.EventsList
	ConvertedServiceEvents() flow.ServiceEventList

	Reset()
}

EventEmitter collect events, separates out service events, and enforces event size limits.

Note that scripts do not emit events, but must expose the API in compliance with the runtime environment interface.

func NewEventEmitter

func NewEventEmitter(
	tracer tracing.TracerSpan,
	meter Meter,
	chain flow.Chain,
	txInfo TransactionInfoParams,
	params EventEmitterParams,
) EventEmitter

NewEventEmitter constructs a new eventEmitter

func NewParseRestrictedEventEmitter added in v0.28.1

func NewParseRestrictedEventEmitter(
	txnState state.NestedTransactionPreparer,
	impl EventEmitter,
) EventEmitter

type EventEmitterParams

type EventEmitterParams struct {
	ServiceEventCollectionEnabled bool
	EventCollectionByteSizeLimit  uint64
	EventEncoder                  EventEncoder
}

func DefaultEventEmitterParams

func DefaultEventEmitterParams() EventEmitterParams

type EventEncoder added in v0.29.0

type EventEncoder interface {
	Encode(event cadence.Event) ([]byte, error)
}

type Meter

type Meter interface {
	MeterComputation(common.ComputationKind, uint) error
	ComputationUsed() (uint64, error)
	ComputationIntensities() meter.MeteredComputationIntensities
	ComputationAvailable(common.ComputationKind, uint) bool

	MeterMemory(usage common.MemoryUsage) error
	MemoryUsed() (uint64, error)

	MeterEmittedEvent(byteSize uint64) error
	TotalEmittedEventBytes() uint64

	InteractionUsed() (uint64, error)
}

func NewCancellableMeter

func NewCancellableMeter(
	ctx context.Context,
	txnState state.NestedTransactionPreparer,
) Meter

func NewMeter

func NewMeter(txnState state.NestedTransactionPreparer) Meter

type MeterParamOverridesInvalidator added in v0.29.0

type MeterParamOverridesInvalidator struct {
	DerivedDataInvalidator
}

func (MeterParamOverridesInvalidator) ShouldInvalidateEntries added in v0.29.0

func (invalidator MeterParamOverridesInvalidator) ShouldInvalidateEntries() bool

func (MeterParamOverridesInvalidator) ShouldInvalidateEntry added in v0.29.0

func (invalidator MeterParamOverridesInvalidator) ShouldInvalidateEntry(
	_ struct{},
	_ derived.MeterParamOverrides,
	_ *snapshot.ExecutionSnapshot,
) bool

type MetricsReporter

type MetricsReporter interface {
	RuntimeTransactionParsed(time.Duration)
	RuntimeTransactionChecked(time.Duration)
	RuntimeTransactionInterpreted(time.Duration)
	RuntimeSetNumberOfAccounts(count uint64)
	RuntimeTransactionProgramsCacheMiss()
	RuntimeTransactionProgramsCacheHit()
}

MetricsReporter captures and reports metrics to back to the execution environment it is a setup passed to the context.

type NoAccountCreator

type NoAccountCreator struct {
}

func (NoAccountCreator) CreateAccount

func (NoAccountCreator) CreateAccount(
	runtimePayer common.Address,
) (
	common.Address,
	error,
)

type NoAccountKeyUpdater

type NoAccountKeyUpdater struct{}

func (NoAccountKeyUpdater) AddAccountKey

func (NoAccountKeyUpdater) AddAccountKey(
	runtimeAddress common.Address,
	publicKey *runtime.PublicKey,
	hashAlgo runtime.HashAlgorithm,
	weight int,
) (
	*runtime.AccountKey,
	error,
)

func (NoAccountKeyUpdater) AddEncodedAccountKey

func (NoAccountKeyUpdater) AddEncodedAccountKey(
	runtimeAddress common.Address,
	publicKey []byte,
) error

func (NoAccountKeyUpdater) RevokeAccountKey

func (NoAccountKeyUpdater) RevokeAccountKey(
	runtimeAddress common.Address,
	keyIndex int,
) (
	*runtime.AccountKey,
	error,
)

func (NoAccountKeyUpdater) RevokeEncodedAccountKey

func (NoAccountKeyUpdater) RevokeEncodedAccountKey(
	runtimeAddress common.Address,
	index int,
) (
	[]byte,
	error,
)

type NoContractUpdater

type NoContractUpdater struct{}

func (NoContractUpdater) Commit

func (NoContractUpdater) RemoveAccountContractCode

func (NoContractUpdater) RemoveAccountContractCode(
	_ common.AddressLocation,
) error

func (NoContractUpdater) Reset

func (NoContractUpdater) Reset()

func (NoContractUpdater) UpdateAccountContractCode

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

type NoEventEmitter

type NoEventEmitter struct{}

NoEventEmitter is usually used in the environment for script execution, where emitting an event does nothing.

func (NoEventEmitter) ConvertedServiceEvents added in v0.30.0

func (NoEventEmitter) ConvertedServiceEvents() flow.ServiceEventList

func (NoEventEmitter) EmitEvent

func (NoEventEmitter) EmitEvent(cadence.Event) error

func (NoEventEmitter) Events

func (NoEventEmitter) Events() flow.EventsList

func (NoEventEmitter) Reset

func (NoEventEmitter) Reset()

func (NoEventEmitter) ServiceEvents

func (NoEventEmitter) ServiceEvents() flow.EventsList

type NoTransactionInfo

type NoTransactionInfo struct {
}

Scripts have no associated transaction information.

func (NoTransactionInfo) GetSigningAccounts

func (NoTransactionInfo) GetSigningAccounts() ([]common.Address, error)

func (NoTransactionInfo) IsServiceAccountAuthorizer

func (NoTransactionInfo) IsServiceAccountAuthorizer() bool

func (NoTransactionInfo) LimitAccountStorage

func (NoTransactionInfo) LimitAccountStorage() bool

func (NoTransactionInfo) TransactionFeesEnabled

func (NoTransactionInfo) TransactionFeesEnabled() bool

func (NoTransactionInfo) TxID

func (NoTransactionInfo) TxIndex

func (NoTransactionInfo) TxIndex() uint32

type NoopBlockFinder

type NoopBlockFinder struct{}

NoopBlockFinder implements the Blocks interface. It is used in the bootstrapping process.

func (NoopBlockFinder) ByHeightFrom

func (NoopBlockFinder) ByHeightFrom(_ uint64, _ *flow.Header) (*flow.Header, error)

type NoopMetricsReporter

type NoopMetricsReporter struct{}

NoopMetricsReporter is a MetricReporter that does nothing.

func (NoopMetricsReporter) RuntimeSetNumberOfAccounts

func (NoopMetricsReporter) RuntimeSetNumberOfAccounts(count uint64)

RuntimeSetNumberOfAccounts is a noop

func (NoopMetricsReporter) RuntimeTransactionChecked

func (NoopMetricsReporter) RuntimeTransactionChecked(time.Duration)

RuntimeTransactionChecked is a noop

func (NoopMetricsReporter) RuntimeTransactionInterpreted

func (NoopMetricsReporter) RuntimeTransactionInterpreted(time.Duration)

RuntimeTransactionInterpreted is a noop

func (NoopMetricsReporter) RuntimeTransactionParsed

func (NoopMetricsReporter) RuntimeTransactionParsed(time.Duration)

RuntimeTransactionParsed is a noop

func (NoopMetricsReporter) RuntimeTransactionProgramsCacheHit added in v0.29.17

func (NoopMetricsReporter) RuntimeTransactionProgramsCacheHit()

RuntimeTransactionProgramsCacheHit is a noop

func (NoopMetricsReporter) RuntimeTransactionProgramsCacheMiss added in v0.29.17

func (NoopMetricsReporter) RuntimeTransactionProgramsCacheMiss()

RuntimeTransactionProgramsCacheMiss is a noop

type ParseRestrictedAccountCreator

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

This ensures cadence can't access unexpected operations while parsing programs.

func (ParseRestrictedAccountCreator) CreateAccount

func (creator ParseRestrictedAccountCreator) CreateAccount(
	runtimePayer common.Address,
) (
	common.Address,
	error,
)

type ParseRestrictedAccountInfo

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

func (ParseRestrictedAccountInfo) GetAccount

func (info ParseRestrictedAccountInfo) GetAccount(
	address flow.Address,
) (
	*flow.Account,
	error,
)

func (ParseRestrictedAccountInfo) GetAccountAvailableBalance

func (info ParseRestrictedAccountInfo) GetAccountAvailableBalance(
	runtimeAddress common.Address,
) (
	uint64,
	error,
)

func (ParseRestrictedAccountInfo) GetAccountBalance

func (info ParseRestrictedAccountInfo) GetAccountBalance(
	runtimeAddress common.Address,
) (
	uint64,
	error,
)

func (ParseRestrictedAccountInfo) GetStorageCapacity

func (info ParseRestrictedAccountInfo) GetStorageCapacity(
	runtimeAddress common.Address,
) (
	uint64,
	error,
)

func (ParseRestrictedAccountInfo) GetStorageUsed

func (info ParseRestrictedAccountInfo) GetStorageUsed(
	runtimeAddress common.Address,
) (
	uint64,
	error,
)

type ParseRestrictedAccountKeyReader added in v0.28.1

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

func (ParseRestrictedAccountKeyReader) AccountKeysCount added in v0.29.0

func (reader ParseRestrictedAccountKeyReader) AccountKeysCount(
	runtimeAddress common.Address,
) (
	uint64,
	error,
)

func (ParseRestrictedAccountKeyReader) GetAccountKey added in v0.28.1

func (reader ParseRestrictedAccountKeyReader) GetAccountKey(
	runtimeAddress common.Address,
	keyIndex int,
) (
	*runtime.AccountKey,
	error,
)

type ParseRestrictedAccountKeyUpdater

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

func (ParseRestrictedAccountKeyUpdater) AddAccountKey

func (updater ParseRestrictedAccountKeyUpdater) AddAccountKey(
	runtimeAddress common.Address,
	publicKey *runtime.PublicKey,
	hashAlgo runtime.HashAlgorithm,
	weight int,
) (
	*runtime.AccountKey,
	error,
)

func (ParseRestrictedAccountKeyUpdater) AddEncodedAccountKey

func (updater ParseRestrictedAccountKeyUpdater) AddEncodedAccountKey(
	runtimeAddress common.Address,
	publicKey []byte,
) error

func (ParseRestrictedAccountKeyUpdater) RevokeAccountKey

func (updater ParseRestrictedAccountKeyUpdater) RevokeAccountKey(
	runtimeAddress common.Address,
	keyIndex int,
) (
	*runtime.AccountKey,
	error,
)

func (ParseRestrictedAccountKeyUpdater) RevokeEncodedAccountKey

func (updater ParseRestrictedAccountKeyUpdater) RevokeEncodedAccountKey(
	runtimeAddress common.Address,
	index int,
) (
	[]byte,
	error,
)

type ParseRestrictedAccountLocalIDGenerator added in v0.31.0

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

func (ParseRestrictedAccountLocalIDGenerator) GenerateAccountID added in v0.31.0

func (generator ParseRestrictedAccountLocalIDGenerator) GenerateAccountID(
	address common.Address,
) (uint64, error)

type ParseRestrictedBlockInfo added in v0.28.1

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

func (ParseRestrictedBlockInfo) GetBlockAtHeight added in v0.28.1

func (info ParseRestrictedBlockInfo) GetBlockAtHeight(
	height uint64,
) (
	runtime.Block,
	bool,
	error,
)

func (ParseRestrictedBlockInfo) GetCurrentBlockHeight added in v0.28.1

func (info ParseRestrictedBlockInfo) GetCurrentBlockHeight() (uint64, error)

type ParseRestrictedContractUpdater

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

func (ParseRestrictedContractUpdater) Commit

func (updater ParseRestrictedContractUpdater) Commit() (
	ContractUpdates,
	error,
)

func (ParseRestrictedContractUpdater) RemoveAccountContractCode

func (updater ParseRestrictedContractUpdater) RemoveAccountContractCode(
	location common.AddressLocation,
) error

func (ParseRestrictedContractUpdater) Reset

func (updater ParseRestrictedContractUpdater) Reset()

func (ParseRestrictedContractUpdater) UpdateAccountContractCode

func (updater ParseRestrictedContractUpdater) UpdateAccountContractCode(
	location common.AddressLocation,
	code []byte,
) error

type ParseRestrictedCryptoLibrary added in v0.28.1

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

func (ParseRestrictedCryptoLibrary) BLSAggregatePublicKeys added in v0.28.1

func (lib ParseRestrictedCryptoLibrary) BLSAggregatePublicKeys(
	keys []*runtime.PublicKey,
) (
	*runtime.PublicKey,
	error,
)

func (ParseRestrictedCryptoLibrary) BLSAggregateSignatures added in v0.28.1

func (lib ParseRestrictedCryptoLibrary) BLSAggregateSignatures(
	sigs [][]byte,
) (
	[]byte,
	error,
)

func (ParseRestrictedCryptoLibrary) BLSVerifyPOP added in v0.28.1

func (lib ParseRestrictedCryptoLibrary) BLSVerifyPOP(
	pk *runtime.PublicKey,
	sig []byte,
) (
	bool,
	error,
)

func (ParseRestrictedCryptoLibrary) Hash added in v0.28.1

func (lib ParseRestrictedCryptoLibrary) Hash(
	data []byte,
	tag string,
	hashAlgorithm runtime.HashAlgorithm,
) (
	[]byte,
	error,
)

func (ParseRestrictedCryptoLibrary) ValidatePublicKey added in v0.28.1

func (lib ParseRestrictedCryptoLibrary) ValidatePublicKey(
	pk *runtime.PublicKey,
) error

func (ParseRestrictedCryptoLibrary) VerifySignature added in v0.28.1

func (lib ParseRestrictedCryptoLibrary) VerifySignature(
	signature []byte,
	tag string,
	signedData []byte,
	publicKey []byte,
	signatureAlgorithm runtime.SignatureAlgorithm,
	hashAlgorithm runtime.HashAlgorithm,
) (
	bool,
	error,
)

type ParseRestrictedEventEmitter added in v0.28.1

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

func (ParseRestrictedEventEmitter) ConvertedServiceEvents added in v0.30.0

func (emitter ParseRestrictedEventEmitter) ConvertedServiceEvents() flow.ServiceEventList

func (ParseRestrictedEventEmitter) EmitEvent added in v0.28.1

func (emitter ParseRestrictedEventEmitter) EmitEvent(event cadence.Event) error

func (ParseRestrictedEventEmitter) Events added in v0.28.1

func (emitter ParseRestrictedEventEmitter) Events() flow.EventsList

func (ParseRestrictedEventEmitter) Reset added in v0.28.1

func (emitter ParseRestrictedEventEmitter) Reset()

func (ParseRestrictedEventEmitter) ServiceEvents added in v0.28.1

func (emitter ParseRestrictedEventEmitter) ServiceEvents() flow.EventsList

type ParseRestrictedRandomGenerator added in v0.32.0

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

func (ParseRestrictedRandomGenerator) ReadRandom added in v0.32.0

func (gen ParseRestrictedRandomGenerator) ReadRandom(buf []byte) error

type ParseRestrictedRandomSourceHistoryProvider added in v0.32.2

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

func (ParseRestrictedRandomSourceHistoryProvider) RandomSourceHistory added in v0.32.2

func (p ParseRestrictedRandomSourceHistoryProvider) RandomSourceHistory() ([]byte, error)

type ParseRestrictedTransactionInfo

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

func (ParseRestrictedTransactionInfo) GetSigningAccounts

func (info ParseRestrictedTransactionInfo) GetSigningAccounts() (
	[]common.Address,
	error,
)

func (ParseRestrictedTransactionInfo) IsServiceAccountAuthorizer

func (info ParseRestrictedTransactionInfo) IsServiceAccountAuthorizer() bool

func (ParseRestrictedTransactionInfo) LimitAccountStorage

func (info ParseRestrictedTransactionInfo) LimitAccountStorage() bool

func (ParseRestrictedTransactionInfo) TransactionFeesEnabled

func (info ParseRestrictedTransactionInfo) TransactionFeesEnabled() bool

func (ParseRestrictedTransactionInfo) TxID

func (ParseRestrictedTransactionInfo) TxIndex

func (info ParseRestrictedTransactionInfo) TxIndex() uint32

type ParseRestrictedUUIDGenerator added in v0.28.1

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

func (ParseRestrictedUUIDGenerator) GenerateUUID added in v0.28.1

func (generator ParseRestrictedUUIDGenerator) GenerateUUID() (uint64, error)

type ParseRestrictedValueStore added in v0.28.1

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

func (ParseRestrictedValueStore) AllocateStorageIndex added in v0.28.1

func (store ParseRestrictedValueStore) AllocateStorageIndex(
	owner []byte,
) (
	atree.StorageIndex,
	error,
)

func (ParseRestrictedValueStore) GetValue added in v0.28.1

func (store ParseRestrictedValueStore) GetValue(
	owner []byte,
	key []byte,
) (
	[]byte,
	error,
)

func (ParseRestrictedValueStore) SetValue added in v0.28.1

func (store ParseRestrictedValueStore) SetValue(
	owner []byte,
	key []byte,
	value []byte,
) error

func (ParseRestrictedValueStore) ValueExists added in v0.28.1

func (store ParseRestrictedValueStore) ValueExists(
	owner []byte,
	key []byte,
) (
	bool,
	error,
)

type ProgramInvalidator added in v0.29.0

type ProgramInvalidator struct {
	DerivedDataInvalidator
}

func (ProgramInvalidator) ShouldInvalidateEntries added in v0.29.0

func (invalidator ProgramInvalidator) ShouldInvalidateEntries() bool

func (ProgramInvalidator) ShouldInvalidateEntry added in v0.29.0

func (invalidator ProgramInvalidator) ShouldInvalidateEntry(
	location common.AddressLocation,
	program *derived.Program,
	snapshot *snapshot.ExecutionSnapshot,
) bool

type ProgramLogger

type ProgramLogger struct {
	ProgramLoggerParams
	// contains filtered or unexported fields
}

func NewProgramLogger

func NewProgramLogger(
	tracer tracing.TracerSpan,
	params ProgramLoggerParams,
) *ProgramLogger

func (*ProgramLogger) ImplementationDebugLog

func (logger *ProgramLogger) ImplementationDebugLog(message string) error

func (*ProgramLogger) Logger

func (logger *ProgramLogger) Logger() zerolog.Logger

func (*ProgramLogger) Logs

func (logger *ProgramLogger) Logs() []string

func (*ProgramLogger) ProgramChecked

func (logger *ProgramLogger) ProgramChecked(
	location common.Location,
	duration time.Duration,
)

ProgramChecked captures time spent on checking a code at specific location

func (*ProgramLogger) ProgramInterpreted

func (logger *ProgramLogger) ProgramInterpreted(
	location common.Location,
	duration time.Duration,
)

ProgramInterpreted captures time spent on interpreting a code at specific location

func (*ProgramLogger) ProgramLog

func (logger *ProgramLogger) ProgramLog(message string) error

func (*ProgramLogger) ProgramParsed

func (logger *ProgramLogger) ProgramParsed(
	location common.Location,
	duration time.Duration,
)

ProgramParsed captures time spent on parsing a code at specific location

func (*ProgramLogger) RecordTrace

func (logger *ProgramLogger) RecordTrace(
	operation string,
	location common.Location,
	duration time.Duration,
	attrs []attribute.KeyValue,
)

func (*ProgramLogger) ValueDecoded

func (logger *ProgramLogger) ValueDecoded(duration time.Duration)

ValueDecoded accumulates time spend on runtime value decoding

func (*ProgramLogger) ValueEncoded

func (logger *ProgramLogger) ValueEncoded(duration time.Duration)

ValueEncoded accumulates time spend on runtime value encoding

type ProgramLoggerParams

type ProgramLoggerParams struct {
	zerolog.Logger

	CadenceLoggingEnabled bool

	MetricsReporter
}

func DefaultProgramLoggerParams

func DefaultProgramLoggerParams() ProgramLoggerParams

type Programs

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

Programs manages operations around cadence program parsing.

Note that cadence guarantees that Get/Set methods are called in a LIFO manner. Hence, we create new nested transactions on Get calls and commit these nested transactions on Set calls in order to capture the states needed for parsing the programs.

func NewPrograms

func NewPrograms(
	tracer tracing.TracerSpan,
	meter Meter,
	metrics MetricsReporter,
	txnState storage.TransactionPreparer,
	accounts Accounts,
) *Programs

NewPrograms constructs a new ProgramHandler

func (*Programs) DecodeArgument

func (programs *Programs) DecodeArgument(
	bytes []byte,
	_ cadence.Type,
) (
	cadence.Value,
	error,
)

func (*Programs) GetOrLoadProgram added in v0.30.0

func (programs *Programs) GetOrLoadProgram(
	location common.Location,
	load func() (*interpreter.Program, error),
) (*interpreter.Program, error)

GetOrLoadProgram gets the program from the cache, or loads it (by calling load) if it is not in the cache. When loading a program, this method will be re-entered to load the dependencies of the program.

func (*Programs) GetProgramDependencies added in v0.33.22

func (programs *Programs) GetProgramDependencies() (derived.ProgramDependencies, error)

func (*Programs) Reset added in v0.30.0

func (programs *Programs) Reset()

Reset resets the program cache. this is called if the transactions happy path fails.

type RandomGenerator added in v0.32.0

type RandomGenerator interface {
	// ReadRandom reads pseudo-random bytes into the input slice, using distributed randomness.
	// The name follows Cadence interface
	ReadRandom([]byte) error
}

func NewParseRestrictedRandomGenerator added in v0.32.0

func NewParseRestrictedRandomGenerator(
	txnState state.NestedTransactionPreparer,
	impl RandomGenerator,
) RandomGenerator

func NewRandomGenerator added in v0.32.0

func NewRandomGenerator(
	tracer tracing.TracerSpan,
	entropySource EntropyProvider,
	salt []byte,
) RandomGenerator

type RandomSourceHistoryProvider added in v0.32.2

type RandomSourceHistoryProvider interface {
	// RandomSourceHistory provides a source of entropy that can be
	// expanded on-chain into randoms (using a pseudo-random generator).
	// This random source is only destined to the history source core-contract
	// to implement commit-reveal schemes.
	// The returned slice should have at least 128 bits of entropy.
	// The function doesn't error in normal operations, any
	// error should be treated as an exception.
	RandomSourceHistory() ([]byte, error)
}

func NewForbiddenRandomSourceHistoryProvider added in v0.32.2

func NewForbiddenRandomSourceHistoryProvider() RandomSourceHistoryProvider

func NewParseRestrictedRandomSourceHistoryProvider added in v0.32.2

func NewParseRestrictedRandomSourceHistoryProvider(
	txnState state.NestedTransactionPreparer,
	impl RandomSourceHistoryProvider,
) RandomSourceHistoryProvider

func NewRandomSourceHistoryProvider added in v0.32.2

func NewRandomSourceHistoryProvider(
	tracer tracing.TracerSpan,
	meter Meter,
	entropyProvider EntropyProvider,
	randomSourceCallAllowed bool,
) RandomSourceHistoryProvider

NewRandomSourceHistoryProvider creates a new RandomSourceHistoryProvider. If randomSourceCallAllowed is true, the returned RandomSourceHistoryProvider will return a random source from the given EntropyProvider. If randomSourceCallAllowed is false, the returned RandomSourceHistoryProvider will always return an error.

type Runtime

type Runtime struct {
	RuntimeParams
	// contains filtered or unexported fields
}

Runtime expose the cadence runtime to the rest of the envionment package.

func NewRuntime

func NewRuntime(params RuntimeParams) *Runtime

func (*Runtime) BorrowCadenceRuntime

func (runtime *Runtime) BorrowCadenceRuntime() *runtime.ReusableCadenceRuntime

func (*Runtime) ReturnCadenceRuntime

func (runtime *Runtime) ReturnCadenceRuntime(
	reusable *runtime.ReusableCadenceRuntime,
)

func (*Runtime) SetEnvironment

func (runtime *Runtime) SetEnvironment(env Environment)

type RuntimeParams

type RuntimeParams struct {
	runtime.ReusableCadenceRuntimePool
}

func DefaultRuntimeParams

func DefaultRuntimeParams() RuntimeParams

type ScriptInfoParams added in v0.32.0

type ScriptInfoParams struct {
	ID        flow.Identifier
	Script    []byte
	Arguments [][]byte
}

func NewScriptInfoParams added in v0.32.0

func NewScriptInfoParams(code []byte, arguments [][]byte) *ScriptInfoParams

func (ScriptInfoParams) Fingerprint added in v0.32.0

func (info ScriptInfoParams) Fingerprint() []byte

type StatefulAccounts

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

func (*StatefulAccounts) AllocateStorageIndex

func (a *StatefulAccounts) AllocateStorageIndex(
	address flow.Address,
) (
	atree.StorageIndex,
	error,
)

func (*StatefulAccounts) AppendPublicKey

func (a *StatefulAccounts) AppendPublicKey(
	address flow.Address,
	publicKey flow.AccountPublicKey,
) error

func (*StatefulAccounts) ContractExists

func (a *StatefulAccounts) ContractExists(
	contractName string,
	address flow.Address,
) (
	bool,
	error,
)

func (*StatefulAccounts) Create

func (a *StatefulAccounts) Create(
	publicKeys []flow.AccountPublicKey,
	newAddress flow.Address,
) error

Create account sets all required registers on an address.

func (*StatefulAccounts) DeleteContract

func (a *StatefulAccounts) DeleteContract(
	contractName string,
	address flow.Address,
) error

func (*StatefulAccounts) Exists

func (a *StatefulAccounts) Exists(address flow.Address) (bool, error)

func (*StatefulAccounts) GenerateAccountLocalID added in v0.31.0

func (a *StatefulAccounts) GenerateAccountLocalID(
	address flow.Address,
) (
	uint64,
	error,
)

GenerateAccountLocalID generates a new account local id for an address it is sequential and starts at 1 Errors can happen if the account state cannot be read or written to

func (*StatefulAccounts) Get

func (a *StatefulAccounts) Get(address flow.Address) (*flow.Account, error)

func (*StatefulAccounts) GetContract

func (a *StatefulAccounts) GetContract(
	contractName string,
	address flow.Address,
) (
	[]byte,
	error,
)

func (*StatefulAccounts) GetContractNames

func (a *StatefulAccounts) GetContractNames(
	address flow.Address,
) (
	[]string,
	error,
)

GetContractNames gets a sorted list of names of contracts deployed on an address

func (*StatefulAccounts) GetPublicKey

func (a *StatefulAccounts) GetPublicKey(
	address flow.Address,
	keyIndex uint64,
) (
	flow.AccountPublicKey,
	error,
)

func (*StatefulAccounts) GetPublicKeyCount

func (a *StatefulAccounts) GetPublicKeyCount(
	address flow.Address,
) (
	uint64,
	error,
)

func (*StatefulAccounts) GetPublicKeys

func (a *StatefulAccounts) GetPublicKeys(
	address flow.Address,
) (
	publicKeys []flow.AccountPublicKey,
	err error,
)

func (*StatefulAccounts) GetStorageUsed

func (a *StatefulAccounts) GetStorageUsed(
	address flow.Address,
) (
	uint64,
	error,
)

GetStorageUsed returns the amount of storage used in bytes by this account

func (*StatefulAccounts) GetValue

func (a *StatefulAccounts) GetValue(
	id flow.RegisterID,
) (
	flow.RegisterValue,
	error,
)

func (*StatefulAccounts) SetAllPublicKeys

func (a *StatefulAccounts) SetAllPublicKeys(
	address flow.Address,
	publicKeys []flow.AccountPublicKey,
) error

func (*StatefulAccounts) SetContract

func (a *StatefulAccounts) SetContract(
	contractName string,
	address flow.Address,
	contract []byte,
) error

func (*StatefulAccounts) SetPublicKey

func (a *StatefulAccounts) SetPublicKey(
	address flow.Address,
	keyIndex uint64,
	publicKey flow.AccountPublicKey,
) (encodedPublicKey []byte, err error)

func (*StatefulAccounts) SetValue

func (a *StatefulAccounts) SetValue(
	id flow.RegisterID,
	value flow.RegisterValue,
) error

SetValue sets a value in address' storage

type SystemContracts

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

SystemContracts provides methods for invoking system contract functions as service account.

func NewSystemContracts

func NewSystemContracts(
	chain flow.Chain,
	tracer tracing.TracerSpan,
	logger *ProgramLogger,
	runtime *Runtime,
) *SystemContracts

func (*SystemContracts) AccountAvailableBalance

func (sys *SystemContracts) AccountAvailableBalance(
	address flow.Address,
) (cadence.Value, error)

AccountAvailableBalance executes the get available balance contract on the storage fees contract.

func (*SystemContracts) AccountBalance

func (sys *SystemContracts) AccountBalance(
	address flow.Address,
) (cadence.Value, error)

AccountBalance executes the get available balance contract on the service account.

func (*SystemContracts) AccountStorageCapacity

func (sys *SystemContracts) AccountStorageCapacity(
	address flow.Address,
) (cadence.Value, error)

AccountStorageCapacity executes the get storage capacity contract on the service account.

func (*SystemContracts) AccountsStorageCapacity

func (sys *SystemContracts) AccountsStorageCapacity(
	addresses []flow.Address,
	payer flow.Address,
	maxTxFees uint64,
) (cadence.Value, error)

AccountsStorageCapacity gets storage capacity for multiple accounts at once.

func (*SystemContracts) CheckDependencies added in v0.33.22

func (sys *SystemContracts) CheckDependencies(
	dependencies []common.AddressLocation,
	authorizers []flow.Address,
) (cadence.Value, error)

CheckDependencies calls the checkDependencies function on the service account. The inputs should be deterministically sorted.

func (*SystemContracts) CheckPayerBalanceAndGetMaxTxFees added in v0.29.0

func (sys *SystemContracts) CheckPayerBalanceAndGetMaxTxFees(
	payer flow.Address,
	inclusionEffort uint64,
	maxExecutionEffort uint64,
) (cadence.Value, error)

CheckPayerBalanceAndGetMaxTxFees executes the verifyPayersBalanceForTransactionExecution on the FlowFees account. It checks whether the given payer has enough balance to cover inclusion fee and max execution fee. It returns (maxTransactionFee, ErrCodeInsufficientPayerBalance) if the payer doesn't have enough balance It returns (maxTransactionFee, nil) if the payer has enough balance

func (*SystemContracts) DeductTransactionFees

func (sys *SystemContracts) DeductTransactionFees(
	payer flow.Address,
	inclusionEffort uint64,
	executionEffort uint64,
) (cadence.Value, error)

DeductTransactionFees executes the fee deduction function on the FlowFees account.

func (*SystemContracts) Invoke

func (sys *SystemContracts) Invoke(
	spec ContractFunctionSpec,
	arguments []cadence.Value,
) (
	cadence.Value,
	error,
)

func (*SystemContracts) SetupNewAccount

func (sys *SystemContracts) SetupNewAccount(
	flowAddress flow.Address,
	payer flow.Address,
) (cadence.Value, error)

SetupNewAccount executes the new account setup contract on the service account.

type TransactionInfo

type TransactionInfo interface {
	TxIndex() uint32
	TxID() flow.Identifier

	TransactionFeesEnabled() bool
	LimitAccountStorage() bool

	IsServiceAccountAuthorizer() bool

	// Cadence's runtime API.  Note that the script variant will return
	// OperationNotSupportedError.
	GetSigningAccounts() ([]common.Address, error)
}

TransactionInfo exposes information associated with the executing transaction.

Note that scripts have no associated transaction information, but must expose the API in compliance with the runtime environment interface.

func NewParseRestrictedTransactionInfo

func NewParseRestrictedTransactionInfo(
	txnState state.NestedTransactionPreparer,
	impl TransactionInfo,
) TransactionInfo

func NewTransactionInfo

func NewTransactionInfo(
	params TransactionInfoParams,
	tracer tracing.TracerSpan,
	serviceAccount flow.Address,
) TransactionInfo

type TransactionInfoParams

type TransactionInfoParams struct {
	TxIndex uint32
	TxId    flow.Identifier
	TxBody  *flow.TransactionBody

	TransactionFeesEnabled bool
	LimitAccountStorage    bool
	// RandomSourceHistoryCallAllowed is true if the transaction is allowed to call the `entropy`
	// cadence function to get the entropy of that block.
	RandomSourceHistoryCallAllowed bool
}

func DefaultTransactionInfoParams

func DefaultTransactionInfoParams() TransactionInfoParams

type UUIDGenerator

type UUIDGenerator interface {
	GenerateUUID() (uint64, error)
}

func NewParseRestrictedUUIDGenerator added in v0.28.1

func NewParseRestrictedUUIDGenerator(
	txnState state.NestedTransactionPreparer,
	impl UUIDGenerator,
) UUIDGenerator

type ValueStore

type ValueStore interface {
	GetValue(owner []byte, key []byte) ([]byte, error)

	SetValue(owner, key, value []byte) error

	ValueExists(owner []byte, key []byte) (bool, error)

	AllocateStorageIndex(owner []byte) (atree.StorageIndex, error)
}

ValueStore provides read/write access to the account storage.

func NewParseRestrictedValueStore added in v0.28.1

func NewParseRestrictedValueStore(
	txnState state.NestedTransactionPreparer,
	impl ValueStore,
) ValueStore

func NewValueStore

func NewValueStore(
	tracer tracing.TracerSpan,
	meter Meter,
	accounts Accounts,
) ValueStore

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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