diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..339fdf2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# build environment +FROM node:14.5.0-alpine + +## ENV variables +ENV PERM=active + +WORKDIR /app +ENV PATH /app/node_modules/.bin:$PATH +COPY scripts/package.json ./ +COPY scripts/package-lock.json ./ +COPY scripts/docker-updater.js ./updater.js +COPY scripts/docker.env .env + + +RUN npm ci +RUN npm install react-scripts@3.4.1 -g + + +# Entrypoint +ADD scripts/start.sh / +RUN chmod +x /start.sh +CMD /start.sh diff --git a/README.md b/README.md index 37f5f2c..1cac341 100644 --- a/README.md +++ b/README.md @@ -208,3 +208,45 @@ if you have `jq` installed, you can show the first record, which should contain ``` cleos get table --limit 100 delphioracle eosusd datapoints |jq .rows[0] ``` + +# Running the updater.js using Docker +## :exclamation: Updater in docker uses EOSJS v2 + +## ENV Variables + +|ENV & ARG |Value |Description | +|--------------------------|-------------------------------|-----------------------------------------------| +|**PRIVATE_KEY** |`5xxxxxxxxxxxx` | The prviate key of your permission | +|**BPNAME** |`sentnlagents` | Your BP account | +|**PERM** |`oracle` | If using Custom permission; defaults to active| +|**API** |`waxapi.sentnl.io` | Wax API endpoint | +|**CHAIN** |`wax` | The EOSIO Chain that hosts the delphioracle | +|**APIPORT** |`443` | The port of API endpoint | + +## Build the production container + +``` +docker build https://github.com/ankh2054/delphioracle.git -t delphioracle +``` + +## Run the container passing required ENV variables + + +### The following ENV variables need to be passed: + +- **BPNAME** - The name of your bp account +- **PERM** - The permissions to sign the transaction with. Defaults to active. +- **API** - The API endpoint you wish to use. +- **CHAIN** - The EOSIO Chain that hosts the delphioracle. :exclamation: Currently only WAX and EOS is supported. + +```Dockerfile: +docker run --name delphioracle.wax \ +-d -e "PRIVATE_KEY=xxxxxxxxxxxxx" \ +-e "BPNAME=sentnlagents" \ +-e "PERM=oracle" \ +-e "API=waxapi.sentnl.io" \ +-e "APIPORT=4343" \ +-e "CHAIN=wax" \ +delphioracle +``` + diff --git a/scripts/docker-updater.js b/scripts/docker-updater.js new file mode 100644 index 0000000..89f0059 --- /dev/null +++ b/scripts/docker-updater.js @@ -0,0 +1,91 @@ +// EOSJS version 2 used +const { Api, JsonRpc, RpcError } = require('eosjs'); +const fetch = require('node-fetch'); +const { TextEncoder, TextDecoder } = require('util'); +const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); +const axios = require('axios'); +const dotenv = require('dotenv'); + +dotenv.load(); + +var chain = process.env.CHAIN; +var cryptocompareKey = process.env.CRYPTOCOMPARE; +priceUrl = `https://min-api.cryptocompare.com/data/pricemulti?fsyms=WAXP,USDC,USDT&tsyms=BTC,USD,ETH,EOS&api_key=${cryptocompareKey}`; +usdpair = "waxpusd"; +btcpair = "waxpbtc"; +eospair = "waxpeos"; +ethpair = "waxpeth"; +usdcpair = "usdcusd"; +usdtpair = "usdtusd"; + +const owner = process.env.ORACLE; +const oracleContract = process.env.CONTRACT; +const defaultPrivateKey = process.env.EOS_KEY; +const permission = process.env.ORACLE_PERMISSION; +const httpEndpoint = process.env.EOS_PROTOCOL + "://" + process.env.EOS_HOST + ":" + process.env.EOS_PORT; + +console.log(owner,oracleContract,permission) +const rpc = new JsonRpc(httpEndpoint, { fetch }); +const signatureProvider = new JsSignatureProvider([defaultPrivateKey]); +const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); + + +const eosmain = async (quotes2) => { + try { + const result = await api.transact({ + actions: [{ + account: oracleContract, + name: 'write', + authorization: [{ + actor: owner, + permission: permission, + }], + data: { + owner: owner, + quotes: quotes2 + }, + }] + }, { + blocksBehind: 3, + expireSeconds: 30, + }); + console.dir(result); + } catch (e) { + console.log('\nCaught exception: ' + e); + if (e instanceof RpcError) + console.log(JSON.stringify(e.json, null, 2)); + } + } + +async function writequotes() { + try { + const waxpResponse = await axios.get(priceUrl); + const [usdcResponse, usdtResponse] = await Promise.all([ + axios.get('https://api.coingecko.com/api/v3/simple/price?ids=usd-coin&vs_currencies=usd'), + axios.get('https://api.coingecko.com/api/v3/simple/price?ids=tether&vs_currencies=usd') + ]); + + const waxpData = waxpResponse.data; + const usdcPrice = usdcResponse.data['usd-coin'].usd; + const usdtPrice = usdtResponse.data.tether.usd; + + const quotes2 = [ + { "value": Math.round(waxpData.WAXP.BTC * 100000000), pair: btcpair }, + { "value": Math.round(waxpData.WAXP.USD * 10000), pair: usdpair }, + { "value": Math.round(waxpData.WAXP.ETH * 100000000), pair: ethpair }, + { "value": Math.round(waxpData.WAXP.EOS * 1000000), pair: eospair }, + { "value": Math.round(usdcPrice * 10000), pair: usdcpair }, + { "value": Math.round(usdtPrice * 10000), pair: usdtpair } + ]; + + console.log(quotes2); + await eosmain(quotes2); + } catch (error) { + console.log('\nCaught exception: ' + error); + if (error instanceof RpcError) { + console.log(JSON.stringify(error.json, null, 2)); + } + } +} + +writequotes(); \ No newline at end of file diff --git a/scripts/docker.env b/scripts/docker.env new file mode 100644 index 0000000..83bce62 --- /dev/null +++ b/scripts/docker.env @@ -0,0 +1,11 @@ +EOS_PROTOCOL='' +EOS_HOST='' +EOS_PORT='' +EOS_KEY='' +EOS_CHAIN='' +ORACLE="bpname" +CONTRACT="delphioracle" +FREQ=15000 +ORACLE_PERMISSION="permission" +CHAIN='' +CRYPTOCOMPARE='' diff --git a/scripts/package-lock.json b/scripts/package-lock.json index 3b63d66..332ae08 100644 --- a/scripts/package-lock.json +++ b/scripts/package-lock.json @@ -9,10 +9,10 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", "requires": { - "fast-deep-equal": "2.0.1", - "fast-json-stable-stringify": "2.0.0", - "json-schema-traverse": "0.4.1", - "uri-js": "4.2.2" + "fast-deep-equal": "^2.0.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" } }, "asn1": { @@ -20,7 +20,7 @@ "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", "requires": { - "safer-buffer": "2.1.2" + "safer-buffer": "~2.1.0" } }, "assert-plus": { @@ -43,21 +43,12 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, - "babel-runtime": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", "requires": { - "core-js": "2.5.7", - "regenerator-runtime": "0.11.1" - } - }, - "base-x": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.4.tgz", - "integrity": "sha512-UYOadoSIkEI/VrRGSG6qp93rp2WdokiAiNYDfGW5qURAY8GiAQkvMbwNNSDYiVJopqv4gCna7xqf4rrNGp+5AA==", - "requires": { - "safe-buffer": "5.1.2" + "follow-redirects": "1.5.10" } }, "bcrypt-pbkdf": { @@ -65,81 +56,24 @@ "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "requires": { - "tweetnacl": "0.14.5" + "tweetnacl": "^0.14.3" } }, - "bigi": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz", - "integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU=" - }, - "binaryen": { - "version": "37.0.0", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-37.0.0.tgz", - "integrity": "sha512-ACBhSXtQvZvJZ8LNM5R/8HTk57Nr4J+HIrGfIfbIM9OpyaMePsXMgzVt+cMcCgX+sm4bmq5ed0kGgxd9RZ3Kkw==" - }, "bn.js": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" - }, - "browserify-aes": { - "version": "1.2.0", - "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", - "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", - "requires": { - "buffer-xor": "1.0.3", - "cipher-base": "1.0.4", - "create-hash": "1.2.0", - "evp_bytestokey": "1.0.3", - "inherits": "2.0.3", - "safe-buffer": "5.1.2" - } - }, - "bs58": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", - "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", - "requires": { - "base-x": "3.0.4" - } + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==" }, - "buffer-xor": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", - "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" - }, - "bytebuffer": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz", - "integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=", - "requires": { - "long": "3.2.0" - } - }, - "camel-case": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-3.0.0.tgz", - "integrity": "sha1-yjw2iKTpzzpM2nd9xNy8cTJJz3M=", - "requires": { - "no-case": "2.3.2", - "upper-case": "1.1.3" - } + "brorand": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", + "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, - "cipher-base": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", - "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", - "requires": { - "inherits": "2.0.3", - "safe-buffer": "5.1.2" - } - }, "colors": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", @@ -150,50 +84,28 @@ "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "requires": { - "delayed-stream": "1.0.0" + "delayed-stream": "~1.0.0" } }, - "core-js": { - "version": "2.5.7", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", - "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, - "create-hash": { - "version": "1.2.0", - "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", - "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", - "requires": { - "cipher-base": "1.0.4", - "inherits": "2.0.3", - "md5.js": "1.3.5", - "ripemd160": "2.0.2", - "sha.js": "2.4.11" - } - }, - "create-hmac": { - "version": "1.1.7", - "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", - "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", - "requires": { - "cipher-base": "1.0.4", - "create-hash": "1.2.0", - "inherits": "2.0.3", - "ripemd160": "2.0.2", - "safe-buffer": "5.1.2", - "sha.js": "2.4.11" - } - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", "requires": { - "assert-plus": "1.0.0" + "assert-plus": "^1.0.0" + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" } }, "delayed-stream": { @@ -211,71 +123,32 @@ "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", "requires": { - "jsbn": "0.1.1", - "safer-buffer": "2.1.2" - } - }, - "ecurve": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz", - "integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==", - "requires": { - "bigi": "1.4.2", - "safe-buffer": "5.1.2" + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" } }, - "encoding": { - "version": "0.1.12", - "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", - "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "elliptic": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", + "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", "requires": { - "iconv-lite": "0.4.24" + "bn.js": "^4.4.0", + "brorand": "^1.0.1", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.0", + "inherits": "^2.0.1", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.0" } }, "eosjs": { - "version": "16.0.9", - "resolved": "https://registry.npmjs.org/eosjs/-/eosjs-16.0.9.tgz", - "integrity": "sha512-aYgzbgH2RhnmYVzEmK4AD6UIboJI54PGYQUesv2i8rCqYhWij+xQx7PtALJ481cxZnQgmFn8s2KMkgG07P5/Ug==", + "version": "21.0.2", + "resolved": "https://registry.npmjs.org/eosjs/-/eosjs-21.0.2.tgz", + "integrity": "sha512-oRrjfzS6An825IupBGKnn9UXqVUSEpjKw5xH17OYtrlOoJdlDN97yuDITSTVOqBeryIBxHvss59FFgnx4c+YEg==", "requires": { - "babel-runtime": "6.26.0", - "binaryen": "37.0.0", - "create-hash": "1.2.0", - "eosjs-api": "7.0.4", - "eosjs-ecc": "4.0.4", - "fcbuffer": "2.2.2" - } - }, - "eosjs-api": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/eosjs-api/-/eosjs-api-7.0.4.tgz", - "integrity": "sha512-oLbM39rcyWYkqu6nIEQ50I92yT2vvD7WZPZ3FujbydG2ssR5Re/uSvbkFfZTB02g3I4D+UDUA1jd65HlM7r3MQ==", - "requires": { - "camel-case": "3.0.0", - "isomorphic-fetch": "2.2.1" - } - }, - "eosjs-ecc": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/eosjs-ecc/-/eosjs-ecc-4.0.4.tgz", - "integrity": "sha512-9wAYefts4TidHOu+eN9nAisZdWpUzlUimZrB63oP7+/s4xRNJEn2Vvep2ICRODpxpidbshM1L7WaSYW9oiV5gA==", - "requires": { - "bigi": "1.4.2", - "browserify-aes": "1.2.0", - "bs58": "4.0.1", - "bytebuffer": "5.0.1", - "create-hash": "1.2.0", - "create-hmac": "1.1.7", - "ecurve": "1.0.6", - "randombytes": "2.0.6" - } - }, - "evp_bytestokey": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", - "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", - "requires": { - "md5.js": "1.3.5", - "safe-buffer": "5.1.2" + "elliptic": "6.5.3", + "hash.js": "1.1.7", + "pako": "1.0.11" } }, "extend": { @@ -298,14 +171,12 @@ "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, - "fcbuffer": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/fcbuffer/-/fcbuffer-2.2.2.tgz", - "integrity": "sha512-4OhDYe3F3iToKkqao6aj72XcvEjCB4p06U8Wy30lYcLQTp2ispBf2cCyeymKPJQGnbG5wpBa2PraaWWJuZVnUg==", + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", "requires": { - "bn.js": "4.11.8", - "bytebuffer": "5.0.1", - "ieee-float": "0.6.0" + "debug": "=3.1.0" } }, "forever-agent": { @@ -318,9 +189,9 @@ "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.8", - "mime-types": "2.1.24" + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" } }, "getpass": { @@ -328,7 +199,7 @@ "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", "requires": { - "assert-plus": "1.0.0" + "assert-plus": "^1.0.0" } }, "har-schema": { @@ -341,17 +212,27 @@ "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", "requires": { - "ajv": "6.10.0", - "har-schema": "2.0.0" + "ajv": "^6.5.5", + "har-schema": "^2.0.0" + } + }, + "hash.js": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", + "requires": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.1" } }, - "hash-base": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", - "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", + "hmac-drbg": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", "requires": { - "inherits": "2.0.3", - "safe-buffer": "5.1.2" + "hash.js": "^1.0.3", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.1" } }, "http-signature": { @@ -359,48 +240,21 @@ "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", "requires": { - "assert-plus": "1.0.0", - "jsprim": "1.4.1", - "sshpk": "1.16.1" + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" } }, - "iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "requires": { - "safer-buffer": "2.1.2" - } - }, - "ieee-float": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/ieee-float/-/ieee-float-0.6.0.tgz", - "integrity": "sha1-poqFa6HvUR5/oOfn4VXDpjZCpV0=" - }, "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" }, - "isomorphic-fetch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", - "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", - "requires": { - "node-fetch": "1.7.3", - "whatwg-fetch": "3.0.0" - } - }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -437,26 +291,6 @@ "verror": "1.10.0" } }, - "long": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", - "integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s=" - }, - "lower-case": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", - "integrity": "sha1-miyr0bno4K6ZOkv31YdcOcQujqw=" - }, - "md5.js": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", - "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", - "requires": { - "hash-base": "3.0.4", - "inherits": "2.0.3", - "safe-buffer": "5.1.2" - } - }, "mime-db": { "version": "1.40.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", @@ -470,28 +304,36 @@ "mime-db": "1.40.0" } }, - "no-case": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz", - "integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==", - "requires": { - "lower-case": "1.1.4" - } + "minimalistic-assert": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" + }, + "minimalistic-crypto-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", - "requires": { - "encoding": "0.1.12", - "is-stream": "1.1.0" - } + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" }, + "pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -512,53 +354,31 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" }, - "randombytes": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz", - "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==", - "requires": { - "safe-buffer": "5.1.2" - } - }, - "regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" - }, "request": { "version": "2.88.0", "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", "requires": { - "aws-sign2": "0.7.0", - "aws4": "1.8.0", - "caseless": "0.12.0", - "combined-stream": "1.0.8", - "extend": "3.0.2", - "forever-agent": "0.6.1", - "form-data": "2.3.3", - "har-validator": "5.1.3", - "http-signature": "1.2.0", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.24", - "oauth-sign": "0.9.0", - "performance-now": "2.1.0", - "qs": "6.5.2", - "safe-buffer": "5.1.2", - "tough-cookie": "2.4.3", - "tunnel-agent": "0.6.0", - "uuid": "3.3.2" - } - }, - "ripemd160": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", - "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", - "requires": { - "hash-base": "3.0.4", - "inherits": "2.0.3" + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.0", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.4.3", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" } }, "safe-buffer": { @@ -571,29 +391,20 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "sha.js": { - "version": "2.4.11", - "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", - "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", - "requires": { - "inherits": "2.0.3", - "safe-buffer": "5.1.2" - } - }, "sshpk": { "version": "1.16.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", "requires": { - "asn1": "0.2.4", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.2", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.2", - "getpass": "0.1.7", - "jsbn": "0.1.1", - "safer-buffer": "2.1.2", - "tweetnacl": "0.14.5" + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" } }, "tough-cookie": { @@ -601,8 +412,8 @@ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", "requires": { - "psl": "1.1.33", - "punycode": "1.4.1" + "psl": "^1.1.24", + "punycode": "^1.4.1" }, "dependencies": { "punycode": { @@ -617,7 +428,7 @@ "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", "requires": { - "safe-buffer": "5.1.2" + "safe-buffer": "^5.0.1" } }, "tweetnacl": { @@ -625,17 +436,12 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, - "upper-case": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz", - "integrity": "sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg=" - }, "uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", "requires": { - "punycode": "2.1.1" + "punycode": "^2.1.0" } }, "uuid": { @@ -648,15 +454,10 @@ "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", "requires": { - "assert-plus": "1.0.0", + "assert-plus": "^1.0.0", "core-util-is": "1.0.2", - "extsprintf": "1.3.0" + "extsprintf": "^1.2.0" } - }, - "whatwg-fetch": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz", - "integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==" } } } diff --git a/scripts/package.json b/scripts/package.json index 6b7255e..8f5cd6c 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -9,9 +9,11 @@ "author": "Guillaume Babin-Tremblay", "license": "ISC", "dependencies": { - "eosjs": "^16.0.9", + "axios": "^0.19.2", + "colors": "*", "dotenv": "^6.0.0", - "request": "*", - "colors": "*" + "eosjs": "^21.0.2", + "node-fetch": "^2.6.0", + "request": "*" } } diff --git a/scripts/sample.env b/scripts/sample.env index a0d65c0..40d1e76 100644 --- a/scripts/sample.env +++ b/scripts/sample.env @@ -6,4 +6,5 @@ EOS_CHAIN='aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906' ORACLE="eostitantest" CONTRACT="delphioracle" FREQ=15000 -ORACLE_PERMISSION="active" \ No newline at end of file +ORACLE_PERMISSION="active" + diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..5b5151a --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,67 @@ +## Docker initial entry script + +env_setup() { + +cd /app +echo "Adding private key to .env" +sed -i "s//$PRIVATE_KEY/" .env +echo "Adding Block Producer to .env" +sed -i "s/bpname/$BPNAME/" .env +echo "Adding permission" +sed -i "s/permission/$PERM/" .env +echo "Setting API" +sed -i "s//$API/" .env +echo "Setting API PORT" +sed -i "s//$APIPORT/" .env +echo "Setting API PROTOCOL" +sed -i "s//$APIPROTOCOL/" .env +echo "Setting CRYPTOCOMPARE API key" +sed -i "s//$CRYPTOCOMPARE/" .env + +# Setting chain ID +waxid_mainnet="1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4" +waxid_testnet="f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12" +eosid_mainnet="aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906" +eosid_testnet="2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840" + +echo "Setting the chain ID" +if [[ $CHAIN = "wax" ]] +then + if [[ $ENV = "mainnet" ]] + then + sed -i "s//$waxid_mainnet/" .env + sed -i "s//wax/" .env + elif [[ $ENV = "testnet" ]] + then + sed -i "s//$waxid_testnet/" .env + sed -i "s//wax/" .env + fi +fi + +if [[ $CHAIN = "eos" ]] +then + if [[ $ENV = "mainnet" ]] + then + sed -i "s//$eosid_mainnet/" .env + sed -i "s//wax/" .env + elif [[ $ENV = "testnet" ]] + then + sed -i "s//$eosid_testnet/" .env + sed -i "s//wax/" .env + fi +fi + +} + +run_oracle(){ +while [ 1 ] +do + cd /app + node updater.js + sleep 60 +done +} + +# Running functions +env_setup +run_oracle diff --git a/scripts/updater.js b/scripts/updater.js index bee98e7..cd34e1c 100644 --- a/scripts/updater.js +++ b/scripts/updater.js @@ -14,7 +14,7 @@ const interval = process.env.FREQ; const owner = process.env.ORACLE; const oracleContract = process.env.CONTRACT; -const eos = Eos({ +const eos = Eos({ httpEndpoint: process.env.EOS_PROTOCOL + "://" + process.env.EOS_HOST + ":" + process.env.EOS_PORT, keyProvider: process.env.EOS_KEY, chainId: process.env.EOS_CHAIN, @@ -35,13 +35,13 @@ function write(){ console.log("EOSUSD:", JSON.parse(eosRes).USD); console.log("EOSBTC:", JSON.parse(eosRes).BTC); console.log("BTCUSD:", JSON.parse(btcRes).USD); - console.log("BTCUSD:", JSON.parse(btcRes).CAD); + console.log("BTCUSD:", JSON.parse(btcRes).CAD); console.log("BTCCNY:", JSON.parse(btccnyRes).CNY.last); - /* var quotes = [{"value": parseInt(Math.round(JSON.parse(eosRes).BTC * 100000000)), pair:"eosbtc"}, - {"value": parseInt(Math.round(JSON.parse(eosRes).USD * 10000)), pair:"eosusd"}, - {"value": parseInt(Math.round(JSON.parse(btcRes).USD * 10000)), pair:"btcusd"}, + /* var quotes = [{"value": parseInt(Math.round(JSON.parse(eosRes).BTC * 100000000)), pair:"eosbtc"}, + {"value": parseInt(Math.round(JSON.parse(eosRes).USD * 10000)), pair:"eosusd"}, + {"value": parseInt(Math.round(JSON.parse(btcRes).USD * 10000)), pair:"btcusd"}, {"value": parseInt(Math.round(JSON.parse(btccnyRes).CNY.last * 10000)), pair:"btccny"}]; */ @@ -57,7 +57,7 @@ function write(){ }, { scope: oracleContract, - authorization: [`${owner}@${process.env.ORACLE_PERMISSION || 'active'}`] + authorization: [`${owner}@${process.env.ORACLE_PERMISSION || 'active'}`] }) .then(results=>{ console.log("results:", results); @@ -79,4 +79,3 @@ function write(){ write(); -