Skip to content

Instantly share code, notes, and snippets.

@khovratovich
Last active December 21, 2016 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khovratovich/45f68082b556b45eb64e8e1c3eb82892 to your computer and use it in GitHub Desktop.
Save khovratovich/45f68082b556b45eb64e8e1c3eb82892 to your computer and use it in GitHub Desktop.
contract Debt{
Token currencyTokenContract;
address issuer;
address owner;
bool free;
uint value;
function Debt(Token _currency, uint _value){ //contract issue
issuer=msg.sender;
currencyTokenContract = _currency;
value = _value;
free=true;
}
function join(uint _value) public{
if(free && _value==value){
owner=msg.sender;
free = false;
if(!currencyTokenContract.transferFrom(msg.sender,issuer,_value))
throw;
}
else throw;
}
function execute() public returns (bool) {
if(msg.sender!=owner)
throw;
if(currencyTokenContract.transferFrom(issuer,owner,value)){
owner=0;
free = true;
return true;
}
else return false;
}
}
contract Issuer{
address owner;
function Issuer(){
owner=msg.sender;
}
function issueDebt(Token _currency, uint _value) public{
Debt debtContract = new Debt(_currency, _value);
_currency.approve(debtContract,_value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment