-
Notifications
You must be signed in to change notification settings - Fork 24
Weather station oracle #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Andy92Pac
wants to merge
3
commits into
iExecBlockchainComputing:master
Choose a base branch
from
Andy92Pac:weather-station-oracle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| node_modules |
This file contains hidden or 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,8 @@ | ||
| FROM node:11-alpine | ||
| COPY weather-station.js /app/weather-station.js | ||
| COPY entrypoint.sh /entrypoint.sh | ||
| ARG APIKEY=APIKEY | ||
| ENV APIKEY=${APIKEY} | ||
| RUN npm i https ethers fs | ||
| RUN chmod +x /entrypoint.sh | ||
| ENTRYPOINT ["/entrypoint.sh"] |
This file contains hidden or 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,2 @@ | ||
| #!/bin/sh | ||
| node app/weather-station.js $@ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,17 @@ | ||
| { | ||
| "name": "app", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "main": "weather-station.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "dotenv": "^8.2.0", | ||
| "ethers": "^4.0.38", | ||
| "fs": "0.0.1-security", | ||
| "https": "^1.0.0" | ||
| } | ||
| } |
This file contains hidden or 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,115 @@ | ||
| const https = require('https'); | ||
| const ethers = require('ethers'); | ||
| const fs = require('fs'); | ||
|
|
||
| const root = 'iexec_out'; | ||
| const determinismFilePath = `${root}/determinism.iexec`; | ||
| const callbackFilePath = `${root}/callback.iexec`; | ||
| const errorFilePath = `${root}/error.iexec`; | ||
|
|
||
|
|
||
| /***************************************************************************** | ||
| * TOOLS * | ||
| *****************************************************************************/ | ||
| const sleep = (ms) => { | ||
| return new Promise(resolve => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| /***************************************************************************** | ||
| * CONFIG * | ||
| *****************************************************************************/ | ||
|
|
||
| // coin api key | ||
| const APIKEY = process.env.APIKEY; | ||
|
|
||
| // random delay | ||
| const WAIT_MIN = parseInt(process.env.WAIT_MIN) || 0; // in ms | ||
| const WAIT_MAX = parseInt(process.env.WAIT_MAX) || 0; // in ms | ||
|
|
||
| /***************************************************************************** | ||
| * ARGUMENTS * | ||
| *****************************************************************************/ | ||
|
|
||
| let [ lat, lon, time ] = process.argv.slice(2); | ||
|
|
||
| const unit = 'si'; | ||
|
|
||
| /***************************************************************************** | ||
| * HTTP QUERY * | ||
| *****************************************************************************/ | ||
| let path = `/forecast/${APIKEY}/${lat},${lon},${time}?exclude=minutely,hourly,daily,alerts&units=${unit}`; | ||
|
|
||
| const query = { | ||
| method: 'GET', | ||
| port: 443, | ||
| host: 'api.darksky.net', | ||
| path: path, | ||
| }; | ||
|
|
||
| /***************************************************************************** | ||
| * EXECUTE * | ||
| *****************************************************************************/ | ||
| new Promise(async (resolve, reject) => { | ||
|
|
||
| const delay = (WAIT_MAX-WAIT_MIN) * Math.random() + WAIT_MIN; | ||
| console.log(`- Waiting for ${delay} ms.`); | ||
| await sleep(delay); | ||
|
|
||
| console.log(`- Calling API ${query.host}${query.path}`); | ||
| let chunks = []; | ||
| let request = https.request(query, res => { | ||
| res.on('data', (chunk) => { | ||
| chunks.push(chunk); | ||
| }); | ||
| res.on('end', () => { | ||
| if (chunks.length) | ||
| { | ||
| resolve(chunks.join('')); | ||
| } | ||
| else | ||
| { | ||
| reject(`[HTTP ERROR]\nstatusCode: ${res.statusCode}`); | ||
| } | ||
| }); | ||
| }); | ||
| request.on('error', reject); | ||
| request.end(); | ||
| }) | ||
| .then(data => { | ||
| let results = JSON.parse(data.toString()); | ||
|
|
||
| if (results.error !== undefined) | ||
| { | ||
| throw new Error(results.error); | ||
| } | ||
|
|
||
| let { latitude, longitude } = results; | ||
| let { time, icon } = results.currently; | ||
|
|
||
| let location = `${latitude},${longitude}`; | ||
|
|
||
| if (isNaN(time) || icon == undefined) | ||
| { | ||
| throw new Error("invalid results"); | ||
| } | ||
|
|
||
| let iexeccallback = ethers.utils.defaultAbiCoder.encode(['uint256', 'string', 'string'], [time, location, icon]); | ||
| let iexecconsensus = ethers.utils.keccak256(iexeccallback); | ||
| fs.writeFile(callbackFilePath, iexeccallback , (err) => {}); | ||
| fs.writeFile(determinismFilePath, iexecconsensus, (err) => {}); | ||
|
|
||
| console.log(`- Success: ${time} ${icon}`); | ||
| }) | ||
| .catch(error => { | ||
| fs.writeFile( | ||
| errorFilePath, | ||
| error.toString(), | ||
| (err) => {} | ||
| ); | ||
| fs.writeFile( | ||
| determinismFilePath, | ||
| ethers.utils.solidityKeccak256(['string'],[error.toString()]), | ||
| (err) => {} | ||
| ); | ||
| console.log(error.toString()); | ||
| }); | ||
This file contains hidden or 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,29 @@ | ||
| { | ||
| "default": "kovan", | ||
| "chains": { | ||
| "dev": { | ||
| "host": "http://localhost:8545", | ||
| "sms": "http://localhost:5000", | ||
| "id": "17", | ||
| "hub": "0x60E25C038D70A15364DAc11A042DB1dD7A2cccBC" | ||
| }, | ||
| "ropsten": { | ||
| "host": "https://ropsten.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", | ||
| "id": "3" | ||
| }, | ||
| "rinkeby": { | ||
| "host": "https://rinkeby.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", | ||
| "id": "4" | ||
| }, | ||
| "kovan": { | ||
| "host": "https://kovan.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", | ||
| "id": "42", | ||
| "sms": "https://sms-kovan.iex.ec" | ||
| }, | ||
| "mainnet": { | ||
| "host": "https://mainnet.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", | ||
| "id": "1", | ||
| "sms": "https://sms-mainnet.iex.ec" | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,5 @@ | ||
| { | ||
| "app": { | ||
| "42": "0xdffFa5f74Ba05A21C8A10E76d41f50F8A0858A5F" | ||
| } | ||
| } |
This file contains hidden or 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,35 @@ | ||
| { | ||
| "description": "My iExec ressource description, must be at least 150 chars long in order to pass the validation checks. Describe your application, dataset or workerpool to your users", | ||
| "license": "MIT", | ||
| "author": "?", | ||
| "social": { | ||
| "website": "?", | ||
| "github": "?" | ||
| }, | ||
| "logo": "logo.png", | ||
| "buyConf": { | ||
| "params": "", | ||
| "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
| "trust": "0", | ||
| "callback": "0x0000000000000000000000000000000000000000" | ||
| }, | ||
| "app": { | ||
| "owner": "0x866A9D83B80266F2D40882b13463615eda305b08", | ||
| "name": "Weather-station", | ||
| "type": "DOCKER", | ||
| "multiaddr": "registry.hub.docker.com/andy92pac/weather-station:1.0.0", | ||
| "checksum": "0xbc500419ccb732102265753ef439bc7c53916549ee5a7567b771c5b80e24d2f3", | ||
| "mrenclave": "" | ||
| }, | ||
| "order": { | ||
| "apporder": { | ||
| "app": "0xdffFa5f74Ba05A21C8A10E76d41f50F8A0858A5F", | ||
| "appprice": "0", | ||
| "volume": "1000000", | ||
| "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
| "datasetrestrict": "0x0000000000000000000000000000000000000000", | ||
| "workerpoolrestrict": "0x0000000000000000000000000000000000000000", | ||
| "requesterrestrict": "0x0000000000000000000000000000000000000000" | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,15 @@ | ||
| { | ||
| "42": { | ||
| "apporder": { | ||
| "app": "0xdffFa5f74Ba05A21C8A10E76d41f50F8A0858A5F", | ||
| "appprice": "0", | ||
| "volume": "1000000", | ||
| "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
| "datasetrestrict": "0x0000000000000000000000000000000000000000", | ||
| "workerpoolrestrict": "0x0000000000000000000000000000000000000000", | ||
| "requesterrestrict": "0x0000000000000000000000000000000000000000", | ||
| "salt": "0x15367e1313f93c1f24c00236d899b482a910ef2222cc931b4f7b1a359ade9c22", | ||
| "sign": "0x56f161ac6f1e04aad6a1553217774e5a8778fb48b8502d60dd443405806e4cd37d77eabedb1b9a7b74492e584523ad98b7e915654bfd83e2b5b4e9745b719fdb1b" | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| node_modules |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.