Simplified but more powerful voting model with number of options & values ranges

As consequence, simplified results as well.

By-account voting now possible with asset balance threshold (e.g. all shareholders having more than 1000 assets have equal weight in voting)

Quote

val pb = new PollBuilder(question, desc, options, finishBlockHeight, votingModel,

minNumberOfChoices, maxNumberOfChoices, minRangeValue, maxRangeValue)

minBalanceOpt.map(mb => pb.minBalance(mb))

assetIdOpt.map(ai => pb.assetId(ai))



issueTx(phrase, new Attachment.MessagingPollCreation(pb))



Quote

val finishBlockHeight = Nxt.getBlockchain.getHeight + 10000



val options = Array("feature A", "feature B", "feature C", "feature D", "feature E")



val votingModel = Constants.VOTING_MODEL_ASSET



val pb = new PollBuilder(question, desc, options, finishBlockHeight, votingModel, 1, 3, 1, 5)

pb.minBalance(100)

pb.assetId(assetId)



issueTx(phrase1, new Attachment.MessagingPollCreation(pb))



Quote

val poll = Poll.getPollsByAccount(accountId, 0, -1).iterator.toSeq.find(_.name == question).get

val vote = Array(3.toByte, Byte.MIN_VALUE, Byte.MIN_VALUE, 5.toByte, Byte.MIN_VALUE)

val attachment = new Attachment.MessagingVoteCasting(poll.getId, vote)

issue(phrase2, attachment)



Quote

val results = Poll.getResults(poll.getId())



assert(resultsOpt.isDefined) //check we have results

assert(results.find(_.getFirst == "featureA").get.getSecond == 2200

assert(results.find(_.getFirst == "featureB").get.getSecond == 1200

assert(results.find(_.getFirst == "featureC").get.getSecond == 0

assert(results.find(_.getFirst == "featureD").get.getSecond == 0

assert(results.find(_.getFirst == "featureE").get.getSecond == 0



Create poll

Quote

VOTING_MODEL_BALANCE = 0;

VOTING_MODEL_ACCOUNT = 1;

VOTING_MODEL_ASSET = 2;



Quote

Vote casting

Quote

Get poll data

Quote

Get poll results

Get polls created by an account

During last days voting system got massive update. Most valuable things done:Detailed description below:This document describes voting system in details and its implementation.* Different voting models supported(see also community proposals gathered prior this implementation https://wiki.nxtcrypto.org/wiki/Voting_System ): voting by account(1 account=1 vote), balance(1 NXT=1 vote) or asset balance(1 QNT=1 vote)* Poll has minimum and maximum number of options to provide opinion for. E.g. choose from 2 to 5 options out of 8* Range is also parameter. E.g. give a rate from 0 to 10* By combining number of options & range a lot of specific poll types could be done. E.g. binary poll is poll where range is from 0 to 1 (i.e. no or yes).* Voting has finite predefined duration(finish block height, to say preciously)* Anonymous voting is not supported for now. It could be implemented with Blind signatures( https://en.wikipedia.org/wiki/Blind_signature ) but it's not known for now how to implement that over blockchain. Anonymous voting could be implemented by trusted 3rd party services.* Leased voting - not implemented for nowThere are three models for now:* By account, 1 account = 1 Vote, where minimum balance in nxts or assets could be set also* By balance, 1 Nxt = 1 Vote.* By asset, 1 Asset QNT = 1 Vote. Additional parameter specifies an asset ID.All models could be enhanced by additional parameter, describing min balance(in NXT / QNT).Counting happens at the finish block height stated during poll creation. And a vote being counted only if it satisfies poll parameters(min balance etc) at that finish height. Please note, voter could vote with balance < min balance needed to vote(at height where vote has been sent), and it's valid, but a vote could be counted only if balance >= threshold balance at poll finish height.* name - a poll's title* description - detailed poll description* options - possible options to choose from and give a rate to* votingModel - three possible values for by-account, by-balance, by-asset voting* finishHeight - block height in future poll is finishing and counting taking at* minNumberOfOptions, maxNumberOfOptions - minimum and maximum number of options a voter can choose* minRangeValue, maxRangeValue - a voter value within this range* assetId - for voting by assets, also used for min_balance in by-account voting(i.e. if assetId!= 0 minBalance is in assets, otherwise in Nxts)* minBalance - 0 by default. Vote counts only if account balance @ counting height (in NXT or QNT) >= minBalance* 10 confirmations limit used for balance calculation* Voting by asset could be started by anyone, not just asset issuer or even asset owner.There are two kinds of attachments related to voting system: MessagingPollCreation & MessagingVoteCasting. As MessagingPollCreation. Also please take a look PollBuilder helper implementing Builder pattern to MessagingPollCreation objects:There are two transaction types related to VS: POLL_CREATION and VOTE_CASTING.Examples below are in Scala but should be easily understandable for an every Java develope too:Shareholders voting, a shareholder has to have 100 shares of 1000 at least. Please also read description:val question = "What are the next features to get done?"val description = "Please take voting seriously as we have very limited amount of resources. So you have to choose from 1 to 3 features out of 5 and rate them from 1 to 5"Poll is created! Now time to send a vote. Please note skipped answers should be marked with Byte.MIN_VALUE value(i.e. -128):Please note that vote will be not counted if acoount has less than 100 shares.Say, we have 4 voters, one has 50 shares(so a vote isn't being counted), second has 4 options chosen(so vote is invalid), third has 200 shares and gave a 5 to first option , fourth has 400 shares and gave 3 to both first&second options. After poll is finished here is the code to get results:Parameters:name - mandatory - poll title, not longer than 100 charsdescription - mandatory - detailed poll description, max 1000 charsfinishHeight - mandatory - height of block when voting will be finished i.e. counted(should be > current one)votingModel - mandatory - by-asset, by-account, or by-balance. see corresponding numeric value belowminBalance - optional - min amount of money or assets to vote, in nxt or qnt. by default 0(if skipped)minNumberOfOptions - mandatory - min number of options to choosemaxNumberOfOptions - mandatory - max number of options to chooseminRangeValue - mandatory - min vote value possible, no more than 100maxRangeValue - mandatory - max vote value possible, no less than -100assetId - mandatory in case of by-asset voting, could be also usedin addition with minBalance in by-account voting - asset id in unsigned formoption1,option2,option3,option4,...option100 - titles of corresponding optionsUse following values to set voting model:Example:[/i][/u]`````````curl -d 'account=7926777737834261541&firstIndex=0&lastIndex=5' http://localhost:6876/nxt?requestType=getAccountPolls ```P.S. Jones is working on UI now!