types

package
v0.0.0-...-c9ddbe3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VoteReject  = -1
	VoteAffirm  = 1
	VoteMissing = 0
)

Types of votes

View Source
const (
	TicketTypeStr   = "Ticket"
	VoteTypeStr     = "Vote"
	RevTypeStr      = "Revocation"
	CoinbaseTypeStr = "Coinbase"
)

These are the text representations of the various special transaction types.

Variables

This section is empty.

Functions

func UnspentOutputIndices

func UnspentOutputIndices(vouts []Vout) (unspents []int)

UnspentOutputIndices finds the indices of the transaction outputs that appear unspent. The indices returned are the index within the passed slice, not within the transaction.

Types

type AddrPrefix

type AddrPrefix struct {
	Name        string
	Prefix      string
	Description string
}

AddrPrefix represent the address name it's prefix and description

func AddressPrefixes

func AddressPrefixes(params *chaincfg.Params) []AddrPrefix

AddressPrefixes generates an array AddrPrefix by using chaincfg.Params

type BlockBasic

type BlockBasic struct {
	Height         int64   `json:"height"`
	Hash           string  `json:"hash"`
	Version        int32   `json:"version"`
	Size           int32   `json:"size"`
	Valid          bool    `json:"valid"`
	MainChain      bool    `json:"mainchain"`
	Voters         uint16  `json:"votes"`
	Transactions   int     `json:"tx"`
	IndexVal       int64   `json:"windowIndex"`
	FreshStake     uint8   `json:"tickets"`
	Revocations    uint32  `json:"revocations"`
	TxCount        uint32  `json:"tx_count"`
	BlockTime      TimeDef `json:"time"`
	FormattedBytes string  `json:"formatted_bytes"`
	Total          float64 `json:"total"`
}

BlockBasic models data for the explorer's explorer page

type BlockID

type BlockID struct {
	Hash   string
	Height int64
	Time   int64
}

BlockID provides basic identifying information about a block.

type BlockInfo

type BlockInfo struct {
	*BlockBasic
	Confirmations         int64
	StakeRoot             string
	MerkleRoot            string
	TxAvailable           bool
	Tx                    []*TrimmedTxInfo
	Tickets               []*TrimmedTxInfo
	Revs                  []*TrimmedTxInfo
	Votes                 []*TrimmedTxInfo
	Misses                []string
	Nonce                 uint32
	VoteBits              uint16
	FinalState            string
	PoolSize              uint32
	Bits                  string
	SBits                 float64
	Difficulty            float64
	ExtraData             string
	StakeVersion          uint32
	PreviousHash          string
	NextHash              string
	TotalSent             float64
	MiningFee             float64
	StakeValidationHeight int64
	Subsidy               *chainjson.GetBlockSubsidyResult
}

BlockInfo models data for display on the block page

type BlockSubsidy

type BlockSubsidy struct {
	Total int64 `json:"total"`
	PoW   int64 `json:"pow"`
	PoS   int64 `json:"pos"`
	Dev   int64 `json:"dev"`
}

BlockSubsidy is an implementation of chainjson.GetBlockSubsidyResult

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

func (*BlockValidation) ForBlock

func (v *BlockValidation) ForBlock(blockHash string) bool

ForBlock indicates if the validation choice is for the specified block.

type BlockValidatorIndex

type BlockValidatorIndex map[string]TicketIndex

BlockValidatorIndex keeps a list of arbitrary indexes for unique combinations of block hash and the ticket being spent to validate the block, i.e. map[validatedBlockHash]map[ticketHash]index.

type ChainParams

type ChainParams struct {
	WindowSize       int64 `json:"window_size"`
	RewardWindowSize int64 `json:"reward_window_size"`
	TargetPoolSize   int64 `json:"target_pool_size"`
	BlockTime        int64 `json:"target_block_time"`
	MeanVotingBlocks int64
}

ChainParams models simple data about the chain server's parameters used for some info on the front page.

type HomeInfo

type HomeInfo struct {
	CoinSupply            int64                 `json:"coin_supply"`
	StakeDiff             float64               `json:"sdiff"`
	NextExpectedStakeDiff float64               `json:"next_expected_sdiff"`
	NextExpectedBoundsMin float64               `json:"next_expected_min"`
	NextExpectedBoundsMax float64               `json:"next_expected_max"`
	IdxBlockInWindow      int                   `json:"window_idx"`
	IdxInRewardWindow     int                   `json:"reward_idx"`
	Difficulty            float64               `json:"difficulty"`
	DevFund               int64                 `json:"dev_fund"`
	DevAddress            string                `json:"dev_address"`
	TicketReward          float64               `json:"reward"`
	RewardPeriod          string                `json:"reward_period"`
	ASR                   float64               `json:"ASR"`
	NBlockSubsidy         BlockSubsidy          `json:"subsidy"`
	Params                ChainParams           `json:"params"`
	PoolInfo              TicketPoolInfo        `json:"pool_info"`
	TotalLockedECR        float64               `json:"total_locked_dcr"`
	HashRate              float64               `json:"hash_rate"`
	HashRateChangeDay     float64               `json:"hash_rate_change_day"`
	HashRateChangeMonth   float64               `json:"hash_rate_change_month"`
	ExchangeRate          *exchanges.Conversion `json:"exchange_rate,omitempty"`
}

HomeInfo represents data used for the home page

type LikelyMineable

type LikelyMineable struct {
	Total         float64 `json:"total"`
	Size          int32   `json:"size"`
	FormattedSize string  `json:"formatted_size"`
	RegularTotal  float64 `json:"regular_total"`
	TicketTotal   float64 `json:"ticket_total"`
	VoteTotal     float64 `json:"vote_total"`
	RevokeTotal   float64 `json:"revoke_total"`
	Count         int     `json:"count"`
}

LikelyMineable holds the totals for all mempool transactions except for votes on non-tip blocks and multiple votes that spend the same ticket.

type MPTxsByHeight

type MPTxsByHeight []MempoolTx

func (MPTxsByHeight) Len

func (votes MPTxsByHeight) Len() int

func (MPTxsByHeight) Less

func (votes MPTxsByHeight) Less(i, j int) bool

func (MPTxsByHeight) Swap

func (votes MPTxsByHeight) Swap(i, j int)

type MPTxsByTime

type MPTxsByTime []MempoolTx

func (MPTxsByTime) Len

func (txs MPTxsByTime) Len() int

func (MPTxsByTime) Less

func (txs MPTxsByTime) Less(i, j int) bool

func (MPTxsByTime) Swap

func (txs MPTxsByTime) Swap(i, j int)

type MempoolInfo

type MempoolInfo struct {
	sync.RWMutex
	MempoolShort
	Transactions []MempoolTx `json:"tx"`
	Tickets      []MempoolTx `json:"tickets"`
	Votes        []MempoolTx `json:"votes"`
	Revocations  []MempoolTx `json:"revs"`
	Ident        uint64      `json:"id"`
}

MempoolInfo models data to update mempool info on the home page

func (*MempoolInfo) DeepCopy

func (mpi *MempoolInfo) DeepCopy() *MempoolInfo

DeepCopy makes a deep copy of MempoolInfo, where all the slice and map data are copied over.

func (*MempoolInfo) ID

func (mpi *MempoolInfo) ID() uint64

ID can be used to track state changes.

func (*MempoolInfo) Trim

func (mpi *MempoolInfo) Trim() *TrimmedMempoolInfo

Trim converts the MempoolInfo to TrimmedMempoolInfo.

func (*MempoolInfo) Tx

func (mpi *MempoolInfo) Tx(txid string) (MempoolTx, bool)

Tx checks the inventory and searches the appropriate lists for a transaction matching the provided transaction ID.

type MempoolInput

type MempoolInput struct {
	TxId   string `json:"txid"`
	Index  uint32 `json:"index"`
	Outdex uint32 `json:"vout"`
}

MempoolInput is basic information about a transaction input.

func MsgTxMempoolInputs

func MsgTxMempoolInputs(msgTx *wire.MsgTx) (inputs []MempoolInput)

MsgTxMempoolInputs parses a MsgTx and creates a list of MempoolInput.

type MempoolShort

type MempoolShort struct {
	LastBlockHeight    int64               `json:"block_height"`
	LastBlockHash      string              `json:"block_hash"`
	LastBlockTime      int64               `json:"block_time"`
	FormattedBlockTime string              `json:"formatted_block_time"`
	Time               int64               `json:"time"`
	TotalOut           float64             `json:"total"`
	TotalSize          int32               `json:"size"`
	NumTickets         int                 `json:"num_tickets"`
	NumVotes           int                 `json:"num_votes"`
	NumRegular         int                 `json:"num_regular"`
	NumRevokes         int                 `json:"num_revokes"`
	NumAll             int                 `json:"num_all"`
	LikelyMineable     LikelyMineable      `json:"likely_mineable"`
	LatestTransactions []MempoolTx         `json:"latest"`
	FormattedTotalSize string              `json:"formatted_size"`
	TicketIndexes      BlockValidatorIndex `json:"-"`
	VotingInfo         VotingInfo          `json:"voting_info"`
	InvRegular         map[string]struct{} `json:"-"`
	InvStake           map[string]struct{} `json:"-"`
}

MempoolShort represents the mempool data sent as the mempool update

func (*MempoolShort) DeepCopy

func (mps *MempoolShort) DeepCopy() *MempoolShort

type MempoolTx

type MempoolTx struct {
	TxID string  `json:"txid"`
	Fees float64 `json:"fees"`
	// Consider atom representation:
	//FeeAmount   int64        `json:"fee_amount"`
	VinCount  int            `json:"vin_count"`
	VoutCount int            `json:"vout_count"`
	Vin       []MempoolInput `json:"vin,omitempty"`
	Coinbase  bool           `json:"coinbase"`
	Hash      string         `json:"hash"`
	Time      int64          `json:"time"`
	Size      int32          `json:"size"`
	TotalOut  float64        `json:"total"`
	// Consider atom representation:
	//TotalOutAmt float64        `json:"total_amount"`
	Type     string    `json:"Type"`
	VoteInfo *VoteInfo `json:"vote_info,omitempty"`
}

MempoolTx models the tx basic data for the mempool page

func CopyMempoolTxSlice

func CopyMempoolTxSlice(s []MempoolTx) []MempoolTx

func (*MempoolTx) DeepCopy

func (mpt *MempoolTx) DeepCopy() *MempoolTx

type MempoolVin

type MempoolVin struct {
	TxId   string
	Inputs []MempoolInput
}

MempoolVin is minimal information about the inputs of a mempool transaction.

type NewMempoolTx

type NewMempoolTx struct {
	Time int64
	Hex  string
}

NewMempoolTx models data sent from the notification handler

type StatsInfo

type StatsInfo struct {
	UltimateSupply             int64
	TotalSupply                int64
	TotalSupplyPercentage      float64
	ProjectFunds               int64
	ProjectAddress             string
	PoWDiff                    float64
	HashRate                   float64
	BlockReward                int64
	NextBlockReward            int64
	PoWReward                  int64
	PoSReward                  int64
	ProjectFundReward          int64
	VotesInMempool             int
	TicketsInMempool           int
	TicketPrice                float64
	NextEstimatedTicketPrice   float64
	TicketPoolSize             uint32
	TicketPoolSizePerToTarget  float64
	TicketPoolValue            float64
	TPVOfTotalSupplyPeecentage float64
	TicketsROI                 float64
	RewardPeriod               string
	ASR                        float64
	APR                        float64
	IdxBlockInWindow           int
	WindowSize                 int64
	BlockTime                  int64
	IdxInRewardWindow          int
	RewardWindowSize           int64
}

StatsInfo represents all of the data for the stats page.

type TicketIndex

type TicketIndex map[string]int

TicketIndex is used to assign an index to a ticket hash.

type TicketInfo

type TicketInfo struct {
	TicketMaturity       int64
	TimeTillMaturity     float64 // Time before a particular ticket reaches maturity, in hours
	PoolStatus           string
	SpendStatus          string
	LotteryBlock         string  // If the ticket was chosen to vote, it was chosen to vote in this block.
	TicketPoolSize       int64   // Total number of ticket in the pool
	TicketExpiry         int64   // Total number of blocks before a ticket expires
	TicketExpiryDaysLeft float64 // Approximate days left before the given ticket expires
	TicketLiveBlocks     int64   // Total number of confirms after maturity and up until the point the ticket votes or expires
	BestLuck             int64   // Best possible Luck for voting
	AvgLuck              int64   // Average Luck for voting
	VoteLuck             float64 // Actual Luck for voting on a ticket
	LuckStatus           string  // Short description based on the VoteLuck
	Probability          float64 // Probability of success before ticket expires
}

TicketInfo is used to represent data shown for a sstx transaction.

type TicketPoolInfo

type TicketPoolInfo struct {
	Size          uint32  `json:"size"`
	Value         float64 `json:"value"`
	ValAvg        float64 `json:"valavg"`
	Percentage    float64 `json:"percent"`
	Target        uint16  `json:"target"`
	PercentTarget float64 `json:"percent_target"`
}

TicketPoolInfo describes the live ticket pool

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) HMSTZ

func (t *TimeDef) HMSTZ() string

HMSTZ is the hour:minute:second with 3-digit timezone code.

func (*TimeDef) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (*TimeDef) PrettyMDY

func (t *TimeDef) PrettyMDY() string

PrettyMDY formats the time down to day only, using 3 day month, unpadded day, comma, and 4 digit year.

func (TimeDef) RFC3339

func (t TimeDef) RFC3339() string

RFC3339 formats the time in a machine-friendly layout.

func (TimeDef) String

func (t TimeDef) String() string

String formats the time in a human-friendly layout. This ends up on the explorer web pages.

func (TimeDef) UNIX

func (t TimeDef) UNIX() int64

UNIX returns the UNIX epoch time stamp.

func (*TimeDef) UnmarshalJSON

func (t *TimeDef) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type TrimmedBlockInfo

type TrimmedBlockInfo struct {
	Time         TimeDef
	Height       int64
	Total        float64
	Fees         float64
	Subsidy      *chainjson.GetBlockSubsidyResult
	Votes        []*TrimmedTxInfo
	Tickets      []*TrimmedTxInfo
	Revocations  []*TrimmedTxInfo
	Transactions []*TrimmedTxInfo
}

TrimmedBlockInfo models data needed to display block info on the new home page

type TrimmedMempoolInfo

type TrimmedMempoolInfo struct {
	Transactions []*TrimmedTxInfo
	Tickets      []*TrimmedTxInfo
	Votes        []*TrimmedTxInfo
	Revocations  []*TrimmedTxInfo
	Subsidy      BlockSubsidy
	Total        float64
	Time         int64
	Fees         float64
}

TrimmedMempoolInfo models data needed to display mempool info on the new home page

type TrimmedTxInfo

type TrimmedTxInfo struct {
	*TxBasic
	Fees      float64
	VinCount  int
	VoutCount int
	VoteValid bool
}

TrimmedTxInfo for use with /visualblocks

func FilterRegularTx

func FilterRegularTx(txs []*TrimmedTxInfo) (transactions []*TrimmedTxInfo)

FilterRegularTx returns a slice of all the regular (non-stake) transactions in the input slice, excluding coinbase (reward) transactions.

func FilterUniqueLastBlockVotes

func FilterUniqueLastBlockVotes(txs []*TrimmedTxInfo) (votes []*TrimmedTxInfo)

FilterUniqueLastBlockVotes returns a slice of all the vote transactions from the input slice that are flagged as voting on the previous block.

func TrimMempoolTx

func TrimMempoolTx(txs []MempoolTx) (trimmedTxs []*TrimmedTxInfo)

TrimMempoolTx converts the input []MempoolTx to a []*TrimmedTxInfo.

type TxBasic

type TxBasic struct {
	TxID          string
	FormattedSize string
	Total         float64
	Fee           dcrutil.Amount
	FeeRate       dcrutil.Amount
	VoteInfo      *VoteInfo
	Coinbase      bool
}

TxBasic models data for transactions on the block page

type TxInID

type TxInID struct {
	Hash  string
	Index uint32
}

TxInID models the identity of a spending transaction input

type TxInfo

type TxInfo struct {
	*TxBasic
	SpendingTxns     []TxInID
	Type             string
	Vin              []Vin
	Vout             []Vout
	BlockHeight      int64
	BlockIndex       uint32
	BlockHash        string
	BlockMiningFee   int64
	Confirmations    int64
	Time             TimeDef
	Mature           string
	VoteFundsLocked  string
	Maturity         int64   // Total number of blocks before mature
	MaturityTimeTill float64 // Time in hours until mature
	TicketInfo
}

TxInfo models data needed for display on the tx page

func (*TxInfo) BlocksToTicketMaturity

func (t *TxInfo) BlocksToTicketMaturity() (blocks int64)

BlocksToTicketMaturity will return 0 if this isn't an immature ticket.

func (*TxInfo) IsExpiredTicket

func (t *TxInfo) IsExpiredTicket() bool

IsExpiredTicket verifies the conditions: 1. is a ticket, 2. is mature, 3. hasn't voted, 4. is past expiration.

func (*TxInfo) IsImmatureCoinbase

func (t *TxInfo) IsImmatureCoinbase() bool

IsImmatureCoinbase verifies the conditions: 1. is coinbase, 2. is not mature.

func (*TxInfo) IsImmatureRevocation

func (t *TxInfo) IsImmatureRevocation() bool

IsImmatureRevocation verifies the conditions: 1. is a revocation, 2. is not mature.

func (*TxInfo) IsImmatureTicket

func (t *TxInfo) IsImmatureTicket() bool

IsImmatureTicket verifies the conditions: 1. is a ticket, 2. is not mature.

func (*TxInfo) IsImmatureVote

func (t *TxInfo) IsImmatureVote() bool

IsImmatureVote verifies the conditions: 1. is a vote, 2. is not mature.

func (*TxInfo) IsLiveTicket

func (t *TxInfo) IsLiveTicket() bool

IsLiveTicket verifies the conditions: 1. is a ticket, 2. is mature, 3. hasn't voted, 4. isn't expired.

func (*TxInfo) IsRevocation

func (t *TxInfo) IsRevocation() bool

IsRevocation checks whether this transaction is a revocation.

func (*TxInfo) IsTicket

func (t *TxInfo) IsTicket() bool

IsTicket checks whether this transaction is a ticket.

func (*TxInfo) IsVote

func (t *TxInfo) IsVote() bool

IsVote checks whether this transaction is a vote.

type Vin

type Vin struct {
	*chainjson.Vin
	Addresses       []string
	FormattedAmount string
	Index           uint32
	DisplayText     string
	TextIsHash      bool
	Link            string
}

Vin models basic data about a tx input for display

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"`
	TicketSpent        string                  `json:"ticket_spent"`
	MempoolTicketIndex int                     `json:"mempool_ticket_index"`
	ForLastBlock       bool                    `json:"last_block"`
}

VoteInfo models data about a SSGen transaction (vote)

func (*VoteInfo) DeepCopy

func (vi *VoteInfo) DeepCopy() *VoteInfo

func (*VoteInfo) SetTicketIndex

func (vi *VoteInfo) SetTicketIndex(ticketSpendInds BlockValidatorIndex)

SetTicketIndex assigns the VoteInfo an index based on the block that the vote is (in)validating and the spent ticket hash. The ticketSpendInds tracks known combinations of target block and spent ticket hash. This index is used for sorting in views and counting total unique votes for a block.

func (*VoteInfo) VotesOnBlock

func (vi *VoteInfo) VotesOnBlock(blockHash string) bool

VotesOnBlock indicates if the vote is voting on the validity of block specified by the given hash.

type VoteTally

type VoteTally struct {
	TicketsPerBlock int    `json:"-"`
	Marks           []bool `json:"marks"`
}

VoteTally manages a list of bools representing the votes for a block.

func (*VoteTally) Affirmations

func (tally *VoteTally) Affirmations() (c int)

Affirmations counts the number of selected ticket holders who have voted in favor of the block for the given hash.

func (*VoteTally) Mark

func (tally *VoteTally) Mark(vote bool)

Mark adds the vote to the VoteTally.

func (*VoteTally) Status

func (tally *VoteTally) Status() ([]int, int)

Status is a list of ints representing votes both received and not yet received for a block, and a single int representing consensus. 0: rejected, 1: affirmed, 2: vote not yet received

func (*VoteTally) VoteCount

func (tally *VoteTally) VoteCount() int

VoteCount is the number of votes received.

type VotingInfo

type VotingInfo struct {
	TicketsVoted     uint16          `json:"tickets_voted"`
	MaxVotesPerBlock uint16          `json:"max_votes_per_block"`
	VotedTickets     map[string]bool `json:"-"`
	// VoteTallys maps block hash to vote counts.
	VoteTallys map[string]*VoteTally `json:"vote_tally"`
}

VotingInfo models data about the validity of the next block from mempool.

func NewVotingInfo

func NewVotingInfo(votesPerBlock uint16) VotingInfo

NewVotingInfo initializes a VotingInfo.

func (*VotingInfo) BlockStatus

func (vi *VotingInfo) BlockStatus(hash string) ([]int, int)

BlockStatus fetches a list of votes in mempool, for the provided block hash. If not found, a list of VoteMissing is returned.

func (*VotingInfo) Tally

func (vi *VotingInfo) Tally(vinfo *VoteInfo)

Tally adds the VoteInfo to the VotingInfo.VoteTally

type Vout

type Vout struct {
	Addresses       []string
	Amount          float64
	FormattedAmount string
	Type            string
	Spent           bool
	OP_RETURN       string
	Index           uint32
}

Vout models basic data about a tx output for display

type WebBasicBlock

type WebBasicBlock 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"`
	NumTx       uint32   `json:"txlength"`
	PoolSize    uint32   `json:"poolsize"`
	PoolValue   float64  `json:"poolvalue"`
	PoolValAvg  float64  `json:"poolvalavg"`
	PoolWinners []string `json:"winners"`
}

WebBasicBlock is used for quick DB data without rpc calls

type WebsocketBlock

type WebsocketBlock struct {
	Block *BlockInfo `json:"block"`
	Extra *HomeInfo  `json:"extra"`
}

WebsocketBlock wraps the new block info for use in the websocket

Jump to

Keyboard shortcuts

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