Skip to content

Commit

Permalink
Merge pull request #168 from LefterisJP/sample_offer_inheritance
Browse files Browse the repository at this point in the history
SampleOffer/s: avoid code duplication
  • Loading branch information
CJentzsch committed May 24, 2016
2 parents 22ee2de + 03d0c62 commit bb9b301
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 99 deletions.
116 changes: 21 additions & 95 deletions SampleOffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,110 +17,36 @@ along with the DAO. If not, see <http://www.gnu.org/licenses/>.


/*
Sample Proposal from a Contractor to the DAO.
Feel free to use as a template for your own proposal.
Sample Proposal from a Contractor to the DAO including a reward towards the
DAO.
Feel free to use as a template for your own proposal.
*/

import "./DAO.sol";
import "./SampleOfferWithoutReward.sol";

contract SampleOffer {

uint public totalCosts;
uint public oneTimeCosts;
uint public dailyWithdrawLimit;

address public contractor;
bytes32 public IPFSHashOfTheProposalDocument;
uint public minDailyWithdrawLimit;
uint public paidOut;

uint public dateOfSignature;
DAO public client; // address of DAO
DAO public originalClient; // address of DAO who signed the contract
bool public isContractValid;
contract SampleOffer is SampleOfferWithoutReward {

uint public rewardDivisor;
uint public deploymentReward;

modifier onlyClient {
if (msg.sender != address(client))
throw;
_
}

// Prevents methods from perfoming any value transfer
modifier noEther() {if (msg.value > 0) throw; _}

function SampleOffer(
address _contractor,
address _client,
bytes32 _IPFSHashOfTheProposalDocument,
uint _totalCosts,
uint _oneTimeCosts,
uint _minDailyWithdrawLimit
) {
contractor = _contractor;
originalClient = DAO(_client);
client = DAO(_client);
IPFSHashOfTheProposalDocument = _IPFSHashOfTheProposalDocument;
totalCosts = _totalCosts;
oneTimeCosts = _oneTimeCosts;
minDailyWithdrawLimit = _minDailyWithdrawLimit;
dailyWithdrawLimit = _minDailyWithdrawLimit;
}

function sign() {
if (msg.sender != address(originalClient) // no good samaritans give us money
|| msg.value != totalCosts // no under/over payment
|| dateOfSignature != 0) // don't sign twice
throw;
if (!contractor.send(oneTimeCosts))
throw;
dateOfSignature = now;
isContractValid = true;
}

function setDailyWithdrawLimit(uint _dailyWithdrawLimit) onlyClient noEther {
if (_dailyWithdrawLimit >= minDailyWithdrawLimit)
dailyWithdrawLimit = _dailyWithdrawLimit;
}

// "fire the contractor"
function returnRemainingEther() onlyClient {
if (originalClient.DAOrewardAccount().call.value(this.balance)())
isContractValid = false;
}

function getDailyPayment() {
if (msg.sender != contractor)
throw;
uint amount = (now - dateOfSignature + 1 days) / (1 days) * dailyWithdrawLimit - paidOut;
if (amount > this.balance) {
amount = this.balance;
function SampleOffer(
address _contractor,
address _client,
bytes32 _IPFSHashOfTheProposalDocument,
uint _totalCosts,
uint _oneTimeCosts,
uint _minDailyWithdrawLimit
) SampleOfferWithoutReward(
_contractor,
_client,
_IPFSHashOfTheProposalDocument,
_totalCosts,
_oneTimeCosts,
_minDailyWithdrawLimit) {
}
if (contractor.send(amount))
paidOut += amount;
}

function setRewardDivisor(uint _rewardDivisor) onlyClient noEther {
rewardDivisor = _rewardDivisor;
}

function setDeploymentReward(uint _deploymentReward) onlyClient noEther {
deploymentReward = _deploymentReward;
}

// Change the client DAO by giving the new DAO's address
// warning: The new DAO must come either from a split of the original
// DAO or an update via `newContract()` so that it can claim rewards
function updateClientAddress(DAO _newClient) onlyClient noEther {
client = _newClient;
}

function () {
throw; // this is a business contract, no donations
}


// interface for Ethereum Computer
function payOneTimeReward() returns(bool) {
// client DAO should not be able to pay itself generating
Expand Down
10 changes: 6 additions & 4 deletions SampleOfferWithoutReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ along with the DAO. If not, see <http://www.gnu.org/licenses/>.


/*
Sample Proposal from a Contractor to the DAO.
Feel free to use as a template for your own proposal.
Sample Proposal from a Contractor to the DAO without any reward going back to
the DAO.
Feel free to use as a template for your own proposal.
*/

import "./DAO.sol";

contract SampleOfferWithoutRewards {
contract SampleOfferWithoutReward {

uint public totalCosts;
uint public oneTimeCosts;
Expand All @@ -48,7 +50,7 @@ contract SampleOfferWithoutRewards {
// Prevents methods from perfoming any value transfer
modifier noEther() {if (msg.value > 0) throw; _}

function SampleOffer(
function SampleOfferWithoutReward(
address _contractor,
address _client,
bytes32 _IPFSHashOfTheProposalDocument,
Expand Down

0 comments on commit bb9b301

Please sign in to comment.