github.com/decred/politeia@v1.4.0/politeiawww/api/www/v2/v2.go (about)

     1  // Copyright (c) 2020 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package v2
     6  
     7  import (
     8  	"fmt"
     9  )
    10  
    11  type ErrorStatusT int
    12  type VoteT int
    13  
    14  const (
    15  	APIVersion = 2
    16  
    17  	// All routes in the package are NO LONGER SUPPORTED.
    18  	RouteStartVote       = "/vote/start"
    19  	RouteStartVoteRunoff = "/vote/startrunoff"
    20  	RouteVoteDetails     = "/vote/{token:[A-z0-9]{64}}"
    21  
    22  	// Vote types
    23  	//
    24  	// VoteTypeStandard is used to indicate a simple approve or reject
    25  	// proposal vote where the winner is the voting option that has met
    26  	// the specified pass and quorum requirements.
    27  	//
    28  	// VoteTypeRunoff specifies a runoff vote that multiple proposals compete in.
    29  	// All proposals are voted on like normal, but there can only be one winner
    30  	// in a runoff vote. The winner is the proposal that meets the quorum
    31  	// requirement, meets the pass requirement, and that has the most net yes
    32  	// votes. The winning proposal is considered approved and all other proposals
    33  	// are considered rejected. If no proposals meet the quorum and pass
    34  	// requirements then all proposals are considered rejected.
    35  	// Note: in a runoff vote it is possible for a proposal to meet the quorum
    36  	// and pass requirements but still be rejected if it does not have the most
    37  	// net yes votes.
    38  	VoteTypeInvalid  VoteT = 0
    39  	VoteTypeStandard VoteT = 1
    40  	VoteTypeRunoff   VoteT = 2
    41  
    42  	// AuthorizeVote actions
    43  	AuthVoteActionAuthorize = "authorize"
    44  	AuthVoteActionRevoke    = "revoke"
    45  )
    46  
    47  var (
    48  	// APIRoute is the prefix to the v2 API routes
    49  	APIRoute = fmt.Sprintf("/v%v", APIVersion)
    50  )
    51  
    52  // VoteOption describes a single vote option.
    53  type VoteOption struct {
    54  	Id          string `json:"id"`          // Single unique word identifying vote (e.g. yes)
    55  	Description string `json:"description"` // Longer description of the vote.
    56  	Bits        uint64 `json:"bits"`        // Bits used for this option
    57  }
    58  
    59  // AuthorizeVote is used to indicate that a proposal has been finalized and is
    60  // ready to be voted on.
    61  type AuthorizeVote struct {
    62  	Token     string `json:"token"`     // Proposal token
    63  	Action    string `json:"action"`    // Authorize or revoke
    64  	PublicKey string `json:"publickey"` // Key used for signature
    65  	Signature string `json:"signature"` // Signature of token+version+action
    66  }
    67  
    68  // Vote represents the vote params and vote options for a proposal vote.
    69  //
    70  // QuorumPercentage is the percent of eligible votes required for a quorum.
    71  // PassPercentage is the percent of total votes required for the proposal to
    72  // be considered approved.
    73  //
    74  // Differences between v1 and v2:
    75  //   - Added the Version field that specifies the version of the proposal that is
    76  //     being voted on. This was added so that the proposal version is included in
    77  //     the StartVote signature.
    78  //   - Added the Type field that specifies the vote type.
    79  type Vote struct {
    80  	Token            string       `json:"token"`            // Proposal token
    81  	ProposalVersion  uint32       `json:"proposalversion"`  // Proposal version of vote
    82  	Type             VoteT        `json:"type"`             // Type of vote
    83  	Mask             uint64       `json:"mask"`             // Valid votebits
    84  	Duration         uint32       `json:"duration"`         // Duration in blocks
    85  	QuorumPercentage uint32       `json:"quorumpercentage"` // Quorum requirement
    86  	PassPercentage   uint32       `json:"passpercentage"`   // Approval requirement
    87  	Options          []VoteOption `json:"options"`          // Vote options
    88  }
    89  
    90  // StartVote starts the voting period on the given proposal.
    91  //
    92  // Signature is a signature of the hex encoded SHA256 digest of the JSON
    93  // encoded v2 Vote struct.
    94  //
    95  // Differences between v1 and v2:
    96  //   - Signature has been updated to be a signature of the Vote hash. It was
    97  //     previously a signature of just the proposal token.
    98  //   - Vote has been updated. See the Vote comment for more details.
    99  //
   100  // This request is NO LONGER SUPPORTED. Use the pi/v1 API instead.
   101  type StartVote struct {
   102  	Vote      Vote   `json:"vote"`
   103  	PublicKey string `json:"publickey"` // Key used for signature
   104  	Signature string `json:"signature"` // Signature of Vote hash
   105  }
   106  
   107  // StartVoteReply is the reply to the StartVote command.
   108  //
   109  // Differences between v1 and v2:
   110  //   - StartBlockHeight was changed from a string to a uint32.
   111  //   - EndBlockHeight was changed from a string to a uint32. It was also renamed
   112  //     from EndHeight to EndBlockHeight to be consistent with StartBlockHeight.
   113  //
   114  // This request is NO LONGER SUPPORTED. Use the pi/v1 API instead.
   115  type StartVoteReply struct {
   116  	StartBlockHeight uint32   `json:"startblockheight"` // Block height of vote start
   117  	StartBlockHash   string   `json:"startblockhash"`   // Block hash of vote start
   118  	EndBlockHeight   uint32   `json:"endblockheight"`   // Block height of vote end
   119  	EligibleTickets  []string `json:"eligibletickets"`  // Valid voting tickets
   120  }
   121  
   122  // StartVoteRunoff starts the runoff voting process on all public,
   123  // non-abandoned RFP submissions for the provided RFP token.
   124  //
   125  // AuthorizeVotes must contain a vote authorization for each RFP submission
   126  // that is participating in the runoff vote. Unlike standard votes, these vote
   127  // authorizations are not signed by the submission author. They are signed by
   128  // the admin starting the runoff vote.
   129  //
   130  // StartVotes must contain a StartVote for each RFP submission that is
   131  // participating in the runoff vote. The runoff vote can only be started once
   132  // the RFP proposal itself has been approved by a vote and once the LinkBy
   133  // submission deadline has expired. Once the LinkBy deadline has expired, the
   134  // runoff vote can be started at any point by an admin. It is not required that
   135  // RFP submission authors authorize the start of the vote.
   136  //
   137  // This request is NO LONGER SUPPORTED. Use the pi/v1 API instead.
   138  type StartVoteRunoff struct {
   139  	Token          string          `json:"token"`
   140  	AuthorizeVotes []AuthorizeVote `json:"authorizevotes"`
   141  	StartVotes     []StartVote     `json:"startvotes"`
   142  }
   143  
   144  // The StartVoteRunoffReply is the reply to the StartVoteRunoff command. The
   145  // returned vote info will be the same for all RFP submissions.
   146  //
   147  // This request is NO LONGER SUPPORTED. Use the pi/v1 API instead.
   148  type StartVoteRunoffReply struct {
   149  	StartBlockHeight uint32   `json:"startblockheight"` // Block height of vote start
   150  	StartBlockHash   string   `json:"startblockhash"`   // Block hash of vote start
   151  	EndBlockHeight   uint32   `json:"endblockheight"`   // Block height of vote end
   152  	EligibleTickets  []string `json:"eligibletickets"`  // Valid voting tickets
   153  }
   154  
   155  // VoteDetails returns the votes details for the specified proposal.
   156  //
   157  // This request is NO LONGER SUPPORTED. Use the pi/v1 API instead.
   158  type VoteDetails struct {
   159  	Token string `json:"token"` // Proposal token
   160  }
   161  
   162  // VoteDetailsReply is the reply to the VoteDetails command. It contains all
   163  // of the information from a StartVote and StartVoteReply.
   164  //
   165  // Version specifies the StartVote version that was used to initiate the
   166  // proposal vote. See the StartVote comment for details on the differences
   167  // between the StartVote versions.
   168  //
   169  // Vote contains a JSON encoded Vote and needs to be decoded according to the
   170  // Version. See the Vote comment for details on the differences between the
   171  // Vote versions.
   172  //
   173  // This request is NO LONGER SUPPORTED. Use the pi/v1 API instead.
   174  type VoteDetailsReply struct {
   175  	Version          uint32   `json:"version"`          // StartVote version
   176  	Vote             string   `json:"vote"`             // JSON encoded Vote struct
   177  	PublicKey        string   `json:"publickey"`        // Key used for signature
   178  	Signature        string   `json:"signature"`        // Start vote signature
   179  	StartBlockHeight uint32   `json:"startblockheight"` // Block height
   180  	StartBlockHash   string   `json:"startblockhash"`   // Block hash
   181  	EndBlockHeight   uint32   `json:"endblockheight"`   // Height of vote end
   182  	EligibleTickets  []string `json:"eligibletickets"`  // Valid voting ticket
   183  }