Voting System

From Nxtwiki
Jump to: navigation, search

Cast Vote

Cast a vote on a poll. POST only.

Request: Refer to Create Transaction Request for common parameters.

  • requestType is castVote
  • poll is the poll ID
  • vote00 is an integer within the allowed range to vote for option (answer) 0 (optional if minNumberOfOptions met, default is -128)
  • vote01 is an integer within the allowed range to vote for option (answer) 1 (optional if minNumberOfOptions met, default is -128)
  • vote02 is an integer within the allowed range to vote for option (answer) 2 (optional if minNumberOfOptions met, default is -128)

Note: The allowed vote values are integers between minRangeValue and maxRangeValue, inclusive. This range, along with the minimum and maximum number of options that can and must be voted on are specified when the poll is created. Refer to Create Poll.

Response: Refer to Create Transaction Response.

Cast Vote Example

http://localhost:7876/nxt?
  requestType=castVote&
  poll=5916389507928675673&
  vote02=1&
  secretPhrase=secretPhrase&
  feeNQT=100000000&
  deadline=60
{
 "signatureHash": "54fb93860d0668477d34f7828d6a2c19be1c9229e7cb5adcebdc4962319ab22b",
 "transactionJSON": {
  "senderPublicKey": "10f09c34f225d425306e5be55a4946908156072afbead4d574a512d7e086ef5c",
  "signature": "d48873e936e74069a56ba0eecdbfe3abe706bb7443e51d6651f59ef2500694087bd...",
  "feeNQT": "100000000",
  "type": 1,
  "fullHash": "ae7b714aadfe5efee0d690dfffac533dbf190827ed2f972d3dd552f4399ed648",
  "version": 1,
  "phased": false,
  "ecBlockId": "1999174047197129566",
  "signatureHash": "54fb93860d0668477d34f7828d6a2c19be1c9229e7cb5adcebdc4962319ab22b",
  "attachment": {
   "version.VoteCasting": 1,
   "poll": "5916389507928675673",
   "vote": [
    -128,
    -128,
    1
   ]
  },
  "senderRS": "NXT-4VDY-LNVT-LMAY-FMCKA",
  "subtype": 3,
  "amountNQT": "0",
  "sender": "15295723609781267838",
  "ecBlockHeight": 256208,
  "deadline": 60,
  "transaction": "18329367553676245934",
  "timestamp": 43095711,
  "height": 2147483647
 },
 "unsignedTransactionBytes": "01139f9691023c0010f09c34f225d425306e5be55a4946908156072a...",
 "broadcasted": true,
 "requestProcessingTime": 99,
 "transactionBytes": "01139f9691023c0010f09c34f225d425306e5be55a4946908156072afbead4d5...",
 "fullHash": "ae7b714aadfe5efee0d690dfffac533dbf190827ed2f972d3dd552f4399ed648",
 "transaction": "18329367553676245934"
}


Create Poll

Create a new poll. POST only.

Request: Refer to Create Transaction Request for common parameters.

  • requestType is createPoll
  • name is the name of the poll
  • description is the description of the poll, or the question to be answered
  • finishHeight is the block height when the poll is completed
  • votingModel is 0 for One Vote Per Account, 1 for Vote By NXT Balance, 2 for Vote By Asset Balance and 3 for Vote By Currency Balance
  • minNumberOfOptions is the minimum number of options (answers) that must be voted for
  • maxNumberOfOptions is the maximum number of options (answers) that can be voted for
  • minRangeValue is the minimum integer value for an option (answer) (>= 0)
  • maxRangeValue is the maximum integer value for an option (answer) (>= minRangeValue)
  • minBalance is the minimum balance (in NQT or QNT) required for voting (optional, default 0)
  • minBalanceModel is (required if minBalance > 0, must match votingModel when votingModel > 0)
    • 1 for NXT balance
    • 2 for an asset balance
    • 3 for a currency balance
  • holding is the asset or currency ID (required if minBalanceModel > 1)
  • option00 is the name of option (answer) 0
  • option01 is the name of option (answer) 1 (optional)
  • option02 is the name of option (answer) 2 (optional)

Notes: Up to 100 options (answers) can be specified, but there is an extra fee for each option beyond 20. Unlike the API, the NRS client treats a vote of 0 as a nonvote not contributing to the number answers (options) chosen. The NRS client uses checkboxes for selecting answers when minRangeValue = 0 and maxRangeValue = 1; otherwise sliding controls are used to select answers from the allowed range.

Note: When a balance affects the poll result, the result depends only on the balance (including pending outgoing phased transfers) computed just prior to the finish height.

Response: Refer to Create Transaction Response. The transaction ID is also the poll ID.

Create Poll Example

http://localhost:7876/nxt?
  requestType=createPoll&
  name=Gender Poll&
  description=What is your gender?&
  minNumberOfOptions=1&
  maxNumberOfOptions=1&
  minRangeValue=0&
  maxRangeValue=1&
  minBalance=100000000000&
  minBalanceModel=1&
  option00=Male&
  option01=Female&
  secretPhrase=secretPhrase&
  feeNQT=1000000000&
  deadline=60
{
 "signatureHash": "c55ceb631d9d9e92b99a326e0323f24d80b7859a28ca43c82e1a03a6b05f02fe",
 "transactionJSON": {
  "senderPublicKey": "10f09c34f225d425306e5be55a4946908156072afbead4d574a512d7e086ef5c",
  "signature": "ffcd924f00e14c9e2cc14a04984f0d0c21bdf4551c3e332e1559c378b2975b0b9f8...",
  "feeNQT": "1000000000",
  "type": 1,
  "fullHash": "fc9e0c8014853b7e48b16e2c51ca28c4cc74939ba193e8c040c97e36a42b89c5",
  "version": 1,
  "phased": false,
  "ecBlockId": "11503767830531050607",
  "signatureHash": "c55ceb631d9d9e92b99a326e0323f24d80b7859a28ca43c82e1a03a6b05f02fe",
  "attachment": {
   "minRangeValue": 0,
   "votingModel": 0,
   "description": "What is your gender?",
   "minNumberOfOptions": 1,
   "holding": "0",
   "minBalance": "100000000000",
   "name": "Gender Poll",
   "finishHeight": 256453,
   "options": [
    "Male",
    "Female"
   ],
   "maxNumberOfOptions": 1,
   "minBalanceModel": 1,
   "version.PollCreation": 1,
   "maxRangeValue": 1
  },
  "senderRS": "NXT-4VDY-LNVT-LMAY-FMCKA",
  "subtype": 2,
  "amountNQT": "0",
  "sender": "15295723609781267838",
  "ecBlockHeight": 256410,
  "deadline": 60,
  "transaction": "9096010195498999548",
  "timestamp": 43114026,
  "height": 2147483647
 },
 "unsignedTransactionBytes": "01122ade91023c0010f09c34f225d425306e5be55a4946908156072afb...",
 "broadcasted": true,
 "requestProcessingTime": 6,
 "transactionBytes": "01122ade91023c0010f09c34f225d425306e5be55a4946908156072afbead4d574...",
 "fullHash": "fc9e0c8014853b7e48b16e2c51ca28c4cc74939ba193e8c040c97e36a42b89c5",
 "transaction": "9096010195498999548"
}


Get Poll

Get the details of a poll.

Request:

  • requestType is getPoll
  • poll is the poll ID
  • requireBlock is the block ID of a block that must be present in the blockchain during execution (optional)
  • requireLastBlock is the block ID of a block that must be last in the blockchain during execution (optional)

Response:

  • poll (S) is the poll ID
  • account (S) is the account number of the poll creator
  • accountRS (S) is the Reed-Solomon address of the account
  • name (S) is the name of the poll
  • description (S) is the description of the poll, or the question to be answered
  • finishHeight (N) is the block height when the poll is completed
  • finished (B) is true if the poll is completed, false otherwise
  • votingModel (N) is 0 for One Vote Per Account, 1 for Vote By NXT Balance, 2 for Vote By Asset Balance and 3 for Vote By Currency Balance
  • minNumberOfOptions (N) is the minimum number of options (answers) that must be voted for
  • maxNumberOfOptions (N) is the maximum number of options (answers) that can be voted for
  • minBalance (S) is the minimum balance (in NQT or QNT) required for voting
  • minBalanceModel (N) is 1 for NXT balance, 2 for an asset balance, 3 for a currency balance when minBalance > 0
  • holding is the asset or currency ID when minBalanceModel > 1
  • options (A) is the array of options (answers)
  • minRangeValue (N) is the minimum integer value for an option (answer)
  • maxRangeValue (N) is the maximum integer value for an option (answer)
  • lastBlock (S) is the last block ID on the blockchain (applies if requireBlock is provided but not requireLastBlock)
  • requestProcessingTime (N) is the API request processing time (in millisec)

Get Poll Example

http://localhost:7876/nxt?
  requestType=getPoll&
  poll=9096010195498999548
{
 "minRangeValue": 0,
 "votingModel": 0,
 "description": "What is your gender?",
 "finished": true,
 "poll": "9096010195498999548",
 "requestProcessingTime": 1,
 "minNumberOfOptions": 1,
 "minBalance": "100000000000",
 "accountRS": "NXT-4VDY-LNVT-LMAY-FMCKA",
 "name": "Gender Poll",
 "options": [
  "Male",
  "Female"
 ],
 "finishHeight": 256453,
 "maxNumberOfOptions": 1,
 "minBalanceModel": 1,
 "account": "15295723609781267838",
 "maxRangeValue": 1
}


Get Poll Result

Get the result of a poll.

Request:

  • requestType is getPollResult
  • poll is the poll ID
  • votingModel (optional, default null)
  • holding (optional, default null)
  • minBalance (optional, default 0)
  • minBalanceModel (required if minBalance > 0, must match votingModel when votingModel > 0)
  • requireBlock is the block ID of a block that must be present in the blockchain during execution (optional)
  • requireLastBlock is the block ID of a block that must be last in the blockchain during execution (optional)

Note: The votingModel, holding, minBalance and minBalanceModel parameters are optional and default to the original values specified when the poll was created (refer to Create Poll). The original values can only be overridden while the votes are still stored in the database, until 1441 blocks after the poll is completed. If votingModel is specified, holding, minBalance and minBalanceModel or the defaults specified above apply, otherwise they are ignored.

Response:

  • poll (S) is the poll ID
  • votingModel (N) is the votingModel used to calculate results (refer to Note above)
  • minBalanceModel (N) is the minBalanceModel used to calculate results (refer to Note above)
  • minBalance (S) is the minBalance used to calculate results (refer to Note above)
  • holding (S) is the asset or currency ID if the voting model uses an asset or currency balance to determine weight, if applicable (refer to Note above)
  • decimals (N) is the number decimal places used by the asset or currency, if applicable
  • finished (B) is true if the poll is complete, false otherwise
  • options (A) is the array of options (answers) of the poll
  • results (A) is an array of result objects with the following fields for each result:
    • weight (S) is the sum of the weight of each account that voted for the corresponding option (answer); an account's weight is 1 if the voting model is 0, otherwise it is the NQT, asset QNT or currency QNT balance of the account if the voting model is 1, 2 or 3 respectively; however, the weight is 0 if minBalance is not met
    • result (S) is the sum over each account that voted for the corresponding option (answer) of: the product of the account's weight and the rangeValue selected when the vote was cast.
  • lastBlock (S) is the last block ID on the blockchain (applies if requireBlock is provided but not requireLastBlock)
  • requestProcessingTime (N) is the API request processing time (in millisec)

Get Poll Result Example

http://localhost:7876/nxt?
  requestType=getPollResult&
  poll=16742897359122764363
{
 "votingModel": 0,
 "minBalance": "0",
 "options": [
  "Option 00",
  "Option 01",
  "Option 02"
 ],
 "finished": true,
 "poll": "16742897359122764363",
 "requestProcessingTime": 2,
 "minBalanceModel": 0,
 "results": [
  {
   "result": "3",
   "weight": "1"
  },
  {
   "result": "9",
   "weight": "2"
  },
  {
   "result": "9",
   "weight": "2"
  }
 ]
}


Get Poll Vote

Get a poll vote given a poll ID and an account ID.

Request:

  • requestType is getPollVote
  • poll is the poll ID
  • account is the account ID
  • includeWeights is true to calculate and return the weight assigned to each vote (optional)
  • requireBlock is the block ID of a block that must be present in the blockchain during execution (optional)
  • requireLastBlock is the block ID of a block that must be last in the blockchain during execution (optional)

Response:

  • votes (A) is an array of votes, the range values (S) corresponding to each option (answer) with empty strings for non-votes
  • voter (S) is the account number of the voter
  • voterRS (S) is the Reed-Solomon address of the voter
  • transaction (S) is the transaction ID of the vote
  • weight (S) is the weight assigned to each vote (applies if includeWeights is true)
  • lastBlock (S) is the last block ID on the blockchain (applies if requireBlock is provided but not requireLastBlock)
  • requestProcessingTime (N) is the API request processing time (in millisec)

Note: Votes are deleted from the database 1441 blocks after the poll is finished. Only aggregate results are kept (refer to Get Poll Result).

Get Poll Vote Example

http://localhost:7876/nxt?
  requestType=getPollVote&
  account=9096010195498999548
{
 "voterRS": "NXT-THLJ-CYAL-JQST-6FNS5",
 "votes": [
  "1",
  ""
 ],
 "voter": "4747512364439223888",
 "requestProcessingTime": 1,
 "transaction": "6214591232702166122"
}


Get Poll Votes

Get all votes on a poll in reverse chronological order.

Request:

  • requestType is getPollVotes
  • poll is the poll ID
  • includeWeights is true to calculate and return the weight assigned to each vote (optional)
  • firstIndex is a zero-based index to the first vote to retrieve (optional)
  • lastIndex is a zero-based index to the last vote to retrieve (optional)
  • requireBlock is the block ID of a block that must be present in the blockchain during execution (optional)
  • requireLastBlock is the block ID of a block that must be last in the blockchain during execution (optional)

Response:

  • votes (A) is an array of vote objects (refer to Get Poll Vote for details)
  • lastBlock (S) is the last block ID on the blockchain (applies if requireBlock is provided but not requireLastBlock)
  • requestProcessingTime (N) is the API request processing time (in millisec)

Note: Votes are deleted from the database 1441 blocks after the poll is finished. Only aggregate results are kept (refer to Get Poll Result).

Get Poll Votes Example

http://localhost:7876/nxt?
  requestType=getPollVotes&
  poll=9096010195498999548&
  lastIndex=0
{
 "votes": [
  {
   "voterRS": "NXT-THLJ-CYAL-JQST-6FNS5",
   "votes": [
    "1",
    ""
   ],
   "voter": "4747512364439223888",
   "transaction": "6214591232702166122"
  }
 ],
 "requestProcessingTime": 1
}


Get Polls

Get poll details in reverse creation order.

Request:

  • requestType is getPolls
  • account is a creation account ID filter (optional)
  • timestamp is the earliest poll (in seconds since the genesis block) to retrieve (optional)
  • firstIndex is a zero-based index to the first poll to retrieve (optional)
  • lastIndex is a zero-based index to the last poll to retrieve (optional)
  • includeFinished is true to include completed polls (optional)
  • finishedOnly is true to exclude not yet executed, phased transactions (optional)
  • requireBlock is the block ID of a block that must be present in the blockchain during execution (optional)
  • requireLastBlock is the block ID of a block that must be last in the blockchain during execution (optional)

Response:

  • polls (A) is an array of polls (refer to Get Poll for details)
  • lastBlock (S) is the last block ID on the blockchain (applies if requireBlock is provided but not requireLastBlock)
  • requestProcessingTime (N) is the API request processing time (in millisec)

Get Polls Example

http://localhost:7876/nxt?
  requestType=getPolls&
  lastIndex=0
{
 "polls": [
  {
   "minRangeValue": 0,
   "votingModel": 3,
   "description": "Should we start fully backing Credits with something tangible?",
   "finished": false,
   "poll": "10307833923604182368",
   "minNumberOfOptions": 1,
   "holding": "415923435949896799",
   "minBalance": "1000000000",
   "accountRS": "NXT-3BCV-8Q5G-9NP6-576DP",
   "name": "CRDTS owners poll",
   "options": [
    "Yes",
    "No",
    "go for fractional reserve backing"
   ],
   "finishHeight": 260218,
   "maxNumberOfOptions": 1,
   "minBalanceModel": 3,
   "account": "4227900615136683355",
   "maxRangeValue": 1
  }
 ],
 "requestProcessingTime": 0
}


Search Polls

Search for poll details given a name/description query string.

Request:

  • requestType is searchPolls
  • query is a full text query on the poll fields name (S) and description (S) in the standard Lucene syntax (optional)
  • firstIndex is a zero-based index to the first poll to retrieve (optional)
  • lastIndex is a zero-based index to the last poll to retrieve (optional)
  • includeFinished is true to include completed polls (optional)
  • requireBlock is the block ID of a block that must be present in the blockchain during execution (optional)
  • requireLastBlock is the block ID of a block that must be last in the blockchain during execution (optional)

Response:

  • polls (A) is an array of polls (refer to Get Poll for details)
  • lastBlock (S) is the last block ID on the blockchain (applies if requireBlock is provided but not requireLastBlock)
  • requestProcessingTime (N) is the API request processing time (in millisec)

Search Polls Example

http://localhost:7876/nxt?
  requestType=searchPolls&
  query=hello&
  includeFinished=true
{
 "polls": [
  {
   "minRangeValue": 0,
   "votingModel": 1,
   "description": "Hello World Poll",
   "finished": true,
   "poll": "3043888702585899321",
   "minNumberOfOptions": 1,
   "minBalance": "0",
   "accountRS": "NXT-XK4R-7VJU-6EQG-7R335",
   "name": "Poll1",
   "options": [
    "Hello",
    "World"
   ],
   "finishHeight": 255816,
   "maxNumberOfOptions": 1,
   "minBalanceModel": 1,
   "account": "5873880488492319831",
   "maxRangeValue": 1
  }
 ],
 "requestProcessingTime": 3
}