diff --git a/.babelrc b/.babelrc index 477c40b..96f556a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,18 @@ { "presets": [ - ["env", { "useBuiltIns": true }], + "es2015", + [ + "env", { "useBuiltIns": true } + ], "stage-2" + ], + "plugins": [ + [ + "transform-runtime", + { + "polyfill": false, + "regenerator": true + } + ] ] } diff --git a/dist/contractLoader.js b/dist/contractLoader.js index 294190d..9b232a1 100644 --- a/dist/contractLoader.js +++ b/dist/contractLoader.js @@ -4,7 +4,21 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); +var _regenerator = require('babel-runtime/regenerator'); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); + +var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); + +var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); + +var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); + +var _createClass2 = require('babel-runtime/helpers/createClass'); + +var _createClass3 = _interopRequireDefault(_createClass2); var _truffleContract = require('truffle-contract'); @@ -12,27 +26,24 @@ var _truffleContract2 = _interopRequireDefault(_truffleContract); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - var contracts = []; var ContractLoader = function () { function ContractLoader() { - _classCallCheck(this, ContractLoader); + (0, _classCallCheck3.default)(this, ContractLoader); } - _createClass(ContractLoader, null, [{ + (0, _createClass3.default)(ContractLoader, null, [{ key: '_doLoad', value: function () { - var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(what, where, provider) { + var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(what, where, provider) { var artifact, contract; - return regeneratorRuntime.wrap(function _callee$(_context) { + return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: // console.log("Loading", what, "from", where) + /* eslint-disable-next-line */ artifact = require('@oceanprotocol/keeper-contracts/artifacts/' + what + '.' + where); contract = (0, _truffleContract2.default)(artifact); @@ -64,7 +75,6 @@ var ContractLoader = function () { return contracts[what] || ContractLoader._doLoad(what, where, provider); } }]); - return ContractLoader; }(); diff --git a/dist/ocean-agent.js b/dist/ocean-agent.js index 35dfefb..af5281c 100644 --- a/dist/ocean-agent.js +++ b/dist/ocean-agent.js @@ -4,20 +4,26 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); +var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); + +var _createClass2 = require('babel-runtime/helpers/createClass'); + +var _createClass3 = _interopRequireDefault(_createClass2); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* global fetch */ var OceanAgent = function () { function OceanAgent(connectionUrl) { - _classCallCheck(this, OceanAgent); + (0, _classCallCheck3.default)(this, OceanAgent); this.assetsUrl = connectionUrl + '/assets'; } - _createClass(OceanAgent, [{ + (0, _createClass3.default)(OceanAgent, [{ key: 'getAssetsMetadata', value: function getAssetsMetadata() { return fetch(this.assetsUrl + '/metadata', { method: 'GET' }).then(function (res) { @@ -48,7 +54,6 @@ var OceanAgent = function () { }); } }]); - return OceanAgent; }(); diff --git a/dist/ocean-keeper.js b/dist/ocean-keeper.js index 4d94011..69cee50 100644 --- a/dist/ocean-keeper.js +++ b/dist/ocean-keeper.js @@ -4,9 +4,25 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends2 = require('babel-runtime/helpers/extends'); -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); +var _extends3 = _interopRequireDefault(_extends2); + +var _regenerator = require('babel-runtime/regenerator'); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); + +var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); + +var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); + +var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); + +var _createClass2 = require('babel-runtime/helpers/createClass'); + +var _createClass3 = _interopRequireDefault(_createClass2); var _web = require('web3'); @@ -18,15 +34,11 @@ var _contractLoader2 = _interopRequireDefault(_contractLoader); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - var DEFAULT_GAS = 300000; var OceanKeeper = function () { function OceanKeeper(uri, network) { - _classCallCheck(this, OceanKeeper); + (0, _classCallCheck3.default)(this, OceanKeeper); var web3Provider = new _web2.default.providers.HttpProvider(uri); this.web3 = new _web2.default(web3Provider); @@ -34,11 +46,11 @@ var OceanKeeper = function () { this.network = network || 'development'; } - _createClass(OceanKeeper, [{ + (0, _createClass3.default)(OceanKeeper, [{ key: 'initContracts', value: function () { - var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { - return regeneratorRuntime.wrap(function _callee$(_context) { + var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { + return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -128,12 +140,12 @@ var OceanKeeper = function () { }, { key: 'getConsumerOrders', value: function () { - var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(consumerAddress) { + var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(consumerAddress) { var _this = this; var accessConsentEvent, _resolve, _reject, promise, getEvents, events, orders; - return regeneratorRuntime.wrap(function _callee3$(_context3) { + return _regenerator2.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: @@ -172,12 +184,12 @@ var OceanKeeper = function () { orders = events.filter(function (obj) { return obj.args._consumer === consumerAddress; }).map(function () { - var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(event) { - return regeneratorRuntime.wrap(function _callee2$(_context2) { + var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(event) { + return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: - _context2.t0 = _extends; + _context2.t0 = _extends3.default; _context2.t1 = {}; _context2.t2 = event.args; _context2.t3 = event.args._timeout.toNumber(); @@ -244,9 +256,9 @@ var OceanKeeper = function () { }, { key: 'registerDataAsset', value: function () { - var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(name, description, price, publisherAddress) { + var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(name, description, price, publisherAddress) { var assetId, result; - return regeneratorRuntime.wrap(function _callee4$(_context4) { + return _regenerator2.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: @@ -281,9 +293,9 @@ var OceanKeeper = function () { }, { key: 'sendPayment', value: function () { - var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(assetId, order, publisherAddress, senderAddress) { + var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(assetId, order, publisherAddress, senderAddress) { var assetPrice; - return regeneratorRuntime.wrap(function _callee5$(_context5) { + return _regenerator2.default.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: @@ -365,7 +377,6 @@ var OceanKeeper = function () { }); } }]); - return OceanKeeper; }(); diff --git a/package-lock.json b/package-lock.json index 8479190..724d7d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -772,6 +772,15 @@ "regenerator-transform": "^0.10.0" } }, + "babel-plugin-transform-runtime": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz", + "integrity": "sha1-iEkNRGUC6puOfvsP4J7E2ZR5se4=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, "babel-plugin-transform-strict-mode": { "version": "6.24.1", "resolved": "https://registry.npmjs.org/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz", @@ -837,6 +846,38 @@ "semver": "^5.3.0" } }, + "babel-preset-es2015": { + "version": "6.24.1", + "resolved": "https://registry.npmjs.org/babel-preset-es2015/-/babel-preset-es2015-6.24.1.tgz", + "integrity": "sha1-1EBQ1rwsn+6nAqrzjXJ6AhBTiTk=", + "dev": true, + "requires": { + "babel-plugin-check-es2015-constants": "^6.22.0", + "babel-plugin-transform-es2015-arrow-functions": "^6.22.0", + "babel-plugin-transform-es2015-block-scoped-functions": "^6.22.0", + "babel-plugin-transform-es2015-block-scoping": "^6.24.1", + "babel-plugin-transform-es2015-classes": "^6.24.1", + "babel-plugin-transform-es2015-computed-properties": "^6.24.1", + "babel-plugin-transform-es2015-destructuring": "^6.22.0", + "babel-plugin-transform-es2015-duplicate-keys": "^6.24.1", + "babel-plugin-transform-es2015-for-of": "^6.22.0", + "babel-plugin-transform-es2015-function-name": "^6.24.1", + "babel-plugin-transform-es2015-literals": "^6.22.0", + "babel-plugin-transform-es2015-modules-amd": "^6.24.1", + "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", + "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1", + "babel-plugin-transform-es2015-modules-umd": "^6.24.1", + "babel-plugin-transform-es2015-object-super": "^6.24.1", + "babel-plugin-transform-es2015-parameters": "^6.24.1", + "babel-plugin-transform-es2015-shorthand-properties": "^6.24.1", + "babel-plugin-transform-es2015-spread": "^6.22.0", + "babel-plugin-transform-es2015-sticky-regex": "^6.24.1", + "babel-plugin-transform-es2015-template-literals": "^6.22.0", + "babel-plugin-transform-es2015-typeof-symbol": "^6.22.0", + "babel-plugin-transform-es2015-unicode-regex": "^6.24.1", + "babel-plugin-transform-regenerator": "^6.24.1" + } + }, "babel-preset-stage-2": { "version": "6.24.1", "resolved": "https://registry.npmjs.org/babel-preset-stage-2/-/babel-preset-stage-2-6.24.1.tgz", @@ -1725,12 +1766,13 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-1.4.2.tgz", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "requires": { + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", "ethereumjs-util": "^5.1.1" }, "dependencies": { "ethereumjs-abi": { "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", - "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", + "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "requires": { "bn.js": "^4.10.0", "ethereumjs-util": "^5.0.0" @@ -5229,6 +5271,7 @@ "resolved": "https://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", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2": "*", @@ -5237,7 +5280,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" } } } @@ -5369,6 +5412,7 @@ "resolved": "https://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", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2": "*", @@ -5377,7 +5421,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" } } }, diff --git a/package.json b/package.json index 4bffa58..cb07327 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.3", + "babel-plugin-transform-runtime": "^6.23.0", + "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1" } } diff --git a/src/contractLoader.js b/src/contractLoader.js index 041c813..26e9ca6 100644 --- a/src/contractLoader.js +++ b/src/contractLoader.js @@ -5,14 +5,15 @@ const contracts = [] export default class ContractLoader { static async _doLoad(what, where, provider) { // console.log("Loading", what, "from", where) + /* eslint-disable-next-line */ const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${what}.${where}`) const contract = TruffleContract(artifact) contract.setProvider(provider) - contracts[what] = await contract.at(artifact.address); + contracts[what] = await contract.at(artifact.address) return contracts[what] } static load(what, where, provider) { return contracts[what] || ContractLoader._doLoad(what, where, provider) } -} \ No newline at end of file +} diff --git a/src/ocean-keeper.js b/src/ocean-keeper.js index 4ce696a..ac5ca62 100644 --- a/src/ocean-keeper.js +++ b/src/ocean-keeper.js @@ -1,5 +1,5 @@ import Web3 from 'web3' -import ContractLoader from "./contractLoader"; +import ContractLoader from './contractLoader' const DEFAULT_GAS = 300000