rpcutils

package
v2.1.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2018 License: ISC Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 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 dcrd 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 GetBlock added in v0.3.2

func GetBlock(ind int64, client *rpcclient.Client) (*dcrutil.Block, *chainhash.Hash, error)

GetBlock gets a block at the given height from a chain server.

func GetBlockByHash

func GetBlockByHash(blockhash *chainhash.Hash, client *rpcclient.Client) (*dcrutil.Block, error)

GetBlockByHash gets the block with the given hash from a chain server.

func GetBlockHeaderVerbose

func GetBlockHeaderVerbose(client *rpcclient.Client, params *chaincfg.Params,
	idx int64) *dcrjson.GetBlockHeaderVerboseResult

GetBlockHeaderVerbose creates a *dcrjson.GetBlockHeaderVerboseResult for the block index specified by idx via an RPC connection to a chain server.

func GetBlockVerbose added in v0.7.0

func GetBlockVerbose(client *rpcclient.Client, params *chaincfg.Params,
	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 added in v0.7.0

func GetBlockVerboseByHash(client *rpcclient.Client, params *chaincfg.Params,
	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

func GetStakeDiffEstimates(client *rpcclient.Client) *apitypes.StakeDiff

GetStakeDiffEstimates combines the results of EstimateStakeDiff and GetStakeDifficulty into a *apitypes.StakeDiff.

func GetTransactionVerboseByID

func GetTransactionVerboseByID(client *rpcclient.Client, txid string) (*dcrjson.TxRawResult, error)

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 UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockGate

type BlockGate struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BlockGate is an implementation of MasterBlockGetter with cache

func NewBlockGate

func NewBlockGate(client *rpcclient.Client, capacity int) *BlockGate

NewBlockGate constructs a new BlockGate, wrapping an RPC client, with a specified block cache capacity.

func (*BlockGate) BestBlock

func (g *BlockGate) BestBlock() (*dcrutil.Block, error)

BestBlock gets the best block in cache.

func (*BlockGate) BestBlockHash

func (g *BlockGate) BestBlockHash() (chainhash.Hash, int64, error)

BestBlockHash gets the hash and height of the best block in cache.

func (*BlockGate) BestBlockHeight

func (g *BlockGate) BestBlockHeight() int64

BestBlockHeight gets the best block height in the block cache.

func (*BlockGate) Block

func (g *BlockGate) Block(hash chainhash.Hash) (*dcrutil.Block, error)

Block attempts to get the block with the specified hash from cache.

func (*BlockGate) NodeHeight

func (g *BlockGate) NodeHeight() (int64, error)

NodeHeight gets the chain height from dcrd.

func (*BlockGate) SetFetchToHeight

func (g *BlockGate) SetFetchToHeight(height int64)

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

func (g *BlockGate) UpdateToBestBlock() (*dcrutil.Block, error)

UpdateToBestBlock gets the best block via RPC and updates the cache.

func (*BlockGate) UpdateToBlock

func (g *BlockGate) UpdateToBlock(height int64) (*dcrutil.Block, error)

UpdateToBlock gets the block at the specified height on the main chain from dcrd and stores it in cache.

func (*BlockGate) UpdateToNextBlock

func (g *BlockGate) UpdateToNextBlock() (*dcrutil.Block, error)

UpdateToNextBlock gets the next block following the best in cache via RPC and updates the cache.

func (*BlockGate) WaitForHash

func (g *BlockGate) WaitForHash(hash chainhash.Hash) chan int64

WaitForHash provides a notification channel for signaling to the caller when the block with the specified hash is available.

func (*BlockGate) WaitForHeight

func (g *BlockGate) WaitForHeight(height int64) chan chainhash.Hash

WaitForHeight provides a notification channel for signaling to the caller when the block at the specified height 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 dcrd via RPC and subsequently update the internal block cache with the retrieved block.

Jump to

Keyboard shortcuts

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