blockchain

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParentDoesNotMatchHead = errors.New("block's parent hash does not match head block hash")
)

Functions

func BlockByNumber added in v0.4.0

func BlockByNumber(txn db.Transaction, number uint64) (*core.Block, error)

BlockByNumber retrieves a block from database by its number

func MakeStateDiffForEmptyBlock added in v0.7.5

func MakeStateDiffForEmptyBlock(bc Reader, blockNumber uint64) (*core.StateDiff, error)

func RegisterCoreTypesToEncoder added in v0.4.0

func RegisterCoreTypesToEncoder()

func StoreBlockCommitments added in v0.6.0

func StoreBlockCommitments(txn db.Transaction, blockNumber uint64, commitments *core.BlockCommitments) error

func StoreBlockHeader added in v0.4.0

func StoreBlockHeader(txn db.Transaction, header *core.Header) error

StoreBlockHeader stores the given block in the database. The db storage for blocks is maintained by two buckets as follows:

db.BlockHeaderNumbersByHash(BlockHash) -> (BlockNumber) db.BlockHeadersByNumber(BlockNumber) -> (BlockHeader)

"[]" is the db prefix to represent a bucket "()" are additional keys appended to the prefix or multiple values marshalled together "->" represents a key value pair.

Types

type Blockchain

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

Blockchain is responsible for keeping track of all things related to the Starknet blockchain

func New

func New(database db.DB, network *utils.Network) *Blockchain

func (*Blockchain) BlockByHash added in v0.2.1

func (b *Blockchain) BlockByHash(hash *felt.Felt) (*core.Block, error)

func (*Blockchain) BlockByNumber added in v0.2.1

func (b *Blockchain) BlockByNumber(number uint64) (*core.Block, error)

func (*Blockchain) BlockCommitmentsByNumber added in v0.6.0

func (b *Blockchain) BlockCommitmentsByNumber(blockNumber uint64) (*core.BlockCommitments, error)

func (*Blockchain) BlockHeaderByHash added in v0.2.1

func (b *Blockchain) BlockHeaderByHash(hash *felt.Felt) (*core.Header, error)

func (*Blockchain) BlockHeaderByNumber added in v0.2.1

func (b *Blockchain) BlockHeaderByNumber(number uint64) (*core.Header, error)

func (*Blockchain) EventFilter added in v0.3.1

func (b *Blockchain) EventFilter(from *felt.Felt, keys [][]felt.Felt) (*EventFilter, error)

EventFilter returns an EventFilter object that is tied to a snapshot of the blockchain

func (*Blockchain) Head

func (b *Blockchain) Head() (*core.Block, error)

func (*Blockchain) HeadState added in v0.3.0

func (b *Blockchain) HeadState() (core.StateReader, StateCloser, error)

HeadState returns a StateReader that provides a stable view to the latest state

func (*Blockchain) HeadsHeader

func (b *Blockchain) HeadsHeader() (*core.Header, error)

func (*Blockchain) Height

func (b *Blockchain) Height() (uint64, error)

Height returns the latest block height. If blockchain is empty nil is returned.

func (*Blockchain) L1Head added in v0.4.0

func (b *Blockchain) L1Head() (*core.L1Head, error)

func (*Blockchain) Network

func (b *Blockchain) Network() *utils.Network

func (*Blockchain) Pending added in v0.4.0

func (b *Blockchain) Pending() (Pending, error)

Pending returns the pending block from the database

func (*Blockchain) PendingState added in v0.4.0

func (b *Blockchain) PendingState() (core.StateReader, StateCloser, error)

PendingState returns the state resulting from execution of the pending block

func (*Blockchain) Receipt added in v0.2.1

func (b *Blockchain) Receipt(hash *felt.Felt) (*core.TransactionReceipt, *felt.Felt, uint64, error)

Receipt gets the transaction receipt for a given transaction hash.

func (*Blockchain) RevertHead added in v0.4.0

func (b *Blockchain) RevertHead() error

RevertHead reverts the head block

func (*Blockchain) SanityCheckNewHeight

func (b *Blockchain) SanityCheckNewHeight(block *core.Block, stateUpdate *core.StateUpdate,
	newClasses map[felt.Felt]core.Class,
) (*core.BlockCommitments, error)

SanityCheckNewHeight checks integrity of a block and resulting state update

func (*Blockchain) SetL1Head added in v0.4.0

func (b *Blockchain) SetL1Head(update *core.L1Head) error

func (*Blockchain) StateAtBlockHash added in v0.3.0

func (b *Blockchain) StateAtBlockHash(blockHash *felt.Felt) (core.StateReader, StateCloser, error)

StateAtBlockHash returns a StateReader that provides a stable view to the state at the given block hash

func (*Blockchain) StateAtBlockNumber added in v0.3.0

func (b *Blockchain) StateAtBlockNumber(blockNumber uint64) (core.StateReader, StateCloser, error)

StateAtBlockNumber returns a StateReader that provides a stable view to the state at the given block number

func (*Blockchain) StateCommitment

func (b *Blockchain) StateCommitment() (*felt.Felt, error)

StateCommitment returns the latest block state commitment. If blockchain is empty zero felt is returned.

func (*Blockchain) StateUpdateByHash added in v0.2.1

func (b *Blockchain) StateUpdateByHash(hash *felt.Felt) (*core.StateUpdate, error)

func (*Blockchain) StateUpdateByNumber added in v0.2.1

func (b *Blockchain) StateUpdateByNumber(number uint64) (*core.StateUpdate, error)

func (*Blockchain) Store

func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommitments,
	stateUpdate *core.StateUpdate, newClasses map[felt.Felt]core.Class,
) error

Store takes a block and state update and performs sanity checks before putting in the database.

func (*Blockchain) StorePending added in v0.4.0

func (b *Blockchain) StorePending(pending *Pending) error

StorePending stores a pending block given that it is for the next height

func (*Blockchain) TransactionByBlockNumberAndIndex added in v0.2.1

func (b *Blockchain) TransactionByBlockNumberAndIndex(blockNumber, index uint64) (core.Transaction, error)

TransactionByBlockNumberAndIndex gets the transaction for a given block number and index.

func (*Blockchain) TransactionByHash added in v0.2.1

func (b *Blockchain) TransactionByHash(hash *felt.Felt) (core.Transaction, error)

TransactionByHash gets the transaction for a given hash.

func (*Blockchain) VerifyBlock

func (b *Blockchain) VerifyBlock(block *core.Block) error

VerifyBlock assumes the block has already been sanity-checked.

func (*Blockchain) WithListener added in v0.7.4

func (b *Blockchain) WithListener(listener EventListener) *Blockchain

type ContinuationToken added in v0.3.1

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

func (*ContinuationToken) FromString added in v0.3.1

func (c *ContinuationToken) FromString(str string) error

func (*ContinuationToken) String added in v0.3.1

func (c *ContinuationToken) String() string

type EventFilter added in v0.3.1

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

func (*EventFilter) Close added in v0.3.1

func (e *EventFilter) Close() error

Close closes the underlying database transaction that provides the blockchain snapshot

func (*EventFilter) Events added in v0.3.1

func (e *EventFilter) Events(cToken *ContinuationToken, chunkSize uint64) ([]*FilteredEvent, *ContinuationToken, error)

func (*EventFilter) SetRangeEndBlockByHash added in v0.3.1

func (e *EventFilter) SetRangeEndBlockByHash(filterRange EventFilterRange, blockHash *felt.Felt) error

SetRangeEndBlockByHash sets an end of the block range by block hash

func (*EventFilter) SetRangeEndBlockByNumber added in v0.3.1

func (e *EventFilter) SetRangeEndBlockByNumber(filterRange EventFilterRange, blockNumber uint64) error

SetRangeEndBlockByNumber sets an end of the block range by block number

func (*EventFilter) WithLimit added in v0.7.5

func (e *EventFilter) WithLimit(limit uint) *EventFilter

WithLimit sets the limit for events scan

type EventFilterRange added in v0.3.1

type EventFilterRange uint
const (
	EventFilterFrom EventFilterRange = iota
	EventFilterTo
)

type EventListener added in v0.7.4

type EventListener interface {
	OnRead(method string)
}

type FilteredEvent added in v0.3.1

type FilteredEvent struct {
	*core.Event
	BlockNumber     uint64
	BlockHash       *felt.Felt
	TransactionHash *felt.Felt
}

type Pending added in v0.4.0

type Pending struct {
	Block       *core.Block
	StateUpdate *core.StateUpdate
	NewClasses  map[felt.Felt]core.Class
}

type PendingState added in v0.4.0

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

func NewPendingState added in v0.4.0

func NewPendingState(stateDiff *core.StateDiff, newClasses map[felt.Felt]core.Class, head core.StateReader) *PendingState

func (*PendingState) Class added in v0.4.0

func (p *PendingState) Class(classHash *felt.Felt) (*core.DeclaredClass, error)

func (*PendingState) ContractClassHash added in v0.4.0

func (p *PendingState) ContractClassHash(addr *felt.Felt) (*felt.Felt, error)

func (*PendingState) ContractNonce added in v0.4.0

func (p *PendingState) ContractNonce(addr *felt.Felt) (*felt.Felt, error)

func (*PendingState) ContractStorage added in v0.4.0

func (p *PendingState) ContractStorage(addr, key *felt.Felt) (*felt.Felt, error)

type Reader

type Reader interface {
	Height() (height uint64, err error)

	Head() (head *core.Block, err error)
	L1Head() (*core.L1Head, error)
	BlockByNumber(number uint64) (block *core.Block, err error)
	BlockByHash(hash *felt.Felt) (block *core.Block, err error)

	HeadsHeader() (header *core.Header, err error)
	BlockHeaderByNumber(number uint64) (header *core.Header, err error)
	BlockHeaderByHash(hash *felt.Felt) (header *core.Header, err error)

	TransactionByHash(hash *felt.Felt) (transaction core.Transaction, err error)
	TransactionByBlockNumberAndIndex(blockNumber, index uint64) (transaction core.Transaction, err error)
	Receipt(hash *felt.Felt) (receipt *core.TransactionReceipt, blockHash *felt.Felt, blockNumber uint64, err error)
	StateUpdateByNumber(number uint64) (update *core.StateUpdate, err error)
	StateUpdateByHash(hash *felt.Felt) (update *core.StateUpdate, err error)

	HeadState() (core.StateReader, StateCloser, error)
	StateAtBlockHash(blockHash *felt.Felt) (core.StateReader, StateCloser, error)
	StateAtBlockNumber(blockNumber uint64) (core.StateReader, StateCloser, error)
	PendingState() (core.StateReader, StateCloser, error)

	BlockCommitmentsByNumber(blockNumber uint64) (*core.BlockCommitments, error)

	EventFilter(from *felt.Felt, keys [][]felt.Felt) (*EventFilter, error)

	Pending() (Pending, error)

	Network() *utils.Network
}

type SelectiveListener added in v0.7.4

type SelectiveListener struct {
	OnReadCb func(method string)
}

func (*SelectiveListener) OnRead added in v0.7.4

func (l *SelectiveListener) OnRead(method string)

type StateCloser added in v0.3.0

type StateCloser = func() error

Jump to

Keyboard shortcuts

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