-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kor
committed
Jul 8, 2016
0 parents
commit 970d01a
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |