blockStorage

package
v0.0.0-...-5fa8bf8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockStorage

type BlockStorage interface {
	UpdateNewestBlock(newestBlockHash []byte)
	AddBlockHeader(blockHash []byte, bh *base.BlockHeader)
	AddBlock(block *base.Block)
	GetBlockHeader(blockHash []byte) (*base.BlockHeader, error)
	GetBlock(blockHash []byte) (*base.Block, error)
	GetNewestBlockHash() ([]byte, error)
	Close() error
}

BlockStorage 针对区块的持久化存储

type BoltStorage

type BoltStorage struct {
	DB *bolt.DB
	// contains filtered or unexported fields
}

BoltStorage 基于 bolt 实现的存储

func NewBoltStorage

func NewBoltStorage(nodeID uint) *BoltStorage

NewBoltStorage 创建BoltStorage nodeID指代节点的唯一ID

func (*BoltStorage) AddBlock

func (s *BoltStorage) AddBlock(block *base.Block)

AddBlock 存储区块

func (*BoltStorage) AddBlockHeader

func (s *BoltStorage) AddBlockHeader(blockHash []byte, bh *base.BlockHeader)

AddBlockHeader 存储区块头

func (*BoltStorage) Close

func (s *BoltStorage) Close() error

func (*BoltStorage) GetBlock

func (s *BoltStorage) GetBlock(blockHash []byte) (*base.Block, error)

GetBlock 获取区块

func (*BoltStorage) GetBlockHeader

func (s *BoltStorage) GetBlockHeader(blockHash []byte) (*base.BlockHeader, error)

GetBlockHeader 获取区块头

func (*BoltStorage) GetNewestBlockHash

func (s *BoltStorage) GetNewestBlockHash() ([]byte, error)

GetNewestBlockHash 获取最新区块的hash

func (*BoltStorage) UpdateNewestBlock

func (s *BoltStorage) UpdateNewestBlock(newestBlockHash []byte)

UpdateNewestBlock 更新newestBlockHashBucket中存储的"最新区块hash"

type RedisStorage

type RedisStorage struct {
}

func (RedisStorage) AddBlock

func (r RedisStorage) AddBlock(block *base.Block)

func (RedisStorage) AddBlockHeader

func (r RedisStorage) AddBlockHeader(blockHash []byte, bh *base.BlockHeader)

func (RedisStorage) Close

func (r RedisStorage) Close() error

func (RedisStorage) GetBlock

func (r RedisStorage) GetBlock(blockHash []byte) (*base.Block, error)

func (RedisStorage) GetBlockHeader

func (r RedisStorage) GetBlockHeader(blockHash []byte) (*base.BlockHeader, error)

func (RedisStorage) GetNewestBlockHash

func (r RedisStorage) GetNewestBlockHash() ([]byte, error)

func (RedisStorage) UpdateNewestBlock

func (r RedisStorage) UpdateNewestBlock(newestBlockHash []byte)

Jump to

Keyboard shortcuts

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