Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
kor committed Jul 8, 2016
0 parents commit 970d01a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.swp
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ether Signal

Contract on Testnet:
http://testnet.etherscan.io/address/0x851a78f09511bf510ad27036f5ff7c8901fdd2e2#code
38 changes: 38 additions & 0 deletions cli/ethersignal.js
Original file line number Diff line number Diff line change
@@ -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}
}
28 changes: 28 additions & 0 deletions cli/readme.txt
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions cli/test1.js
Original file line number Diff line number Diff line change
@@ -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});
}
}
12 changes: 12 additions & 0 deletions contracts/ethersignal.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 970d01a

Please sign in to comment.