cmsplugin

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version              = "1"
	ID                   = "cms"
	CmdVoteDetails       = "votedccdetails"
	CmdStartVote         = "startdccvote"
	CmdCastVote          = "castdccvote"
	CmdInventory         = "cmsinventory"
	CmdVoteSummary       = "votedccsummary"
	CmdDCCVoteResults    = "dccvoteresults"
	MDStreamVoteBits     = 16 // Vote bits and mask
	MDStreamVoteSnapshot = 17 // Vote tickets and start/end parameters

	VoteDurationMin = 2016 // Minimum vote duration (in blocks)
	VoteDurationMax = 4032 // Maximum vote duration (in blocks)

	// Error status codes
	ErrorStatusInvalid          ErrorStatusT = 0
	ErrorStatusInternalError    ErrorStatusT = 1
	ErrorStatusDCCNotFound      ErrorStatusT = 2
	ErrorStatusInvalidVoteBit   ErrorStatusT = 3
	ErrorStatusVoteHasEnded     ErrorStatusT = 4
	ErrorStatusDuplicateVote    ErrorStatusT = 5
	ErrorStatusIneligibleUserID ErrorStatusT = 6
	ErrorStatusLast             ErrorStatusT = 7

	// String constant to ensure that the observed dcc vote option is tabulated
	// as "approved" or "disapproved".
	DCCApprovalString    = "yes"
	DCCDisapprovalString = "no"
)

Plugin settings, kinda doesn't go here but for now it is fine

View Source
const VersionStartVote = 1
View Source
const VersionStartVoteReply = 1

Variables

View Source
var (
	// ErrorStatus converts error status codes to human readable text.
	ErrorStatus = map[ErrorStatusT]string{
		ErrorStatusInvalid:          "invalid error status",
		ErrorStatusInternalError:    "internal error",
		ErrorStatusDCCNotFound:      "dcc not found",
		ErrorStatusInvalidVoteBit:   "invalid vote bit",
		ErrorStatusVoteHasEnded:     "vote has ended",
		ErrorStatusDuplicateVote:    "duplicate vote",
		ErrorStatusIneligibleUserID: "inegligible user id",
	}
)

Functions

func EncodeCastVote

func EncodeCastVote(cv CastVote) ([]byte, error)

EncodeCastVote encodes CastVotes into a JSON byte slice.

func EncodeCastVoteReply

func EncodeCastVoteReply(cvr CastVoteReply) ([]byte, error)

EncodeCastVoteReply encodes CastVoteReply into a JSON byte slice.

func EncodeInventory

func EncodeInventory(i Inventory) ([]byte, error)

EncodeInventory encodes Inventory into a JSON byte slice.

func EncodeInventoryReply

func EncodeInventoryReply(ir InventoryReply) ([]byte, error)

EncodeInventoryReply encodes a InventoryReply into a JSON byte slice.

func EncodeLoadVoteResults

func EncodeLoadVoteResults(lvr LoadVoteResults) ([]byte, error)

EncodeLoadVoteResults encodes a LoadVoteResults into a JSON byte slice.

func EncodeLoadVoteResultsReply

func EncodeLoadVoteResultsReply(reply LoadVoteResultsReply) ([]byte, error)

EncodeLoadVoteResultsReply encodes a LoadVoteResultsReply into a JSON byte slice.

func EncodeStartVote

func EncodeStartVote(v StartVote) ([]byte, error)

EncodeStartVote a JSON byte slice.

func EncodeStartVoteReply

func EncodeStartVoteReply(v StartVoteReply) ([]byte, error)

EncodeStartVoteReply encodes StartVoteReply into a JSON byte slice.

func EncodeVote

func EncodeVote(v Vote) ([]byte, error)

EncodeVote encodes Vote into a JSON byte slice.

func EncodeVoteDetails

func EncodeVoteDetails(vd VoteDetails) ([]byte, error)

EncodeVoteDetails encodes VoteDetails into a JSON byte slice.

func EncodeVoteDetailsReply

func EncodeVoteDetailsReply(vdr VoteDetailsReply) ([]byte, error)

EncodeVoteDetailsReply encodes VoteDetailsReply into a JSON byte slice.

func EncodeVoteResults

func EncodeVoteResults(v VoteResults) ([]byte, error)

EncodeVoteResults encodes VoteResults into a JSON byte slice.

func EncodeVoteResultsReply

func EncodeVoteResultsReply(v VoteResultsReply) ([]byte, error)

EncodeVoteResultsReply encodes VoteResults into a JSON byte slice.

func EncodeVoteSummary

func EncodeVoteSummary(v VoteSummary) ([]byte, error)

EncodeVoteSummary encodes VoteSummary into a JSON byte slice.

func EncodeVoteSummaryReply

func EncodeVoteSummaryReply(v VoteSummaryReply) ([]byte, error)

EncodeVoteSummaryReply encodes VoteSummary into a JSON byte slice.

Types

type CastVote

type CastVote struct {
	Token     string `json:"token"`     // DCC ID
	UserID    string `json:"publickey"` // User ID provided by cmswww
	VoteBit   string `json:"votebit"`   // Vote bit that was selected, this is encode in hex
	Signature string `json:"signature"` // Signature of the Token+VoteBit+UserID by the submitting user.
}

CastVote is a signed vote.

func DecodeCastVote

func DecodeCastVote(payload []byte) (*CastVote, error)

DecodeCastVote decodes a JSON byte slice into a CastVote.

type CastVoteReply

type CastVoteReply struct {
	ClientSignature string       `json:"clientsignature"`       // Signature that was sent in
	Signature       string       `json:"signature"`             // Signature of the ClientSignature
	Error           string       `json:"error"`                 // Error status message
	ErrorStatus     ErrorStatusT `json:"errorstatus,omitempty"` // Error status code
}

CastVoteReply contains the signature or error to a cast vote command. The Error and ErrorStatus fields will only be populated if something went wrong while attempting to cast the vote.

func DecodeCastVoteReply

func DecodeCastVoteReply(payload []byte) (*CastVoteReply, error)

DecodeCastVoteReply decodes a JSON byte slice into a CastVote.

type ErrorStatusT

type ErrorStatusT int

type Inventory

type Inventory struct{}

Inventory is used to retrieve the decred plugin inventory.

func DecodeInventory

func DecodeInventory(payload []byte) (*Inventory, error)

DecodeInventory decodes a JSON byte slice into a Inventory.

type InventoryReply

type InventoryReply struct {
	StartVoteTuples []StartVoteTuple `json:"startvotetuples"` // Start vote tuples
	CastVotes       []CastVote       `json:"castvotes"`       // Cast votes
}

InventoryReply returns the cms plugin inventory.

func DecodeInventoryReply

func DecodeInventoryReply(payload []byte) (*InventoryReply, error)

DecodeInventoryReply decodes a JSON byte slice into a inventory.

type LoadVoteResults

type LoadVoteResults struct {
	BestBlock uint64 `json:"bestblock"` // Best block height
}

LoadVoteResults creates a vote results entry in the cache for any proposals that have finsished voting but have not yet been added to the lazy loaded vote results table.

func DecodeLoadVoteResults

func DecodeLoadVoteResults(payload []byte) (*LoadVoteResults, error)

DecodeLoadVoteResults decodes a JSON byte slice into a LoadVoteResults.

type LoadVoteResultsReply

type LoadVoteResultsReply struct{}

LoadVoteResultsReply is the reply to the LoadVoteResults command.

func DecodeLoadVoteResultsReply

func DecodeLoadVoteResultsReply(payload []byte) (*LoadVoteResultsReply, error)

DecodeLoadVoteResultsReply decodes a JSON byte slice into a LoadVoteResults.

type StartVote

type StartVote struct {
	// decred plugin only data
	Version uint   `json:"version"` // Version of this structure
	Token   string `json:"token"`   // Token

	PublicKey   string       `json:"publickey"`   // Key used for signature.
	UserWeights []UserWeight `json:"userweights"` // Array of User ID + weight
	Vote        Vote         `json:"vote"`        // Vote + options
	Signature   string       `json:"signature"`   // Signature of Votehash
}

StartVote instructs the plugin to commence voting on a proposal with the provided vote bits.

func DecodeStartVote

func DecodeStartVote(payload []byte) (StartVote, error)

DecodeStartVote a JSON byte slice into a StartVote.

func (*StartVote) VerifySignature

func (s *StartVote) VerifySignature() error

VerifySignature verifies that the StartVoteV2 signature is correct.

type StartVoteReply

type StartVoteReply struct {
	// cms plugin only data
	Version uint `json:"version"` // Version of this structure

	// Shared data
	StartBlockHeight uint32 `json:"startblockheight"` // Block height
	StartBlockHash   string `json:"startblockhash"`   // Block hash
	EndHeight        uint32 `json:"endheight"`        // Height of vote end
}

StartVoteReply is the reply to StartVote.

func DecodeStartVoteReply

func DecodeStartVoteReply(payload []byte) (StartVoteReply, error)

DecodeStartVoteReply decodes a JSON byte slice into a StartVoteReply.

type StartVoteTuple

type StartVoteTuple struct {
	StartVote      StartVote      `json:"startvote"`      // Start vote
	StartVoteReply StartVoteReply `json:"startvotereply"` // Start vote reply
}

StartVoteTuple is used to return the StartVote and StartVoteReply for a record. StartVoteReply does not contain any record identifying data so it must be returned with the StartVote in order to know what record it belongs to.

type UserWeight

type UserWeight struct {
	UserID string `json:"userid"` // Unique user id from cmswww.
	Weight int64  `json:"weight"` // Calculated user voted weight, provided by cmswww.
}

UserWeight describes a single vote option.

type Vote

type Vote struct {
	Token            string       `json:"token"`            // Token that identifies vote
	Mask             uint64       `json:"mask"`             // Valid votebits
	Duration         uint32       `json:"duration"`         // Duration in blocks
	QuorumPercentage uint32       `json:"quorumpercentage"` // Percent of eligible votes required for quorum
	PassPercentage   uint32       `json:"passpercentage"`   // Percent of total votes required to pass
	Options          []VoteOption `json:"options"`          // Vote option
}

Vote represents the vote options for vote that is identified by its token.

func DecodeVote

func DecodeVote(payload []byte) (*Vote, error)

DecodeVote decodes a JSON byte slice into a Vote.

type VoteDetails

type VoteDetails struct {
	Token string `json:"token"` // Censorship token
}

VoteDetails is used to retrieve the voting period details for a record.

func DecodeVoteDetails

func DecodeVoteDetails(payload []byte) (*VoteDetails, error)

DecodeVoteDetails decodes a JSON byte slice into a VoteDetails.

type VoteDetailsReply

type VoteDetailsReply struct {
	StartVote      StartVote      `json:"startvote"`      // Vote ballot
	StartVoteReply StartVoteReply `json:"startvotereply"` // Start vote snapshot
}

VoteDetailsReply is the reply to VoteDetails.

func DecodeVoteDetailsReply

func DecodeVoteDetailsReply(payload []byte) (*VoteDetailsReply, error)

DecodeVoteReply decodes a JSON byte slice into a VoteDetailsReply.

type VoteOption

type VoteOption struct {
	Id          string `json:"id"`          // Single unique word identifying vote (e.g. yes)
	Description string `json:"description"` // Longer description of the vote.
	Bits        uint64 `json:"bits"`        // Bits used for this option
}

VoteOption describes a single vote option.

type VoteOptionResult

type VoteOptionResult struct {
	ID          string `json:"id"`          // Single unique word identifying vote (e.g. yes)
	Description string `json:"description"` // Longer description of the vote.
	Bits        uint64 `json:"bits"`        // Bits used for this option
	Votes       uint64 `json:"votes"`       // Number of votes cast for this option
}

VoteOptionResult describes a vote option and the total number of votes that have been cast for this option.

type VoteResults

type VoteResults struct {
	Token string `json:"token"` // Censorship token
}

func DecodeVoteResults

func DecodeVoteResults(payload []byte) (*VoteResults, error)

DecodeVoteResults decodes a JSON byte slice into a VoteResults.

type VoteResultsReply

type VoteResultsReply struct {
	StartVote StartVote  `json:"startvote"` // Original ballot
	CastVotes []CastVote `json:"castvotes"` // All votes
}

func DecodeVoteResultsReply

func DecodeVoteResultsReply(payload []byte) (*VoteResultsReply, error)

DecodeVoteResultsReply decodes a JSON byte slice into a VoteResults.

type VoteSummary

type VoteSummary struct {
	Token string `json:"token"` // Censorship token
}

VoteSummary requests a summary of a proposal vote. This includes certain voting period parameters and a summary of the vote results.

func DecodeVoteSummary

func DecodeVoteSummary(payload []byte) (*VoteSummary, error)

DecodeVoteSummary decodes a JSON byte slice into a VoteSummary.

type VoteSummaryReply

type VoteSummaryReply struct {
	Duration       uint32             `json:"duration"`       // Vote duration
	EndHeight      uint32             `json:"endheight"`      // End block height
	PassPercentage uint32             `json:"passpercentage"` // Percent of total votes required to pass
	Results        []VoteOptionResult `json:"results"`        // Vote results
}

VoteSummaryReply is the reply to the VoteSummary command and returns certain voting period parameters as well as a summary of the vote results.

func DecodeVoteSummaryReply

func DecodeVoteSummaryReply(payload []byte) (*VoteSummaryReply, error)

DecodeVoteSummaryReply decodes a JSON byte slice into a VoteSummaryReply.

Jump to

Keyboard shortcuts

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