Documentation
¶
Overview ¶
Package emulator provides an emulated version of the Flow blockchain that can be used for development purposes.
This package can be used as a library or as a standalone application.
When used as a library, this package provides tools to write programmatic tests for Flow applications.
When used as a standalone application, this package implements the Flow Access API and is fully-compatible with Flow gRPC client libraries.
Index ¶
- Constants
- type AccountNotFoundError
- type BlockNotFoundByHeightError
- type BlockNotFoundByIDError
- type BlockNotFoundError
- type Blockchain
- func (b *Blockchain) AddTransaction(tx sdk.Transaction) error
- func (b *Blockchain) CommitBlock() (*flowgo.Block, error)
- func (b *Blockchain) CreateAccount(publicKeys []*sdk.AccountKey, contracts []templates.Contract) (sdk.Address, error)
- func (b *Blockchain) ExecuteAndCommitBlock() (*flowgo.Block, []*types.TransactionResult, error)
- func (b *Blockchain) ExecuteBlock() ([]*types.TransactionResult, error)
- func (b *Blockchain) ExecuteNextTransaction() (*types.TransactionResult, error)
- func (b *Blockchain) ExecuteScript(script []byte, arguments [][]byte) (*types.ScriptResult, error)
- func (b *Blockchain) ExecuteScriptAtBlock(script []byte, arguments [][]byte, blockHeight uint64) (*types.ScriptResult, error)
- func (b *Blockchain) GetAccount(address sdk.Address) (*sdk.Account, error)
- func (b *Blockchain) GetAccountAtBlock(address sdk.Address, blockHeight uint64) (*sdk.Account, error)
- func (b *Blockchain) GetBlockByHeight(height uint64) (*flowgo.Block, error)
- func (b *Blockchain) GetBlockByID(id sdk.Identifier) (*flowgo.Block, error)
- func (b *Blockchain) GetCollection(colID sdk.Identifier) (*sdk.Collection, error)
- func (b *Blockchain) GetEventsByHeight(blockHeight uint64, eventType string) ([]sdk.Event, error)
- func (b *Blockchain) GetLatestBlock() (*flowgo.Block, error)
- func (b *Blockchain) GetTransaction(id sdk.Identifier) (*sdk.Transaction, error)
- func (b *Blockchain) GetTransactionResult(ID sdk.Identifier) (*sdk.TransactionResult, error)
- func (b *Blockchain) PendingBlockID() flowgo.Identifier
- func (b *Blockchain) PendingBlockTimestamp() time.Time
- func (b *Blockchain) ResetPendingBlock() error
- func (b *Blockchain) ServiceKey() ServiceKey
- type CollectionNotFoundError
- type DuplicateTransactionError
- type ExecutionError
- type ExpiredTransactionError
- type IncompleteTransactionError
- type IndexedTransactionResult
- type InvalidStateVersionError
- type InvalidTransactionGasLimitError
- type InvalidTransactionScriptError
- type NotFoundError
- type Option
- func WithGenesisTokenSupply(supply cadence.UFix64) Option
- func WithScriptGasLimit(limit uint64) Option
- func WithServicePublicKey(servicePublicKey sdkcrypto.PublicKey, sigAlgo sdkcrypto.SignatureAlgorithm, ...) Option
- func WithSimpleAddresses() Option
- func WithStore(store storage.Store) Option
- func WithTransactionExpiry(expiry uint) Option
- type PendingBlockCommitBeforeExecutionError
- type PendingBlockMidExecutionError
- type PendingBlockTransactionsExhaustedError
- type ServiceKey
- type StorageError
- type TransactionNotFoundError
- type TransactionValidationError
Constants ¶
const DefaultServiceKeyHashAlgo = sdkcrypto.SHA3_256
const DefaultServiceKeySigAlgo = sdkcrypto.ECDSA_P256
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountNotFoundError ¶
An AccountNotFoundError indicates that an account could not be found.
func (*AccountNotFoundError) Error ¶
func (e *AccountNotFoundError) Error() string
type BlockNotFoundByHeightError ¶
type BlockNotFoundByHeightError struct {
Height uint64
}
A BlockNotFoundByHeightError indicates that a block could not be found at the specified height.
func (*BlockNotFoundByHeightError) Error ¶
func (e *BlockNotFoundByHeightError) Error() string
type BlockNotFoundByIDError ¶
type BlockNotFoundByIDError struct {
ID flow.Identifier
}
A BlockNotFoundByIDError indicates that a block with the specified ID could not be found.
func (*BlockNotFoundByIDError) Error ¶
func (e *BlockNotFoundByIDError) Error() string
type BlockNotFoundError ¶
type BlockNotFoundError interface {
// contains filtered or unexported methods
}
A BlockNotFoundError indicates that a block could not be found.
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain emulates the functionality of the Flow blockchain.
func NewBlockchain ¶
func NewBlockchain(opts ...Option) (*Blockchain, error)
NewBlockchain instantiates a new emulated blockchain with the provided options.
func (*Blockchain) AddTransaction ¶
func (b *Blockchain) AddTransaction(tx sdk.Transaction) error
AddTransaction validates a transaction and adds it to the current pending block.
func (*Blockchain) CommitBlock ¶
func (b *Blockchain) CommitBlock() (*flowgo.Block, error)
CommitBlock seals the current pending block and saves it to storage.
This function clears the pending transaction pool and resets the pending block.
func (*Blockchain) CreateAccount ¶
func (b *Blockchain) CreateAccount(publicKeys []*sdk.AccountKey, contracts []templates.Contract) (sdk.Address, error)
CreateAccount submits a transaction to create a new account with the given account keys and contracts. The transaction is paid by the service account.
func (*Blockchain) ExecuteAndCommitBlock ¶
func (b *Blockchain) ExecuteAndCommitBlock() (*flowgo.Block, []*types.TransactionResult, error)
ExecuteAndCommitBlock is a utility that combines ExecuteBlock with CommitBlock.
func (*Blockchain) ExecuteBlock ¶
func (b *Blockchain) ExecuteBlock() ([]*types.TransactionResult, error)
ExecuteBlock executes the remaining transactions in pending block.
func (*Blockchain) ExecuteNextTransaction ¶
func (b *Blockchain) ExecuteNextTransaction() (*types.TransactionResult, error)
ExecuteNextTransaction executes the next indexed transaction in pending block.
func (*Blockchain) ExecuteScript ¶
func (b *Blockchain) ExecuteScript(script []byte, arguments [][]byte) (*types.ScriptResult, error)
ExecuteScript executes a read-only script against the world state and returns the result.
func (*Blockchain) ExecuteScriptAtBlock ¶
func (b *Blockchain) ExecuteScriptAtBlock(script []byte, arguments [][]byte, blockHeight uint64) (*types.ScriptResult, error)
func (*Blockchain) GetAccount ¶
GetAccount returns the account for the given address.
func (*Blockchain) GetAccountAtBlock ¶
func (b *Blockchain) GetAccountAtBlock(address sdk.Address, blockHeight uint64) (*sdk.Account, error)
TODO: Implement
func (*Blockchain) GetBlockByHeight ¶
func (b *Blockchain) GetBlockByHeight(height uint64) (*flowgo.Block, error)
GetBlockByHeight gets a block by height.
func (*Blockchain) GetBlockByID ¶
func (b *Blockchain) GetBlockByID(id sdk.Identifier) (*flowgo.Block, error)
GetBlockByID gets a block by ID.
func (*Blockchain) GetCollection ¶
func (b *Blockchain) GetCollection(colID sdk.Identifier) (*sdk.Collection, error)
func (*Blockchain) GetEventsByHeight ¶
GetEventsByHeight returns the events in the block at the given height, optionally filtered by type.
func (*Blockchain) GetLatestBlock ¶
func (b *Blockchain) GetLatestBlock() (*flowgo.Block, error)
GetLatestBlock gets the latest sealed block.
func (*Blockchain) GetTransaction ¶
func (b *Blockchain) GetTransaction(id sdk.Identifier) (*sdk.Transaction, error)
GetTransaction gets an existing transaction by ID.
The function first looks in the pending block, then the current blockchain state.
func (*Blockchain) GetTransactionResult ¶
func (b *Blockchain) GetTransactionResult(ID sdk.Identifier) (*sdk.TransactionResult, error)
func (*Blockchain) PendingBlockID ¶
func (b *Blockchain) PendingBlockID() flowgo.Identifier
PendingBlockID returns the ID of the pending block.
func (*Blockchain) PendingBlockTimestamp ¶
func (b *Blockchain) PendingBlockTimestamp() time.Time
PendingBlockTimestamp returns the Timestamp of the pending block.
func (*Blockchain) ResetPendingBlock ¶
func (b *Blockchain) ResetPendingBlock() error
ResetPendingBlock clears the transactions in pending block.
func (*Blockchain) ServiceKey ¶
func (b *Blockchain) ServiceKey() ServiceKey
ServiceKey returns the service private key for this blockchain.
type CollectionNotFoundError ¶
type CollectionNotFoundError struct {
ID flow.Identifier
}
A CollectionNotFoundError indicates that a collection could not be found.
func (*CollectionNotFoundError) Error ¶
func (e *CollectionNotFoundError) Error() string
type DuplicateTransactionError ¶
type DuplicateTransactionError struct {
TxID flowgo.Identifier
}
A DuplicateTransactionError indicates that a transaction has already been submitted.
func (*DuplicateTransactionError) Error ¶
func (e *DuplicateTransactionError) Error() string
type ExecutionError ¶
An ExecutionError occurs when a transaction fails to execute.
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
type ExpiredTransactionError ¶
type ExpiredTransactionError struct {
RefHeight, FinalHeight uint64
}
ExpiredTransactionError indicates that a transaction has expired.
func (*ExpiredTransactionError) Error ¶
func (e *ExpiredTransactionError) Error() string
type IncompleteTransactionError ¶
type IncompleteTransactionError struct {
MissingFields []string
}
IncompleteTransactionError indicates that a transaction is missing one or more required fields.
func (*IncompleteTransactionError) Error ¶
func (e *IncompleteTransactionError) Error() string
type IndexedTransactionResult ¶
type IndexedTransactionResult struct { Transaction *fvm.TransactionProcedure Index uint32 }
type InvalidStateVersionError ¶
An InvalidStateVersionError indicates that a state version hash provided is invalid.
func (*InvalidStateVersionError) Error ¶
func (e *InvalidStateVersionError) Error() string
type InvalidTransactionGasLimitError ¶
InvalidTransactionGasLimitError indicates that a transaction specifies a gas limit that exceeds the maximum.
func (*InvalidTransactionGasLimitError) Error ¶
func (e *InvalidTransactionGasLimitError) Error() string
type InvalidTransactionScriptError ¶
type InvalidTransactionScriptError struct {
ParserErr error
}
InvalidTransactionScriptError indicates that a transaction contains an invalid Cadence script.
func (*InvalidTransactionScriptError) Error ¶
func (e *InvalidTransactionScriptError) Error() string
func (*InvalidTransactionScriptError) Unwrap ¶
func (e *InvalidTransactionScriptError) Unwrap() error
type NotFoundError ¶
type NotFoundError interface {
// contains filtered or unexported methods
}
A NotFoundError indicates that an entity could not be found.
type Option ¶
type Option func(*config)
Option is a function applying a change to the emulator config.
func WithGenesisTokenSupply ¶
WithGenesisTokenSupply sets the genesis token supply.
func WithScriptGasLimit ¶
WithScriptGasLimit sets the gas limit for scripts.
This limit does not affect transactions, which declare their own limit.
func WithServicePublicKey ¶
func WithServicePublicKey( servicePublicKey sdkcrypto.PublicKey, sigAlgo sdkcrypto.SignatureAlgorithm, hashAlgo sdkcrypto.HashAlgorithm, ) Option
WithServicePublicKey sets the service key from a public key.
func WithSimpleAddresses ¶
func WithSimpleAddresses() Option
WithSimpleAddresses enables simple addresses, which are sequential starting with 0x01.
func WithTransactionExpiry ¶
WithTransactionExpiry sets the transaction expiry measured in blocks.
If set to zero, transaction expiry is disabled and the reference block ID field is not required.
type PendingBlockCommitBeforeExecutionError ¶
type PendingBlockCommitBeforeExecutionError struct {
BlockID flowgo.Identifier
}
A PendingBlockCommitBeforeExecutionError indicates that the current pending block has not been executed (cannot commit).
func (*PendingBlockCommitBeforeExecutionError) Error ¶
func (e *PendingBlockCommitBeforeExecutionError) Error() string
type PendingBlockMidExecutionError ¶
type PendingBlockMidExecutionError struct {
BlockID flowgo.Identifier
}
A PendingBlockMidExecutionError indicates that the current pending block is mid-execution.
func (*PendingBlockMidExecutionError) Error ¶
func (e *PendingBlockMidExecutionError) Error() string
type PendingBlockTransactionsExhaustedError ¶
type PendingBlockTransactionsExhaustedError struct {
BlockID flowgo.Identifier
}
A PendingBlockTransactionsExhaustedError indicates that the current pending block has finished executing (no more transactions to execute).
func (*PendingBlockTransactionsExhaustedError) Error ¶
func (e *PendingBlockTransactionsExhaustedError) Error() string
type ServiceKey ¶
type ServiceKey struct { Index int Address sdk.Address SequenceNumber uint64 PrivateKey *sdkcrypto.PrivateKey PublicKey *sdkcrypto.PublicKey HashAlgo sdkcrypto.HashAlgorithm SigAlgo sdkcrypto.SignatureAlgorithm Weight int }
func DefaultServiceKey ¶
func DefaultServiceKey() ServiceKey
func GenerateDefaultServiceKey ¶
func GenerateDefaultServiceKey( sigAlgo sdkcrypto.SignatureAlgorithm, hashAlgo sdkcrypto.HashAlgorithm, ) ServiceKey
func (ServiceKey) AccountKey ¶
func (s ServiceKey) AccountKey() *sdk.AccountKey
func (ServiceKey) Signer ¶
func (s ServiceKey) Signer() sdkcrypto.Signer
type StorageError ¶
type StorageError struct {
// contains filtered or unexported fields
}
A StorageError indicates that an error occurred in the storage provider.
func (*StorageError) Error ¶
func (e *StorageError) Error() string
func (*StorageError) Unwrap ¶
func (e *StorageError) Unwrap() error
type TransactionNotFoundError ¶
type TransactionNotFoundError struct {
ID flowgo.Identifier
}
A TransactionNotFoundError indicates that a transaction could not be found.
func (*TransactionNotFoundError) Error ¶
func (e *TransactionNotFoundError) Error() string
type TransactionValidationError ¶
type TransactionValidationError interface {
// contains filtered or unexported methods
}
A TransactionValidationError indicates that a submitted transaction is invalid.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
backend/mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
Package storage defines the interface and implementations for interacting with persistent chain state.
|
Package storage defines the interface and implementations for interacting with persistent chain state. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
utils
|
|