This repository has been archived by the owner on Jan 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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"); | ||
} | ||
|
||
} |