Skip to content

Instantly share code, notes, and snippets.

@tomconte tomconte/ApolloTrade forked from anonymous/Untitled
Created May 24, 2016

Embed
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];
}
}
@mynameisvinn

This comment has been minimized.

Copy link

commented Aug 3, 2017

throw has been deprecated.

instead, use this code block:

    modifier onlyOwner {
        // if (msg.sender != owner) throw;
        require(msg.sender != owner);
        _;
    }
@hoanbka

This comment has been minimized.

Copy link

commented Oct 24, 2017

// I am selling some energy; this will credit my account
function sellEnergy(uint kwh) public {
coinAccount[msg.sender] += (kwh * kWh_rate);
}

When the producer sells energy, his coin account will be deposited but I think his energy account has to be deducted also?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.