Last active
June 17, 2021 19:52
-
-
Save dominiek/16d846d617c4659f5372409c8282c08c to your computer and use it in GitHub Desktop.
EtherDelta Fund Management
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
mapping (address => mapping (address => uint)) public tokens; | |
function deposit() payable { | |
tokens[0][msg.sender] = safeAdd(tokens[0][msg.sender], msg.value); | |
Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]); | |
} | |
function withdraw(uint amount) { | |
if (tokens[0][msg.sender] < amount) throw; | |
tokens[0][msg.sender] = safeSub(tokens[0][msg.sender], amount); | |
if (!msg.sender.call.value(amount)()) throw; | |
Withdraw(0, msg.sender, amount, tokens[0][msg.sender]); | |
} | |
function depositToken(address token, uint amount) { | |
//remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf. | |
if (token==0) throw; | |
if (!Token(token).transferFrom(msg.sender, this, amount)) throw; | |
tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount); | |
Deposit(token, msg.sender, amount, tokens[token][msg.sender]); | |
} | |
function withdrawToken(address token, uint amount) { | |
if (token==0) throw; | |
if (tokens[token][msg.sender] < amount) throw; | |
tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount); | |
if (!Token(token).transfer(msg.sender, amount)) throw; | |
Withdraw(token, msg.sender, amount, tokens[token][msg.sender]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mapping (address => mapping (address => uint)) public tokens;
function deposit() payable {
tokens[0][msg.sender] = safeAdd(tokens[0][msg.sender], msg.value);
Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]);
}
function withdraw(uint amount) {
if (tokens[0][msg.sender] < amount) throw;
tokens[0][msg.sender] = safeSub(tokens[0][msg.sender], amount);
if (!msg.sender.call.value(amount)()) throw;
Withdraw(0, msg.sender, amount, tokens[0][msg.sender]);
}
function depositToken(address token, uint amount) {
//remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf.
if (token==0) throw;
if (!Token(token).transferFrom(msg.sender, this, amount)) throw;
tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount);
Deposit(token, msg.sender, amount, tokens[token][msg.sender]);
}
function withdrawToken(address token, uint amount) {
if (token==0) throw;
if (tokens[token][msg.sender] < amount) throw;
tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
if (!Token(token).transfer(msg.sender, amount)) throw;
Withdraw(token, msg.sender, amount, tokens[token][msg.sender]);
}