Blockchain

class Blockchain(val chainSelector: ChainSelector, val name: String, val net: CnxnMgr, val genesisBlockHash: Hash256, var checkpointPriorBlockId: Hash256, var checkpointId: Hash256, var checkpointHeight: Long, var checkpointWork: BigInteger, val dbPrefix: String = "blkhdr_", var fullSync: Boolean = true)

Access and track a blockchain

Parameters

chainSelector

Specify which blockchain to track.

name

You may give this blockchain a name, for logging.

net

Provide an object that manages connections to blockchain data providers (full and electrum nodes).

genesisBlockHash

Specify the genesis block hash for this blockchain

checkpointPriorBlockId

Specify the block hash of the parent of your chosen checkpoint. Use Hash256() if you are using the genesis block as your checkpoint.

checkpointId

Specify the block hash for your chosen checkpoint. A checkpoint is a block that is known to be on the main chain. The blockchain will start headers sync from this point. Some blockchain implementations (BCH) cannot rewind prior to this point to access wallet data. You may use the genesis block as your checkpoint.

checkpointHeight

Specify the block height of this checkpoint?

checkpointWork

Specify the cumulative work (NOT THE BLOCK WORK) of all prior blocks including the checkpoint block. This information is available in block explorers, or via the full node getblock RPC call.

dbPrefix

Block headers are stored in a database. Specify a prefix for DB name here (default is "blkhdr_"). The full name will be dbPrefix_name.db.

Constructors

Link copied to clipboard
constructor(chainSelector: ChainSelector, name: String, net: CnxnMgr, genesisBlockHash: Hash256, checkpointPriorBlockId: Hash256, checkpointId: Hash256, checkpointHeight: Long, checkpointWork: BigInteger, dbPrefix: String = "blkhdr_", fullSync: Boolean = true)

Properties

Link copied to clipboard
Link copied to clipboard

Increase this to increase the interval of time before a bloom filter needs to be refreshed. Bloom filters are modified by full nodes to automatically include information "of interest" based on current "of interest" information. For example if a tx is interesting, then its outputs will be added into the bloom filter. But the existence of false positives (and because the wallet is likely interested in only a subset of the outputs) means that the bloom filter will slowly fill up with useless information. Setting this multiplier the N will make a bloom filter that is N times your current data size meet the bloomFalsePositiveRate.

Link copied to clipboard

Change this to increase privacy at the expense of bandwidth

Link copied to clipboard
Link copied to clipboard

wake up the blockchain header processing loop

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var checkpointWork: BigInteger
Link copied to clipboard
Link copied to clipboard
lateinit var db: BlockHeaderDatabase
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

installable callback for when some blockchain or connection state changes

Link copied to clipboard
var processingThread: iThread?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val wakey: iGate

Functions

Link copied to clipboard

Return the ancestor of the passed block at the passed height, or the iBlockHeader of the passed hash is the height is larger. Throws RequestedPrehistoryHeader if you go back too far.

Link copied to clipboard

Add a wallet to start accessing the blockchain The blockchain will stop updating if no wallets are attached

Link copied to clipboard

Return the header corresponding to this hash.

Return the main chain block header at this height.

Link copied to clipboard

Takes a chain tip and produces a set of blocks that on that chain that allow someone to find the approximate fork location if they are on a different tip

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun detachWallet(filterHandle: Int?)

remove a wallet from accessing this blockchain Right now its 1 wallet per chain, so stop this chain, but keep the DB around for a new wallet

Link copied to clipboard
Link copied to clipboard
fun finalize()
Link copied to clipboard

In rare cases of a tie where one block is invalid, this will kick the wallet over to a different block.

Link copied to clipboard

Returns the header nearest to but before the passed epoch time. If the passed epoch time is later than the tip, the tip is returned.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun getHeaderChain(height: Long, hash: Hash256, endAt: Hash256, maxCount: Int = Int.MAX_VALUE): MutableList<iBlockHeader>
Link copied to clipboard

return the cached tip or recalculate it if it is null. Returns null if the tip cannot be determined

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun invHandler(invLst: List<Inv>, source: P2pClient?)
Link copied to clipboard
fun isInMostWorkChain(height: Long, hash: Hash256): Boolean

return true if the passed block is on the most work chain

Link copied to clipboard

Attach these headers to existing chains in our DB and commit them. The passed hdrs list are expected to be in parent->child order

Link copied to clipboard
fun reacquireHeaders(height: Long, endAt: Hash256)

Download and save some headers that aren't at the end of the blockchain

Link copied to clipboard

Rediscover the chain tip by looking at the block header database

Link copied to clipboard

Erase all previous blockchain knowledge and re-download it

Link copied to clipboard
fun restart()

Restart block processing after stop is called

Link copied to clipboard
fun run()
Link copied to clipboard
fun setFilterObjects(objects: Array<Any>, handle: Int?, onBloomInstalled: () -> Unit?): Int

tell all nodes, including future connections, that we are only interested in these things. a handle to this data is returned that can be used to update or delete the data. Pass null to create a new entry This blockchain will take data from all callers, and combine them into a single Bloom filter for installation into connected full nodes.

Link copied to clipboard
Link copied to clipboard
fun start()
Link copied to clipboard
fun stop()

Stop processing incoming blocks. You may call restart to resume processing

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun updateBloomFilter(onBloomInstalled: () -> Unit?)

Get all filter data connected wallets have offered us, and install it into all of our connections. Once all bloom filters are installed, call the passed callback.