-
-
Save khovratovich/45f68082b556b45eb64e8e1c3eb82892 to your computer and use it in GitHub Desktop.
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
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