hcdataapi

package
v0.0.0-...-9342d9d Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: ISC Imports: 8 Imported by: 9

Documentation

Index

Constants

View Source
const (
	SecondsPerMinute int64 = 60
	SecondsPerHour   int64 = 60 * 60
	SecondsPerDay    int64 = 24 * SecondsPerHour
	SecondsPerWeek   int64 = 7 * SecondsPerDay
)

constants from time

Variables

This section is empty.

Functions

func LessByAccessCount

func LessByAccessCount(bi, bj *CachedBlock) bool

LessByAccessCount defines higher priority CachedBlock as having been accessed more often.

func LessByAccessCountThenHeight

func LessByAccessCountThenHeight(bi, bj *CachedBlock) bool

LessByAccessCountThenHeight compares access count with LessByAccessCount if the blocks have different accessTime values, otherwise it compares height with LessByHeight.

func LessByAccessTime

func LessByAccessTime(bi, bj *CachedBlock) bool

LessByAccessTime defines higher priority CachedBlock as having a more recent access time. More recent accesses have a larger accessTime value (Unix time).

func LessByHeight

func LessByHeight(bi, bj *CachedBlock) bool

LessByHeight defines a higher priority CachedBlock as having a higher height. That is, more recent blocks have higher priority than older blocks.

func MakeLessByAccessTimeThenCount

func MakeLessByAccessTimeThenCount(millisecondsBinned int64) func(bi, bj *CachedBlock) bool

MakeLessByAccessTimeThenCount will create a CachedBlock comparison function given the specified time resolution in milliseconds. Two access times less than the given time apart are considered the same time, and access count is used to break the tie.

func WatchPriorityQueue

func WatchPriorityQueue(bpq *BlockPriorityQueue)

WatchPriorityQueue is a hack since the priority of a CachedBlock is modified (if access or access time is in the LessFn) without triggering a reheap.

Types

type APICache

type APICache struct {
	sync.RWMutex

	MainchainBlocks []chainhash.Hash // needs to be handled in reorg
	// contains filtered or unexported fields
}

APICache maintains a fixed-capacity cache of CachedBlocks. Use NewAPICache to create the cache with the desired capacity.

func NewAPICache

func NewAPICache(capacity uint32) *APICache

NewAPICache creates an APICache with the specified capacity.

NOTE: The consumer of APICache should fill out MainChainBlocks before using it. For example, given a struct DB at height dbHeight with an APICache:

 DB.APICache = NewAPICache(10000)
	DB.APICache.MainchainBlocks = make([]chainhash.Hash, 0, dbHeight+NExtra)
	for i := int64(0); i <= dbHeight; i++ {
		hash := DB.SomeFunctionToGetBlockHash(i)
		DB.APICache.MainchainBlocks = append(DB.APICache.MainchainBlocks, *hash)
	}

func (*APICache) Capacity

func (apic *APICache) Capacity() uint32

Capacity returns the capacity of the APICache

func (*APICache) Disable

func (apic *APICache) Disable()

Disable sets the isEnabled flag of the APICache. The does little presently.

func (*APICache) Enable

func (apic *APICache) Enable()

Enable sets the isEnabled flag of the APICache. The does little presently.

func (*APICache) GetBlockSummary

func (apic *APICache) GetBlockSummary(height int64) *BlockDataBasic

GetBlockSummary attempts to retrieve the block summary for the input height. The return is nil if no block with that height is cached.

func (*APICache) GetCachedBlockByHash

func (apic *APICache) GetCachedBlockByHash(hash chainhash.Hash) *CachedBlock

GetCachedBlockByHash attempts to fetch a CachedBlock with the given hash. The return is nil if no block with that hash is cached.

func (*APICache) GetCachedBlockByHashStr

func (apic *APICache) GetCachedBlockByHashStr(hashStr string) *CachedBlock

GetCachedBlockByHashStr attempts to fetch a CachedBlock with the given hash. The return is nil if no block with that hash is cached.

func (*APICache) GetCachedBlockByHeight

func (apic *APICache) GetCachedBlockByHeight(height int64) *CachedBlock

GetCachedBlockByHeight attempts to fetch a CachedBlock with the given height. The return is nil if no block with that height is cached.

func (*APICache) Hits

func (apic *APICache) Hits() uint64

Hits returns the hit count of the APICache

func (*APICache) Misses

func (apic *APICache) Misses() uint64

Misses returns the miss count of the APICache

func (*APICache) RemoveCachedBlock

func (apic *APICache) RemoveCachedBlock(cachedBlock *CachedBlock)

RemoveCachedBlock removes the input CachedBlock the cache. If the block is not in cache, this is essentially a silent no-op.

func (*APICache) SetLessFn

func (apic *APICache) SetLessFn(lessFn func(bi, bj *CachedBlock) bool)

SetLessFn sets the comparator used by the priority queue. For information on the input function, see the docs for (pq *BlockPriorityQueue).SetLessFn.

func (*APICache) StoreBlockSummary

func (apic *APICache) StoreBlockSummary(blockSummary *BlockDataBasic) error

StoreBlockSummary caches the input BlockDataBasic, if the priority queue indicates that the block should be added.

func (*APICache) Utilization

func (apic *APICache) Utilization() float64

Utilization returns the percent utilization of the cache

func (*APICache) UtilizationBlocks

func (apic *APICache) UtilizationBlocks() int64

UtilizationBlocks returns the number of blocks stored in the cache

type Address

type Address struct {
	Address      string            `json:"address"`
	Transactions []*AddressTxShort `json:"address_transactions"`
}

Address models the address string with the transactions as AddressTxShort

type AddressTxRaw

type AddressTxRaw struct {
	Size          int32               `json:"size"`
	TxID          string              `json:"txid"`
	Version       int32               `json:"version"`
	Locktime      uint32              `json:"locktime"`
	Vin           []hcjson.VinPrevOut `json:"vin"`
	Vout          []Vout              `json:"vout"`
	Confirmations int64               `json:"confirmations"`
	BlockHash     string              `json:"blockhash"`
	Time          int64               `json:"time,omitempty"`
	Blocktime     int64               `json:"blocktime,omitempty"`
}

AddressTxRaw is modeled from SearchRawTransactionsResult but with size in place of hex

type AddressTxShort

type AddressTxShort struct {
	TxID          string  `json:"txid"`
	Size          int32   `json:"size"`
	Time          int64   `json:"time"`
	Value         float64 `json:"value"`
	Confirmations int64   `json:"confirmations"`
}

AddressTxShort is a subset of AddressTxRaw with just the basic tx details pertaining the particular address

type BlockDataBasic

type BlockDataBasic struct {
	Height     uint32  `json:"height"`
	Size       uint32  `json:"size"`
	Hash       string  `json:"hash"`
	Difficulty float64 `json:"diff"`
	StakeDiff  float64 `json:"sdiff"`
	Time       int64   `json:"time"`
	//TicketPoolInfo
	PoolInfo TicketPoolInfo `json:"ticket_pool"`
}

BlockDataBasic models primary information about block at height Height

type BlockDataWithTxType

type BlockDataWithTxType struct {
	*hcjson.GetBlockVerboseResult
	Votes   []TxRawWithVoteInfo
	Tickets []hcjson.TxRawResult
	Revs    []hcjson.TxRawResult
}

BlockDataWithTxType adds an array of TxRawWithTxType to hcjson.GetBlockVerboseResult to include the stake transaction type

type BlockExplorerBasic

type BlockExplorerBasic struct {
	Height      uint32  `json:"height"`
	Size        uint32  `json:"size"`
	Voters      uint16  `json:"votes"`
	FreshStake  uint8   `json:"tickets"`
	Revocations uint8   `json:"revocations"`
	StakeDiff   float64 `json:"sdiff"`
	Time        int64   `json:"time"`
	BlockExplorerExtraInfo
}

BlockExplorerBasic models primary information about block at height Height for the block explorer.

type BlockExplorerExtraInfo

type BlockExplorerExtraInfo struct {
	TxLen            int                           `json:"tx"`
	FormattedTime    string                        `json:"formatted_time"`
	CoinSupply       int64                         `json:"coin_supply"`
	NextBlockSubsidy *hcjson.GetBlockSubsidyResult `json:"next_block_subsidy"`
}

BlockExplorerExtraInfo contains supplemental block metadata used by the explorer.

type BlockID

type BlockID struct {
	BlockHash   string `json:"blockhash"`
	BlockHeight int64  `json:"blockheight"`
	BlockIndex  uint32 `json:"blockindex"`
	Time        int64  `json:"time"`
	BlockTime   int64  `json:"blocktime"`
}

BlockID models very basic info about a block

type BlockPriorityQueue

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

BlockPriorityQueue implements heap.Interface and holds CachedBlocks

func NewBlockPriorityQueue

func NewBlockPriorityQueue(capacity uint32) *BlockPriorityQueue

NewBlockPriorityQueue is the constructor for BlockPriorityQueue that initializes an empty heap with the given capacity, and sets the default LessFn as a comparison by access time with 1 day resolution (blocks accessed within the 24 hours are considered to have the same access time), followed by access count. Use BlockPriorityQueue.SetLessFn to redefine the comparator.

func (*BlockPriorityQueue) Insert

func (pq *BlockPriorityQueue) Insert(summary *BlockDataBasic) (bool, *chainhash.Hash)

Insert will add an element, while respecting the queue's capacity if at capacity

  • compare with top and replace or return
  • if replaced top, heapdown (Fix(pq,0))

else (not at capacity)

  • heap.Push, which is pq.Push (append at bottom) then heapup

func (BlockPriorityQueue) Len

func (pq BlockPriorityQueue) Len() int

Len is require for heap.Interface

func (BlockPriorityQueue) Less

func (pq BlockPriorityQueue) Less(i, j int) bool

Less performs the comparison priority(i) < priority(j). Use BlockPriorityQueue.SetLessFn to define the desired behavior for the CachedBlocks heap[i] and heap[j].

func (*BlockPriorityQueue) Pop

func (pq *BlockPriorityQueue) Pop() interface{}

Pop will return an interface{} that may be cast to *CachedBlock. Use heap.Pop, not this.

func (*BlockPriorityQueue) Push

func (pq *BlockPriorityQueue) Push(blockSummary interface{})

Push a *BlockDataBasic. Use heap.Push, not this directly.

func (*BlockPriorityQueue) Reheap

func (pq *BlockPriorityQueue) Reheap()

Reheap is a shortcut for heap.Init(pq)

func (*BlockPriorityQueue) RemoveBlock

func (pq *BlockPriorityQueue) RemoveBlock(b *CachedBlock)

RemoveBlock removes the specified CachedBlock from the queue. Remember to remove it from the actual block cache!

func (*BlockPriorityQueue) RemoveIndex

func (pq *BlockPriorityQueue) RemoveIndex(idx int)

RemoveIndex removes the CachedBlock at the specified position in the heap. This function is NOT thread-safe.

func (*BlockPriorityQueue) RescanMinMax

func (pq *BlockPriorityQueue) RescanMinMax()

RescanMinMax rescans the enitire heap to get the current min/max heights. This function is NOT thread-safe.

func (*BlockPriorityQueue) RescanMinMaxForAdd

func (pq *BlockPriorityQueue) RescanMinMaxForAdd(height uint32)

RescanMinMaxForAdd conditionally updates the heap min/max height given the height of the block to add (push). No scan, just update min/max. This function is NOT thread-safe.

func (*BlockPriorityQueue) RescanMinMaxForRemove

func (pq *BlockPriorityQueue) RescanMinMaxForRemove(height uint32)

RescanMinMaxForRemove conditionally rescans the heap min/max height given the height of the block to remove (pop). Make sure to remove the block BEFORE running this, as any rescan of the heap will see the block. This function is NOT thread-safe.

func (*BlockPriorityQueue) RescanMinMaxForUpdate

func (pq *BlockPriorityQueue) RescanMinMaxForUpdate(heightAdd, heightRemove uint32)

RescanMinMaxForUpdate conditionally rescans the heap min/max height given old and new heights of the CachedBlock being updated. This function is NOT thread-safe.

func (*BlockPriorityQueue) ResetHeap

func (pq *BlockPriorityQueue) ResetHeap(bh []*CachedBlock)

ResetHeap creates a fresh queue given the input []*CachedBlock. For every CachedBlock in the queue, ResetHeap resets the access count and time, and heap index. The min/max heights are reset, the heap is heapifies. NOTE: the input slice is modifed, but not reordered. A fresh slice is created for PQ internal use.

func (*BlockPriorityQueue) SetLessFn

func (pq *BlockPriorityQueue) SetLessFn(lessFn func(bi, bj *CachedBlock) bool)

SetLessFn sets the function called by Less. The input lessFn must accept two *CachedBlock and return a bool, unlike Less, which accepts heap indexes i, j. This allows to define a comparator without requiring a heap.

func (BlockPriorityQueue) Swap

func (pq BlockPriorityQueue) Swap(i, j int)

Swap swaps the cachedBlocks at i and j. This is used container/heap.

func (*BlockPriorityQueue) UpdateBlock

func (pq *BlockPriorityQueue) UpdateBlock(b *CachedBlock, summary *BlockDataBasic)

UpdateBlock will update the specified CachedBlock, which must be in the queue. This function is NOT thread-safe.

type BlockSummarySaver

type BlockSummarySaver interface {
	StoreBlockSummary(blockSummary *BlockDataBasic) error
}

BlockSummarySaver is likely to be required to be implemented by the type utilizing APICache.

type BlockTransactions

type BlockTransactions struct {
	Tx  []string `json:"tx"`
	STx []string `json:"stx"`
}

BlockTransactions models an array of stake and regular transactions for a block

type BlockValidation

type BlockValidation struct {
	Hash     string `json:"hash"`
	Height   int64  `json:"height"`
	Validity bool   `json:"validity"`
}

BlockValidation models data about a vote's decision on a block

type CachedBlock

type CachedBlock struct {
	// contains filtered or unexported fields
}

CachedBlock represents a block that is managed by the cache.

func (*CachedBlock) Access

func (b *CachedBlock) Access() *BlockDataBasic

Access increments the access count and sets the accessTime to now. The BlockDataBasic stored in the CachedBlock is returned.

func (CachedBlock) String

func (b CachedBlock) String() string

String satisfies the Stringer interface.

type MempoolTicketDetails

type MempoolTicketDetails struct {
	Height  uint32         `json:"height"`
	Time    int64          `json:"time"`
	Length  uint32         `json:"length"`
	Total   uint32         `json:"total"`
	Tickets TicketsDetails `json:"tickets"`
}

MempoolTicketDetails models basic mempool info with ticket details Tickets

type MempoolTicketFeeInfo

type MempoolTicketFeeInfo struct {
	Height uint32 `json:"height"`
	Time   int64  `json:"time"`
	hcjson.FeeInfoMempool
	LowestMineable float64 `json:"lowest_mineable"`
}

MempoolTicketFeeInfo models statistical ticket fee info at block height Height

type MempoolTicketFees

type MempoolTicketFees struct {
	Height   uint32    `json:"height"`
	Time     int64     `json:"time"`
	Length   uint32    `json:"length"`
	Total    uint32    `json:"total"`
	FeeRates []float64 `json:"top_fees"`
}

MempoolTicketFees models info about ticket fees at block height Height

type OutPoint

type OutPoint struct {
	Hash  string `json:"hash"`
	Index uint32 `json:"index"`
	Tree  int8   `json:"tree"`
}

OutPoint is used to track previous transaction outputs.

type PrevOut

type PrevOut struct {
	Addresses []string `json:"addresses,omitempty"`
	Value     float64  `json:"value"`
}

PrevOut represents previous output for an input Vin.

type ScriptPubKey

type ScriptPubKey struct {
	Asm       string   `json:"asm"`
	ReqSigs   int32    `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
	CommitAmt *float64 `json:"commitamt,omitempty"`
}

ScriptPubKey is the result of decodescript(ScriptPubKeyHex)

type ScriptSig

type ScriptSig struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

ScriptSig models the signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)

type StakeDiff

type StakeDiff struct {
	hcjson.GetStakeDifficultyResult
	Estimates        hcjson.EstimateStakeDiffResult `json:"estimates"`
	IdxBlockInWindow int                            `json:"window_block_index"`
	PriceWindowNum   int                            `json:"window_number"`
}

StakeDiff represents data about the evaluated stake difficulty and estimates

type StakeInfoExtended

type StakeInfoExtended struct {
	Feeinfo          hcjson.FeeInfoBlock `json:"feeinfo"`
	StakeDiff        float64             `json:"stakediff"`
	PriceWindowNum   int                 `json:"window_number"`
	IdxBlockInWindow int                 `json:"window_block_index"`
	PoolInfo         TicketPoolInfo      `json:"ticket_pool"`
}

StakeInfoExtended models data about the fee, pool and stake difficulty

type StakeInfoExtendedEstimates

type StakeInfoExtendedEstimates struct {
	Feeinfo          hcjson.FeeInfoBlock `json:"feeinfo"`
	StakeDiff        StakeDiff           `json:"stakediff"`
	PriceWindowNum   int                 `json:"window_number"`
	IdxBlockInWindow int                 `json:"window_block_index"`
	PoolInfo         TicketPoolInfo      `json:"ticket_pool"`
}

StakeInfoExtendedEstimates is similar to StakeInfoExtended but includes stake difficulty estimates with the stake difficulty

type Status

type Status struct {
	Ready           bool   `json:"ready"`
	DBHeight        uint32 `json:"db_height"`
	Height          uint32 `json:"node_height"`
	NodeConnections int64  `json:"node_connections"`
	APIVersion      int    `json:"api_version"`
	HcdataVersion   string `json:"hcdata_version"`
}

Status indicates the state of the server, including the API version and the software version.

type TicketDetails

type TicketDetails struct {
	Hash    string  `json:"hash"`
	Fee     float64 `json:"abs_fee"`
	FeeRate float64 `json:"fee"`
	Size    int32   `json:"size"`
	Height  int64   `json:"height_received"`
}

TicketDetails models details about ticket Hash received at height Height

type TicketPoolInfo

type TicketPoolInfo struct {
	Size   uint32  `json:"size"`
	Value  float64 `json:"value"`
	ValAvg float64 `json:"valavg"`
}

TicketPoolInfo models data about ticket pool

type TicketPoolValsAndSizes

type TicketPoolValsAndSizes struct {
	StartHeight uint32    `json:"start_height"`
	EndHeight   uint32    `json:"end_height"`
	Value       []float64 `json:"value"`
	Size        []float64 `json:"size"`
}

TicketPoolValsAndSizes models two arrays, one each for ticket values and sizes for blocks StartHeight to EndHeight

type TicketsDetails

type TicketsDetails []*TicketDetails

TicketsDetails is an array of pointers of TicketDetails used in MempoolTicketDetails

type TrimmedTx

type TrimmedTx struct {
	TxID     string       `json:"txid"`
	Version  int32        `json:"version"`
	Locktime uint32       `json:"locktime"`
	Expiry   uint32       `json:"expiry"`
	Vin      []hcjson.Vin `json:"vin"`
	Vout     []Vout       `json:"vout"`
}

TrimmedTx models data to resemble to result of the decoderawtransaction RPC.

type Tx

type Tx struct {
	TxShort
	Confirmations int64    `json:"confirmations"`
	Block         *BlockID `json:"block,omitempty"`
}

Tx models TxShort with the number of confirmations and block info Block

type TxIn

type TxIn struct {
	// Non-witness
	PreviousOutPoint OutPoint `json:"prevout"`
	Sequence         uint32   `json:"sequence"`

	// Witness
	ValueIn         float64 `json:"value"`
	BlockHeight     uint32  `json:"blockheight"`
	BlockIndex      uint32  `json:"blockindex"`
	SignatureScript string  `json:"sigscript"`
}

TxIn defines a HcashOrg transaction input.

type TxInputID

type TxInputID struct {
	Hash  string `json:"hash"`
	Index uint32 `json:"vin_index"`
}

TxInputID specifies a transaction input as hash:vin_index.

type TxOut

type TxOut struct {
	Value     float64  `json:"value"`
	Version   uint16   `json:"version"`
	PkScript  string   `json:"pkscript"`
	Addresses []string `json:"addresses,omitempty"`
}

TxOut defines a HcashOrg transaction output.

type TxRawWithTxType

type TxRawWithTxType struct {
	hcjson.TxRawResult
	TxType string
}

TxRawWithTxType adds the stake transaction type to hcjson.TxRawResult

type TxRawWithVoteInfo

type TxRawWithVoteInfo struct {
	hcjson.TxRawResult
	VoteInfo VoteInfo
}

TxRawWithVoteInfo adds the vote info to hcjson.TxRawResult

type TxShort

type TxShort struct {
	TxID     string       `json:"txid"`
	Size     int32        `json:"size"`
	Version  int32        `json:"version"`
	Locktime uint32       `json:"locktime"`
	Expiry   uint32       `json:"expiry"`
	Vin      []hcjson.Vin `json:"vin"`
	Vout     []Vout       `json:"vout"`
}

TxShort models info about transaction TxID

type Txns

type Txns struct {
	Transactions []string `json:"transactions"`
}

Txns models the multi transaction post data structure

type VinPrevOut

type VinPrevOut struct {
	Coinbase    string     `json:"coinbase"`
	Stakebase   string     `json:"stakebase"`
	Txid        string     `json:"txid"`
	Vout        uint32     `json:"vout"`
	Tree        int8       `json:"tree"`
	AmountIn    *float64   `json:"amountin,omitempty"`
	BlockHeight *uint32    `json:"blockheight,omitempty"`
	BlockIndex  *uint32    `json:"blockindex,omitempty"`
	ScriptSig   *ScriptSig `json:"scriptSig"`
	PrevOut     *PrevOut   `json:"prevOut"`
	Sequence    uint32     `json:"sequence"`
}

VinPrevOut is like Vin except it includes PrevOut. It is used by searchrawtransaction

type VoteInfo

type VoteInfo struct {
	Validation BlockValidation         `json:"block_validation"`
	Version    uint32                  `json:"vote_version"`
	Bits       uint16                  `json:"vote_bits"`
	Choices    []*txhelpers.VoteChoice `json:"vote_choices"`
}

VoteInfo models data about a SSGen transaction (vote)

type Vout

type Vout struct {
	Value               float64      `json:"value"`
	N                   uint32       `json:"n"`
	Version             uint16       `json:"version"`
	ScriptPubKeyDecoded ScriptPubKey `json:"scriptPubKey"`
}

Vout defines a transaction output

type VoutHexScript

type VoutHexScript struct {
	Value           float64 `json:"value"`
	N               uint32  `json:"n"`
	Version         uint16  `json:"version"`
	ScriptPubKeyHex string  `json:"scriptPubKey"`
}

VoutHexScript models the hex script for a transaction output

type VoutMined

type VoutMined struct {
	Vout
	BestBlock     string `json:"bestblock"`
	Confirmations int64  `json:"confirmations"`
	Coinbase      bool   `json:"coinbase"`
}

VoutMined appends a best block hash, number of confimations and if a transaction is a coinbase to a transaction output

Jump to

Keyboard shortcuts

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