Documentation
¶
Index ¶
- func CreateNew(dbFile, feeXPub string) error
- type AltSignAddrData
- type FeeStatus
- type FeeXPub
- type Ticket
- type TicketList
- type TicketOutcome
- type VoteChangeRecord
- type VspDatabase
- func (vdb *VspDatabase) AllXPubs() (map[uint32]FeeXPub, error)
- func (vdb *VspDatabase) AltSignAddrData(ticketHash string) (*AltSignAddrData, error)
- func (vdb *VspDatabase) BackupDB(w http.ResponseWriter) error
- func (vdb *VspDatabase) Close(writeBackup bool)
- func (vdb *VspDatabase) CookieSecret() ([]byte, error)
- func (vdb *VspDatabase) CountTickets() (int64, int64, int64, int64, error)
- func (vdb *VspDatabase) DeleteAltSignAddr(ticketHash string) error
- func (vdb *VspDatabase) DeleteTicket(ticket Ticket) error
- func (vdb *VspDatabase) FeeXPub() (FeeXPub, error)
- func (vdb *VspDatabase) GetMissedTickets() (TicketList, error)
- func (vdb *VspDatabase) GetMissingPurchaseHeight() (TicketList, error)
- func (vdb *VspDatabase) GetPendingFees() (TicketList, error)
- func (vdb *VspDatabase) GetRevokedTickets() (TicketList, error)
- func (vdb *VspDatabase) GetTicketByHash(ticketHash string) (Ticket, bool, error)
- func (vdb *VspDatabase) GetUnconfirmedFees() (TicketList, error)
- func (vdb *VspDatabase) GetUnconfirmedTickets() (TicketList, error)
- func (vdb *VspDatabase) GetVotableTickets() (TicketList, error)
- func (vdb *VspDatabase) GetVoteChanges(ticketHash string) (map[uint32]VoteChangeRecord, error)
- func (vdb *VspDatabase) GetVotedTickets() (TicketList, error)
- func (vdb *VspDatabase) InsertAltSignAddr(ticketHash string, data *AltSignAddrData) error
- func (vdb *VspDatabase) InsertNewTicket(ticket Ticket) error
- func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error)
- func (vdb *VspDatabase) RetireXPub(xpub string) error
- func (vdb *VspDatabase) SaveVoteChange(ticketHash string, record VoteChangeRecord) error
- func (vdb *VspDatabase) SetLastAddressIndex(idx uint32) error
- func (vdb *VspDatabase) Size() (uint64, error)
- func (vdb *VspDatabase) UpdateTicket(ticket Ticket) error
- func (vdb *VspDatabase) Upgrade(currentVersion uint32) error
- func (vdb *VspDatabase) Version() (uint32, error)
- func (vdb *VspDatabase) WriteHotBackupFile() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateNew ¶
CreateNew intializes a new bbolt database with all of the necessary vspd buckets, and inserts: - the provided extended pubkey (to be used for deriving fee addresses). - an ed25519 keypair to sign API responses. - a secret key to use for initializing a HTTP cookie store. Note: CreateNew should always initialize a database of the most recent version, meaning that every change described in upgrade_vX.go files is already applied.
Types ¶
type AltSignAddrData ¶
type AltSignAddrData struct { // AltSignAddr is the new alternate signing address. It is base 58 encoded. AltSignAddr string // Req is the original request to set an alternate signing address. Req string // ReqSig is the request's signature signed by the commitment address of the // corresponding ticket. It is base 64 encoded. ReqSig string // Resp is the original response from the server to the alternate signing // address. Resp string // RespSig is the response's signature signed by the server. It is base 64 // encoded. RespSig string }
AltSignAddrData holds the information needed to prove that a client added an alternate signing address.
type FeeStatus ¶
type FeeStatus string
FeeStatus represents the current state of a ticket fee payment.
const ( // NoFee indicates no fee tx has been received yet. NoFee FeeStatus = "none" // FeeReceieved indicates fee tx has been received but not broadcast. FeeReceieved FeeStatus = "received" // FeeBroadcast indicates fee tx has been broadcast but not confirmed. FeeBroadcast FeeStatus = "broadcast" // FeeConfirmed indicates fee tx has been broadcast and confirmed. FeeConfirmed FeeStatus = "confirmed" // FeeError indicates fee tx could not be broadcast due to an error. FeeError FeeStatus = "error" )
type FeeXPub ¶
type FeeXPub struct { ID uint32 `json:"id"` Key string `json:"key"` LastUsedIdx uint32 `json:"lastusedidx"` // Retired is a unix timestamp representing the moment the key was retired, // or zero for the currently active key. Retired int64 `json:"retired"` }
FeeXPub is serialized to json and stored in bbolt db.
type Ticket ¶
type Ticket struct { Hash string PurchaseHeight int64 CommitmentAddress string FeeAddressXPubID uint32 FeeAddressIndex uint32 FeeAddress string FeeAmount int64 FeeExpiration int64 // Confirmed will be set when the ticket has 6+ confirmations. Confirmed bool // VotingWIF is set in /payfee. VotingWIF string // VoteChoices, TSpendPolicy and TreasuryPolicy are initially set in // /payfee, but can be updated in /setvotechoices. VoteChoices map[string]string TSpendPolicy map[string]string TreasuryPolicy map[string]string // FeeTxHex and FeeTxHash will be set when the fee tx has been received. FeeTxHex string FeeTxHash string // FeeTxStatus indicates the current state of the fee transaction. FeeTxStatus FeeStatus // Outcome is set once a ticket is either voted or revoked. An empty outcome // indicates that a ticket is still votable. Outcome TicketOutcome }
func (*Ticket) FeeExpired ¶
type TicketList ¶
type TicketList []Ticket
func (TicketList) EarliestPurchaseHeight ¶
func (t TicketList) EarliestPurchaseHeight() int64
EarliestPurchaseHeight returns the lowest non-zero purchase height in the list of tickets. Zero will be returned if the list is empty, or if every ticket in the list has zero purchase height.
func (TicketList) SortByPurchaseHeight ¶
func (t TicketList) SortByPurchaseHeight()
type TicketOutcome ¶
type TicketOutcome string
TicketOutcome describes the reason a ticket is no longer votable.
const ( // Expired indicates the ticket expired and has been revoked. Expired TicketOutcome = "expired" // Missed indicates the ticket was missed and has been revoked. Missed TicketOutcome = "missed" // Voted indicates the ticket has already voted. Voted TicketOutcome = "voted" // Revoked is a deprecated status which should no longer be used. It was // used before vspd was able to distinguish between expired and missed // tickets. Revoked TicketOutcome = "revoked" )
type VoteChangeRecord ¶
type VoteChangeRecord struct { Request string `json:"req"` RequestSignature string `json:"reqs"` Response string `json:"rsp"` ResponseSignature string `json:"rsps"` }
VoteChangeRecord is serialized to json and stored in bbolt db. The json keys are deliberately kept short because they are duplicated many times in the db.
type VspDatabase ¶
type VspDatabase struct {
// contains filtered or unexported fields
}
VspDatabase wraps an instance of bolt.DB and provides VSP specific convenience functions.
func Open ¶
Open initializes and returns an open database. An error is returned if no database file is found at the provided path.
func (*VspDatabase) AllXPubs ¶
func (vdb *VspDatabase) AllXPubs() (map[uint32]FeeXPub, error)
AllXPubs retrieves the current and any retired extended pubkeys from the database.
func (*VspDatabase) AltSignAddrData ¶
func (vdb *VspDatabase) AltSignAddrData(ticketHash string) (*AltSignAddrData, error)
AltSignAddrData retrieves a ticket's alternate signing data. Existence of an alternate signing address can be inferred by no error and nil data return.
func (*VspDatabase) BackupDB ¶
func (vdb *VspDatabase) BackupDB(w http.ResponseWriter) error
BackupDB streams a backup of the database over an http response writer.
func (*VspDatabase) Close ¶
func (vdb *VspDatabase) Close(writeBackup bool)
Close will close the database and, if requested, make a copy of the database to the backup location.
func (*VspDatabase) CookieSecret ¶
func (vdb *VspDatabase) CookieSecret() ([]byte, error)
CookieSecret retrieves the generated cookie store secret key from the database.
func (*VspDatabase) CountTickets ¶
CountTickets returns the total number of voted, expired, missed, and currently voting tickets. This func iterates over every ticket so should be used sparingly.
func (*VspDatabase) DeleteAltSignAddr ¶
func (vdb *VspDatabase) DeleteAltSignAddr(ticketHash string) error
DeleteAltSignAddr deletes an alternate signing address from the database. Does not error if there is no record in the database to delete.
func (*VspDatabase) DeleteTicket ¶
func (vdb *VspDatabase) DeleteTicket(ticket Ticket) error
func (*VspDatabase) FeeXPub ¶
func (vdb *VspDatabase) FeeXPub() (FeeXPub, error)
FeeXPub retrieves the currently active extended pubkey used for generating fee addresses from the database.
func (*VspDatabase) GetMissedTickets ¶
func (vdb *VspDatabase) GetMissedTickets() (TicketList, error)
GetMissedTickets returns all tickets which have outcome == missed.
func (*VspDatabase) GetMissingPurchaseHeight ¶
func (vdb *VspDatabase) GetMissingPurchaseHeight() (TicketList, error)
GetMissingPurchaseHeight returns tickets which are confirmed but do not have a purchase height.
func (*VspDatabase) GetPendingFees ¶
func (vdb *VspDatabase) GetPendingFees() (TicketList, error)
GetPendingFees returns tickets which are confirmed and have a fee tx which is not yet broadcast.
func (*VspDatabase) GetRevokedTickets ¶
func (vdb *VspDatabase) GetRevokedTickets() (TicketList, error)
GetRevokedTickets returns all tickets which have outcome == revoked.
func (*VspDatabase) GetTicketByHash ¶
func (vdb *VspDatabase) GetTicketByHash(ticketHash string) (Ticket, bool, error)
func (*VspDatabase) GetUnconfirmedFees ¶
func (vdb *VspDatabase) GetUnconfirmedFees() (TicketList, error)
GetUnconfirmedFees returns tickets with a fee tx that is broadcast but not confirmed yet.
func (*VspDatabase) GetUnconfirmedTickets ¶
func (vdb *VspDatabase) GetUnconfirmedTickets() (TicketList, error)
GetUnconfirmedTickets returns tickets which are not yet confirmed.
func (*VspDatabase) GetVotableTickets ¶
func (vdb *VspDatabase) GetVotableTickets() (TicketList, error)
GetVotableTickets returns tickets with a confirmed fee tx and no outcome (ie. not expired/voted/missed).
func (*VspDatabase) GetVoteChanges ¶
func (vdb *VspDatabase) GetVoteChanges(ticketHash string) (map[uint32]VoteChangeRecord, error)
GetVoteChanges retrieves all of the stored vote change records for the provided ticket hash.
func (*VspDatabase) GetVotedTickets ¶
func (vdb *VspDatabase) GetVotedTickets() (TicketList, error)
GetVotedTickets returns tickets with a confirmed fee tx and outcome == voted.
func (*VspDatabase) InsertAltSignAddr ¶
func (vdb *VspDatabase) InsertAltSignAddr(ticketHash string, data *AltSignAddrData) error
InsertAltSignAddr will insert the provided alternate signing address into the database. Returns an error if data for the ticket hash already exist.
Passed data must have no empty fields.
func (*VspDatabase) InsertNewTicket ¶
func (vdb *VspDatabase) InsertNewTicket(ticket Ticket) error
InsertNewTicket will insert the provided ticket into the database. Returns an error if either the ticket hash or fee address already exist.
func (*VspDatabase) KeyPair ¶
func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error)
KeyPair retrieves the keypair used to sign API responses from the database.
func (*VspDatabase) RetireXPub ¶
func (vdb *VspDatabase) RetireXPub(xpub string) error
RetireXPub will mark the currently active xpub key as retired and insert the provided pubkey as the currently active one.
func (*VspDatabase) SaveVoteChange ¶
func (vdb *VspDatabase) SaveVoteChange(ticketHash string, record VoteChangeRecord) error
SaveVoteChange will insert the provided vote change record into the database, and if this breaches the maximum amount of allowed records, delete the oldest one which is currently stored. Records are stored using a serially increasing integer as the key.
func (*VspDatabase) SetLastAddressIndex ¶
func (vdb *VspDatabase) SetLastAddressIndex(idx uint32) error
SetLastAddressIndex updates the last index used to derive a new fee address from the fee xpub key.
func (*VspDatabase) Size ¶
func (vdb *VspDatabase) Size() (uint64, error)
Size returns the current size of the database in bytes. Note that this may not exactly match the size of the database file stored on disk.
func (*VspDatabase) UpdateTicket ¶
func (vdb *VspDatabase) UpdateTicket(ticket Ticket) error
func (*VspDatabase) Upgrade ¶
func (vdb *VspDatabase) Upgrade(currentVersion uint32) error
Upgrade will update the database to the latest known version.
func (*VspDatabase) Version ¶
func (vdb *VspDatabase) Version() (uint32, error)
Version returns the current database version.
func (*VspDatabase) WriteHotBackupFile ¶
func (vdb *VspDatabase) WriteHotBackupFile() error
WriteHotBackupFile writes a backup of the database file while the database is still open.