Here's how I propose to use Blockchains to create a better system.
Each voter has a computer connected to a blockchain, and each polling station does too, like this:
Voting works like this:
In this project, we'll have one Voter and one Polling station, and the Polling station will be the only miner. We'll only implement the online voting method, for now.
On that machine, in a Terminal window, execute these commands:
cd /tmp
wget http://www.multichain.com/download/multichain-1.0-alpha-21.tar.gz
tar -xvzf multichain-1.0-alpha-21.tar.gz
cd multichain-1.0-alpha-21
sudo mv multichaind multichain-cli multichain-util /usr/local/bin
multichain-util create survey
nano ~/.multichain/survey/params.dat
In the "Global permissions" section,
change these four parameters,
as shown below.
anyone-can-connect = true
anyone-can-send = true
allow-p2sh-outputs = false
allow-multisig-outputs = false
In the "Consensus requirements" section,
change this parameter,
as shown below.
setup-first-blocks = 10000
Save the file with Ctrl+X, Y, Enter.
multichaind survey -daemon
The server starts, and you see
the node address that others can use to connect to this chain.
Make a note of your node address. In the figure below, it is
survey@172.16.1.134:7413
multichain-cli survey getnewaddress
An address appears. Make a note of it.
In the example below,
the address is
1345gLikEVK4KtkZrT6ejmhqvceHGQ2pZdrheX
multichain-cli survey grant 1345gLikEVK4KtkZrT6ejmhqvceHGQ2pZdrheX receive,send
The command succeeds, as shown below.
On the Poll Server, execute these commands. Replace the address with the correct address for your Poll server.
multichain-cli survey issue 1345gLikEVK4KtkZrT6ejmhqvceHGQ2pZdrheX token 10000 1
multichain-cli survey listassets
The commands succeed, so the Poll server
now has 10,000 tokens, as shown below.
sudo apt-get update
sudo apt-get install apache2 -y
sudo service apache2 start
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-cli -y
cat ~/.multichain/survey/multichain.conf
Your RPC username and password appear,
as shown below. Make a note of them--you will
need them later.
On the Poll Server, execute:
sudo nano /var/www/html/info.php
Enter or paste in this code.
You will need to change two items:
1. Replace
the password in the line beginning with "$a" with
the correct password on your Poll Server
2. Replace the port number at the end of the
line beginning with "$c" with the actual port number
on your server.
<?php
echo "<h1>Information About the Survey Blockchain</h1>";
$a = 'curl -s --user multichainrpc:FHtgQdshp7bo96gNv4MtT64cQwj1inTQAEuonr5jG7hv --data-binary \'';
$b = '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [';
$c = '] }\' -H "content-type: text/plain;" http://127.0.0.1:7412/';
$cmd = $a . $b . $c;
echo "\n<h2>Raw Output</h2><pre>\n";
$ret=system($cmd);
echo "\n<h2>Decoded Output</h2>\n";
$rets = json_decode($ret, true);
print_r($rets);
echo "\n<h2>Single-Item Output</h2>\n";
echo $rets['result']['version'];
?>
Save the file with Ctrl+X, Y, Enter.
To test the script, on the Poll Server, execute:
php /var/www/html/info.php
You should see the same information three different
ways, as shown below.
On the Poll Server, execute:
sudo nano /var/www/html/pay.php
Enter or paste in this code.
Enter or paste in this code. You will need to change two items:
1. Replace
the password in the line beginning with "$a" with
the correct password on your Poll Server
2. Replace the port number at the end of the
line beginning with "$d" with the actual port number
on your server.
<?php
echo "<h1>Sending you a Survey Token!</h1>";
$addr = $_POST["address"];
$a = 'curl -s --user multichainrpc:FHtgQdshp7bo96gNv4MtT64cQwj1inTQAEuonr5jG7hv --data-binary \'';
$b = '{"jsonrpc": "1.0", "id":"curltest", "method": "sendassettoaddress", "params": ["';
$c = '", "token", 1';
$d = '] }\' -H "content-type: text/plain;" http://127.0.0.1:7412/';
$cmd = $a . $b . $addr . $c . $d;
$ret=system($cmd);
echo $ret;
?>
Save the file with Ctrl+X, Y, Enter.
sudo nano /var/www/html/faucet.htm
Enter or paste in this code.
<html><head><title>Survey Token Faucet</title></head>
<body bgcolor="#cccccc">
<h1 align="center">Survey Token Faucet</h1>
<form method="post" action="pay.php">
<p align="center"><b>Enter your address</b></p>
<p align="center"><input type="text" name="address" size="90"></textarea></p>
<p align="center">
<button type="submit" name="submitButton" value="">Get Token</button>
</form>
</body></html>
Save the file with Ctrl+X, Y, Enter.
On that machine, in a Terminal window, execute these commands:
cd /tmp
wget http://www.multichain.com/download/multichain-1.0-alpha-21.tar.gz
tar -xvzf multichain-1.0-alpha-21.tar.gz
cd multichain-1.0-alpha-21
sudo mv multichaind multichain-cli multichain-util /usr/local/bin
multichaind survey@172.16.1.134:7413 -daemon
Your node connects,
and shows a "Node started" message,
as shown below.
multichain-cli survey getnewaddress
An address appears. Make a note of it.
In the example below,
the address is
1Vf3VdFjgfnEJLM812A8EY35gUbzPP5b897X8r
172.16.1.134/faucet.htm
Paste your address into the Faucet page,
as shown below.
Click the "Get Token" button.
An error message appears, showing that the address doesn't have receive permission.
What we really want is to grant the Voter receive permission just long enough to receive 1 token, and then revoke it.
Looking at the MultiChain JSON-RPC API commands reveals that there are commands to do precisely that.
On the Poll Server, execute:
sudo nano /var/www/html/pay2.php
Enter or paste in this code.
<?php
echo "<h1>Sending you a Survey Token!</h1>";
$addr = $_POST["address"];
$a = 'curl -s --user multichainrpc:FHtgQdshp7bo96gNv4MtT64cQwj1inTQAEuonr5jG7hv --data-binary \'';
$b = '{"jsonrpc": "1.0", "id":"curltest", "method": "grant", "params": ["';
$c = '", "receive"';
$d = '] }\' -H "content-type: text/plain;" http://127.0.0.1:7412/';
$cmd = $a . $b . $addr . $c . $d;
$ret=system($cmd);
$a = 'curl -s --user multichainrpc:FHtgQdshp7bo96gNv4MtT64cQwj1inTQAEuonr5jG7hv --data-binary \'';
$b = '{"jsonrpc": "1.0", "id":"curltest", "method": "sendassettoaddress", "params": ["';
$c = '", "token", 1';
$d = '] }\' -H "content-type: text/plain;" http://127.0.0.1:7412/';
$cmd = $a . $b . $addr . $c . $d;
$ret=system($cmd);
$a = 'curl -s --user multichainrpc:FHtgQdshp7bo96gNv4MtT64cQwj1inTQAEuonr5jG7hv --data-binary \'';
$b = '{"jsonrpc": "1.0", "id":"curltest", "method": "revoke", "params": ["';
$c = '", "receive"';
$d = '] }\' -H "content-type: text/plain;" http://127.0.0.1:7412/';
$cmd = $a . $b . $addr . $c . $d;
$ret=system($cmd);
?>
Save the file with Ctrl+X, Y, Enter.
On the Poll Server, execute:
sudo nano /var/www/html/faucet.htm
In the form tag, change the
action to pay2.php,
as shown below.
Save the file with Ctrl+X, Y, Enter.
Paste in your address, as shown below.
Click the "Get Token" button.
Three messages appear, all showing "error:null" -- it worked!
multichain-cli survey gettotalbalances
You now have 1 token, as shown below.
multichain-cli survey getnewaddress
The address appears, as shown below.
Make a note of it.
On the Poll Server, execute this command. Replace the address with the address you just found.
multichain-cli survey grant 17CFf1ZJV73igpcb2egZRFjGYiabTf21T61kiQ receive
The operation proceeds without errors, as shown below.
multichain-cli survey getnewaddress
The address appears, as shown below.
Make a note of it.
On the Poll Server, execute this command. Replace the address with the address you just found.
multichain-cli survey grant 17CFf1ZJV73igpcb2egZRFjGYiabTf21T61kiQ receive
sudo nano /var/www/html/candidates.htm
Paste in this code. Replace the addresses with the
two addresses you just made.
<html>
<head><title>Candidates</title></head>
<body>
<h2>Candidate #1</h2>
17CFf1ZJV73igpcb2egZRFjGYiabTf21T61kiQ
<h2>Candidate #1</h2>
1CTMCxciVnWCGorSzgErkRjA2ogDK7XF7nT1nG
</body>
</html>
Save the file with Ctrl+X, Y, Enter.
172.16.1.134/candidates.htm
You see the candidate addresses,
as shown below.
To vote, on your Voter Machine, execute this command, replacing the address with one of the addresses from the Candidates page.
multichain-cli survey sendassettoaddress 17CFf1ZJV73igpcb2egZRFjGYiabTf21T61kiQ token 1
The transaction proceeds without errors, as shown below.
To check your account balance, on your Voter Machine, execute this command, replacing the address with one of the addresses from the Candidates page.
multichain-cli survey getmultibalances 17CFf1ZJV73igpcb2egZRFjGYiabTf21T61kiQ,1CTMCxciVnWCGorSzgErkRjA2ogDK7XF7nT1nG
Your token is gone, as shown below.
multichain-cli survey getaddressbalances 17CFf1ZJV73igpcb2egZRFjGYiabTf21T61kiQ
multichain-cli survey getaddressbalances 1CTMCxciVnWCGorSzgErkRjA2ogDK7XF7nT1nG
As shown below, one candidate has 1 token, and the other has no tokens.