walker

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	RETRY_DELAY   = 5 * time.Second  // for RPC and Database errors.
	POLL_INTERVAL = 60 * time.Second // average time between blocks.
	POLL_WAITING  = 10 * time.Second // polling interval when a block is due.
	POLL_FALLBACK = 90 * time.Second // fallback interval when using TipChaser.
)

Variables

This section is empty.

Functions

func ChainFromName

func ChainFromName(chainName string) (*doge.ChainParams, error)

chainFromName returns ChainParams for: 'main', 'test', 'regtest'.

func FindTheTip

func FindTheTip(ctx context.Context, client spec.Blockchain, blocksBelowTip int64) (hash string, height int64)

* Find a starting block near the tip of the chain. * * Use this if you don't need to walk the entire blockchain, but instead want to * start somewhere near the current tip of the chain. * * `ctx` allows cancellation/timeout, otherwise pass nil. * `client` must implement spec.Blockchain, e.g. `core.NewCoreRPCClient()` * `blocksBeforeTip` allows you to start e.g. 100 blocks before the current tip. * * Returns the hash and height of the tip, or a block before the tip.

func WalkTheDoge

func WalkTheDoge(opts WalkerOptions) (service governor.Service, blocks chan BlockOrUndo)

* WalkTheDoge walks the blockchain, keeping up with the Tip (Best Block) * * It outputs decoded blocks to the returned 'blocks' channel. * * If there's a reorganisation (fork), it will walk backwards to the * fork-point, building a list of blocks to undo, until it finds a block * that's still on the main chain. Then it will output UndoForkBlocks * to allow you to undo any data in your systems related to those blocks. * * Note: when you undo blocks, you will need to restore any UTXOs spent * by those blocks (spending blocks don't contain enough information to * re-create the spent UTXOs, so you must keep them for e.g. 100 blocks) * * `Chain`: a ChainParams instance containing the GenesisBlock hash. * e.g. doge.DogeMainNetChain or use `walker.ChainFromName` * * `LastProcessedBlock`: the last block hash you have processed * (i.e. stored in your database.) To start from the beginning of the * chain, pass "". Alternatively use `FindTheTip` to find a block * at or near the current tip of the blockchain. * * `FullUndoBlocks`: pass fully decoded blocks to the UndoForkBlocks callback. * Useful if you want to manually undo each transaction, rather than undoing * everything above `LastValidHeight` by tagging your data with block-heights. * * `TipChanged`: optional `chan string` to notify WalkTheDoge that a new block * has been broadcast on the Dogecoin network. e.g. `core.NewTipChaser` * If this is nil, WalkTheDoge will use a timer to poll Core.

Types

type BlockMetadata added in v0.0.14

type BlockMetadata struct {
	MedianTime uint64  // The median block time in seconds since UNIX epoch (Jan 1 1970 GMT)
	Difficulty float64 // The difficulty
	ChainWork  string  // Expected number of hashes required to produce the chain up to this block (hex)
	BlockSize  int     // The size of the block in bytes
}

type BlockOrUndo

type BlockOrUndo struct {
	LastProcessedBlock string          // the `LastProcessedBlock` hash to resume from (always)
	Height             int64           // the new block height (after this message is processed)
	Block              *ChainBlock     // either the next block in the chain
	Undo               *UndoForkBlocks // or an undo event (roll back blocks on a fork)
	Idle               bool            // or "idle" meaning we're at the tip of the blockchain
}

The type of the DogeWalker output channel; either block, undo or idle.

type ChainBlock

type ChainBlock struct {
	Hash     string        // hash of the block
	Height   int64         // height of the block
	Block    doge.Block    // decoded block header and transactions
	Metadata BlockMetadata // block metadata from Core Node
}

NextBlock represents the next block in the blockchain.

type UndoForkBlocks

type UndoForkBlocks struct {
	LastValidHeight int64         // undo all blocks greater than this height
	LastValidHash   string        // hash of the last on-chain block that's still valid
	UndoBlocks      []string      // hashes of blocks to be undone
	FullBlocks      []*ChainBlock // optional: present if FullUndoBlocks is true in WalkerOptions
}

UndoForkBlocks represents a Fork in the Blockchain: blocks to undo on the off-chain fork

type WalkerOptions

type WalkerOptions struct {
	Chain              *doge.ChainParams           // chain parameters, e.g. doge.DogeMainNetChain
	LastProcessedBlock string                      // last processed block hash to begin walking from (hex)
	Client             spec.Blockchain             // from NewCoreRPCClient()
	ChainEvents        <-chan spec.BlockchainEvent // from TipChaser()
	FullUndoBlocks     bool                        // fully decode blocks in UndoForkBlocks (or just hash and height)
	BufferBlocks       int                         // number of blocks to decode ahead of the consumer (channel size, default 10)
}

Configuraton for WalkTheDoge.

Jump to

Keyboard shortcuts

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