Documentation ¶
Overview ¶
Package blockfetcher aims to reduce boilerplate code that one needs to write over and over again when implementing a program that is processing blocks that are being fetched over steemd WebSocket RPC endpoint.
All you need from now in is to import this package and implement BlockProcessor interface, then run the block fetcher with your custom BlockProcessor implementation:
ctx, err := blockfetcher.Run(blockProcessor)
You can wait for the fetcher to be done by calling
err := ctx.Wait()
In case you want to interrupt the process, just call
ctx.Interrupt() err := ctx.Wait()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockProcessor ¶
type BlockProcessor interface { // BlockRange is called at the beginning to let the block fetching logic know // what blocks to fetch and pass to ProcessBlock. // // In case blockRangeTo returned is 0, the fetcher will keep fetching new blocks // forever as they arrive (until interrupted, of course). BlockRange() (blockRangeFrom, blockRangeTo uint32) // ProcessBlock is called when a new block is received. ProcessBlock(block *database.Block) error // Finalize is called when the whole block range is fetcher or the process is interrupted. Finalize() error }
BlockProcessor is the interface that represents the block processing logic.
When an error is returned from any for the following methods, the fetching process is interrupted and Finalize() is called.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents a running block fetcher that can be interrupted.
func Run ¶
func Run(client *rpc.Client, processor BlockProcessor) (*Context, error)
Run spawns a new block fetcher using the given BlockProcessor.
The fetcher keeps fetching blocks until the whole block range specified is fetched or an error is encountered. It is not trying to be clever about closed connections and such.
client.Close() is not called by this package, it has to be called manually.