daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Dec 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.15;
  2.  
  3. contract MyBitcoin {
  4.     mapping (address => uint256) public balanceOf;
  5.     event Transfer(address indexed from, address indexed to, uint256 value);
  6.    
  7.     function MyBitcoin(uint256 initialSupply) {
  8.         balanceOf[msg.sender] = initialSupply;
  9.     }
  10.  
  11.     function transfer(address _to, uint256 _value) {
  12.         require(balanceOf[msg.sender] >= _value);
  13.         require(balanceOf[_to] + _value >= balanceOf[_to]);
  14.         balanceOf[msg.sender] -= _value;
  15.         balanceOf[_to] += _value;
  16.         Transfer(msg.sender, _to, _value);
  17.     }
  18.    
  19.     uint256 public bitCoinPrice = 1000000000000000000;
  20.    
  21.     function buy() payable returns (uint amount){
  22.         amount = msg.value / bitCoinPrice;
  23.         require(balanceOf[this] >= amount);
  24.         balanceOf[msg.sender] += amount;
  25.         balanceOf[this] -= amount;
  26.         Transfer(this, msg.sender, amount);
  27.         return amount;
  28.     }
  29.  
  30.     function sell(uint amount) returns (uint revenue){
  31.         require(balanceOf[msg.sender] >= amount);
  32.         balanceOf[this] += amount;
  33.         balanceOf[msg.sender] -= amount;
  34.         revenue = amount * bitCoinPrice;
  35.         require(msg.sender.send(revenue));
  36.         Transfer(msg.sender, this, amount);
  37.         return revenue;
  38.     }
  39. }
RAW Paste Data
Top