Created
February 26, 2018 02:24
-
-
Save AbstractFruitFactory/c9e39699086252af81392ebe54a01c1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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.17; | |
import '../node_modules/zeppelin-solidity/contracts/math/SafeMath.sol'; | |
import './IVotingMechanism.sol'; | |
contract OutcomeBondsToken { | |
using SafeMath for uint256; | |
struct OutcomeBond { | |
IVotingMechanism voting; | |
mapping (address => uint) backerTokens; | |
mapping (address => uint) rewardTokens; | |
} | |
mapping (address => OutcomeBond) outcomes; | |
function OutcomeBondsToken() public { | |
} | |
function createOutcomeBond(IVotingMechanism _voting, address _outcome) public { | |
outcomes[_outcome].voting = _voting; | |
} | |
function vote(address _subject, address _topic, IVotingMechanism.Vote _vote, address _outcome) { | |
outcomes[_outcome].voting.vote(_subject, _topic, _vote); | |
} | |
function back(address _outcome) public payable { | |
outcomes[_outcome].backerTokens[msg.sender] += msg.value; | |
outcomes[_outcome].rewardTokens[msg.sender] += msg.value; | |
} | |
function redeemBackerTokens(address _outcome, uint _amountToRedeem) public { | |
require(_amountToRedeem > 0); | |
require(outcomes[_outcome].voting.checkVote(_outcome, this) == IVotingMechanism.Vote.NOT_MET); | |
uint amountInStore = outcomes[_outcome].backerTokens[msg.sender]; | |
require(amountInStore >= _amountToRedeem); | |
outcomes[_outcome].backerTokens[msg.sender] -= _amountToRedeem; | |
msg.sender.transfer(_amountToRedeem); | |
} | |
function redeemRewardTokens(address _outcome, uint _amountToRedeem) public { | |
require(_amountToRedeem > 0); | |
require(outcomes[_outcome].voting.checkVote(_outcome, this) == IVotingMechanism.Vote.MET); | |
uint amountInStore = outcomes[_outcome].rewardTokens[msg.sender]; | |
require(amountInStore >= _amountToRedeem); | |
outcomes[_outcome].rewardTokens[msg.sender] -= _amountToRedeem; | |
msg.sender.transfer(_amountToRedeem); | |
} | |
function transferRewardTokens(address _from, address _to, uint256 _value, address _outcome) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= outcomes[_outcome].rewardTokens[_from]); | |
outcomes[_outcome].rewardTokens[_from] = outcomes[_outcome].rewardTokens[_from].sub(_value); | |
outcomes[_outcome].rewardTokens[_to] = outcomes[_outcome].rewardTokens[_to].add(_value); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment