mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
made keeper-js web ready
This commit is contained in:
parent
09e980cf8f
commit
ac0757ea9f
14
.babelrc
14
.babelrc
@ -1,6 +1,18 @@
|
||||
{
|
||||
"presets": [
|
||||
["env", { "useBuiltIns": true }],
|
||||
"es2015",
|
||||
[
|
||||
"env", { "useBuiltIns": true }
|
||||
],
|
||||
"stage-2"
|
||||
],
|
||||
"plugins": [
|
||||
[
|
||||
"transform-runtime",
|
||||
{
|
||||
"polyfill": false,
|
||||
"regenerator": true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
30
dist/contractLoader.js
vendored
30
dist/contractLoader.js
vendored
@ -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;
|
||||
}();
|
||||
|
||||
|
15
dist/ocean-agent.js
vendored
15
dist/ocean-agent.js
vendored
@ -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;
|
||||
}();
|
||||
|
||||
|
51
dist/ocean-keeper.js
vendored
51
dist/ocean-keeper.js
vendored
@ -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;
|
||||
}();
|
||||
|
||||
|
50
package-lock.json
generated
50
package-lock.json
generated
@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Web3 from 'web3'
|
||||
import ContractLoader from "./contractLoader";
|
||||
import ContractLoader from './contractLoader'
|
||||
|
||||
const DEFAULT_GAS = 300000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user