environment

package
v0.29.16-access-remove... Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: AGPL-3.0 Imports: 39 Imported by: 5

Documentation

Index

Constants

View Source
const (
	FungibleTokenAccountIndex = 2
	FlowTokenAccountIndex     = 3
	FlowFeesAccountIndex      = 4
)
View Source
const (
	// [2_000, 3_000) reserved for the FVM
	ComputationKindHash                       = 2001
	ComputationKindVerifySignature            = 2002
	ComputationKindAddAccountKey              = 2003
	ComputationKindAddEncodedAccountKey       = 2004
	ComputationKindAllocateStorageIndex       = 2005
	ComputationKindCreateAccount              = 2006
	ComputationKindEmitEvent                  = 2007
	ComputationKindGenerateUUID               = 2008
	ComputationKindGetAccountAvailableBalance = 2009
	ComputationKindGetAccountBalance          = 2010
	ComputationKindGetAccountContractCode     = 2011
	ComputationKindGetAccountContractNames    = 2012
	ComputationKindGetAccountKey              = 2013
	ComputationKindGetBlockAtHeight           = 2014
	ComputationKindGetCode                    = 2015
	ComputationKindGetCurrentBlockHeight      = 2016
	ComputationKindGetProgram                 = 2017
	ComputationKindGetStorageCapacity         = 2018
	ComputationKindGetStorageUsed             = 2019
	ComputationKindGetValue                   = 2020
	ComputationKindRemoveAccountContractCode  = 2021
	ComputationKindResolveLocation            = 2022
	ComputationKindRevokeAccountKey           = 2023
	ComputationKindRevokeEncodedAccountKey    = 2024
	ComputationKindSetProgram                 = 2025
	ComputationKindSetValue                   = 2026
	ComputationKindUpdateAccountContractCode  = 2027
	ComputationKindValidatePublicKey          = 2028
	ComputationKindValueExists                = 2029
	ComputationKindAccountKeysCount           = 2030
	ComputationKindBLSVerifyPOP               = 2031
	ComputationKindBLSAggregateSignatures     = 2032
	ComputationKindBLSAggregatePublicKeys     = 2033
)
View Source
const (
	DefaultEventCollectionByteSizeLimit = 256_000 // 256KB
)
View Source
const (
	MaxPublicKeyCount = math.MaxUint64
)

Variables

This section is empty.

Functions

func ContractKey

func ContractKey(contractName string) string

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(event cadence.Event, 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 KeyPublicKey

func KeyPublicKey(index uint64) string

func NewAccountFreezer

func NewAccountFreezer(
	serviceAddress flow.Address,
	accounts Accounts,
	transactionInfo TransactionInfo,
) *accountFreezer

func NewAccountKeyUpdater

func NewAccountKeyUpdater(
	tracer *Tracer,
	meter Meter,
	accounts Accounts,
	txnState *state.TransactionState,
	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 NewScriptEnvironment

func NewScriptEnvironment(
	ctx context.Context,
	params EnvironmentParams,
	txnState *state.TransactionState,
	derivedTxnData DerivedTransactionData,
) *facadeEnvironment

func NewTransactionEnvironment

func NewTransactionEnvironment(
	params EnvironmentParams,
	txnState *state.TransactionState,
	derivedTxnData DerivedTransactionData,
) *facadeEnvironment

func NewUUIDGenerator

func NewUUIDGenerator(
	tracer *Tracer,
	meter Meter,
	txnState *state.TransactionState,
) *uUIDGenerator

func RegisterSize

func RegisterSize(address flow.Address, key string, 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(payer runtime.Address) (runtime.Address, error)
}

func NewAccountCreator

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

func NewParseRestrictedAccountCreator

func NewParseRestrictedAccountCreator(
	txnState *state.TransactionState,
	creator AccountCreator,
) AccountCreator

type AccountFreezer

type AccountFreezer interface {
	// Note that the script variant will return OperationNotSupportedError.
	SetAccountFrozen(address common.Address, frozen bool) error

	FrozenAccounts() []common.Address

	Reset()
}

AccountFreezer disables accounts.

Note that scripts cannot freeze accounts, but must expose the API in compliance with the environment interface.

func NewParseRestrictedAccountFreezer

func NewParseRestrictedAccountFreezer(
	txnState *state.TransactionState,
	impl AccountFreezer,
) AccountFreezer

type AccountInfo

type AccountInfo interface {
	GetStorageUsed(address common.Address) (uint64, error)
	GetStorageCapacity(address common.Address) (uint64, error)
	GetAccountBalance(address common.Address) (uint64, error)
	GetAccountAvailableBalance(address common.Address) (uint64, error)
	GetAccount(address flow.Address) (*flow.Account, error)
}

AccountInfo exposes various account balance and storage statistics.

func NewAccountInfo

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

func NewParseRestrictedAccountInfo

func NewParseRestrictedAccountInfo(
	txnState *state.TransactionState,
	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(
		address runtime.Address,
		keyIndex int,
	) (
		*runtime.AccountKey,
		error,
	)
	AccountKeysCount(address runtime.Address) (uint64, error)
}

AccountKeyReader provide read access to account keys.

func NewAccountKeyReader

func NewAccountKeyReader(
	tracer *Tracer,
	meter Meter,
	accounts Accounts,
) AccountKeyReader

func NewParseRestrictedAccountKeyReader added in v0.28.1

func NewParseRestrictedAccountKeyReader(
	txnState *state.TransactionState,
	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(address runtime.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(
		address runtime.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(
		address runtime.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(
		address runtime.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 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 (e.g. frozen) 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 and the last 8 bytes (big-endian) captures the number of public keys stored on this account

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) IsAccountFrozen

func (a *AccountStatus) IsAccountFrozen() bool

IsAccountFrozen returns true if account's frozen flag is set

func (*AccountStatus) PublicKeyCount

func (a *AccountStatus) PublicKeyCount() uint64

PublicKeyCount returns the public key count of the account

func (*AccountStatus) SetFrozenFlag

func (a *AccountStatus) SetFrozenFlag(frozen bool)

SetFrozenFlag sets the frozen flag

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 an 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(address flow.Address, key string) (flow.RegisterValue, error)
	CheckAccountNotFrozen(address flow.Address) error
	GetStorageUsed(address flow.Address) (uint64, error)
	SetValue(address flow.Address, key string, value flow.RegisterValue) error
	AllocateStorageIndex(address flow.Address) (atree.StorageIndex, error)
	SetAccountFrozen(address flow.Address, frozen bool) error
}

type AddressGenerator

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

func NewAddressGenerator

func NewAddressGenerator(
	txnState *state.TransactionState,
	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 *Tracer,
	meter Meter,
	blockHeader *flow.Header,
	blocks Blocks,
) BlockInfo

func NewParseRestrictedBlockInfo added in v0.28.1

func NewParseRestrictedBlockInfo(
	txnState *state.TransactionState,
	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.TransactionState,
	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 *Tracer,
	meter Meter,
	accounts Accounts,
) *ContractReader

func (*ContractReader) GetAccountContractCode

func (reader *ContractReader) GetAccountContractCode(
	address runtime.Address,
	name string,
) (
	code []byte,
	err error,
)

func (*ContractReader) GetAccountContractNames

func (reader *ContractReader) GetAccountContractNames(
	address runtime.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 {
	ContractUpdateKey
	Code []byte
}

type ContractUpdateKey added in v0.29.0

type ContractUpdateKey struct {
	Address flow.Address
	Name    string
}

type ContractUpdater

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

	// Cadence's runtime API.  Note that the script variant will return
	// OperationNotSupportedError.
	RemoveAccountContractCode(address runtime.Address, name string) error

	Commit() ([]ContractUpdateKey, error)

	Reset()
}

ContractUpdater handles all smart contracts modification. It also captures all changes as deltas and only commit them when called so smart contract updates can be delayed until end of the tx 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 *Tracer,
	meter Meter,
	accounts Accounts,
	transactionInfo TransactionInfo,
	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() ([]ContractUpdateKey, 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(
	address runtime.Address,
	name string,
) error

func (*ContractUpdaterImpl) RemoveContract added in v0.29.0

func (updater *ContractUpdaterImpl) RemoveContract(
	address runtime.Address,
	name string,
	signingAccounts []runtime.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(
	address runtime.Address,
	name string,
	code []byte,
	signingAccounts []runtime.Address,
) (err error)

func (*ContractUpdaterImpl) UpdateAccountContractCode added in v0.29.0

func (updater *ContractUpdaterImpl) UpdateAccountContractCode(
	address runtime.Address,
	name string,
	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) []common.Address

	UseContractAuditVoucher(address runtime.Address, code []byte) (bool, error)
}

Expose stub interface for testing.

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 *Tracer, meter Meter) CryptoLibrary

func NewParseRestrictedCryptoLibrary added in v0.28.1

func NewParseRestrictedCryptoLibrary(
	txnState *state.TransactionState,
	impl CryptoLibrary,
) CryptoLibrary

type DerivedDataInvalidator added in v0.29.0

type DerivedDataInvalidator struct {
	ContractUpdateKeys []ContractUpdateKey
	FrozenAccounts     []common.Address

	MeterParamOverridesUpdated bool
}

func NewDerivedDataInvalidator added in v0.29.0

func NewDerivedDataInvalidator(
	contractKeys []ContractUpdateKey,
	env *facadeEnvironment,
) 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 DerivedTransactionData added in v0.29.0

type DerivedTransactionData interface {
	GetProgram(loc common.AddressLocation) (*interpreter.Program, *state.State, bool)
	SetProgram(loc common.AddressLocation, prog *interpreter.Program, state *state.State)
}

TODO(patrick): remove and switch to *programs.DerivedTransactionData once https://github.com/onflow/flow-emulator/pull/229 is integrated.

type Environment

type Environment interface {
	runtime.Interface

	// Tracer
	StartSpanFromRoot(name trace.SpanName) otelTrace.Span

	Meter

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

	TransactionInfo

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

	// EventEmitter
	Events() []flow.Event
	ServiceEvents() []flow.Event

	// SystemContracts
	AccountsStorageCapacity(
		addresses []common.Address,
		payer common.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)

	AccountFreezer

	// FlushPendingUpdates flushes pending updates from the stateful environment
	// modules (i.e., ContractUpdater) to the state transaction, and return
	// corresponding modified sets invalidator.
	FlushPendingUpdates() (
		derived.TransactionInvalidator,
		error,
	)

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

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

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(
	event flow.Event,
	size uint64,
) error

func (*EventCollection) Events

func (collection *EventCollection) Events() []flow.Event

func (*EventCollection) ServiceEvents

func (collection *EventCollection) ServiceEvents() []flow.Event

func (*EventCollection) TotalByteSize

func (collection *EventCollection) TotalByteSize() uint64

func (*EventCollection) TotalEventCounter

func (collection *EventCollection) TotalEventCounter() uint32

type EventEmitter

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

	Events() []flow.Event
	ServiceEvents() []flow.Event

	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 *Tracer,
	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.TransactionState,
	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
	ComputationIntensities() meter.MeteredComputationIntensities

	MeterMemory(usage common.MemoryUsage) error
	MemoryEstimate() uint64

	MeterEmittedEvent(byteSize uint64) error
	TotalEmittedEventBytes() uint64
}

func NewCancellableMeter

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

func NewMeter

func NewMeter(txnState *state.TransactionState) 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,
	_ *state.State,
) bool

type MetricsReporter

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

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(
	payer runtime.Address,
) (
	runtime.Address,
	error,
)

type NoAccountFreezer

type NoAccountFreezer struct{}

func (NoAccountFreezer) FrozenAccounts

func (NoAccountFreezer) FrozenAccounts() []common.Address

func (NoAccountFreezer) Reset

func (NoAccountFreezer) Reset()

func (NoAccountFreezer) SetAccountFrozen

func (NoAccountFreezer) SetAccountFrozen(_ common.Address, _ bool) error

type NoAccountKeyUpdater

type NoAccountKeyUpdater struct{}

func (NoAccountKeyUpdater) AddAccountKey

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

func (NoAccountKeyUpdater) AddEncodedAccountKey

func (NoAccountKeyUpdater) AddEncodedAccountKey(
	address runtime.Address,
	publicKey []byte,
) error

func (NoAccountKeyUpdater) RevokeAccountKey

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

func (NoAccountKeyUpdater) RevokeEncodedAccountKey

func (NoAccountKeyUpdater) RevokeEncodedAccountKey(
	address runtime.Address,
	index int,
) (
	[]byte,
	error,
)

type NoContractUpdater

type NoContractUpdater struct{}

func (NoContractUpdater) Commit

func (NoContractUpdater) RemoveAccountContractCode

func (NoContractUpdater) RemoveAccountContractCode(
	address runtime.Address,
	name string,
) error

func (NoContractUpdater) Reset

func (NoContractUpdater) Reset()

func (NoContractUpdater) UpdateAccountContractCode

func (NoContractUpdater) UpdateAccountContractCode(
	address runtime.Address,
	name string,
	code []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) EmitEvent

func (NoEventEmitter) EmitEvent(event cadence.Event) error

func (NoEventEmitter) Events

func (NoEventEmitter) Events() []flow.Event

func (NoEventEmitter) Reset

func (NoEventEmitter) Reset()

func (NoEventEmitter) ServiceEvents

func (NoEventEmitter) ServiceEvents() []flow.Event

type NoTransactionInfo

type NoTransactionInfo struct {
}

Scripts have no associated transaction information.

func (NoTransactionInfo) GetSigningAccounts

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

func (NoTransactionInfo) IsServiceAccountAuthorizer

func (NoTransactionInfo) IsServiceAccountAuthorizer() bool

func (NoTransactionInfo) LimitAccountStorage

func (NoTransactionInfo) LimitAccountStorage() bool

func (NoTransactionInfo) SigningAccounts

func (NoTransactionInfo) SigningAccounts() []runtime.Address

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

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(
	payer runtime.Address,
) (
	runtime.Address,
	error,
)

type ParseRestrictedAccountFreezer

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

func (ParseRestrictedAccountFreezer) FrozenAccounts

func (freezer ParseRestrictedAccountFreezer) FrozenAccounts() []common.Address

func (ParseRestrictedAccountFreezer) Reset

func (freezer ParseRestrictedAccountFreezer) Reset()

func (ParseRestrictedAccountFreezer) SetAccountFrozen

func (freezer ParseRestrictedAccountFreezer) SetAccountFrozen(
	address common.Address,
	frozen bool,
) 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(
	address common.Address,
) (
	uint64,
	error,
)

func (ParseRestrictedAccountInfo) GetAccountBalance

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

func (ParseRestrictedAccountInfo) GetStorageCapacity

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

func (ParseRestrictedAccountInfo) GetStorageUsed

func (info ParseRestrictedAccountInfo) GetStorageUsed(
	address 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(address runtime.Address) (uint64, error)

func (ParseRestrictedAccountKeyReader) GetAccountKey added in v0.28.1

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

type ParseRestrictedAccountKeyUpdater

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

func NewParseRestrictedAccountKeyUpdater

func NewParseRestrictedAccountKeyUpdater(
	txnState *state.TransactionState,
	impl AccountKeyUpdater,
) ParseRestrictedAccountKeyUpdater

func (ParseRestrictedAccountKeyUpdater) AddAccountKey

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

func (ParseRestrictedAccountKeyUpdater) AddEncodedAccountKey

func (updater ParseRestrictedAccountKeyUpdater) AddEncodedAccountKey(
	address runtime.Address,
	publicKey []byte,
) error

func (ParseRestrictedAccountKeyUpdater) RevokeAccountKey

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

func (ParseRestrictedAccountKeyUpdater) RevokeEncodedAccountKey

func (updater ParseRestrictedAccountKeyUpdater) RevokeEncodedAccountKey(
	address runtime.Address,
	index int,
) (
	[]byte,
	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 NewParseRestrictedContractUpdater

func NewParseRestrictedContractUpdater(
	txnState *state.TransactionState,
	impl ContractUpdater,
) ParseRestrictedContractUpdater

func (ParseRestrictedContractUpdater) Commit

func (updater ParseRestrictedContractUpdater) Commit() (
	[]ContractUpdateKey,
	error,
)

func (ParseRestrictedContractUpdater) RemoveAccountContractCode

func (updater ParseRestrictedContractUpdater) RemoveAccountContractCode(
	address runtime.Address,
	name string,
) error

func (ParseRestrictedContractUpdater) Reset

func (updater ParseRestrictedContractUpdater) Reset()

func (ParseRestrictedContractUpdater) UpdateAccountContractCode

func (updater ParseRestrictedContractUpdater) UpdateAccountContractCode(
	address runtime.Address,
	name string,
	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) 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.Event

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.Event

type ParseRestrictedTransactionInfo

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

func (ParseRestrictedTransactionInfo) GetSigningAccounts

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

func (ParseRestrictedTransactionInfo) IsServiceAccountAuthorizer

func (info ParseRestrictedTransactionInfo) IsServiceAccountAuthorizer() bool

func (ParseRestrictedTransactionInfo) LimitAccountStorage

func (info ParseRestrictedTransactionInfo) LimitAccountStorage() bool

func (ParseRestrictedTransactionInfo) SigningAccounts

func (info ParseRestrictedTransactionInfo) SigningAccounts() []runtime.Address

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 ParseRestrictedUnsafeRandomGenerator added in v0.28.1

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

func (ParseRestrictedUnsafeRandomGenerator) UnsafeRandom added in v0.28.1

func (gen ParseRestrictedUnsafeRandomGenerator) UnsafeRandom() (
	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 *interpreter.Program,
	state *state.State,
) bool

type ProgramLogger

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

func NewProgramLogger

func NewProgramLogger(
	tracer *Tracer,
	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 *Tracer,
	meter Meter,
	txnState *state.TransactionState,
	accounts Accounts,
	derivedTxnData DerivedTransactionData,
) *Programs

NewPrograms construts a new ProgramHandler

func (*Programs) DecodeArgument

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

func (*Programs) GetProgram

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

func (*Programs) SetProgram

func (programs *Programs) SetProgram(
	location common.Location,
	program *interpreter.Program,
) 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 StatefulAccounts

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

func NewAccounts

func NewAccounts(txnState *state.TransactionState) *StatefulAccounts

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) CheckAccountNotFrozen

func (a *StatefulAccounts) CheckAccountNotFrozen(address flow.Address) error

handy function to error out if account is frozen

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) Get

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

func (*StatefulAccounts) GetAccountFrozen

func (a *StatefulAccounts) GetAccountFrozen(address flow.Address) (bool, 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(address flow.Address, key string) (flow.RegisterValue, error)

func (*StatefulAccounts) SetAccountFrozen

func (a *StatefulAccounts) SetAccountFrozen(address flow.Address, frozen bool) 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(address flow.Address, key string, value flow.RegisterValue) error

SetValue sets a value in address' storage

func (*StatefulAccounts) TouchContract

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

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 *Tracer,
	logger *ProgramLogger,
	runtime *Runtime,
) *SystemContracts

func (*SystemContracts) AccountAvailableBalance

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

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

func (*SystemContracts) AccountBalance

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

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

func (*SystemContracts) AccountStorageCapacity

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

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

func (*SystemContracts) AccountsStorageCapacity

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

AccountsStorageCapacity gets storage capacity for multiple accounts at once.

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 common.Address,
) (cadence.Value, error)

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

func (*SystemContracts) UseContractAuditVoucher

func (sys *SystemContracts) UseContractAuditVoucher(
	address common.Address,
	code string,
) (bool, error)

UseContractAuditVoucher executes the use a contract deployment audit voucher contract.

type Tracer

type Tracer struct {
	TracerParams
}

func NewTracer

func NewTracer(params TracerParams) *Tracer

func (*Tracer) RecordSpanFromRoot

func (tracer *Tracer) RecordSpanFromRoot(
	spanName trace.SpanName,
	duration time.Duration,
	attrs []attribute.KeyValue,
)

func (*Tracer) StartExtensiveTracingSpanFromRoot

func (tracer *Tracer) StartExtensiveTracingSpanFromRoot(
	name trace.SpanName,
) otelTrace.Span

func (*Tracer) StartSpanFromRoot

func (tracer *Tracer) StartSpanFromRoot(name trace.SpanName) otelTrace.Span

type TracerParams

type TracerParams struct {
	module.Tracer
	ExtensiveTracing bool

	RootSpan otelTrace.Span
}

func DefaultTracerParams

func DefaultTracerParams() TracerParams

type TransactionInfo

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

	TransactionFeesEnabled() bool
	LimitAccountStorage() bool

	SigningAccounts() []runtime.Address

	IsServiceAccountAuthorizer() bool

	// Cadence's runtime API.  Note that the script variant will return
	// OperationNotSupportedError.
	GetSigningAccounts() ([]runtime.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.TransactionState,
	impl TransactionInfo,
) TransactionInfo

func NewTransactionInfo

func NewTransactionInfo(
	params TransactionInfoParams,
	tracer *Tracer,
	serviceAccount flow.Address,
) TransactionInfo

type TransactionInfoParams

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

	TransactionFeesEnabled bool
	LimitAccountStorage    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.TransactionState,
	impl UUIDGenerator,
) UUIDGenerator

type UnsafeRandomGenerator

type UnsafeRandomGenerator interface {
	// UnsafeRandom returns a random uint64, where the process of random number
	// derivation is not cryptographically secure.
	UnsafeRandom() (uint64, error)
}

func NewParseRestrictedUnsafeRandomGenerator added in v0.28.1

func NewParseRestrictedUnsafeRandomGenerator(
	txnState *state.TransactionState,
	impl UnsafeRandomGenerator,
) UnsafeRandomGenerator

func NewUnsafeRandomGenerator

func NewUnsafeRandomGenerator(
	tracer *Tracer,
	blockHeader *flow.Header,
) UnsafeRandomGenerator

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.TransactionState,
	impl ValueStore,
) ValueStore

func NewValueStore

func NewValueStore(tracer *Tracer, 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