Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=
contract ApolloTrade {
uint public kWh_rate = 1000;
mapping (address => uint) energyAccount;
mapping (address => uint) coinAccount;
address public owner;
function ApolloTrade() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_
}
function setRate(uint rate) onlyOwner {
kWh_rate = rate;
}
// I am selling some energy; this will credit my account
function sellEnergy(uint kwh) public {
coinAccount[msg.sender] += (kwh * kWh_rate);
}
// I am buying some energy, thus crediting my energy account
function buyEnergy(uint coin) {
if (coinAccount[msg.sender] > coin) {
coinAccount[msg.sender] -= coin;
energyAccount[msg.sender] += (coin / kWh_rate);
}
}
function getEnergyAccount() returns (uint kwh) {
return energyAccount[msg.sender];
}
function getCoinAccount() returns (uint coin) {
return coinAccount[msg.sender];
}
}

throw has been deprecated.

instead, use this code block:

    modifier onlyOwner {
        // if (msg.sender != owner) throw;
        require(msg.sender != owner);
        _;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment