dcrdataapi

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2018 License: ISC Imports: 8 Imported by: 0

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 added in v0.8.0

func LessByAccessCount(bi, bj *CachedBlock) bool

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

func LessByAccessCountThenHeight added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

func (apic *APICache) Capacity() uint32

Capacity returns the capacity of the APICache

func (*APICache) Disable added in v0.8.0

func (apic *APICache) Disable()

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

func (*APICache) Enable added in v0.8.0

func (apic *APICache) Enable()

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

func (*APICache) GetBlockSummary added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

func (apic *APICache) Hits() uint64

Hits returns the hit count of the APICache

func (*APICache) Misses added in v0.8.0

func (apic *APICache) Misses() uint64

Misses returns the miss count of the APICache

func (*APICache) RemoveCachedBlock added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

func (apic *APICache) Utilization() float64

Utilization returns the percent utilization of the cache

func (*APICache) UtilizationBlocks added in v0.8.0

func (apic *APICache) UtilizationBlocks() int64

UtilizationBlocks returns the number of blocks stored in the cache

type Address added in v0.7.0

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

Address models the address string with the transactions as AddressTxShort

type AddressTxRaw added in v0.7.0

type AddressTxRaw struct {
	Size          int32                `json:"size"`
	TxID          string               `json:"txid"`
	Version       int32                `json:"version"`
	Locktime      uint32               `json:"locktime"`
	Vin           []dcrjson.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 added in v0.7.0

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 added in v0.8.0

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

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

type BlockExplorerBasic added in v0.8.0

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 added in v0.8.0

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

BlockExplorerExtraInfo contains supplemental block metadata used by the explorer.

type BlockID added in v0.7.0

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 added in v0.8.0

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

BlockPriorityQueue implements heap.Interface and holds CachedBlocks

func NewBlockPriorityQueue added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

func (pq BlockPriorityQueue) Len() int

Len is require for heap.Interface

func (BlockPriorityQueue) Less added in v0.8.0

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 added in v0.8.0

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

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

func (*BlockPriorityQueue) Push added in v0.8.0

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

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

func (*BlockPriorityQueue) Reheap added in v0.8.0

func (pq *BlockPriorityQueue) Reheap()

Reheap is a shortcut for heap.Init(pq)

func (*BlockPriorityQueue) RemoveBlock added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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

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

func (*BlockPriorityQueue) UpdateBlock added in v0.8.0

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 added in v0.8.0

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

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

type BlockTransactions added in v0.7.0

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 added in v0.8.0

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 added in v0.8.0

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

CachedBlock represents a block that is managed by the cache.

func (*CachedBlock) Access added in v0.8.0

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 added in v0.8.0

func (b CachedBlock) String() string

String satisfies the Stringer interface.

type MempoolTicketDetails added in v0.1.2

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 added in v0.1.2

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

MempoolTicketFeeInfo models statistical ticket fee info at block height Height

type MempoolTicketFees added in v0.1.2

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 added in v0.7.0

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 added in v0.7.0

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

PrevOut represents previous output for an input Vin.

type ScriptPubKey added in v0.7.0

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 added in v0.7.0

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 {
	dcrjson.GetStakeDifficultyResult
	Estimates        dcrjson.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          dcrjson.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          dcrjson.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"`
	DcrdataVersion  string `json:"dcrdata_version"`
}

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

type TicketDetails added in v0.1.2

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 added in v0.1.2

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 added in v0.1.2

type TicketsDetails []*TicketDetails

TicketsDetails is an array of pointers of TicketDetails used in MempoolTicketDetails

type TrimmedTx added in v1.1.0

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

TrimmedTx models data to resemble to result of the decoderawtransaction call

type Tx added in v0.7.0

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 added in v0.7.0

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 decred transaction input.

type TxOut added in v0.7.0

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

TxOut defines a decred transaction output.

type TxRawWithTxType added in v0.8.0

type TxRawWithTxType struct {
	dcrjson.TxRawResult
	TxType string
}

TxRawWithTxType adds the stake transaction type to dcrjson.TxRawResult

type TxRawWithVoteInfo added in v0.8.0

type TxRawWithVoteInfo struct {
	dcrjson.TxRawResult
	VoteInfo VoteInfo
}

TxRawWithVoteInfo adds the vote info to dcrjson.TxRawResult

type TxShort added in v0.7.0

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

TxShort models info about transaction TxID

type VinPrevOut added in v0.7.0

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 added in v0.8.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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