From 72c9bebc2e7eef03aee7b37d5ae3950984dad97e Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 25 Sep 2018 09:14:01 +0200 Subject: [PATCH] replaced eslint with tslint --- .babelrc | 13 --- .eslintrc | 3 - package-lock.json | 210 ++++++++++++++++++++++++++++------- package.json | 9 +- src/keeper/auth.ts | 28 ++--- src/keeper/contractLoader.ts | 36 +++--- src/keeper/keeper-base.ts | 11 +- src/keeper/market.ts | 60 +++++----- src/keeper/token.ts | 42 +++---- src/metadata.ts | 43 +++---- src/ocean.ts | 171 ++++++++++++++-------------- src/squid.ts | 8 +- src/utils/Web3Helper.ts | 69 ++++++------ src/utils/config.ts | 2 + src/utils/logger.ts | 37 +++--- tsconfig.json | 2 +- 16 files changed, 431 insertions(+), 313 deletions(-) delete mode 100644 .babelrc delete mode 100644 .eslintrc diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 86e5cc0..0000000 --- a/.babelrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "presets": [ - ["@babel/preset-env", { "useBuiltIns": "entry" }] - ], - "plugins": [ - ["@babel/plugin-transform-runtime", - { - "regenerator": true - } - ], - ["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }] - ] -} diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index be850fa..0000000 --- a/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["oceanprotocol"] -} diff --git a/package-lock.json b/package-lock.json index ace2807..a1590e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "@oceanprotocol/keeper-contracts": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.2.0.tgz", - "integrity": "sha512-9qEun7a9fcQ3Z4a5O3sLyXIm4SPQpLFeIbQRg/BY29aNOXEoD/wUG4mNStM6ogdMDckLgR4KyOR2mPOQs7Yh3A==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.2.1.tgz", + "integrity": "sha512-mmgLhW0wpa42Ziaq/DRyNVnFtxfPAWQ03WeFRpwxi1h+ctyClr8ry1GGtzb7JTZkaefUlyNe71n88RBJcAe+ww==", "requires": { "bignumber": "^1.1.0", "bignumber.js": "^7.2.1", @@ -121,6 +121,15 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -759,7 +768,7 @@ }, "babelify": { "version": "7.3.0", - "resolved": "https://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz", + "resolved": "http://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz", "integrity": "sha1-qlau3nBn/XvVSWZu4W3ChQh+iOU=", "requires": { "babel-core": "^6.0.14", @@ -894,7 +903,7 @@ }, "browserify-aes": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "requires": { "buffer-xor": "^1.0.3", @@ -1056,6 +1065,21 @@ } } }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, "combined-stream": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", @@ -1096,9 +1120,12 @@ "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" }, "convert-source-map": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.1.tgz", - "integrity": "sha1-uCeAl7m8IpNl3lxiz1/K7YtVmeU=" + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", + "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", + "requires": { + "safe-buffer": "~5.1.1" + } }, "cookie": { "version": "0.3.1", @@ -1136,7 +1163,7 @@ }, "create-hash": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "requires": { "cipher-base": "^1.0.1", @@ -1148,7 +1175,7 @@ }, "create-hmac": { "version": "1.1.7", - "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", + "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.3", @@ -1166,13 +1193,6 @@ "requires": { "node-fetch": "2.1.2", "whatwg-fetch": "2.0.4" - }, - "dependencies": { - "whatwg-fetch": { - "version": "2.0.4", - "resolved": "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", - "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" - } } }, "crypto-js": { @@ -1299,9 +1319,9 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "electron-to-chromium": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.62.tgz", - "integrity": "sha512-x09ndL/Gjnuk3unlAyoGyUg3wbs4w/bXurgL7wL913vXHAOWmMhrLf1VNGRaMLngmadd5Q8gsV9BFuIr6rP+Xg==" + "version": "1.3.70", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.70.tgz", + "integrity": "sha512-WYMjqCnPVS5JA+XvwEnpwucJpVi2+q9cdCFpbhxgWGsCtforFBEkuP9+nCyy/wnU/0SyLcLRIeZct9ayMGcXoQ==" }, "elliptic": { "version": "6.4.1", @@ -1386,6 +1406,12 @@ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", @@ -2044,7 +2070,7 @@ }, "express": { "version": "4.16.3", - "resolved": "https://registry.npmjs.org/express/-/express-4.16.3.tgz", + "resolved": "http://registry.npmjs.org/express/-/express-4.16.3.tgz", "integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=", "requires": { "accepts": "~1.3.5", @@ -2270,7 +2296,7 @@ "dependencies": { "combined-stream": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", + "resolved": "http://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", "requires": { "delayed-stream": "~1.0.0" @@ -2463,7 +2489,7 @@ }, "http-errors": { "version": "1.6.3", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", + "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", "requires": { "depd": "~1.1.2", @@ -2534,7 +2560,7 @@ }, "is-builtin-module": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", + "resolved": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", "requires": { "builtin-modules": "^1.0.0" @@ -2632,6 +2658,16 @@ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" }, + "js-yaml": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", + "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -2699,7 +2735,7 @@ }, "jsonfile": { "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", "requires": { "graceful-fs": "^4.1.6" @@ -2788,7 +2824,7 @@ }, "readable-stream": { "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "requires": { "core-util-is": "~1.0.0", @@ -2825,7 +2861,7 @@ }, "readable-stream": { "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", "requires": { "core-util-is": "~1.0.0", @@ -2872,7 +2908,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "requires": { "graceful-fs": "^4.1.2", @@ -3198,7 +3234,7 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "requires": { "lcid": "^1.0.0" @@ -3448,7 +3484,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -3751,7 +3787,7 @@ }, "sha.js": { "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "requires": { "inherits": "^2.0.1", @@ -3835,9 +3871,15 @@ } }, "spdx-license-ids": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz", - "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==" + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.1.tgz", + "integrity": "sha512-TfOfPcYGBB5sDuPn3deByxPhmfegAhpDYKSOXZQN81Oyrrif8ZCodOLzK3AesELnCx03kikhyDwh0pfvvQvF8w==" + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true }, "sshpk": { "version": "1.14.2", @@ -3954,7 +3996,7 @@ }, "through": { "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "through2": { @@ -4136,6 +4178,84 @@ "web3": "0.20.6" } }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", + "dev": true + }, + "tslint": { + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz", + "integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=", + "dev": true, + "requires": { + "babel-code-frame": "^6.22.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^3.2.0", + "glob": "^7.1.1", + "js-yaml": "^3.7.0", + "minimatch": "^3.0.4", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.8.0", + "tsutils": "^2.27.2" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "commander": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.18.0.tgz", + "integrity": "sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ==", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -4164,6 +4284,12 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "typescript": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.0.3.tgz", + "integrity": "sha512-kk80vLW9iGtjMnIv11qyxLqZm20UklzuR2tL0QAnDIygIUIemcZMxlMWudl9OOt76H3ntVzcTiddQ1/pAAJMYg==", + "dev": true + }, "ultron": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", @@ -4244,7 +4370,7 @@ }, "web3": { "version": "0.20.6", - "resolved": "https://registry.npmjs.org/web3/-/web3-0.20.6.tgz", + "resolved": "http://registry.npmjs.org/web3/-/web3-0.20.6.tgz", "integrity": "sha1-PpcwauAk+yThCj11yIQwJWIhUSA=", "requires": { "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", @@ -4256,7 +4382,7 @@ "dependencies": { "bignumber.js": { "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", - "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934" + "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git" } } }, @@ -4331,9 +4457,9 @@ } }, "whatwg-fetch": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz", - "integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==" + "version": "2.0.4", + "resolved": "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" }, "which-module": { "version": "1.0.0", @@ -4347,7 +4473,7 @@ }, "wrap-ansi": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "requires": { "string-width": "^1.0.1", @@ -4430,7 +4556,7 @@ }, "yargs": { "version": "4.8.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz", + "resolved": "http://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz", "integrity": "sha1-wMQpJMpKqmsObaFznfshZDn53cA=", "requires": { "cliui": "^3.2.0", diff --git a/package.json b/package.json index 36d115d..d84de37 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "JavaScript client library for Ocean Protocol", "main": "dist/squid.js", "scripts": { - "test": "eslint ./src", + "test": "tslint -c tslint.json 'src/**/*.ts'", "start": "tsc -w", "build": "tsc", "release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive", @@ -27,13 +27,14 @@ "@oceanprotocol/keeper-contracts": "^0.2.0", "bn.js": "^4.11.8", "truffle-contract": "^3.0.6", - "web3": "0.20.6", - "whatwg-fetch": "^3.0.0" + "web3": "0.20.6" }, "engines": { "node": ">=8 <10" }, "devDependencies": { - "@types/web3": "^1.0.6" + "@types/web3": "^1.0.6", + "tslint": "^5.11.0", + "typescript": "^3.0.3" } } diff --git a/src/keeper/auth.ts b/src/keeper/auth.ts index 9d64140..361baa7 100644 --- a/src/keeper/auth.ts +++ b/src/keeper/auth.ts @@ -1,30 +1,30 @@ -import ContractLoader from './contractLoader' -import KeeperBase from './keeper-base' -import Web3Helper from "../utils/Web3Helper"; import Config from "../utils/config"; +import Web3Helper from "../utils/Web3Helper"; +import ContractLoader from "./contractLoader"; +import KeeperBase from "./keeper-base"; export default class OceanAuth extends KeeperBase { - private constructor(config: Config, web3Helper: Web3Helper) { - super(config, web3Helper) - } - public static async getInstance(config: Config, web3Helper) { const auth = new OceanAuth(config, web3Helper); - auth.contract = await ContractLoader.load('OceanAuth', auth._web3Helper) + auth.contract = await ContractLoader.load("OceanAuth", auth.web3Helper); return auth; } - cancelAccessRequest(orderId: string, senderAddress: string) { - return this.contract.cancelAccessRequest(orderId, {from: senderAddress}) + private constructor(config: Config, web3Helper: Web3Helper) { + super(config, web3Helper); } - getOrderStatus(orderId: string) { - return this.contract.statusOfAccessRequest(orderId) + public cancelAccessRequest(orderId: string, senderAddress: string) { + return this.contract.cancelAccessRequest(orderId, {from: senderAddress}); } - getEncryptedAccessToken(orderId: string, senderAddress: string) { - return this.contract.getEncryptedAccessToken(orderId, {from: senderAddress}) + public getOrderStatus(orderId: string) { + return this.contract.statusOfAccessRequest(orderId); + } + + public getEncryptedAccessToken(orderId: string, senderAddress: string) { + return this.contract.getEncryptedAccessToken(orderId, {from: senderAddress}); } } diff --git a/src/keeper/contractLoader.ts b/src/keeper/contractLoader.ts index 7041130..bf8c65d 100644 --- a/src/keeper/contractLoader.ts +++ b/src/keeper/contractLoader.ts @@ -1,29 +1,29 @@ -import * as TruffleContract from 'truffle-contract' -import Logger from '../utils/logger' -import Web3Helper from '../utils/Web3Helper' +import * as TruffleContract from "truffle-contract"; +import Logger from "../utils/logger"; +import Web3Helper from "../utils/Web3Helper"; -const contracts: Map = new Map() +const contracts: Map = new Map(); export default class ContractLoader { - static async _doLoad(what: string, web3Helper: Web3Helper): Promise { - const where = (await web3Helper.getNetworkName()).toLowerCase() - Logger.log('Loading', what, 'from', where) + public static async load(what: string, web3Helper: Web3Helper) { + return contracts.get(what) || await ContractLoader._doLoad(what, web3Helper); + } + + private static async _doLoad(what: string, web3Helper: Web3Helper): Promise { + const where = (await web3Helper.getNetworkName()).toLowerCase(); + Logger.log("Loading", what, "from", where); try { /* eslint-disable-next-line security/detect-non-literal-require */ - const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${what}.${where}`) + const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${what}.${where}`); // Logger.log('Loaded artifact', artifact) - const contract = TruffleContract(artifact) - Logger.log('Getting instance of', what, 'from', where, 'at', artifact.address) - contract.setProvider(web3Helper.web3.currentProvider) - contracts.set(what, await contract.at(artifact.address)) - return contracts.get(what) + const contract = TruffleContract(artifact); + Logger.log("Getting instance of", what, "from", where, "at", artifact.address); + contract.setProvider(web3Helper.web3.currentProvider); + contracts.set(what, await contract.at(artifact.address)); + return contracts.get(what); } catch (err) { - Logger.error('Failed to load', what, 'from', where) + Logger.error("Failed to load", what, "from", where); } } - - static async load(what: string, web3Helper: Web3Helper) { - return contracts.get(what) || await ContractLoader._doLoad(what, web3Helper) - } } diff --git a/src/keeper/keeper-base.ts b/src/keeper/keeper-base.ts index 40b9c82..2e94049 100644 --- a/src/keeper/keeper-base.ts +++ b/src/keeper/keeper-base.ts @@ -1,14 +1,15 @@ -import Web3Helper from '../utils/Web3Helper' import Config from "../utils/config"; +import Web3Helper from "../utils/Web3Helper"; export default class KeeperBase { - protected _config: Config - protected _web3Helper: Web3Helper; public contract: any = null; + protected config: Config; + protected web3Helper: Web3Helper; + constructor(config: Config, web3Helper: Web3Helper) { - this._config = config; - this._web3Helper = web3Helper + this.config = config; + this.web3Helper = web3Helper; } } diff --git a/src/keeper/market.ts b/src/keeper/market.ts index a539845..2b48303 100644 --- a/src/keeper/market.ts +++ b/src/keeper/market.ts @@ -1,61 +1,61 @@ -import ContractLoader from './contractLoader' -import KeeperBase from './keeper-base' -import Logger from '../utils/logger' -import Web3Helper from "../utils/Web3Helper"; import BigNumber from "bignumber.js"; import Config from "../utils/config"; +import Logger from "../utils/logger"; +import Web3Helper from "../utils/Web3Helper"; +import ContractLoader from "./contractLoader"; +import KeeperBase from "./keeper-base"; export default class OceanMarket extends KeeperBase { - private constructor(config: Config, web3Helper: Web3Helper) { - super(config, web3Helper) - } - public static async getInstance(config: Config, web3Helper: Web3Helper) { const market = new OceanMarket(config, web3Helper); - market.contract = await ContractLoader.load('OceanMarket', market._web3Helper) + market.contract = await ContractLoader.load("OceanMarket", market.web3Helper); return market; } + private constructor(config: Config, web3Helper: Web3Helper) { + super(config, web3Helper); + } + // call functions (costs no gas) - checkAsset(assetId: string) { - return this.contract.checkAsset(assetId) + public checkAsset(assetId: string) { + return this.contract.checkAsset(assetId); } - verifyOrderPayment(orderId: string): boolean { - return this.contract.verifyPaymentReceived(orderId) + public verifyOrderPayment(orderId: string): boolean { + return this.contract.verifyPaymentReceived(orderId); } - getAssetPrice(assetId: string) { + public getAssetPrice(assetId: string) { return this.contract.getAssetPrice(assetId) - .then((price: BigNumber) => price.toNumber()) + .then((price: BigNumber) => price.toNumber()); } // Transactions with gas cost - requestTokens(amount: number, address: string) { - return this.contract.requestTokens(amount, {from: address}) + public requestTokens(amount: number, address: string) { + return this.contract.requestTokens(amount, {from: address}); } - async registerAsset(name: string, description: string, price: number, publisherAddress: string) { - const assetId = await this.contract.generateId(name + description) + public async registerAsset(name: string, description: string, price: number, publisherAddress: string) { + const assetId = await this.contract.generateId(name + description); const result = await this.contract.register( assetId, price, { - from: publisherAddress, gas: - this._config.defaultGas - } - ) - Logger.log('registered: ', result) - return assetId + from: publisherAddress, + gas: this.config.defaultGas, + }, + ); + Logger.log("registered: ", result); + return assetId; } - async payAsset(assetId: string, order: any, publisherAddress: string, senderAddress: string) { - let assetPrice = await this.contract.getAssetPrice(assetId) - .then((price: BigNumber) => price.toNumber()) + public async payAsset(assetId: string, order: any, publisherAddress: string, senderAddress: string) { + const assetPrice = await this.contract.getAssetPrice(assetId) + .then((price: BigNumber) => price.toNumber()); this.contract.sendPayment(order.id, publisherAddress, assetPrice, order.timeout, { from: senderAddress, - gas: 2000000 - }) + gas: 2000000, + }); } } diff --git a/src/keeper/token.ts b/src/keeper/token.ts index baf658d..5c44bb4 100644 --- a/src/keeper/token.ts +++ b/src/keeper/token.ts @@ -1,34 +1,36 @@ -import ContractLoader from './contractLoader' -import KeeperBase from './keeper-base' -import Logger from '../utils/logger' -import Web3Helper from "../utils/Web3Helper" import Config from "../utils/config"; +import Logger from "../utils/logger"; +import Web3Helper from "../utils/Web3Helper"; +import ContractLoader from "./contractLoader"; +import KeeperBase from "./keeper-base"; export default class OceanToken extends KeeperBase { - private constructor(config: Config, web3Helper: Web3Helper) { - super(config, web3Helper) - } - public static async getInstance(config: Config, web3Helper: Web3Helper) { - const token = new OceanToken(config, web3Helper) - token.contract = await ContractLoader.load('OceanToken', token._web3Helper) + const token = new OceanToken(config, web3Helper); + token.contract = await ContractLoader.load("OceanToken", token.web3Helper); return token; } - getTokenBalance(accountAddress: string) { - return this.contract.balanceOf.call(accountAddress) + private constructor(config: Config, web3Helper: Web3Helper) { + super(config, web3Helper); } - async getEthBalance(account: string): Promise { + public getTokenBalance(accountAddress: string) { + return this.contract.balanceOf.call(accountAddress); + } + + public async getEthBalance(account: string): Promise { return new Promise((resolve, reject) => { - Logger.log('getting balance for', account) - this._web3Helper.web3.eth.getBalance(account, 'latest', (err: any, balance: number) => { - if (err) return reject(err) - Logger.log('balance', balance) - resolve(balance) - }) - }) + Logger.log("getting balance for", account); + this.web3Helper.web3.eth.getBalance(account, "latest", (err: any, balance: number) => { + if (err) { + return reject(err); + } + Logger.log("balance", balance); + resolve(balance); + }); + }); } } diff --git a/src/metadata.ts b/src/metadata.ts index 51735fd..2b9aa04 100644 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -1,44 +1,45 @@ -import Logger from './utils/logger' import Config from "./utils/config"; +import Logger from "./utils/logger"; -declare var fetch +declare var fetch; export default class MetaData { private assetsUrl: string; constructor(config: Config) { - const providerUri = config.providerUri || null + const providerUri = config.providerUri || null; - this.assetsUrl = providerUri + '/assets' + this.assetsUrl = providerUri + "/assets"; } - getAssetsMetadata() { - return fetch(this.assetsUrl + '/metadata', { method: 'GET' }) - .then(res => res.json()) - .then(data => JSON.parse(data)) + public getAssetsMetadata() { + return fetch(this.assetsUrl + "/metadata", {method: "GET"}) + .then((res) => res.json()) + .then((data) => JSON.parse(data)); } - publishDataAsset(asset: object) { - return fetch(this.assetsUrl + '/metadata', + public publishDataAsset(asset: object) { + return fetch(this.assetsUrl + "/metadata", { - method: 'POST', + method: "POST", body: JSON.stringify(asset), - headers: { 'Content-type': 'application/json' } + headers: {"Content-type": "application/json"}, }) .then((response: any) => { - Logger.log('Success:', response) + Logger.log("Success:", response); if (response.ok) { - Logger.log('Success:', response) - return true + Logger.log("Success:", response); + return true; } - Logger.log('Failed: ', response.status, response.statusText) - return false - // throw new Error(response.statusText ? response.statusText : `publish asset failed with status ${response.status}`) + Logger.log("Failed: ", response.status, response.statusText); + return false; + // throw new Error(response.statusText ? response.statusText : + // `publish asset failed with status ${response.status}`) }) .catch((error: Error) => { - Logger.log(`Publish asset to ocean database could not be completed: ${error.message}`) - return false - }) + Logger.log(`Publish asset to ocean database could not be completed: ${error.message}`); + return false; + }); } } diff --git a/src/ocean.ts b/src/ocean.ts index 4c9fe56..84e3065 100644 --- a/src/ocean.ts +++ b/src/ocean.ts @@ -1,15 +1,24 @@ -import OceanMarket from './keeper/market' -import OceanAuth from './keeper/auth' -import OceanToken from './keeper/token' -import Logger from './utils/logger' -import Web3Helper from './utils/Web3Helper' -import MetaData from './metadata' -import BigNumber = require("bn.js") +import BigNumber = require("bn.js"); +import OceanAuth from "./keeper/auth"; +import OceanMarket from "./keeper/market"; +import OceanToken from "./keeper/token"; +import MetaData from "./metadata"; import Config from "./utils/config"; +import Logger from "./utils/logger"; +import Web3Helper from "./utils/Web3Helper"; export default class Ocean { - private _config: Config; + public static async getInstance(config) { + + const ocean = new Ocean(config); + + ocean.market = await OceanMarket.getInstance(config, ocean.helper); + ocean.auth = await OceanAuth.getInstance(config, ocean.helper); + ocean.token = await OceanToken.getInstance(config, ocean.helper); + + return ocean; + } public token: OceanToken; public market: OceanMarket; @@ -17,66 +26,58 @@ export default class Ocean { public helper: Web3Helper; public metadata: MetaData; + private config: Config; + private constructor(config: Config) { - this._config = config; + this.config = config; - this.helper = new Web3Helper(config) - this.metadata = new MetaData(config) + this.helper = new Web3Helper(config); + this.metadata = new MetaData(config); } - public static async getInstance(config) { - - const ocean = new Ocean(config); - - ocean.market = await OceanMarket.getInstance(config, ocean.helper) - ocean.auth = await OceanAuth.getInstance(config, ocean.helper) - ocean.token = await OceanToken.getInstance(config, ocean.helper) - - return ocean; - } - - async getAccounts() { + public async getAccounts() { return Promise.all((await this.helper.getAccounts()).map(async (account: string) => { // await ocean.market.requestTokens(account, 1000) - + const {token} = this; return { name: account, balance: { - ocn: await this.token.getTokenBalance(account), - eth: await this.token.getEthBalance(account) - } - } - })) + eth: await token.getEthBalance(account), + ocn: await token.getTokenBalance(account), + }, + }; + })); } - async getOrdersByConsumer(consumerAddress: string) { - let accessConsentEvent = this.auth.contract.AccessConsentRequested({_consumer: consumerAddress}, { + public async getOrdersByConsumer(consumerAddress: string) { + const {auth} = this; + const accessConsentEvent = auth.contract.AccessConsentRequested({_consumer: consumerAddress}, { fromBlock: 0, - toBlock: 'latest' - }) + toBlock: "latest", + }); - let _resolve: Function = null - let _reject: Function = null + let outerResolve = null; + let outerReject = null; const promise = new Promise((resolve, reject) => { - _resolve = resolve - _reject = reject - }) + outerResolve = resolve; + outerReject = reject; + }); const getEvents = (): Promise => { accessConsentEvent.get((error: any, logs: any[]) => { if (error) { - _reject(error) - throw new Error(error) + outerReject(error); + throw new Error(error); } else { - _resolve(logs) + outerResolve(logs); } - }) - return promise - } - const events = await getEvents().then((events) => events) + }); + return promise; + }; + const events = await getEvents().then((result) => result); // let orders = await this.buildOrdersFromEvents(events, consumerAddress).then((result) => result) - let orders = events + const orders = events .filter((obj: any) => (obj.args._consumer === consumerAddress)) .map(async (event: any) => ({ ...event.args, @@ -84,69 +85,69 @@ export default class Ocean { status: await this.auth.getOrderStatus(event.args._id) .then((status: BigNumber) => status.toNumber()), paid: this.market.verifyOrderPayment(event.args._id), - key: null - })) - Logger.debug('got orders: ', orders) - return orders + key: null, + })); + Logger.debug("got orders: ", orders); + return orders; } - async purchaseAsset( - assetId: string, publisherId: string, price: number, privateKey: string, publicKey: string, timeout: number, senderAddress: string, - initialRequestEventHandler: Function, accessCommittedEventHandler: Function, tokenPublishedEventHandler: Function) { - const {token: OceanToken, market: OceanMarket, auth} = this + public async purchaseAsset( + assetId: string, publisherId: string, price: number, privateKey: string, publicKey: string, timeout: number, + senderAddress: string, initialRequestEventHandler, accessCommittedEventHandler, tokenPublishedEventHandler) { + const {token, market, auth, config} = this; try { - // Allow market contract to transfer funds on the consumer's behalf - await this.token.contract.approve(this.market.contract.address, price, {from: senderAddress, gas: 2000000}) + // Allow market contract to transfer funds on the consumer"s behalf + await token.contract.approve(market.contract.address, price, {from: senderAddress, gas: config.defaultGas}); } catch (err) { - Logger.log('token approve', err) + Logger.log("token approve", err); } try { // Submit the access request await auth.contract.initiateAccessRequest( assetId, publisherId, publicKey, - timeout, {from: senderAddress, gas: 1000000} - ) + timeout, {from: senderAddress, gas: 1000000}, + ); } catch (err) { - Logger.log('initiateAccessRequest', err) + Logger.log("initiateAccessRequest", err); } - const resourceFilter = {_resourceId: assetId, _consumer: senderAddress} - const initRequestEvent = auth.contract.AccessConsentRequested(resourceFilter) - let order: any = {} + const resourceFilter = {_resourceId: assetId, _consumer: senderAddress}; + const initRequestEvent = auth.contract.AccessConsentRequested(resourceFilter); + let order: any = {}; this._listenOnce( initRequestEvent, - 'AccessConsentRequested', + "AccessConsentRequested", (result: any, error: any) => { - order = initialRequestEventHandler(result, error) - const requestIdFilter = {_id: order.id} - const accessCommittedEvent = auth.contract.AccessRequestCommitted(requestIdFilter) - const tokenPublishedEvent = auth.contract.EncryptedTokenPublished(requestIdFilter) + order = initialRequestEventHandler(result, error); + const requestIdFilter = {_id: order.id}; + const accessCommittedEvent = auth.contract.AccessRequestCommitted(requestIdFilter); + const tokenPublishedEvent = auth.contract.EncryptedTokenPublished(requestIdFilter); this._listenOnce( accessCommittedEvent, - 'AccessRequestCommitted', - (result: any, error: any) => { - accessCommittedEventHandler(result, order, error) - } - ) + "AccessRequestCommitted", + (accessRequestCommittedResult: any, accessRequestCommittedError: any) => { + accessCommittedEventHandler(accessRequestCommittedResult, order, accessRequestCommittedError); + }, + ); this._listenOnce( tokenPublishedEvent, - 'EncryptedTokenPublished', - (result: any, error: any) => { - tokenPublishedEventHandler(result, order, error) - } - ) - }) - return order + "EncryptedTokenPublished", + (encryptedTokenPublishedResult: any, encryptedTokenPublishedError: any) => { + tokenPublishedEventHandler(encryptedTokenPublishedResult, order, encryptedTokenPublishedError); + }, + ); + }); + return order; } // Helper functions (private) - _listenOnce(event: any, eventName: string, callback: Function) { + public _listenOnce(event: any, eventName: string, callback) { // eslint-disable-next-line security/detect-non-literal-fs-filename event.watch((error: any, result: any) => { - event.stopWatching() + event.stopWatching(); if (error) { - Logger.log(`Error in keeper ${eventName} event: `, error) + Logger.log(`Error in keeper ${eventName} event: `, error); } - callback(result, error) - }) + callback(result, error); + }); } } diff --git a/src/squid.ts b/src/squid.ts index 5cdd22b..b23751e 100644 --- a/src/squid.ts +++ b/src/squid.ts @@ -1,7 +1,7 @@ -import Ocean from './ocean' -import Logger from './utils/logger' +import Ocean from "./ocean"; +import Logger from "./utils/logger"; export { Ocean, - Logger -} + Logger, +}; diff --git a/src/utils/Web3Helper.ts b/src/utils/Web3Helper.ts index 54183bc..75e1b93 100644 --- a/src/utils/Web3Helper.ts +++ b/src/utils/Web3Helper.ts @@ -1,58 +1,59 @@ import Web3 = require("web3"); +import Config from "./config"; export default class Web3Helper { public web3: Web3; - constructor(config: any) { - const web3Provider = config.web3Provider || new Web3.providers.HttpProvider(config.nodeUri) - this.web3 = new Web3(web3Provider) + public constructor(config: Config) { + const web3Provider = config.web3Provider || new Web3.providers.HttpProvider(config.nodeUri); + this.web3 = new Web3(web3Provider); } - async getAccounts(): Promise { - return new Promise((resolve: Function, reject: Function) => { + public async getAccounts(): Promise { + return new Promise((resolve, reject) => { this.web3.eth.getAccounts((err: any, accounts: string[]) => { if (err) { - throw err + throw err; } - resolve(accounts) - }) - }) + resolve(accounts); + }); + }); } - async getNetworkName(): Promise { - return new Promise((resolve: Function, reject: Function) => { - let network: string = 'unknown' + public async getNetworkName(): Promise { + return new Promise((resolve, reject) => { + let network: string = "unknown"; // @ts-ignore old version of web3, lets get to 1.0 this.web3.version.getNetwork((err, networkId) => { if (err) { - throw err + throw err; } switch (networkId) { - case '1': - network = 'Main' - break - case '2': - network = 'Morden' - break - case '3': - network = 'Ropsten' - break - case '4': - network = 'Rinkeby' - break - case '42': - network = 'Kovan' - break + case "1": + network = "Main"; + break; + case "2": + network = "Morden"; + break; + case "3": + network = "Ropsten"; + break; + case "4": + network = "Rinkeby"; + break; + case "42": + network = "Kovan"; + break; default: - network = 'development' + network = "development"; } - resolve(network) - }) - }) + resolve(network); + }); + }); } // web3 wrappers - sign(accountAddress: string, message: string) { - return this.web3.eth.sign(accountAddress, message) + public sign(accountAddress: string, message: string) { + return this.web3.eth.sign(accountAddress, message); } } diff --git a/src/utils/config.ts b/src/utils/config.ts index 5c7676c..fb33f23 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -2,4 +2,6 @@ export default class Config { public defaultGas: number = 300000; public providerUri: string; + public nodeUri: string; + public web3Provider: any; } diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 1f3372d..571664d 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,23 +1,22 @@ export default class Logger { - static dispatch(verb: string, ...args: any[]) { + public static log(...args: any[]) { + Logger.dispatch("log", ...args); + } + + public static debug(...args: any[]) { + Logger.dispatch("debug", ...args); + } + + public static warn(...args: any[]) { + Logger.dispatch("warn", ...args); + } + + public static error(...args: any[]) { + Logger.dispatch("error", ...args); + } + + private static dispatch(verb: string, ...args: any[]) { /* eslint-disable-next-line no-console */ - // @ts-ignore - console[verb](...args) - } - - static log(...args: any[]) { - Logger.dispatch('log', ...args) - } - - static debug(...args: any[]) { - Logger.dispatch('debug', ...args) - } - - static warn(...args: any[]) { - Logger.dispatch('warn', ...args) - } - - static error(...args: any[]) { - Logger.dispatch('error', ...args) + console[verb](...args); } } diff --git a/tsconfig.json b/tsconfig.json index 6111d54..db6eae0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,4 +19,4 @@ "node_modules", "**/*.spec.ts" ] -} \ No newline at end of file +}