Skip to content

BaerChain vote transaction

weidong edited this page Apr 9, 2020 · 5 revisions

Voting transaction(vote)

1. Request Json file description(vote_data.json)

{
	"source":[
	{
		"from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
		"to":"0x00000000000000000000000000000000766f7465",
		"value":"0x0",
		"data":[
		{
			"type":1,
			"m_from":"0xc6f73c3b14456434c7db388bcb4fd47377c0d738",
			"m_to":"0x4eb60bfab454b5aaece4e8759e62ed36266fde39",
			"m_vote_type":5,
			"m_vote_numbers":"0xa"
		}
		],
		"chainId":"0x1",
		"nonce":"0x0",
		"gas":"0x13880",
		"gasPrice":"0x5"
		}
		],
	"keys":[
		"8kZJMg3BfpkD6yzWh84N2ACPZaqWSZof1G23YQ7PD3u6"
	]
}
from     : string, vote transaction originating address
to       : string, Fixed address, cannot be changed
value    : string, default: "0"
data     : Voting transaction data, array structure
           > type           : int, Transaction identification number, the type is fixed at 1, indicating vote transaction
           > m_from         : string, Voting transaction initiation address, same as from address
           > m_to           : string, Addresses that accept vote transactions
           > m_vote_type    : int, Explanation:
           		      (1)Available values are(1: buy votes, 2: sell votes, 5: vote, 6: cancel the vote)
                              (2) The case type is 5, which means voting for the specified address
                              (3) Note: It needs to be performed before the voting operation (1: ticket buying operation) to ensure that you can vote
                              (4) Note: The addresses of m_from and m_to need to be the same when buying and selling votes
           > m_vote_numbers : string, Votes
           		      Note: The number of votes is passed in hexadecimal, that is, if you buy 10 votes, you need to pass "0xa"
chainId  : string, Hexadecimal, chain ID, must be the same as chain creation chainId
nonce    : string, Hexadecimal, nonce value, +1 after each execution
gas      : string, Hexadecimal, the gas integer provided for transaction execution
gasPrice : string, Hexadecimal, for each gasPrice integer paid for gas
  • Remarks: When to fill in another address, and data is not empty, the default to is the contract address of the call, and transfer the value of the value from (from value if there is a value) to to, generally prohibit this operation

2. Voting transaction description Back Dir

  • Users can spend BRC to buy votes, but only addresses in the candidate set can be voted

  • Query candidate collection

    • command

      curl -d '{"jsonrpc":"2.0","id":9,"method":"brc_getElector","params":["latest"]}' http://127.0.0.1:8111
      
    • The result is returned as follows, indicating that at this time, 6 candidates can be voted

          {
        "id": 9,
        "jsonrpc": "2.0",
        "result": {
        	"electors": [{
        	"address": "0xcccc7a30bf688c060524dfd759fe2627ed3387bc",
        	"vote_num": "0x0"
        	}, {
        	"address": "0xdb1874c67cf3628690c795f0553e0e2904b02ffd",
        	"vote_num": "0x0"
        	}, {
        	"address": "0xc3eb4d16a99e0a04de3242729a759a45809d2628",
        	"vote_num": "0x0"
        	}, {
        	"address": "0x02b3d7c2f9f53f5bbcb3794da5282566f5632b46",
        	"vote_num": "0x0"
        	}, {
        	"address": "0xd15c70cb560cea42995c9f52858778aa8b08c1c1",
        	"vote_num": "0x0"
        	}, {
        	"address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
        	"vote_num": "0x0"
        	}]
        }
          }
      

3. Explanation of vote transaction process Back Dir

  • According to the actual situation respectively: (1: buy votes, 2: sell votes, 5: vote, 6: cancel the vote)

    • command:

      ./cmdWallet -j ./vote_data.json -s 127.0.0.1:8111
      
    • cmdWallet Perform file acquisition

    cd cpp-lsac/build : Enter the directory
    cmake ..          : Execute instruction
    make              : Execute instruction
    cd cpp-lsac/build/wallet/cmdWallet : You can find the cmdWallet executable file just compiled in this directory
    
3.1 Buy votes
  • If execution 1: buy 10 votes

  • You can use the brc_getBalance interface to query the number of votes you have after buying a ticket.

curl -d '{"jsonrpc":"2.0","id":9,"method":"brc_getBalance","params":["6e8c3d142894db1e06a026497f6b506c49069908","latest"]}' 127.0.0.1:8111
  • search result
  {
  	"id": 22,
  	"jsonrpc": "2.0",
  	"result": {
  	    "Address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
  	    "BRC": "0xa4d87b3d34e00",
  	    "FBRC": "0x0",
   	    "FBalance": "0x2710",
  	    "balance": "0xa4d88ddd452c0",
  	    "ballot": "0xa", 	(Represents the number of votes it has, at this time it is 10 votes, if there are no votes, it is "0x0")
    	    "cookieinsummury": "0x0",
  	    "nonce": "0x2",
  	    "poll": "0x0",("0x0" means 0 votes)
  	    "vote": null
  	}
  }
3.2 Sell votes
  • If performing 2: Sell 1 ticket

  • search result

{
    "id": 22,
    "jsonrpc": "2.0",
	"result": {
	    "Address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
         "BRC": "0x997a1b0ac38df",
         "FBRC": "0x0",
         "FBalance": "0x0",
         "balance": "0xa4d88ddcdc3ec",
         "ballot": "0x9",             (Indicate the number of votes you own, at this time 9 votes, indicating that 1 vote was sold)
         "cookieinsummury": "0x0",
         "nonce": "0x3",
         "poll": "0x0",               ("0x0" means 0 votes)
         "vote": null
}

3.3 Vote
  • 5:Vote 3 votes

  • If performing 5: vote 3 votes

  • In this test: 0x6e8c3d142894db1e06a026497f6b506c49069908 is the address of the candidate, Vote for yourself in this test

  • search result

 {
 	"id": 22,
  	"jsonrpc": "2.0",
 	"result": {
 	    "Address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
 	    "BRC": "0x997a1b0ac38df",
         "FBRC": "0x0",
 	    "FBalance": "0x0",
 	    "balance": "0xa4d88ddcb885c",
 	    "ballot": "0x6",   (Represents the number of votes you own, at this time 6 votes, indicating that 3 votes were cast)
 	    "cookieinsummury": "0x0",
 	    "nonce": "0x4",
 	    "poll": "0x3",     (The number of votes received, this time is 3 votes, indicating that 3 votes were cast)
 	    "vote":[{
 		"Address": "0x6e8c3d142894db1e06a026497f6b506c49069908",   (Voting address)
 		"vote_num": "0x3"       (Number of votes cast at this address)
 	    }]
 	}
 }
3.4 Unvote Back Dir
  • If performing 6, cancel 1 vote
  • search result
 {
 	"id": 22,
  	"jsonrpc": "2.0",
 	"result": {
 	    "Address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
 	    "BRC": "0x997a1b0ac38df",
 	    "FBRC": "0x0",
 	    "FBalance": "0x0",
 	    "balance": "0xa4d88ddc352a4",
 	    "ballot": "0x7",       (Represents the number of votes it has, at this time 7 votes, indicating that 1 ticket is cancel)
 	    "cookieinsummury": "0x0",
 	    "nonce": "0x8",
 	    "poll": "0x2",         (The number of votes received, at this time is 2 votes, indicating that 2 votes were cast)
 	    "vote": [{	           (Record which addresses voted for yourself)
 		"Address": "0x6e8c3d142894db1e06a026497f6b506c49069908",     (Voting address)
 		"vote_num": "0x2"      (Number of votes cast at this address)
 	     }]
 	}
 }

4. Voting process query instructions Back Dir

4.1 Query candidate collection

  • Command:

    • After the above operations, query the candidate set again to see the changes
    curl -d '{"jsonrpc":"2.0","id":9,"method":"brc_getElector","params":["latest"]}' http://127.0.0.1:8111
    
  • Return result

    {
    	"id": 9,
    	"jsonrpc": "2.0",
    	"result": {
    	     "electors": [{
    		  "address": "0xcccc7a30bf688c060524dfd759fe2627ed3387bc",
    		  "vote_num": "0x0"
    	     }, {
    		  "address": "0xdb1874c67cf3628690c795f0553e0e2904b02ffd",
    		  "vote_num": "0x0"
    	    }, {
    		  "address": "0xc3eb4d16a99e0a04de3242729a759a45809d2628",
    		  "vote_num": "0x0"
    	    }, {
    		  "address": "0x02b3d7c2f9f53f5bbcb3794da5282566f5632b46",
      		  "vote_num": "0x0"
    	    }, {
    		  "address": "0xd15c70cb560cea42995c9f52858778aa8b08c1c1",
    		  "vote_num": "0x0"
    	    }, {
    		  "address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
    		  "vote_num": "0x2"    (You can see that at this time you have got 2 votes to change your address)
    	    }]
    	}
    }
    

4.2 Query the voting details Back Dir

  • Command:

    • Query the specific voting situation of an address
    curl -d '{"jsonrpc":"2.0","id":9,"method":"brc_getVoted","params":["0x6e8c3d142894db1e06a026497f6b506c49069908","latest"]}' http://127.0.0.1:8111
    
  • Return result

    {
    	"id": 9,
    	"jsonrpc": "2.0",
    	"result": {
    		"total_voted_num": "0x3",
    		"vote": [{
    			"address": "0x6e8c3d142894db1e06a026497f6b506c49069908",
    			"voted_num": "0x2"
    		}, {
    			"address": "0xdb1874c67cf3628690c795f0553e0e2904b02ffd",
    			"voted_num": "0x1"
    		}]
    	}
    }
    
    • Explanation : Address 0x6e8c3d142894db1e06a026497f6b506c49069908votes to itself(0x6e8c3d142894db1e06a026497f6b506c49069908)2 votes, it voted 2 votes for the address 0xdb1874c67cf3628690c795f0553e0e2904b02ffd

4.3 Query candidates' votes Back Dir

  • Command

    • Query the number of votes of designated candidates
    curl -d '{"jsonrpc":"2.0","id":9,"method":"brc_getObtainVote","params":["0x6e8c3d142894db1e06a026497f6b506c49069908","latest"]}' http://127.0.0.1:8111
    
  • Return result

    {
    	"id": 9,
    	"jsonrpc": "2.0",
    	"result": {
    		"addrsss": "0x6e8c3d142894db1e06a026497f6b506c49069908",
    		"obtain_vote": "0x2"
    	}
    }
    
    • Explanation : Address 0x6e8c3d142894db1e06a026497f6b506c49069908 At this time, the total number of votes is 2

4.4 Query the number of votes that can be cast at the address Back Dir

  • Command:
curl -d '{"jsonrpc":"2.0","method":"brc_getBallot","params":["0x6e8c3d142894db1e06a026497f6b506c49069908", "latest"],"id":1}' http://127.0.0.1:8111
  • Return result
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "0x7" (Indicates that the address now has 7 votes)
}

Clone this wiki locally