Documentation
¶
Index ¶
- Variables
- func BuildBlockHeaderVerbose(header *wire.BlockHeader, params *chaincfg.Params, currentHeight int64, ...) *dcrjson.GetBlockHeaderVerboseResult
- func CommonAncestor(client *rpcclient.Client, hashA, hashB chainhash.Hash) (*chainhash.Hash, []chainhash.Hash, []chainhash.Hash, error)
- func ConnectNodeRPC(host, user, pass, cert string, disableTLS bool, ...) (*rpcclient.Client, semver.Semver, error)
- func DisableLog()
- func GetBlock(ind int64, client *rpcclient.Client) (*dcrutil.Block, *chainhash.Hash, error)
- func GetBlockByHash(blockhash *chainhash.Hash, client *rpcclient.Client) (*dcrutil.Block, error)
- func GetBlockHeaderVerbose(client *rpcclient.Client, idx int64) *dcrjson.GetBlockHeaderVerboseResult
- func GetBlockHeaderVerboseByString(client *rpcclient.Client, hash string) *dcrjson.GetBlockHeaderVerboseResult
- func GetBlockVerbose(client *rpcclient.Client, idx int64, verboseTx bool) *dcrjson.GetBlockVerboseResult
- func GetBlockVerboseByHash(client *rpcclient.Client, hash string, verboseTx bool) *dcrjson.GetBlockVerboseResult
- func GetStakeDiffEstimates(client *rpcclient.Client) *apitypes.StakeDiff
- func GetTransactionVerboseByID(client *rpcclient.Client, txid string) (*dcrjson.TxRawResult, error)
- func SearchRawTransaction(client *rpcclient.Client, count int, address string) ([]*dcrjson.SearchRawTransactionsResult, error)
- func SideChainFull(client *rpcclient.Client, tipHash string) ([]string, error)
- func SideChains(client *rpcclient.Client) ([]dcrjson.GetChainTipsResult, error)
- func UseLogger(logger slog.Logger)
- type BlockGate
- func (g *BlockGate) BestBlock() (*dcrutil.Block, error)
- func (g *BlockGate) BestBlockHash() (chainhash.Hash, int64, error)
- func (g *BlockGate) BestBlockHeight() int64
- func (g *BlockGate) Block(hash chainhash.Hash) (*dcrutil.Block, error)
- func (g *BlockGate) NodeHeight() (int64, error)
- func (g *BlockGate) SetFetchToHeight(height int64)
- func (g *BlockGate) UpdateToBestBlock() (*dcrutil.Block, error)
- func (g *BlockGate) UpdateToBlock(height int64) (*dcrutil.Block, error)
- func (g *BlockGate) UpdateToNextBlock() (*dcrutil.Block, error)
- func (g *BlockGate) WaitForHash(hash chainhash.Hash) chan int64
- func (g *BlockGate) WaitForHeight(height int64) chan chainhash.Hash
- type BlockGetter
- type MasterBlockGetter
Constants ¶
This section is empty.
Variables ¶
var ( ErrAncestorAtGenesis = errors.New("no ancestor: at genesis") ErrAncestorMaxChainLength = errors.New("no ancestor: max chain length reached") )
Functions ¶
func BuildBlockHeaderVerbose ¶
func BuildBlockHeaderVerbose(header *wire.BlockHeader, params *chaincfg.Params, currentHeight int64, nextHash ...string) *dcrjson.GetBlockHeaderVerboseResult
BuildBlockHeaderVerbose creates a *dcrjson.GetBlockHeaderVerboseResult from an input *wire.BlockHeader and current best block height, which is used to compute confirmations. The next block hash may optionally be provided.
func CommonAncestor ¶
func CommonAncestor(client *rpcclient.Client, hashA, hashB chainhash.Hash) (*chainhash.Hash, []chainhash.Hash, []chainhash.Hash, error)
CommonAncestor attempts to determine the common ancestor block for two chains specified by the hash of the chain tip block. The full chains from the tips back to but not including the common ancestor are also returned. The first element in the chain slices is the lowest block following the common ancestor, while the last element is the chain tip. The common ancestor will never by one of the chain tips. Thus, if one of the chain tips is on the other chain, that block will be shared between the two chains, and the common ancestor will be the previous block. However, the intended use of this function is to find a common ancestor for two chains with no common blocks.
func ConnectNodeRPC ¶
func ConnectNodeRPC(host, user, pass, cert string, disableTLS bool, ntfnHandlers ...*rpcclient.NotificationHandlers) (*rpcclient.Client, semver.Semver, error)
ConnectNodeRPC attempts to create a new websocket connection to a pfcd node, with the given credentials and optional notification handlers.
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func GetBlockByHash ¶
GetBlockByHash gets the block with the given hash from a chain server.
func GetBlockHeaderVerbose ¶
func GetBlockHeaderVerbose(client *rpcclient.Client, idx int64) *dcrjson.GetBlockHeaderVerboseResult
GetBlockHeaderVerbose creates a *dcrjson.GetBlockHeaderVerboseResult for the block at height idx via an RPC connection to a chain server.
func GetBlockHeaderVerboseByString ¶
func GetBlockHeaderVerboseByString(client *rpcclient.Client, hash string) *dcrjson.GetBlockHeaderVerboseResult
GetBlockHeaderVerboseByString creates a *dcrjson.GetBlockHeaderVerboseResult for the block specified by hash via an RPC connection to a chain server.
func GetBlockVerbose ¶
func GetBlockVerbose(client *rpcclient.Client, idx int64, verboseTx bool) *dcrjson.GetBlockVerboseResult
GetBlockVerbose creates a *dcrjson.GetBlockVerboseResult for the block index specified by idx via an RPC connection to a chain server.
func GetBlockVerboseByHash ¶
func GetBlockVerboseByHash(client *rpcclient.Client, hash string, verboseTx bool) *dcrjson.GetBlockVerboseResult
GetBlockVerboseByHash creates a *dcrjson.GetBlockVerboseResult for the specified block hash via an RPC connection to a chain server.
func GetStakeDiffEstimates ¶
GetStakeDiffEstimates combines the results of EstimateStakeDiff and GetStakeDifficulty into a *apitypes.StakeDiff.
func GetTransactionVerboseByID ¶
GetTransactionVerboseByID get a transaction by transaction id
func SearchRawTransaction ¶
func SearchRawTransaction(client *rpcclient.Client, count int, address string) ([]*dcrjson.SearchRawTransactionsResult, error)
SearchRawTransaction fetch transactions the belong to an address
func SideChainFull ¶
SideChainFull gets all of the blocks in the side chain with the specified tip block hash. The first block in the slice is the lowest height block in the side chain, and its previous block is the main/side common ancestor, which is not included in the slice since it is main chain. The last block in the slice is thus the side chain tip.
func SideChains ¶
func SideChains(client *rpcclient.Client) ([]dcrjson.GetChainTipsResult, error)
SideChains gets a slice of known side chain tips. This corresponds to the results of the getchaintips node RPC where the block tip "status" is either "valid-headers" or "valid-fork".
Types ¶
type BlockGate ¶
BlockGate is an implementation of MasterBlockGetter with cache
func NewBlockGate ¶
NewBlockGate constructs a new BlockGate, wrapping an RPC client, with a specified block cache capacity.
func (*BlockGate) BestBlockHash ¶
BestBlockHash gets the hash and height of the best block in cache.
func (*BlockGate) BestBlockHeight ¶
BestBlockHeight gets the best block height in the block cache.
func (*BlockGate) NodeHeight ¶
NodeHeight gets the chain height from pfcd.
func (*BlockGate) SetFetchToHeight ¶
SetFetchToHeight sets the height up to which WaitForHeight will trigger an RPC to retrieve the block immediately. For the given height and up, WaitForHeight will only return a notification channel.
func (*BlockGate) UpdateToBestBlock ¶
UpdateToBestBlock gets the best block via RPC and updates the cache.
func (*BlockGate) UpdateToBlock ¶
UpdateToBlock gets the block at the specified height on the main chain from pfcd and stores it in cache.
func (*BlockGate) UpdateToNextBlock ¶
UpdateToNextBlock gets the next block following the best in cache via RPC and updates the cache.
func (*BlockGate) WaitForHash ¶
WaitForHash provides a notification channel for signaling to the caller when the block with the specified hash is available.
type BlockGetter ¶
type BlockGetter interface { NodeHeight() (int64, error) BestBlockHeight() int64 BestBlockHash() (chainhash.Hash, int64, error) BestBlock() (*dcrutil.Block, error) Block(chainhash.Hash) (*dcrutil.Block, error) WaitForHeight(int64) chan chainhash.Hash WaitForHash(chainhash.Hash) chan int64 }
BlockGetter is an interface for requesting blocks
type MasterBlockGetter ¶
type MasterBlockGetter interface { BlockGetter UpdateToBestBlock() (*dcrutil.Block, error) UpdateToNextBlock() (*dcrutil.Block, error) UpdateToBlock(height int64) (*dcrutil.Block, error) }
MasterBlockGetter builds on BlockGetter, adding functions that fetch blocks directly from pfcd via RPC and subsequently update the internal block cache with the retrieved block.