diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1bd7226 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..a04032f --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Ether Signal + +Contract on Testnet: +http://testnet.etherscan.io/address/0x851a78f09511bf510ad27036f5ff7c8901fdd2e2#code diff --git a/cli/ethersignal.js b/cli/ethersignal.js new file mode 100644 index 0000000..dc32248 --- /dev/null +++ b/cli/ethersignal.js @@ -0,0 +1,38 @@ +/* 4096 iters gas burn */ +var esContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"positionHash","type":"bytes32"},{"name":"pro","type":"bool"}],"name":"setSignal","outputs":[],"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"positionHash","type":"bytes32"},{"indexed":false,"name":"pro","type":"bool"},{"indexed":false,"name":"addr","type":"address"}],"name":"LogSignal","type":"event"}]); +var ethersignal = esContract.at('0x851a78f09511bf510ad27036f5ff7c8901fdd2e2') + + +function CalcSignal(positionHash) { + var proMap = {}; + var antiMap = {}; + + ethersignal.LogSignal({positionHash: positionHash}, {fromBlock: 1200000}, function(error, result){ + if (!error) + { + if (result.args.pro) { + proMap[result.args.addr] = 1; + antiMap[result.args.addr] = 0; + } else { + proMap[result.args.addr] = 0; + antiMap[result.args.addr] = 1; + } + } + }) + + var totalPro = 0; + var totalAgainst = 0; + + // call getBalance just once per address + Object.keys(proMap).map(function(a) { + var bal = web3.fromWei(web3.eth.getBalance(a)); + proMap[a] = proMap[a] * bal; + antiMap[a] = antiMap[a] * bal; + }); + + // sum the pro and anti account values + Object.keys(proMap).map(function(a) { totalPro += parseFloat(proMap[a]); }); + Object.keys(antiMap).map(function(a) { totalAgainst += parseFloat(antiMap[a]); }); + + return {pro: totalPro, against: totalAgainst} +} diff --git a/cli/readme.txt b/cli/readme.txt new file mode 100644 index 0000000..ee848c9 --- /dev/null +++ b/cli/readme.txt @@ -0,0 +1,28 @@ +EtherSignal CLI + +Quick Start. + +1) Launch a geth node if it is not already running. +geth + +2) Attach via the geth command line client +geth attach + +3) Load the ethersignal script. +> loadScript("ethersignal.js") +true + +Now you can either signal on a position or tally the current signal levels +for a position. + +To Vote on position "0xba32c71348cf21e808067890691aa790486e3a99e628b68cd2bfeb51381bfec1": +> ethersignal.setSignal("0xba32c71348cf21e808067890691aa790486e3a99e628b68cd2bfeb51381bfec1",true, {from: web3.eth.accounts[0], gas: 300000}); + +To Tally the signal level for position "0xba32c71348cf21e808067890691aa790486e3a99e628b68cd2bfeb51381bfec1": +> CalcSignal("0xba32c71348cf21e808067890691aa790486e3a99e628b68cd2bfeb51381bfec1") +{ + against: 0, + pro: 92.37653959643757 +} + +Enjoy. diff --git a/cli/test1.js b/cli/test1.js new file mode 100644 index 0000000..c7a284e --- /dev/null +++ b/cli/test1.js @@ -0,0 +1,5 @@ +function test1_voteSpam() { + for (i = 0; i < 100; i++) { + ethersignal.setSignal(0, ((i % 2) == 0) ? true : false, {from: web3.eth.accounts[0], gas: 300000}); + } +} diff --git a/contracts/ethersignal.sol b/contracts/ethersignal.sol new file mode 100644 index 0000000..68ab55a --- /dev/null +++ b/contracts/ethersignal.sol @@ -0,0 +1,12 @@ +contract EtherSignal { + event LogSignal(bytes32 indexed positionHash, bool pro, address addr); + function setSignal(bytes32 positionHash, bool pro) { + for (uint i = 0; i < 4096; i++) { } // burn some gas to increase DOS cost + LogSignal(positionHash, pro, msg.sender); + if(!msg.sender.send(this.balance)){ throw; } + } + + function () { + throw; + } +}