Created
August 18, 2020 18:27
-
-
Save tyrion70/8520269e0b02836706277fb3cb214ec8 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var job = process.argv[2] | |
var bridge = process.argv[3] | |
var operator = process.argv[4] | |
const fs = require('fs'); | |
let rawdata = fs.readFileSync('directory.json'); | |
let directory = JSON.parse(rawdata); | |
let contracts = directory.contracts; | |
let operators = directory.operators; | |
let opkeys = Object.keys(operators); | |
let operatorapi = new Object(); | |
let found = false | |
let contractkeys = Object.keys(contracts); | |
let oracleAddress = "" | |
// Find oracle address | |
for (var a = 0; a < opkeys.length; a++) { | |
if (opkeys[a] == operator) { | |
oracleAddress = operators[opkeys[a]].oracleAddress | |
} | |
} | |
// Find job | |
for (var a = 0; a < contractkeys.length; a++) { | |
if (contracts[contractkeys[a]].marketing.path == job) { | |
// found the job, create jobspec | |
let jobspec = new Object(); | |
jobspec.initiators = new Array(); | |
jobspec.initiators.push({ | |
"type": "runlog", | |
"params": { | |
"address": oracleAddress | |
} | |
}) | |
jobspec.tasks = new Array(); | |
jobspec.tasks.push({ | |
"type": bridge, | |
"params": { | |
"from": contracts[contractkeys[a]].marketing.pair[0], | |
"to": contracts[contractkeys[a]].marketing.pair[1] | |
} | |
}) | |
jobspec.tasks.push({ | |
"type": "copy", | |
"params": { | |
"copyPath": [ | |
"result" | |
] | |
} | |
}) | |
jobspec.tasks.push({ | |
"type": "multiply", | |
"params": { | |
"times": Math.pow(10, contracts[contractkeys[a]].decimals) | |
} | |
}) | |
jobspec.tasks.push({ | |
"type": "ethint256", | |
"params": { | |
} | |
}) | |
jobspec.tasks.push({ | |
"type": "ethtx", | |
"params": { | |
} | |
}) | |
console.log(JSON.stringify(jobspec)) | |
} | |
} |
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
nodeurl=https://test.com | |
username=test@test.com | |
password=12345678 | |
operator=chainlayer | |
node jobcreator.js $1 $2 ${operator} >jobspec | |
rm -f cookiefile | |
curl -s -c cookiefile -X POST -H 'Content-Type: application/json' -d '{"email":"'${username}'", "password":"'${password}'"}' ${nodeurl}/sessions >/dev/null | |
echo "logged in creating job with jobid: " | |
curl -s -b cookiefile -c cookiefile -H 'content-type: application/json' --data @jobspec ${nodeurl}/v2/specs|jq '.data.id' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment