Last active
September 1, 2017 09:08
-
-
Save karthickpdy/b077779837d2873167688d89199e2477 to your computer and use it in GitHub Desktop.
Stock Exchange smart contract
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.4.2; | |
contract StockExchange { | |
mapping (address => uint) balances; | |
uint holdings; | |
event Transaction(string _type, address indexed user); | |
function StockExchange() { | |
holdings = 10000; | |
} | |
function buy() payable{ | |
if(msg.value == 1 ether){ | |
balances[msg.sender] += 1; | |
holdings -= 1; | |
Transaction("Buy",msg.sender); | |
} | |
} | |
function sell(){ | |
balances[msg.sender] -= 1; | |
holdings += 1; | |
msg.sender.transfer(1 ether); | |
Transaction("Sell",msg.sender); | |
} | |
function getBalance(address addr) returns(uint) { | |
return balances[addr]; | |
} | |
function getHoldings() returns(uint) { | |
return holdings; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment