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 ups-package-tracker/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 6 additions & 0 deletions ups-package-tracker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:11-alpine
COPY package-tracker.js /src/package-tracker.js
COPY entrypoint.sh /entrypoint.sh
RUN npm i https ethers fs
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 2 additions & 0 deletions ups-package-tracker/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
node src/package-tracker.js $@
98 changes: 98 additions & 0 deletions ups-package-tracker/app/package-lock.json

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

157 changes: 157 additions & 0 deletions ups-package-tracker/app/package-tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
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`;

<<<<<<< HEAD
// Type of activity status:
// I = In Transit
// D = Delivered
// X = Exception
// P = Pickup
// M = Manifest Pickup

const DeliveryStatus = {
I : 1,
D : 2,
X : 3,
P : 4,
M : 5
}
=======
>>>>>>> dbad13c1e40309d9e9c9e3007b0f5e77f3a353ac

/*****************************************************************************
* TOOLS *
*****************************************************************************/
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}

const cat = (path) => {
try { return fs.readFileSync(path).toString(); } catch (e) { return null; }
}

/*****************************************************************************
* CONFIG *
*****************************************************************************/

// UPS api key
const APIKEY = '7D6C7B558EF337F2';

// 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 *
*****************************************************************************/

var [ UPS_username, UPS_password, trackingNumber ] = process.argv.slice(2);

/*****************************************************************************
* HTTP QUERY *
*****************************************************************************/

const post_data = JSON.stringify({
"UPSSecurity": {
"UsernameToken": {
"Username": UPS_username,
"Password": UPS_password
},
"ServiceAccessToken": {
"AccessLicenseNumber": APIKEY
}
},
"TrackRequest": {
"Request": {
"RequestOption": "1",
"TransactionReference": {
"CustomerContext": "Your Test Case Summary Description"
}
},
"InquiryNumber": trackingNumber
}

});

const options = {
method: 'POST',
host: 'onlinetools.ups.com',
path: '/rest/Track',
headers: {'Content-Type': 'application/json', 'Content-Length': post_data.length},
};

/*****************************************************************************
* 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(`making request`);
let chunks = [];
let request = https.request(options, 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.write(post_data);
request.on('error', reject);
request.end();
})
.then(data => {
console.log("parsing JSON");
let results = JSON.parse(data.toString());
// console.log(results);

if (results.Fault !== undefined)
{
console.log("error");
throw new Error(JSON.stringify(results.Fault.detail));
}
<<<<<<< HEAD
// let deliveryStatus = results.TrackResponse.Shipment.Package.Activity[0].Status.Description;
let deliveryStatus = DeliveryStatus[results.TrackResponse.Shipment.Package.Activity[0].Status.Type];

var iexeccallback = ethers.utils.defaultAbiCoder.encode(['uint256'], [deliveryStatus]);
=======
let deliveryStatus = results.TrackResponse.Shipment.Package.Activity[0].Status.Description;

var iexeccallback = ethers.utils.defaultAbiCoder.encode(['string'], [deliveryStatus]);
>>>>>>> dbad13c1e40309d9e9c9e3007b0f5e77f3a353ac
var iexecconsensus = ethers.utils.keccak256(iexeccallback);
fs.writeFile(callbackFilePath, iexeccallback , (err) => {});
fs.writeFile(determinismFilePath, iexecconsensus, (err) => {});

console.log(`- Success: ${deliveryStatus}`);
})
.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 ups-package-tracker/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 ups-package-tracker/deployed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"app": {
"42": "0x8Ee07bCf22573a5D934e907E71E5127a55DAe6A0"
}
}
35 changes: 35 additions & 0 deletions ups-package-tracker/iexec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"description": "UPS package tracker - simple doracle to get delivery status given a UPS username, password, and tracking number. ",
"license": "MIT",
"author": "?",
"social": {
"website": "?",
"github": "?"
},
"logo": "logo.png",
"buyConf": {
"params": "",
"tag": "0x0000000000000000000000000000000000000000000000000000000000000000",
"trust": "0",
"callback": "0x0000000000000000000000000000000000000000"
},
"app": {
"owner": "0xe4B6901be4bc68f5de8E62af44Ee1773B103c461",
"name": "UPSPackageTracker",
"type": "DOCKER",
"multiaddr": "registry.hub.docker.com/frippo40/ups-package-tracker:1.0.2",
"checksum": "0x78c67f7d576f2982943adbd8273d50244a2cdb082bb01c5fad4582be4b7d12cd",
"mrenclave": ""
},
"order": {
"apporder": {
"app": "0x8Ee07bCf22573a5D934e907E71E5127a55DAe6A0",
"appprice": "0",
"volume": "1000000",
"tag": "0x0000000000000000000000000000000000000000000000000000000000000000",
"datasetrestrict": "0x0000000000000000000000000000000000000000",
"workerpoolrestrict": "0x0000000000000000000000000000000000000000",
"requesterrestrict": "0x0000000000000000000000000000000000000000"
}
}
}
15 changes: 15 additions & 0 deletions ups-package-tracker/orders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"42": {
"apporder": {
"app": "0x8Ee07bCf22573a5D934e907E71E5127a55DAe6A0",
"appprice": "0",
"volume": "1000000",
"tag": "0x0000000000000000000000000000000000000000000000000000000000000000",
"datasetrestrict": "0x0000000000000000000000000000000000000000",
"workerpoolrestrict": "0x0000000000000000000000000000000000000000",
"requesterrestrict": "0x0000000000000000000000000000000000000000",
"salt": "0x6818fc0531f2d84d95ccf574de6a61e2cfcae35bac9a1ff7e4e0b08caa016d5b",
"sign": "0xea2feb31fe4edebb788ac7a002b5d5313f371cbd8e1c42d2ce8ea9a578b0aa6e2e54618acd0118c0ab08f9e1a700bf640d33c8e792bf87d0d6c3373b358b9d1e1b"
}
}
}
7 changes: 7 additions & 0 deletions ups-package-tracker/smart-contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
subgraph
subgraph-kovan
daemon
migrations
contracts
build
Loading