dbtypes

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: ISC Imports: 19 Imported by: 131

Documentation

Index

Constants

View Source
const (
	// InitialDBLoad is a sync where data is first loaded from the chain db into
	// the respective dbs currently supported. Runs on both liteMode and fullMode.
	// InitialDBLoad value references the first progress bar id on the status page.
	InitialDBLoad = "initial-load"
	// AddressesTableSync is a sync that runs immediately after initialDBLoad. Data
	// previously loaded into vins table is sync'd with the addresses table.
	// Runs only in fullMode. AddressesTableSync value references the second
	// progress bar id on the status page.
	AddressesTableSync = "addresses-sync"
)
View Source
const (
	AvgBlockSize    = "avg-block-size"
	BlockChainSize  = "blockchain-size"
	ChainWork       = "chainwork"
	CoinSupply      = "coin-supply"
	DurationBTW     = "duration-btw-blocks"
	HashRate        = "hashrate"
	POWDifficulty   = "pow-difficulty"
	TicketByWindows = "ticket-by-outputs-windows"
	TicketPrice     = "ticket-price"
	TicketsByBlocks = "ticket-by-outputs-blocks"
	TicketSpendT    = "ticket-spend-type"
	TxPerBlock      = "tx-per-block"
	TxPerDay        = "tx-per-day"
	FeePerBlock     = "fee-per-block"
	TicketPoolSize  = "ticket-pool-size"
	TicketPoolValue = "ticket-pool-value"
)
View Source
const NumIntervals = 5

NumIntervals is the number of known values for TimeBasedGrouping.

Variables

View Source
var (
	// PGCancelError is the error string PostgreSQL returns when a query fails
	// to complete due to user requested cancellation.
	PGCancelError       = "pq: canceling statement due to user request"
	CtxDeadlineExceeded = context.DeadlineExceeded.Error()
	TimeoutPrefix       = "TIMEOUT of PostgreSQL query"
)
View Source
var (
	// SqliteCharts helps select all the charts that use the SQlite db as a data
	// source from the charts cache data.
	SqliteCharts = [...]string{FeePerBlock, TicketPoolSize, TicketPoolValue}

	// PgCharts helps select all the charts that use the auxiliary db as a data
	// source from the charts cache data.
	PgCharts = [...]string{AvgBlockSize, BlockChainSize, ChainWork, CoinSupply,
		DurationBTW, HashRate, POWDifficulty, TicketByWindows, TicketPrice,
		TicketsByBlocks, TicketSpendT, TxPerBlock, TxPerDay}
)
View Source
var AddrTxnViewTypes = map[AddrTxnViewType]string{
	AddrTxnAll:          "all",
	AddrTxnCredit:       "credit",
	AddrTxnDebit:        "debit",
	AddrMergedTxnDebit:  "merged_debit",
	AddrMergedTxnCredit: "merged_credit",
	AddrMergedTxn:       "merged",
	AddrTxnUnknown:      "unknown",
}

AddrTxnViewTypes is the canonical mapping from AddrTxnViewType to string.

View Source
var TimeBasedGroupings = map[TimeBasedGrouping]string{
	AllGrouping:   "all",
	YearGrouping:  "year",
	MonthGrouping: "month",
	WeekGrouping:  "week",
	DayGrouping:   "day",
}

TimeBasedGroupings maps a given time grouping to its standard string value.

TimeIntervals is an array of distinct time intervals used for grouping data.

Functions

func CalculateHashRate

func CalculateHashRate(difficulty, targetTimePerBlock float64) float64

CalculateHashRate calculates the hashrate from the difficulty value and the targetTimePerBlock in seconds. The hashrate returned is in form PetaHash per second (PH/s).

func CalculateWindowIndex

func CalculateWindowIndex(height, stakeDiffWindowSize int64) int64

CalculateWindowIndex calculates the window index from the quotient of a block height and the chainParams.StakeDiffWindowSize.

func CountMergedRows

func CountMergedRows(rows []*AddressRow, txnView AddrTxnViewType) (numMerged int, err error)

CountMergedRows counts the number of merged rows that would result from calling MergeRows on the input slice. As with MergeRows, the input must be regular (non-merged) addresses table rows.

func CountMergedRowsCompact

func CountMergedRowsCompact(rows []AddressRowCompact, txnView AddrTxnViewType) (numMerged int, err error)

CountMergedRowsCompact counts the number of merged rows that would result from calling MergeRowsCompact (a non-merged row) on the input slice.

func DevSubsidyAddress

func DevSubsidyAddress(params *chaincfg.Params) (string, error)

DevSubsidyAddress returns the development subsidy address for the specified network.

func ExtractBlockTransactions

func ExtractBlockTransactions(msgBlock *wire.MsgBlock, txTree int8,
	chainParams *chaincfg.Params, isValid, isMainchain bool) ([]*Tx, [][]*Vout, []VinTxPropertyARRAY)

ExtractBlockTransactions extracts transaction information from a wire.MsgBlock and returns the processed information in slices of the dbtypes Tx, Vout, and VinTxPropertyARRAY.

func IsTimeout

func IsTimeout(msg string) bool

IsTimeout checks if the message is prefixed with the expected DB timeout message prefix.

func IsTimeoutErr

func IsTimeoutErr(err error) bool

IsTimeoutErr checks if error's message is prefixed with the expected DB timeout message prefix.

func TimeBasedGroupingToInterval

func TimeBasedGroupingToInterval(grouping TimeBasedGrouping) (float64, error)

TimeBasedGroupingToInterval converts the TimeBasedGrouping value to an actual time value in seconds based on the gregorian calendar except AllGrouping that returns 1 while the unknownGrouping returns -1 and an error.

Types

type AddrTxnViewType

type AddrTxnViewType int

AddrTxnViewType enumerates the different address transaction view types as displayed by the address page.

const (
	AddrTxnAll AddrTxnViewType = iota
	AddrTxnCredit
	AddrTxnDebit
	AddrMergedTxnDebit
	AddrMergedTxnCredit
	AddrMergedTxn
	AddrTxnUnknown
)

func AddrTxnViewTypeFromStr

func AddrTxnViewTypeFromStr(txnType string) AddrTxnViewType

AddrTxnViewTypeFromStr attempts to decode a string into an AddrTxnViewType.

func (AddrTxnViewType) IsMerged

func (a AddrTxnViewType) IsMerged() (bool, error)

IsMerged indicates if the address transactions view type is a merged view. If the type is invalid, a non-nil error is returned.

func (AddrTxnViewType) String

func (a AddrTxnViewType) String() string

type AddressBalance

type AddressBalance struct {
	Address      string  `json:"address"`
	NumSpent     int64   `json:"num_stxos"`
	NumUnspent   int64   `json:"num_utxos"`
	TotalSpent   int64   `json:"amount_spent"`
	TotalUnspent int64   `json:"amount_unspent"`
	FromStake    float64 `json:"from_stake"`
	ToStake      float64 `json:"to_stake"`
}

AddressBalance represents the number and value of spent and unspent outputs for an address.

func (*AddressBalance) HasStakeInputs

func (balance *AddressBalance) HasStakeInputs() bool

HasStakeInputs checks whether any of the Address tx inputs were stake-related.

func (*AddressBalance) HasStakeOutputs

func (balance *AddressBalance) HasStakeOutputs() bool

HasStakeOutputs checks whether any of the Address tx outputs were stake-related.

type AddressInfo

type AddressInfo struct {
	// Address is the decred address on the current page
	Address string
	Net     string

	// IsDummyAddress is true when the address is the dummy address typically
	// used for unspendable ticket change outputs. See
	// https://github.com/decred/dcrdata/v4/issues/358 for details.
	IsDummyAddress bool

	// Page parameters
	MaxTxLimit    int64
	Fullmode      bool
	Path          string
	Limit, Offset int64  // ?n=Limit&start=Offset
	TxnType       string // ?txntype=TxnType
	TxnCount      int64
	IsMerged      bool

	// NumUnconfirmed is the number of unconfirmed txns for the address
	NumUnconfirmed  int64
	UnconfirmedTxns *AddressTransactions

	// Transactions on the current page
	Transactions    []*AddressTx
	TxnsFunding     []*AddressTx
	TxnsSpending    []*AddressTx
	NumTransactions int64 // The number of transactions in the address
	NumFundingTxns  int64 // number paying to the address
	NumSpendingTxns int64 // number spending outpoints associated with the address
	AmountReceived  dcrutil.Amount
	AmountSent      dcrutil.Amount
	AmountUnspent   dcrutil.Amount

	// Balance is used in full mode, describing all known transactions
	Balance *AddressBalance

	// KnownTransactions refers to the total transaction count in the DB when in
	// full mode, the sum of funding (crediting) and spending (debiting) txns.
	KnownTransactions int64
	KnownFundingTxns  int64
	KnownSpendingTxns int64
}

AddressInfo models data for display on the address page.

func ReduceAddressHistory

func ReduceAddressHistory(addrHist []*AddressRow) (*AddressInfo, float64, float64)

ReduceAddressHistory generates a template AddressInfo from a slice of AddressRow. All fields except NumUnconfirmed and Transactions are set completely. Transactions is partially set, with each transaction having only the TxID and ReceivedTotal set. The rest of the data should be filled in by other means, such as RPC calls or database queries. Additionally, the fractions of sent and received from stake-related transactions is returned. These values are analogous to AddressBalance.FromStake and AddressBalance.ToStake, but based on only the rows given.

func (*AddressInfo) PostProcess

func (a *AddressInfo) PostProcess(tipHeight uint32)

PostProcess performs time/vin/vout sorting and block height calculations.

type AddressMetrics

type AddressMetrics struct {
	OldestBlockTime TimeDef
	YearTxsCount    int64 // number of year intervals with transactions
	MonthTxsCount   int64 // number of year month with transactions
	WeekTxsCount    int64 // number of year week with transactions
	DayTxsCount     int64 // number of year day with transactions
}

AddressMetrics defines address metrics needed to make decisions by which grouping buttons on the address history page charts should be disabled or enabled by default.

type AddressRow

type AddressRow struct {
	Address        string
	ValidMainChain bool
	// MatchingTxHash provides the relationship between spending tx inputs and
	// funding tx outputs.
	MatchingTxHash string
	IsFunding      bool
	TxBlockTime    TimeDef
	TxHash         string
	TxVinVoutIndex uint32
	Value          uint64
	VinVoutDbID    uint64
	MergedCount    uint64
	TxType         int16
	// In merged view, both Atoms members might be non-zero.
	// In that case, Value is abs(AtomsCredit - AtomsDebit) and
	// IsFunding should true if AtomsCredit > AtomsDebit
	AtomsCredit uint64
	AtomsDebit  uint64
}

AddressRow represents a row in the addresses table

func UncompactMergedRows

func UncompactMergedRows(merged []AddressRowMerged) []*AddressRow

UncompactMergedRows converts (to the extent possible) a []AddressRowMerged to a []*AddressRow. VinVoutDbID is unknown and set to zero. Do not use VinVoutDbID, or insert the AddressRow.

func UncompactRows

func UncompactRows(compact []AddressRowCompact) []*AddressRow

UncompactRows converts (to the extent possible) a []AddressRowCompact to a []*AddressRow. VinVoutDbID is unknown and set to zero. Do not use VinVoutDbID, or insert the AddressRow.

func (*AddressRow) IsMerged

func (ar *AddressRow) IsMerged() bool

IsMerged indicates if the AddressRow represents data for a "merged" address table view by checking the MergedCount.

type AddressRowCompact

type AddressRowCompact struct {
	Address        string
	TxBlockTime    int64
	MatchingTxHash chainhash.Hash
	TxHash         chainhash.Hash
	TxVinVoutIndex uint32
	TxType         int16
	ValidMainChain bool
	IsFunding      bool
	Value          uint64
}

AddressRowCompact is like AddressRow for efficient in-memory storage of non-merged address transaction data. The fields are ordered to avoid unneeded padding and extra data is omitted for efficient caching. The hashes are stored as chainhash.Hash ([32]byte) for efficiency and data locality. The fields of AddressRow that only pertain to merged views (AtomsCredit, AtomsDebit, and MergedTxCount) are omitted. VinVoutDbID is also omitted since it is only used when inserting data (see InsertVouts and storeBlockTxnTree).

func CompactRows

func CompactRows(rows []*AddressRow) []AddressRowCompact

CompactRows converts a []*AddressRow to a []AddressRowCompact.

type AddressRowMerged

type AddressRowMerged struct {
	Address        string
	TxBlockTime    int64
	TxHash         chainhash.Hash
	AtomsCredit    uint64
	AtomsDebit     uint64
	MergedCount    int32
	TxType         int16
	ValidMainChain bool
}

AddressRowMerged is like AddressRow for efficient in-memory storage of merged address transaction data. The fields are ordered to avoid needless padding, and extra data is omitted for memory efficient caching. The fields that only pertain to non-merged views (IsFunding, TxVinVoutIndex, VinVoutDbID, and MatchingTxHash) are omitted. The IsFunding and Value fields are also omitted and replaced with methods to get these values from AtomsCredit and AtomsDebit as needed. Also node that MergedCount is of type int32 since that is big enough and it allows using the padding with TxType and ValidMainChain.

func MergeRows

func MergeRows(rows []*AddressRow) ([]AddressRowMerged, error)

MergeRows converts a slice of non-merged (regular addresses table row data) into a slice of merged address rows. This involves merging rows with the same transaction hash into a single entry by combining the signed values. The IsFunding field of a merged transaction indicates if the net value is positive or not, although the Value field is an absolute value (always positive). MergedRows will return a non-nil error of a merged row is detected in the input since only non-merged rows are expected.

func MergeRowsCompact

func MergeRowsCompact(rows []AddressRowCompact) []AddressRowMerged

MergeRowsCompact converts a []AddressRowCompact (non-merged rows) into a slice of merged address rows. This involves merging rows with the same transaction hash into a single entry by combining the signed values. The IsFunding function of an AddressRowMerged indicates if the net value is positive or not, although the Value function returns an absolute value (always positive).

func MergeRowsCompactRange

func MergeRowsCompactRange(rows []AddressRowCompact, N, offset int, txnView AddrTxnViewType) []AddressRowMerged

func (*AddressRowMerged) IsFunding

func (arm *AddressRowMerged) IsFunding() bool

IsFunding indicates the the transaction is "net funding", meaning that AtomsCredit > AtomsDebit.

func (*AddressRowMerged) Value

func (arm *AddressRowMerged) Value() uint64

Value returns the absolute (non-negative) net value of the transaction as abs(AtomsCredit - AtomsDebit).

type AddressTransactions

type AddressTransactions struct {
	Transactions []*AddressTx
	TxnsFunding  []*AddressTx
	TxnsSpending []*AddressTx
}

AddressTransactions collects the transactions for an address as AddressTx slices.

type AddressTx

type AddressTx struct {
	TxID           string
	TxType         string
	InOutID        uint32
	Size           uint32
	FormattedSize  string
	Total          float64
	Confirmations  uint64
	Time           TimeDef
	ReceivedTotal  float64
	SentTotal      float64
	IsFunding      bool
	MatchedTx      string
	MatchedTxIndex uint32
	MergedTxnCount uint64 `json:",omitempty"`
	BlockHeight    uint32
}

AddressTx models data for transactions on the address page.

func (*AddressTx) IOID

func (a *AddressTx) IOID(txType ...string) string

IOID formats an identification string for the transaction input (or output) represented by the AddressTx.

func (a *AddressTx) Link() string

Link formats a link for the transaction, with vin/vout index if the AddressTx is not merged.

type AgendaStatusType

type AgendaStatusType int8

AgendaStatusType defines the various agenda statuses.

const (
	// InitialAgendaStatus is the agenda status when the agenda is not yet up for
	// voting and the votes tally is not also available.
	InitialAgendaStatus AgendaStatusType = iota

	// StartedAgendaStatus is the agenda status when the agenda is up for voting.
	StartedAgendaStatus

	// FailedAgendaStatus is the agenda status set when the votes tally does not
	// attain the minimum threshold set. Activation height is not set for such an
	// agenda.
	FailedAgendaStatus

	// LockedInAgendaStatus is the agenda status when the agenda is considered to
	// have passed after attaining the minimum set threshold. This agenda will
	// have its activation height set.
	LockedInAgendaStatus

	// ActivatedAgendaStatus is the agenda status chaincfg.RuleChangeActivationInterval
	// blocks (e.g. 8064 blocks = 2016 * 4 for 4 weeks on mainnet) after
	// LockedInAgendaStatus ("lockedin") that indicates when the rule change is to
	// be effected. https://docs.decred.org/glossary/#rule-change-interval-rci.
	ActivatedAgendaStatus

	UnknownStatus
)

func AgendaStatusFromStr

func AgendaStatusFromStr(status string) AgendaStatusType

AgendaStatusFromStr creates an agenda status from a string. If "UnknownStatus" is returned then an invalid status string has been passed.

func (AgendaStatusType) MarshalJSON

func (a AgendaStatusType) MarshalJSON() ([]byte, error)

MarshalJSON is AgendaStatusType default marshaller.

func (AgendaStatusType) String

func (a AgendaStatusType) String() string

func (*AgendaStatusType) UnmarshalJSON

func (a *AgendaStatusType) UnmarshalJSON(b []byte) error

UnmarshalJSON is the default unmarshaller for AgendaStatusType.

type AgendaSummary

type AgendaSummary struct {
	Yes           uint32
	No            uint32
	Abstain       uint32
	VotingStarted int64
	LockedIn      int64
}

AgendaSummary describes a short summary of a given agenda that includes vote choices tally and deployment rule change intervals.

type AgendaVoteChoices

type AgendaVoteChoices struct {
	Abstain []uint64  `json:"abstain"`
	Yes     []uint64  `json:"yes"`
	No      []uint64  `json:"no"`
	Total   []uint64  `json:"total"`
	Height  []uint64  `json:"height,omitempty"`
	Time    []TimeDef `json:"time,omitempty"`
}

AgendaVoteChoices contains the vote counts on multiple intervals of time. The interval length may be either a single block, in which case Height contains the block heights, or a day, in which case Time contains the time stamps of each interval. Total is always the sum of Yes, No, and Abstain.

type Block

type Block struct {
	Hash         string `json:"hash"`
	Size         uint32 `json:"size"`
	Height       uint32 `json:"height"`
	Version      uint32 `json:"version"`
	NumTx        uint32
	NumRegTx     uint32
	Tx           []string `json:"tx"`
	TxDbIDs      []uint64
	NumStakeTx   uint32
	STx          []string `json:"stx"`
	STxDbIDs     []uint64
	Time         TimeDef `json:"time"`
	Nonce        uint64  `json:"nonce"`
	VoteBits     uint16  `json:"votebits"`
	Voters       uint16  `json:"voters"`
	FreshStake   uint8   `json:"freshstake"`
	Revocations  uint8   `json:"revocations"`
	PoolSize     uint32  `json:"poolsize"`
	Bits         uint32  `json:"bits"`
	SBits        uint64  `json:"sbits"`
	Difficulty   float64 `json:"difficulty"`
	StakeVersion uint32  `json:"stakeversion"`
	PreviousHash string  `json:"previousblockhash"`
	ChainWork    string  `json:"chainwork"`
}

Block models a Decred block.

func MsgBlockToDBBlock

func MsgBlockToDBBlock(msgBlock *wire.MsgBlock, chainParams *chaincfg.Params, chainWork string) *Block

MsgBlockToDBBlock creates a dbtypes.Block from a wire.MsgBlock

type BlockChainData

type BlockChainData struct {
	Chain                  string
	SyncHeight             int64
	BestHeight             int64
	BestBlockHash          string
	Difficulty             uint32
	VerificationProgress   float64
	ChainWork              string
	IsInitialBlockDownload bool
	MaxBlockSize           int64
	AgendaMileStones       map[string]MileStone
}

BlockChainData defines data holding the latest block chain state from the getblockchaininfo rpc endpoint.

type BlockDataBasic

type BlockDataBasic struct {
	Height     uint32  `json:"height,omitempty"`
	Size       uint32  `json:"size,omitempty"`
	Hash       string  `json:"hash,omitempty"`
	Difficulty float64 `json:"diff,omitempty"`
	StakeDiff  float64 `json:"sdiff,omitempty"`
	Time       TimeDef `json:"time,omitempty"`
	NumTx      uint32  `json:"txlength,omitempty"`
}

type BlockStatus

type BlockStatus struct {
	IsValid     bool   `json:"is_valid"`
	IsMainchain bool   `json:"is_mainchain"`
	Height      uint32 `json:"height"`
	PrevHash    string `json:"previous_hash"`
	Hash        string `json:"hash"`
	NextHash    string `json:"next_hash"`
}

BlockStatus describes a block's status in the block chain.

type BlocksGroupedInfo

type BlocksGroupedInfo struct {
	// intrinsic properties
	IndexVal           int64
	EndBlock           int64
	Difficulty         float64
	TicketPrice        int64
	StartTime          TimeDef
	FormattedStartTime string
	EndTime            TimeDef
	FormattedEndTime   string
	Size               int64
	FormattedSize      string
	// Aggregate properties
	Voters       uint64
	Transactions uint64
	FreshStake   uint64
	Revocations  uint64
	TxCount      uint64
	BlocksCount  int64
}

BlocksGroupedInfo contains the data about a stake difficulty (ticket price) window, including intrinsic properties (e.g. window index, ticket price, start block, etc.), and aggregate transaction counts (e.g. number of votes, regular transactions, new tickets, etc.)

type ChartsData

type ChartsData struct {
	Difficulty  []float64 `json:"difficulty,omitempty"`
	Time        []TimeDef `json:"time,omitempty"`
	Size        []uint64  `json:"size,omitempty"`
	ChainSize   []uint64  `json:"chainsize,omitempty"`
	Count       []uint64  `json:"count,omitempty"`
	SizeF       []float64 `json:"sizef,omitempty"`
	ValueF      []float64 `json:"valuef,omitempty"`
	Unspent     []uint64  `json:"unspent,omitempty"`
	Revoked     []uint64  `json:"revoked,omitempty"`
	Height      []uint64  `json:"height,omitempty"`
	Pooled      []uint64  `json:"pooled,omitempty"`
	Solo        []uint64  `json:"solo,omitempty"`
	SentRtx     []uint64  `json:"sentRtx,omitempty"`
	ReceivedRtx []uint64  `json:"receivedRtx,omitempty"`
	Tickets     []uint64  `json:"tickets,omitempty"`
	Votes       []uint64  `json:"votes,omitempty"`
	RevokeTx    []uint64  `json:"revokeTx,omitempty"`
	Amount      []float64 `json:"amount,omitempty"`
	Received    []float64 `json:"received,omitempty"`
	Sent        []float64 `json:"sent,omitempty"`
	Net         []float64 `json:"net,omitempty"`
	ChainWork   []uint64  `json:"chainwork,omitempty"`
	NetHash     []uint64  `json:"nethash,omitempty"`
}

ChartsData defines the fields that store the values needed to plot the charts on the frontend.

type DeletionSummary

type DeletionSummary struct {
	Blocks, Vins, Vouts, Addresses, Transactions, Tickets, Votes, Misses int64
	Timings                                                              *DeletionSummary
}

DeletionSummary provides the number of rows removed from the tables when a block is removed.

func (DeletionSummary) String

func (s DeletionSummary) String() string

String makes a pretty summary of the totals.

type DeletionSummarySlice

type DeletionSummarySlice []DeletionSummary

DeletionSummarySlice is used to define methods on DeletionSummary slices.

func (DeletionSummarySlice) Reduce

Reduce returns a single DeletionSummary with the corresponding fields summed.

type HistoryChart

type HistoryChart int8

HistoryChart is used to differentiate the distinct graphs that appear on the address history page.

const (
	TxsType HistoryChart = iota
	AmountFlow
	ChartUnknown
)

type JSONB

type JSONB map[string]interface{}

JSONB is used to implement the sql.Scanner and driver.Valuer interfaces required for the type to make a postgresql compatible JSONB type.

type MileStone

type MileStone struct {
	ID            int64            `json:"-"`
	Status        AgendaStatusType `json:"status"`
	VotingStarted int64            `json:"votingStarted"`
	VotingDone    int64            `json:"votingdone"`
	Activated     int64            `json:"activated"`
	HardForked    int64            `json:"hardforked"`
	StartTime     time.Time        `json:"starttime"`
	ExpireTime    time.Time        `json:"expiretime"`
}

MileStone defines the various stages passed by vote on a given agenda. Activated is the height at which the delay time begins before a vote activates. HardForked is the height at which the consensus rule changes. VotingDone is the height at which voting is considered complete or when the status changes from "started" to either "failed" or "lockedin".

type PoolTicketsData

type PoolTicketsData struct {
	Time     []TimeDef `json:"time,omitempty"`
	Price    []float64 `json:"price,omitempty"`
	Mempool  []uint64  `json:"mempool,omitempty"`
	Immature []uint64  `json:"immature,omitempty"`
	Live     []uint64  `json:"live,omitempty"`
	Solo     uint64    `json:"solo,omitempty"`
	Pooled   uint64    `json:"pooled,omitempty"`
	TxSplit  uint64    `json:"txsplit,omitempty"`
}

PoolTicketsData defines the real time data needed for ticket pool visualization charts.

type ProgressBarLoad

type ProgressBarLoad struct {
	From      int64
	To        int64
	Msg       string
	Subtitle  string
	BarID     string
	Timestamp int64
}

ProgressBarLoad contains the raw data needed to populate the status sync updates. It is used to update the status sync through a channel.

type ScriptPubKeyData

type ScriptPubKeyData struct {
	ReqSigs   uint32   `json:"reqSigs"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses"`
}

ScriptPubKeyData is part of 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 SideChain

type SideChain struct {
	Hashes  []string
	Heights []int64
}

SideChain represents blocks of a side chain, in ascending height order.

type SyncResult

type SyncResult struct {
	Height int64
	Error  error
}

SyncResult is the result of a database sync operation, containing the height of the last block and an arror value.

type TicketPoolStatus

type TicketPoolStatus int16
const (
	PoolStatusLive TicketPoolStatus = iota
	PoolStatusVoted
	PoolStatusExpired
	PoolStatusMissed
)

NB:PoolStatusLive also defines immature tickets in addition to defining live tickets.

func (TicketPoolStatus) String

func (p TicketPoolStatus) String() string

type TicketSpendType

type TicketSpendType int16
const (
	TicketUnspent TicketSpendType = iota
	TicketRevoked
	TicketVoted
)

func (TicketSpendType) String

func (p TicketSpendType) String() string

type TimeBasedGrouping

type TimeBasedGrouping int8

TimeBasedGrouping defines the possible ways that a time can be grouped according to all, year, month, week or day grouping. This time grouping is used in time-based grouping like charts and blocks list view.

const (
	AllGrouping TimeBasedGrouping = iota
	YearGrouping
	MonthGrouping
	WeekGrouping
	DayGrouping
	UnknownGrouping
)

func TimeGroupingFromStr

func TimeGroupingFromStr(groupings string) TimeBasedGrouping

TimeGroupingFromStr converts groupings string to its respective TimeBasedGrouping value.

func (TimeBasedGrouping) String

func (g TimeBasedGrouping) String() string

type TimeDef

type TimeDef struct {
	T time.Time
}

TimeDef is time.Time wrapper that formats time by default as a string without a timezone. The time Stringer interface formats the time into a string with a timezone.

func NewTimeDef

func NewTimeDef(t time.Time) TimeDef

NewTimeDef constructs a TimeDef from the given time.Time. It presets the timezone for formatting to UTC.

func NewTimeDefFromUNIX

func NewTimeDefFromUNIX(t int64) TimeDef

NewTimeDefFromUNIX constructs a TimeDef from the given UNIX epoch time stamp in seconds. It presets the timezone for formatting to UTC.

func (TimeDef) Format

func (t TimeDef) Format(layout string) string

func (*TimeDef) MarshalJSON

func (t *TimeDef) MarshalJSON() ([]byte, error)

MarshalJSON is set as the default marshalling function for TimeDef struct.

func (TimeDef) RFC3339

func (t TimeDef) RFC3339() string

RFC3339 formats the time in a machine-friendly layout.

func (*TimeDef) Scan

func (t *TimeDef) Scan(src interface{}) error

Scan implements the sql.Scanner interface for TimeDef. This will not reinterpret the stored time string for a particular time zone. That is, if the stored time stamp shows no time zone (as with TIMESTAMP), the default time.Time scanner will load it as a local time, and this Scan converts to UTC. If the timestamp has a timezone (as with TIMESTAMPTZ), including UTC explicitly set, it will be accounted for when converting to UTC. All this Scan implementation does beyond the default time.Time scanner is to set the time.Time's location to UTC, which keeps the instant in time the same, adjusting the numbers in the time string to the equivalent time in UTC. For example, if the time read from the DB is "2016-02-08 12:00:00" (with no time zone) and the server time zone is CST (UTC-6), this ensures the default displayed time string is in UTC: "2016-02-08 18:00:00Z". On the other hand, if the time read from the DB is "2016-02-08 12:00:00+6", it does not matter what the server time zone is set to, and the time will still be converted to UTC as "2016-02-08 18:00:00Z".

func (TimeDef) String

func (t TimeDef) String() string

String formats the time in a human-friendly layout. This may be used when TimeDef values end up on the explorer pages.

func (TimeDef) UNIX

func (t TimeDef) UNIX() int64

UNIX returns the UNIX epoch time stamp.

func (TimeDef) Value

func (t TimeDef) Value() (driver.Value, error)

Value implements the sql.Valuer interface. It ensures that the Time Values are for the UTC time zone. Times will only survive a round trip to and from the DB tables if they are stored from a time.Time with Location set to UTC.

type TimeDefLocal

type TimeDefLocal TimeDef

TimeDefLocal satisfies the sql.Valuer interface, but it provides Local Time.

func (TimeDefLocal) Value

func (t TimeDefLocal) Value() (driver.Value, error)

Value implements the sql.Valuer interface. It ensures that the Time Values are for the Local time zone. It is unlikely to be desirable to store values this way. Only storing a time.Time in UTC allows round trip fidelity.

type Tx

type Tx struct {
	//blockDbID  int64
	BlockHash   string  `json:"block_hash"`
	BlockHeight int64   `json:"block_height"`
	BlockTime   TimeDef `json:"block_time"`
	Time        TimeDef `json:"time"`
	TxType      int16   `json:"tx_type"`
	Version     uint16  `json:"version"`
	Tree        int8    `json:"tree"`
	TxID        string  `json:"txid"`
	BlockIndex  uint32  `json:"block_index"`
	Locktime    uint32  `json:"locktime"`
	Expiry      uint32  `json:"expiry"`
	Size        uint32  `json:"size"`
	Spent       int64   `json:"spent"`
	Sent        int64   `json:"sent"`
	Fees        int64   `json:"fees"`
	NumVin      uint32  `json:"numvin"`
	//Vins        VinTxPropertyARRAY `json:"vins"`
	VinDbIds  []uint64 `json:"vindbids"`
	NumVout   uint32   `json:"numvout"`
	Vouts     []*Vout  `json:"vouts"`
	VoutDbIds []uint64 `json:"voutdbids"`
	// NOTE: VoutDbIds may not be needed if there is a vout table since each
	// vout will have a tx_dbid
	IsValidBlock     bool `json:"valid_block"`
	IsMainchainBlock bool `json:"mainchain"`
}

Tx models a Decred transaction. It is stored in a Block.

type UInt64Array

type UInt64Array []uint64

UInt64Array represents a one-dimensional array of PostgreSQL integer types

func (*UInt64Array) Scan

func (a *UInt64Array) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (UInt64Array) Value

func (a UInt64Array) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type UTXO

type UTXO struct {
	TxHash  string
	TxIndex uint32
	UTXOData
}

UTXO represents a transaction output, but it is intended to help track unspent outputs.

type UTXOData

type UTXOData struct {
	Addresses []string
	Value     int64
}

UTXOData stores an address and value associated with a transaction output.

type Vin

type Vin struct {
	//txDbID      int64
	Coinbase    string  `json:"coinbase"`
	TxHash      string  `json:"txhash"`
	VoutIdx     uint32  `json:"voutidx"`
	Tree        int8    `json:"tree"`
	Sequence    uint32  `json:"sequence"`
	AmountIn    float64 `json:"amountin"`
	BlockHeight uint32  `json:"blockheight"`
	BlockIndex  uint32  `json:"blockindex"`
	ScriptHex   string  `json:"scripthex"`
}

Vin models a transaction input.

type VinTxProperty

type VinTxProperty struct {
	PrevOut     string  `json:"prevout"`
	PrevTxHash  string  `json:"prevtxhash"`
	PrevTxIndex uint32  `json:"prevvoutidx"`
	PrevTxTree  uint16  `json:"tree"`
	Sequence    uint32  `json:"sequence"`
	ValueIn     int64   `json:"amountin"`
	TxID        string  `json:"tx_hash"`
	TxIndex     uint32  `json:"tx_index"`
	TxTree      uint16  `json:"tx_tree"`
	TxType      int16   `json:"tx_type"`
	BlockHeight uint32  `json:"blockheight"`
	BlockIndex  uint32  `json:"blockindex"`
	ScriptHex   []byte  `json:"scripthex"`
	IsValid     bool    `json:"is_valid"`
	IsMainchain bool    `json:"is_mainchain"`
	Time        TimeDef `json:"time"`
}

VinTxProperty models a transaction input with previous outpoint information.

type VinTxPropertyARRAY

type VinTxPropertyARRAY []VinTxProperty

VinTxPropertyARRAY is a slice of VinTxProperty sturcts that implements sql.Scanner and driver.Valuer.

func (*VinTxPropertyARRAY) Scan

func (p *VinTxPropertyARRAY) Scan(src interface{}) error

Scan satisfies sql.Scanner

func (VinTxPropertyARRAY) Value

func (p VinTxPropertyARRAY) Value() (driver.Value, error)

Value satisfies driver.Valuer

type VoteChoice

type VoteChoice uint8

VoteChoice defines the type of vote choice, and the undelying integer value is stored in the database (do not change these without upgrading the DB!).

const (
	Yes VoteChoice = iota
	Abstain
	No
	VoteChoiceUnknown
)

func ChoiceIndexFromStr

func ChoiceIndexFromStr(choice string) (VoteChoice, error)

ChoiceIndexFromStr converts the vote choice string to a vote choice index.

func (VoteChoice) String

func (v VoteChoice) String() string

type Vout

type Vout struct {
	// txDbID           int64
	TxHash           string           `json:"tx_hash"`
	TxIndex          uint32           `json:"tx_index"`
	TxTree           int8             `json:"tx_tree"`
	TxType           int16            `json:"tx_type"`
	Value            uint64           `json:"value"`
	Version          uint16           `json:"version"`
	ScriptPubKey     []byte           `json:"pkScriptHex"`
	ScriptPubKeyData ScriptPubKeyData `json:"pkScript"`
}

Vout defines a transaction output

Directories

Path Synopsis
Package internal provides helper functions borrowed from lib/pq's array.go, to facilitate the new UInt64Array type.
Package internal provides helper functions borrowed from lib/pq's array.go, to facilitate the new UInt64Array type.

Jump to

Keyboard shortcuts

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