Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrBlockNotFound is returned when looking for a block that is not in the chain. ErrBlockNotFound = errors.New("block not found in the chain") // ErrBlockNumberIncorrect is returned when adding a block with a bad number. ErrBlockNumberIncorrect = errors.New("block number does not correspond to hash") // ErrInvalidPreviousBlock is returned when adding a block with a bad number or previous hash. ErrInvalidPreviousBlock = errors.New("link to previous block is invalid") )
View Source
var OptGenesisBlock = func(genesis *pb.Block) Opt { if genesis.BlockNumber() != 0 { panic("Genesis block should have number 0") } return func(c *chainDB) { if err := c.AddBlock(genesis); err != nil { panic(err) } if err := c.SetHead(genesis); err != nil { panic(err) } } }
OptGenesisBlock sets the genesis block for the chain.
View Source
var OptPrefix = func(prefix []byte) Opt {
return func(c *chainDB) {
c.prefix = prefix
}
}
OptPrefix sets a prefix for all the database keys.
Functions ¶
Types ¶
type Reader ¶
type Reader interface { // Config retrieves the blockchain's chain configuration. Config() *Config // CurrentHeader retrieves the current header from the local chain. CurrentHeader() (*pb.Header, error) // GetHeadersByNumber retrieves block headers from the database by number. // In case of forks there might be multiple headers with the same number, GetHeadersByNumber(number uint64) ([]*pb.Header, error) // GetHeaderByNumber retrieves a header from the main branch by number. GetHeaderByNumber(number uint64) (*pb.Header, error) // GetHeaderByHash retrieves a block header from the database by its hash. GetHeaderByHash(hash []byte) (*pb.Header, error) // CurrentBlock retrieves the current block from the local chain. CurrentBlock() (*pb.Block, error) // GetBlock retrieves a block from the database by header hash and number. GetBlock(hash []byte, number uint64) (*pb.Block, error) // GetBlockByHash retrieves a block from the database by header hash. GetBlockByHash(hash []byte) (*pb.Block, error) // GetBlockByNumber retrieves a block from the main branch by number. GetBlockByNumber(number uint64) (*pb.Block, error) // GetParentBlock retrieves the header's parent block. GetParentBlock(header *pb.Header) (*pb.Block, error) }
Reader defines a small collection of methods needed to access the local blockchain.
Click to show internal directories.
Click to hide internal directories.