Created
July 5, 2018 04:32
-
-
Save JoshOrndorff/4060b7dc3081511288789fae19ec1c1a to your computer and use it in GitHub Desktop.
A very primitive sketch of RHours logic.
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
pragma solidity ^0.4.24; | |
// WARNING: This code is intended for brainstorming purposes. No effort has been | |
// made to use safe math, write tests, or pen test. I haven't really even | |
// thought about function access. | |
contract RHoursProject { | |
string public name; | |
// This mapping keeps track of all the contributions an individual has made. | |
// Perhaps we don't actually need to keep these on chain, but could just | |
// emit events. We sould need to keep a running liability onchain. One | |
// possibile complication is when the same contributor submits two | |
// contributions with diferent interest rates | |
mapping(address => Contribution[]) public contributions; | |
// The mapping from | |
event contributionAccepted(address _contributor, Contribution _c); | |
event paymentMade(address _payer, uint amount); | |
// This implementation allows for start and end time to catalog your actual | |
// hours of time. It has a separate value to let individual contributors set | |
// their own rate (currently denominated in eth). | |
struct Contribution { | |
uint startTime; | |
uint endTime; | |
uint value; // How much the contribution is worth at acceptence time | |
uint rate; // Interest rate | |
uint witness; // Maybe like hash of merged PR or blob or something? | |
} | |
} | |
contract singleLeader is RHoursProject { | |
// The single person in charge of adding contributions | |
address public leader; | |
constructor(string _name) public { | |
name = _name; | |
leader = msg.sender; | |
// Discussion point: msg.sender can be another contract. Do we want | |
// contracts to be able to contribute? Similar to: | |
// (12) "Person" means an individual, corporation, business trust... | |
} | |
/** | |
* Only the leader can register contributions in this project. The entire | |
* process of proposing a contribution, governance, and acceptance happens | |
* off chain. | |
* @param _contributor Who did the work | |
* @param _startTime What actual clock time the work started | |
* @param _endTime What actual clock time the work ended | |
* @param _value The value of the contribution in eth | |
* @param _rate The interest rate at which the liability grows | |
* @param _witness A hash that confirms the work's existance and authorship | |
*/ | |
function addContribution(address _contributor, | |
uint _startTime, | |
uint _endTime, | |
uint _value, | |
uint _rate, | |
uint _witness) public { | |
//TODO Do I really want memory here? I was just trying to get rid | |
// of a Compiler Error | |
Contribution memory c = Contribution(_startTime, | |
_endTime, | |
_value, | |
_rate, | |
_witness); | |
contributions[_contributor].push(c); | |
emit contributionAccepted(_contributor, c); | |
} | |
/** | |
* Anyone can contribute funds toward liberating the software. | |
*/ | |
function makePayment() public payable { | |
// Discussion topic: When someone chooses to pay, are they paying for | |
// Specific contributions? If so, what if they pay for only part of a | |
// contribution? Perhaps the project would be wise to pay off the | |
// highest interest-rate liabilities first? | |
//TODO Update the liability state variables | |
emit paymentMade(msg.sender, msg.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment