Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Commit

Permalink
Create EnergyTariffOracle.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
anafiallo authored Dec 5, 2018
1 parent ca40459 commit ab65024
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions EnergyTariffOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Energy Price Peg
This contract keeps in storage a reference
to the Energy Price in USD
*/


pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";

contract EnergyTariff is usingOraclize {

uint public EnergyTariffUSD;

event newOraclizeQuery(string description);
event newEnergyTariff(string price);

function EnergyTariff() {
update(); // first check at contract creation
}

function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
newEnergyTariff(result);
EnergyTariffUSD = viewInt(result, 2); // let's save it as $ cents
}

function update() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "xml(https://www.eia.gov/state/print.php?sid=RQ");
}

}

0 comments on commit ab65024

Please sign in to comment.