-
-
Save tomconte/ca2e2927d72b472c5ee24f3db71a0987 to your computer and use it in GitHub Desktop.
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=
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
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]; | |
} | |
} |
// 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
throw
has been deprecated.instead, use this code block: