Created
April 23, 2019 22:30
-
-
Save d1ll0n/e49de8334009c01c50da32bb8a31affb 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
pragma solidity ^0.5.7; | |
contract OrderMaker5000 { | |
struct Order { | |
address from; | |
uint haveAmt; | |
uint haveTokenIdx; | |
uint wantAmt; | |
uint wantTokenIdx; | |
} | |
mapping(address => uint) tokenIds; | |
address[] tokenAddresses; | |
Order[] openOrders; | |
modifier tokenNotExists(address tokenAddress) { | |
require(tokenIds[tokenAddress] != 0, "Token already exists"); | |
_; | |
} | |
modifier tokenExists(address tokenAddress) { | |
require(tokenIds[tokenAddress] == 0, "Token does not exist."); | |
_; | |
} | |
constructor() public { | |
tokenIds[address(0)] = 1; | |
tokenAddresses[0] = address(0); | |
} | |
function addToken(address tokenAddress) public tokenNotExists(tokenAddress) { | |
tokenIds[tokenAddress] = tokenAddresses.length; | |
tokenAddresses.push(tokenAddress); | |
} | |
function makeOrder(address wantToken, address haveToken, uint wantAmt, uint haveAmt) | |
public payable tokenExists(wantToken) tokenExists(haveToken) { | |
// lock eth or token up here | |
openOrders.push(Order({ | |
from: msg.sender, | |
haveAmt: haveAmt, | |
haveTokenIdx: tokenIds[haveToken], | |
wantAmt: wantAmt, | |
wantTokenIdx: tokenIds[wantToken] | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment