mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
9440126ddf
* Enable the `clique` option in the `--http.api` flag. * List of Clique commands: `clique_getSnapshot(block number)` `clique_getSnapshotAtHash(block hash)` `clique_getSnapshotAtHash(block hash)` `clique_getSigners(block number)` `clique_getSignersAtHash(block hash)` `clique_proposals()` `clique_propose(signer address, bool)` `clique_discard(signer address)` `clique_status()` Example: `curl --data '{"method":"clique_getSigners","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST http://localhost:8545` * Please be careful while using the Clique API. Do not make the HTTP API public on the Clique's signer node, as anyone can directly call a Clique command. Instead, it should only be allowed in the localhost by using the flag `--http.addr "127.0.0.1"`.
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
package consensus
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/chain"
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
)
|
|
|
|
// Implements consensus.ChainReader
|
|
type ChainReaderImpl struct {
|
|
Cfg chain.Config
|
|
Db kv.Getter
|
|
}
|
|
|
|
// Config retrieves the blockchain's chain configuration.
|
|
func (cr ChainReaderImpl) Config() *chain.Config {
|
|
return &cr.Cfg
|
|
}
|
|
|
|
// CurrentHeader retrieves the current header from the local chain.
|
|
func (cr ChainReaderImpl) CurrentHeader() *types.Header {
|
|
hash := rawdb.ReadHeadHeaderHash(cr.Db)
|
|
number := rawdb.ReadHeaderNumber(cr.Db, hash)
|
|
return rawdb.ReadHeader(cr.Db, hash, *number)
|
|
}
|
|
|
|
// GetHeader retrieves a block header from the database by hash and number.
|
|
func (cr ChainReaderImpl) GetHeader(hash libcommon.Hash, number uint64) *types.Header {
|
|
return rawdb.ReadHeader(cr.Db, hash, number)
|
|
}
|
|
|
|
// GetHeaderByNumber retrieves a block header from the database by number.
|
|
func (cr ChainReaderImpl) GetHeaderByNumber(number uint64) *types.Header {
|
|
hash, err := rawdb.ReadCanonicalHash(cr.Db, number)
|
|
if err != nil {
|
|
log.Error("ReadCanonicalHash failed", "err", err)
|
|
return nil
|
|
}
|
|
return rawdb.ReadHeader(cr.Db, hash, number)
|
|
}
|
|
|
|
// GetHeaderByHash retrieves a block header from the database by its hash.
|
|
func (cr ChainReaderImpl) GetHeaderByHash(hash libcommon.Hash) *types.Header {
|
|
number := rawdb.ReadHeaderNumber(cr.Db, hash)
|
|
return rawdb.ReadHeader(cr.Db, hash, *number)
|
|
}
|
|
|
|
// GetBlock retrieves a block from the database by hash and number.
|
|
func (cr ChainReaderImpl) GetBlock(hash libcommon.Hash, number uint64) *types.Block {
|
|
return rawdb.ReadBlock(cr.Db, hash, number)
|
|
}
|
|
|
|
// HasBlock retrieves a block from the database by hash and number.
|
|
func (cr ChainReaderImpl) HasBlock(hash libcommon.Hash, number uint64) bool {
|
|
return rawdb.HasBlock(cr.Db, hash, number)
|
|
}
|
|
|
|
// GetTd retrieves the total difficulty from the database by hash and number.
|
|
func (cr ChainReaderImpl) GetTd(hash libcommon.Hash, number uint64) *big.Int {
|
|
td, err := rawdb.ReadTd(cr.Db, hash, number)
|
|
if err != nil {
|
|
log.Error("ReadTd failed", "err", err)
|
|
return nil
|
|
}
|
|
return td
|
|
}
|