-
Notifications
You must be signed in to change notification settings - Fork 9
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
0 parents
commit 6525cbc
Showing
13 changed files
with
2,655 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,19 @@ | ||
Copyright (c) 2017 Martin Charles | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,40 @@ | ||
splitter-contract | ||
================= | ||
|
||
An Ethereum smart contract which evenly splits all funds sent to it between a | ||
number of receving parties. | ||
|
||
Usage | ||
----- | ||
To use this contract, clone the repo and hardcode the addresses you would like | ||
to evenly split received funds between in the constructor. The contract can be | ||
found in [`contracts/Splitter.sol`][contract]. | ||
|
||
You can deploy the contract like you would any truffle contract, by configuring | ||
your `./truffle.js` and running: | ||
|
||
$ npm install | ||
$ npm run truffle deploy | ||
|
||
Now, when ether is sent to the contract using a wallet or code like this: | ||
|
||
var WEI = 1; | ||
var ETHER = 10 ** 18 * WEI; | ||
web3.eth.sendTransaction({to: contractAddress, value: 1 * ETHER}); | ||
|
||
The incoming transaction will be split between the parties specified in the | ||
constructor and be available for withdrawl by calling `withdraw` or | ||
`withdrawAll`. Check out the [tests] for examples. | ||
|
||
Tests | ||
----- | ||
You can run test tests by running: | ||
|
||
$ npm install | ||
$ npm run testrpc | ||
|
||
$ # in another session | ||
$ npm run test | ||
|
||
[contract]: contracts/Splitter.sol | ||
[tests]: test/splitter.js |
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,73 @@ | ||
{ | ||
"contract_name": "Migrations", | ||
"abi": [ | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "new_address", | ||
"type": "address" | ||
} | ||
], | ||
"name": "upgrade", | ||
"outputs": [], | ||
"payable": false, | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "last_completed_migration", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"payable": false, | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "completed", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "setCompleted", | ||
"outputs": [], | ||
"payable": false, | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"payable": false, | ||
"type": "constructor" | ||
} | ||
], | ||
"unlinked_binary": "0x6060604052341561000c57fe5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101a0806100396000396000f300606060405263ffffffff60e060020a6000350416630900f0108114610042578063445df0ac146100605780638da5cb5b14610082578063fdacd576146100ae575bfe5b341561004a57fe5b61005e600160a060020a03600435166100c3565b005b341561006857fe5b61007061013d565b60408051918252519081900360200190f35b341561008a57fe5b610092610143565b60408051600160a060020a039092168252519081900360200190f35b34156100b657fe5b61005e600435610152565b005b6000805433600160a060020a03908116911614156101375781905080600160a060020a031663fdacd5766001546040518263ffffffff1660e060020a02815260040180828152602001915050600060405180830381600087803b151561012557fe5b6102c65a03f1151561013357fe5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a039081169116141561016f5760018190555b5b5b505600a165627a7a723058204949e0426aed33e4f878db5aa6fe4ffcc90d96a44257cc813a6f31745beefd5c0029", | ||
"networks": { | ||
"1500155372674": { | ||
"events": {}, | ||
"links": {}, | ||
"address": "0xe78a0f7e598cc8b0bb87894b0f60dd2a88d6a8ab", | ||
"updated_at": 1500155395335 | ||
} | ||
}, | ||
"schema_version": "0.0.5", | ||
"updated_at": 1500155395335 | ||
} |
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,25 @@ | ||
{ | ||
"contract_name": "Splitter", | ||
"abi": [ | ||
{ | ||
"inputs": [], | ||
"payable": false, | ||
"type": "constructor" | ||
}, | ||
{ | ||
"payable": true, | ||
"type": "fallback" | ||
} | ||
], | ||
"unlinked_binary": "0x6060604052341561000c57fe5b5b6001805460ff19166002178155600060208190527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb58054600160a060020a03199081167390f8bf6a479f320ead074411a4b0e7944ea8c9c1179091559190527fada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d805490911673ffcf8fdee72ac11b5c542428b35eef5769c409f01790555b5b60cc806100ba6000396000f30060606040525b609e5b6001546000908190819060ff16600160a060020a03301631811515602857fe5b049250821560365760006000fd5b600091505b60015460ff90811690831610156098575060ff8116600090815260208190526040808220549051600160a060020a0390911691829185156108fc0291869190818181858888f193505050501515608d57fe5b5b600190910190603b565b5b505050565b0000a165627a7a72305820c0f669fadeefe144c7c4a68b9f2fbc897c64045741aaa5387a995283a78a6e060029", | ||
"networks": { | ||
"1500155372674": { | ||
"events": {}, | ||
"links": {}, | ||
"address": "0xcfeb869f69431e42cdb54a4f4f105c19c080a601", | ||
"updated_at": 1500155395335 | ||
} | ||
}, | ||
"schema_version": "0.0.5", | ||
"updated_at": 1500155466662 | ||
} |
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,23 @@ | ||
pragma solidity ^0.4.4; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function Migrations() { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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,43 @@ | ||
pragma solidity ^0.4.11; | ||
|
||
contract Splitter { | ||
mapping(address => uint) public balances; | ||
mapping(uint8 => address) between; | ||
uint8 count; | ||
|
||
function Splitter() { | ||
count = 2; | ||
between[0] = 0x0090f8bf6a479f320ead074411a4b0e7944ea8c9c1; | ||
between[1] = 0x00ffcf8fdee72ac11b5c542428b35eef5769c409f0; | ||
} | ||
|
||
// To save on transaction fees, it's beneficial to withdraw in one big | ||
// transaction instead of many little ones. | ||
function withdraw(uint amount) { | ||
uint balance = balances[msg.sender]; | ||
require(balance <= amount); | ||
|
||
balances[msg.sender] -= amount; | ||
|
||
// the gas for this transaction is paid for by msg.sender | ||
msg.sender.transfer(amount); | ||
} | ||
|
||
function withdrawAll() { | ||
uint balance = balances[msg.sender]; | ||
Splitter.withdraw(balance); | ||
} | ||
|
||
function() payable { | ||
// We do integer division floor(a / b) here. There will be a maximum | ||
// remainder of count wei left in the contract after all the transfers. | ||
|
||
// TODO: properly handle the remainder, this will cause compounding | ||
uint addedToEach = this.balance / count; | ||
|
||
for (uint8 i = 0; i < count; i++) { | ||
address to = between[i]; | ||
balances[to] += addedToEach; | ||
} | ||
} | ||
} |
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 @@ | ||
var Migrations = artifacts.require("./Migrations.sol"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Migrations); | ||
}; |
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 @@ | ||
var Splitter = artifacts.require("./Splitter.sol"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Splitter); | ||
}; |
Oops, something went wrong.