Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions weather-station-oracle/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions weather-station-oracle/app/Dockerfile
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"]
2 changes: 2 additions & 0 deletions weather-station-oracle/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
node app/weather-station.js $@
115 changes: 115 additions & 0 deletions weather-station-oracle/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions weather-station-oracle/app/package.json
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"
}
}
115 changes: 115 additions & 0 deletions weather-station-oracle/app/weather-station.js
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]);
Comment thread
Andy92Pac marked this conversation as resolved.
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());
});
29 changes: 29 additions & 0 deletions weather-station-oracle/chain.json
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"
}
}
}
5 changes: 5 additions & 0 deletions weather-station-oracle/deployed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"app": {
"42": "0xdffFa5f74Ba05A21C8A10E76d41f50F8A0858A5F"
}
}
35 changes: 35 additions & 0 deletions weather-station-oracle/iexec.json
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"
}
}
}
15 changes: 15 additions & 0 deletions weather-station-oracle/orders.json
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"
}
}
}
1 change: 1 addition & 0 deletions weather-station-oracle/smart-contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading