SHARE
TWEET

Untitled

a guest Sep 21st, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function buy() payable returns (uint amount){
  2.     amount = msg.value / buyPrice;                    // calculates the amount
  3.     require(balanceOf[this] >= amount);               // checks if it has enough to sell
  4.     balanceOf[msg.sender] += amount;                  // adds the amount to buyer's balance
  5.     balanceOf[this] -= amount;                        // subtracts amount from seller's balance
  6.     Transfer(this, msg.sender, amount);               // execute an event reflecting the change
  7.     return amount;                                    // ends function and returns
  8. }
  9.  
  10. function sell(uint amount) returns (uint revenue){
  11.     require(balanceOf[msg.sender] >= amount);         // checks if the sender has enough to sell
  12.     balanceOf[this] += amount;                        // adds the amount to owner's balance
  13.     balanceOf[msg.sender] -= amount;                  // subtracts the amount from seller's balance
  14.     revenue = amount * sellPrice;
  15.     require(msg.sender.send(revenue));                // sends ether to the seller: it's important to do this last to prevent recursion attacks
  16.     Transfer(msg.sender, this, amount);               // executes an event reflecting on the change
  17.     return revenue;                                   // ends function and returns
  18. }
RAW Paste Data
Top