Skip to content

Instantly share code, notes, and snippets.

@xotonic
Created May 6, 2019 03:26
Show Gist options
  • Save xotonic/65b615d040644fca993b5762043781ed to your computer and use it in GitHub Desktop.
Save xotonic/65b615d040644fca993b5762043781ed to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.0;
contract OrderBookLUXBTC {
enum OrderType { BUY, SELL }
event OrderPlaced(uint64 id,OrderType t, uint64 price, uint64 quantity);
event OrderMatched(uint64 id);
mapping(address => uint) deposits;
/// Deposit = 10 lux
function place(uint64 id, OrderType t, uint64 price, uint64 quantity) payable {
if (msg.value < 10 ether || price == 0 || quantity == 0) { throw; }
OrderPlaced(id, t, price, quantity);
deposits[msg.sender] += msg.value;
}
function take(uint64 id) returns (bool) {
uint amount = deposits[msg.sender];
if (amount < 10 ether) { throw; }
// It is important to substract now this because the recipient
// can call this function again as part of the receiving call
// before `send` returns.
deposits[msg.sender] -= 10 ether;
if (!msg.sender.send(amount)) {
// No need to call throw here, just reset the amount owing
deposits[msg.sender] = amount;
return false;
}
OrderMatched(id);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment