1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

dev updates

* switch to Babel 7
* consistent npm start command
* mention production build
* correct license and author in package.json
* important emoji change
* simplify travis.yml
This commit is contained in:
Matthias Kretschmann 2018-09-06 16:58:39 +02:00
parent 4145e1ba75
commit e87b6fc421
Signed by: m
GPG Key ID: 606EEEF3C479A91F
9 changed files with 2815 additions and 1022 deletions

View File

@ -1,18 +1,13 @@
{ {
"presets": [ "presets": [
"es2015", ["@babel/preset-env", { "useBuiltIns": "entry" }]
[
"env", { "useBuiltIns": true }
],
"stage-2"
], ],
"plugins": [ "plugins": [
[ ["@babel/plugin-transform-runtime",
"transform-runtime",
{ {
"polyfill": false,
"regenerator": true "regenerator": true
} }
] ],
["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }]
] ]
} }

View File

@ -1,6 +1,3 @@
dist: trusty
sudo: required
group: beta
language: node_js language: node_js
node_js: node_js:
- "8" - "8"

View File

@ -2,7 +2,7 @@
# squid-js # squid-js
> 🐋 JavaScript implementation of ocean protocol keeper > 🦑 JavaScript implementation of Ocean Protocol Keeper
> [oceanprotocol.com](https://oceanprotocol.com) > [oceanprotocol.com](https://oceanprotocol.com)
[![Travis (.com)](https://img.shields.io/travis/com/oceanprotocol/squid-js.svg)](https://travis-ci.com/oceanprotocol/squid-js) [![Travis (.com)](https://img.shields.io/travis/com/oceanprotocol/squid-js.svg)](https://travis-ci.com/oceanprotocol/squid-js)
@ -17,15 +17,24 @@
## Table of Contents ## Table of Contents
- [Get Started](#get-started) - [Get Started](#get-started)
- [Production Build](#production-build)
- [License](#license) - [License](#license)
--- ---
## Get Started ## Get Started
To start develppment you need to: To start develppment you need to:
```batch ```batch
npm i npm i
npm run start:dev npm start
```
## Production Build
```bash
npm run build
``` ```
This will start a watcher for changes of the code. This will start a watcher for changes of the code.

View File

@ -1,76 +1,69 @@
'use strict'; "use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.default = void 0;
var _regenerator = require('babel-runtime/regenerator'); var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _regenerator2 = _interopRequireDefault(_regenerator); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _truffleContract = _interopRequireDefault(require("truffle-contract"));
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _truffleContract = require('truffle-contract');
var _truffleContract2 = _interopRequireDefault(_truffleContract);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var contracts = []; var contracts = [];
var ContractLoader = function () { var ContractLoader =
/*#__PURE__*/
function () {
function ContractLoader() { function ContractLoader() {
(0, _classCallCheck3.default)(this, ContractLoader); (0, _classCallCheck2.default)(this, ContractLoader);
} }
(0, _createClass3.default)(ContractLoader, null, [{ (0, _createClass2.default)(ContractLoader, null, [{
key: '_doLoad', key: "_doLoad",
value: function () { value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(what, where, provider) { var _doLoad2 = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(what, where, provider) {
var artifact, contract; var artifact, contract;
return _regenerator2.default.wrap(function _callee$(_context) { return _regenerator.default.wrap(function _callee$(_context) {
while (1) { while (1) {
switch (_context.prev = _context.next) { switch (_context.prev = _context.next) {
case 0: case 0:
// console.log("Loading", what, "from", where) // console.log("Loading", what, "from", where)
/* eslint-disable-next-line */
artifact = require('@oceanprotocol/keeper-contracts/artifacts/' + what + '.' + where);
contract = (0, _truffleContract2.default)(artifact);
/* eslint-disable-next-line */
artifact = require("@oceanprotocol/keeper-contracts/artifacts/".concat(what, ".").concat(where));
contract = (0, _truffleContract.default)(artifact);
contract.setProvider(provider); contract.setProvider(provider);
_context.next = 5; _context.next = 5;
return contract.at(artifact.address); return contract.at(artifact.address);
case 5: case 5:
contracts[what] = _context.sent; contracts[what] = _context.sent;
return _context.abrupt('return', contracts[what]); return _context.abrupt("return", contracts[what]);
case 7: case 7:
case 'end': case "end":
return _context.stop(); return _context.stop();
} }
} }
}, _callee, this); }, _callee, this);
})); }));
function _doLoad(_x, _x2, _x3) { return function _doLoad(_x, _x2, _x3) {
return _ref.apply(this, arguments); return _doLoad2.apply(this, arguments);
} };
return _doLoad;
}() }()
}, { }, {
key: 'load', key: "load",
value: function load(what, where, provider) { value: function load(what, where, provider) {
return contracts[what] || ContractLoader._doLoad(what, where, provider); return contracts[what] || ContractLoader._doLoad(what, where, provider);
} }

44
dist/ocean-agent.js vendored
View File

@ -1,55 +1,57 @@
'use strict'; "use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.default = void 0;
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* global fetch */ /* global fetch */
var OceanAgent =
var OceanAgent = function () { /*#__PURE__*/
function () {
function OceanAgent(connectionUrl) { function OceanAgent(connectionUrl) {
(0, _classCallCheck3.default)(this, OceanAgent); (0, _classCallCheck2.default)(this, OceanAgent);
this.assetsUrl = connectionUrl + '/assets'; this.assetsUrl = connectionUrl + '/assets';
} }
(0, _createClass3.default)(OceanAgent, [{ (0, _createClass2.default)(OceanAgent, [{
key: 'getAssetsMetadata', key: "getAssetsMetadata",
value: function getAssetsMetadata() { value: function getAssetsMetadata() {
return fetch(this.assetsUrl + '/metadata', { method: 'GET' }).then(function (res) { return fetch(this.assetsUrl + '/metadata', {
method: 'GET'
}).then(function (res) {
return res.json(); return res.json();
}).then(function (data) { }).then(function (data) {
return JSON.parse(data); return JSON.parse(data);
}); });
} }
}, { }, {
key: 'publishDataAsset', key: "publishDataAsset",
value: function publishDataAsset(asset) { value: function publishDataAsset(asset) {
return fetch(this.assetsUrl + '/metadata', { return fetch(this.assetsUrl + '/metadata', {
method: 'POST', method: 'POST',
body: JSON.stringify(asset), body: JSON.stringify(asset),
headers: { 'Content-type': 'application/json' } headers: {
'Content-type': 'application/json'
}
}).then(function (response) { }).then(function (response) {
console.log('Success:', response); console.log('Success:', response);
if (response.ok) { if (response.ok) {
console.log('Success:', response); console.log('Success:', response);
return true; return true;
} }
console.log('Failed: ', response.status, response.statusText); console.log('Failed: ', response.status, response.statusText);
return false; return false; // throw new Error(response.statusText ? response.statusText : `publish asset failed with status ${response.status}`)
// throw new Error(response.statusText ? response.statusText : `publish asset failed with status ${response.status}`)
}).catch(function (error) { }).catch(function (error) {
console.log('Publish asset to ocean database could not be completed: ' + error.message()); console.log("Publish asset to ocean database could not be completed: ".concat(error.message()));
return false; return false;
}); });
} }

251
dist/ocean-keeper.js vendored
View File

@ -1,155 +1,145 @@
'use strict'; "use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.default = void 0;
var _extends2 = require('babel-runtime/helpers/extends'); var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _extends3 = _interopRequireDefault(_extends2); var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _regenerator = require('babel-runtime/regenerator'); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _regenerator2 = _interopRequireDefault(_regenerator); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); var _web = _interopRequireDefault(require("web3"));
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _contractLoader = _interopRequireDefault(require("./contractLoader"));
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _web = require('web3');
var _web2 = _interopRequireDefault(_web);
var _contractLoader = require('./contractLoader');
var _contractLoader2 = _interopRequireDefault(_contractLoader);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var DEFAULT_GAS = 300000; var DEFAULT_GAS = 300000;
var OceanKeeper = function () { var OceanKeeper =
/*#__PURE__*/
function () {
function OceanKeeper(uri, network) { function OceanKeeper(uri, network) {
(0, _classCallCheck3.default)(this, OceanKeeper); (0, _classCallCheck2.default)(this, OceanKeeper);
var web3Provider = new _web.default.providers.HttpProvider(uri);
var web3Provider = new _web2.default.providers.HttpProvider(uri); this.web3 = new _web.default(web3Provider);
this.web3 = new _web2.default(web3Provider);
this.defaultGas = DEFAULT_GAS; this.defaultGas = DEFAULT_GAS;
this.network = network || 'development'; this.network = network || 'development';
} }
(0, _createClass3.default)(OceanKeeper, [{ (0, _createClass2.default)(OceanKeeper, [{
key: 'initContracts', key: "initContracts",
value: function () { value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { var _initContracts = (0, _asyncToGenerator2.default)(
return _regenerator2.default.wrap(function _callee$(_context) { /*#__PURE__*/
_regenerator.default.mark(function _callee() {
return _regenerator.default.wrap(function _callee$(_context) {
while (1) { while (1) {
switch (_context.prev = _context.next) { switch (_context.prev = _context.next) {
case 0: case 0:
_context.next = 2; _context.next = 2;
return _contractLoader2.default.load('OceanToken', this.network, this.web3.currentProvider); return _contractLoader.default.load('OceanToken', this.network, this.web3.currentProvider);
case 2: case 2:
this.oceanToken = _context.sent; this.oceanToken = _context.sent;
_context.next = 5; _context.next = 5;
return _contractLoader2.default.load('OceanMarket', this.network, this.web3.currentProvider); return _contractLoader.default.load('OceanMarket', this.network, this.web3.currentProvider);
case 5: case 5:
this.oceanMarket = _context.sent; this.oceanMarket = _context.sent;
_context.next = 8; _context.next = 8;
return _contractLoader2.default.load('OceanAuth', this.network, this.web3.currentProvider); return _contractLoader.default.load('OceanAuth', this.network, this.web3.currentProvider);
case 8: case 8:
this.oceanAuth = _context.sent; this.oceanAuth = _context.sent;
return _context.abrupt('return', { return _context.abrupt("return", {
oceanToken: this.oceanToken, oceanToken: this.oceanToken,
oceanMarket: this.oceanMarket, oceanMarket: this.oceanMarket,
oceanAuth: this.oceanAuth oceanAuth: this.oceanAuth
}); });
case 10: case 10:
case 'end': case "end":
return _context.stop(); return _context.stop();
} }
} }
}, _callee, this); }, _callee, this);
})); }));
function initContracts() { return function initContracts() {
return _ref.apply(this, arguments); return _initContracts.apply(this, arguments);
} };
}() // web3 wrappers
return initContracts;
}()
// web3 wrappers
}, { }, {
key: 'sign', key: "sign",
value: function sign(accountAddress, message) { value: function sign(accountAddress, message) {
return this.web3.eth.sign(accountAddress, message); return this.web3.eth.sign(accountAddress, message);
} }
}, { }, {
key: 'getMessageHash', key: "getMessageHash",
value: function getMessageHash(message) { value: function getMessageHash(message) {
return this.web3.sha3('\x19Ethereum Signed Message:\n' + message.length + message); return this.web3.sha3("\x19Ethereum Signed Message:\n".concat(message.length).concat(message));
} } // call functions (costs no gas)
// call functions (costs no gas)
}, { }, {
key: 'checkAsset', key: "checkAsset",
value: function checkAsset(assetId) { value: function checkAsset(assetId) {
return this.oceanMarket.checkAsset(assetId); return this.oceanMarket.checkAsset(assetId);
} }
}, { }, {
key: 'getBalance', key: "getBalance",
value: function getBalance(accountAddress) { value: function getBalance(accountAddress) {
return this.oceanToken.balanceOf.call(accountAddress); return this.oceanToken.balanceOf.call(accountAddress);
} }
}, { }, {
key: 'getAssetPrice', key: "getAssetPrice",
value: function getAssetPrice(assetId) { value: function getAssetPrice(assetId) {
return this.oceanMarket.getAssetPrice(assetId).then(function (price) { return this.oceanMarket.getAssetPrice(assetId).then(function (price) {
return price.toNumber(); return price.toNumber();
}); });
} }
}, { }, {
key: 'getOrderStatus', key: "getOrderStatus",
value: function getOrderStatus(orderId) { value: function getOrderStatus(orderId) {
return this.oceanAuth.statusOfAccessRequest(orderId); return this.oceanAuth.statusOfAccessRequest(orderId);
} }
}, { }, {
key: 'verifyOrderPayment', key: "verifyOrderPayment",
value: function verifyOrderPayment(orderId) { value: function verifyOrderPayment(orderId) {
return this.oceanMarket.verifyPaymentReceived(orderId); return this.oceanMarket.verifyPaymentReceived(orderId);
} }
}, { }, {
key: 'getEncryptedAccessToken', key: "getEncryptedAccessToken",
value: function getEncryptedAccessToken(orderId, senderAddress) { value: function getEncryptedAccessToken(orderId, senderAddress) {
return this.oceanAuth.getEncryptedAccessToken(orderId, { from: senderAddress }); return this.oceanAuth.getEncryptedAccessToken(orderId, {
from: senderAddress
});
} }
}, { }, {
key: 'getConsumerOrders', key: "getConsumerOrders",
value: function () { value: function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(consumerAddress) { var _getConsumerOrders = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee3(consumerAddress) {
var _this = this; var _this = this;
var accessConsentEvent, _resolve, _reject, promise, getEvents, events, orders; var accessConsentEvent, _resolve, _reject, promise, getEvents, events, orders;
return _regenerator2.default.wrap(function _callee3$(_context3) { return _regenerator.default.wrap(function _callee3$(_context3) {
while (1) { while (1) {
switch (_context3.prev = _context3.next) { switch (_context3.prev = _context3.next) {
case 0: case 0:
accessConsentEvent = this.oceanAuth.AccessConsentRequested({ _consumer: consumerAddress }, { accessConsentEvent = this.oceanAuth.AccessConsentRequested({
_consumer: consumerAddress
}, {
fromBlock: 0, fromBlock: 0,
toBlock: 'latest' toBlock: 'latest'
}); });
@ -164,6 +154,7 @@ var OceanKeeper = function () {
accessConsentEvent.get(function (error, logs) { accessConsentEvent.get(function (error, logs) {
if (error) { if (error) {
_reject(error); _reject(error);
throw new Error(error); throw new Error(error);
} else { } else {
_resolve(logs); _resolve(logs);
@ -179,17 +170,20 @@ var OceanKeeper = function () {
case 7: case 7:
events = _context3.sent; events = _context3.sent;
// let orders = await this.buildOrdersFromEvents(events, consumerAddress).then((result) => result) // let orders = await this.buildOrdersFromEvents(events, consumerAddress).then((result) => result)
orders = events.filter(function (obj) { orders = events.filter(function (obj) {
return obj.args._consumer === consumerAddress; return obj.args._consumer === consumerAddress;
}).map(function () { }).map(
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(event) { /*#__PURE__*/
return _regenerator2.default.wrap(function _callee2$(_context2) { function () {
var _ref = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee2(event) {
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) { while (1) {
switch (_context2.prev = _context2.next) { switch (_context2.prev = _context2.next) {
case 0: case 0:
_context2.t0 = _extends3.default; _context2.t0 = _objectSpread2.default;
_context2.t1 = {}; _context2.t1 = {};
_context2.t2 = event.args; _context2.t2 = event.args;
_context2.t3 = event.args._timeout.toNumber(); _context2.t3 = event.args._timeout.toNumber();
@ -213,52 +207,51 @@ var OceanKeeper = function () {
paid: _context2.t5, paid: _context2.t5,
key: null key: null
}; };
return _context2.abrupt('return', (0, _context2.t0)(_context2.t1, _context2.t2, _context2.t6)); return _context2.abrupt("return", (0, _context2.t0)(_context2.t1, _context2.t2, _context2.t6));
case 12: case 12:
case 'end': case "end":
return _context2.stop(); return _context2.stop();
} }
} }
}, _callee2, _this); }, _callee2, this);
})); }));
return function (_x2) { return function (_x2) {
return _ref3.apply(this, arguments); return _ref.apply(this, arguments);
}; };
}()); }());
console.debug('got orders: ', orders); console.debug('got orders: ', orders);
return _context3.abrupt('return', orders); return _context3.abrupt("return", orders);
case 11: case 11:
case 'end': case "end":
return _context3.stop(); return _context3.stop();
} }
} }
}, _callee3, this); }, _callee3, this);
})); }));
function getConsumerOrders(_x) { return function getConsumerOrders(_x) {
return _ref2.apply(this, arguments); return _getConsumerOrders.apply(this, arguments);
} };
}() // Transactions with gas cost
return getConsumerOrders;
}()
// Transactions with gas cost
}, { }, {
key: 'requestTokens', key: "requestTokens",
value: function requestTokens(senderAddress, numTokens) { value: function requestTokens(senderAddress, numTokens) {
return this.oceanMarket.requestTokens(numTokens, { from: senderAddress }); return this.oceanMarket.requestTokens(numTokens, {
from: senderAddress
});
} }
}, { }, {
key: 'registerDataAsset', key: "registerDataAsset",
value: function () { value: function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(name, description, price, publisherAddress) { var _registerDataAsset = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee4(name, description, price, publisherAddress) {
var assetId, result; var assetId, result;
return _regenerator2.default.wrap(function _callee4$(_context4) { return _regenerator.default.wrap(function _callee4$(_context4) {
while (1) { while (1) {
switch (_context4.prev = _context4.next) { switch (_context4.prev = _context4.next) {
case 0: case 0:
@ -268,34 +261,36 @@ var OceanKeeper = function () {
case 2: case 2:
assetId = _context4.sent; assetId = _context4.sent;
_context4.next = 5; _context4.next = 5;
return this.oceanMarket.register(assetId, price, { from: publisherAddress, gas: this.defaultGas }); return this.oceanMarket.register(assetId, price, {
from: publisherAddress,
gas: this.defaultGas
});
case 5: case 5:
result = _context4.sent; result = _context4.sent;
console.log('registered: ', result); console.log('registered: ', result);
return _context4.abrupt('return', assetId); return _context4.abrupt("return", assetId);
case 8: case 8:
case 'end': case "end":
return _context4.stop(); return _context4.stop();
} }
} }
}, _callee4, this); }, _callee4, this);
})); }));
function registerDataAsset(_x3, _x4, _x5, _x6) { return function registerDataAsset(_x3, _x4, _x5, _x6) {
return _ref4.apply(this, arguments); return _registerDataAsset.apply(this, arguments);
} };
return registerDataAsset;
}() }()
}, { }, {
key: 'sendPayment', key: "sendPayment",
value: function () { value: function () {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(assetId, order, publisherAddress, senderAddress) { var _sendPayment = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee5(assetId, order, publisherAddress, senderAddress) {
var assetPrice; var assetPrice;
return _regenerator2.default.wrap(function _callee5$(_context5) { return _regenerator.default.wrap(function _callee5$(_context5) {
while (1) { while (1) {
switch (_context5.prev = _context5.next) { switch (_context5.prev = _context5.next) {
case 0: case 0:
@ -306,73 +301,85 @@ var OceanKeeper = function () {
case 2: case 2:
assetPrice = _context5.sent; assetPrice = _context5.sent;
this.oceanMarket.sendPayment(order.id, publisherAddress, assetPrice, order.timeout, { this.oceanMarket.sendPayment(order.id, publisherAddress, assetPrice, order.timeout, {
from: senderAddress, from: senderAddress,
gas: 2000000 gas: 2000000
}); });
case 4: case 4:
case 'end': case "end":
return _context5.stop(); return _context5.stop();
} }
} }
}, _callee5, this); }, _callee5, this);
})); }));
function sendPayment(_x7, _x8, _x9, _x10) { return function sendPayment(_x7, _x8, _x9, _x10) {
return _ref5.apply(this, arguments); return _sendPayment.apply(this, arguments);
} };
return sendPayment;
}() }()
}, { }, {
key: 'cancelAccessRequest', key: "cancelAccessRequest",
value: function cancelAccessRequest(orderId, senderAddress) { value: function cancelAccessRequest(orderId, senderAddress) {
return this.oceanAuth.cancelAccessRequest(orderId, { from: senderAddress }); return this.oceanAuth.cancelAccessRequest(orderId, {
from: senderAddress
});
} }
}, { }, {
key: 'orchestrateResourcePurchase', key: "orchestrateResourcePurchase",
value: function orchestrateResourcePurchase(assetId, publisherId, price, privateKey, publicKey, timeout, senderAddress, initialRequestEventHandler, accessCommittedEventHandler, tokenPublishedEventHandler) { value: function orchestrateResourcePurchase(assetId, publisherId, price, privateKey, publicKey, timeout, senderAddress, initialRequestEventHandler, accessCommittedEventHandler, tokenPublishedEventHandler) {
var _this2 = this; var _this2 = this;
var oceanToken = this.oceanToken, var oceanToken = this.oceanToken,
oceanMarket = this.oceanMarket, oceanMarket = this.oceanMarket,
oceanAuth = this.oceanAuth; oceanAuth = this.oceanAuth; // Allow OceanMarket contract to transfer funds on the consumer's behalf
// Allow OceanMarket contract to transfer funds on the consumer's behalf
oceanToken.approve(oceanMarket.address, price, { from: senderAddress, gas: 2000000 }); oceanToken.approve(oceanMarket.address, price, {
// Submit the access request from: senderAddress,
oceanAuth.initiateAccessRequest(assetId, publisherId, publicKey, timeout, { from: senderAddress, gas: 1000000 }); gas: 2000000
}); // Submit the access request
var resourceFilter = { _resourceId: assetId, _consumer: senderAddress }; oceanAuth.initiateAccessRequest(assetId, publisherId, publicKey, timeout, {
from: senderAddress,
gas: 1000000
});
var resourceFilter = {
_resourceId: assetId,
_consumer: senderAddress
};
var initRequestEvent = oceanAuth.AccessConsentRequested(resourceFilter); var initRequestEvent = oceanAuth.AccessConsentRequested(resourceFilter);
var order = {}; var order = {};
this._listenOnce(initRequestEvent, 'AccessConsentRequested', function (result, error) { this._listenOnce(initRequestEvent, 'AccessConsentRequested', function (result, error) {
order = initialRequestEventHandler(result, error); order = initialRequestEventHandler(result, error);
var requestIdFilter = { _id: order.id }; var requestIdFilter = {
_id: order.id
};
var accessCommittedEvent = oceanAuth.AccessRequestCommitted(requestIdFilter); var accessCommittedEvent = oceanAuth.AccessRequestCommitted(requestIdFilter);
var tokenPublishedEvent = oceanAuth.EncryptedTokenPublished(requestIdFilter); var tokenPublishedEvent = oceanAuth.EncryptedTokenPublished(requestIdFilter);
_this2._listenOnce(accessCommittedEvent, 'AccessRequestCommitted', function (result, error) { _this2._listenOnce(accessCommittedEvent, 'AccessRequestCommitted', function (result, error) {
accessCommittedEventHandler(result, order, error); accessCommittedEventHandler(result, order, error);
}); });
_this2._listenOnce(tokenPublishedEvent, 'EncryptedTokenPublished', function (result, error) { _this2._listenOnce(tokenPublishedEvent, 'EncryptedTokenPublished', function (result, error) {
tokenPublishedEventHandler(result, order, error); tokenPublishedEventHandler(result, order, error);
}); });
}); });
return order;
}
// Helper functions (private) return order;
} // Helper functions (private)
}, { }, {
key: '_listenOnce', key: "_listenOnce",
value: function _listenOnce(event, eventName, callback) { value: function _listenOnce(event, eventName, callback) {
event.watch(function (error, result) { event.watch(function (error, result) {
event.stopWatching(); event.stopWatching();
if (error) { if (error) {
console.log('Error in keeper ' + eventName + ' event: ', error); console.log("Error in keeper ".concat(eventName, " event: "), error);
} }
callback(result, error); callback(result, error);
}); });
} }

30
dist/squid.js vendored
View File

@ -1,19 +1,23 @@
'use strict'; "use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.OceanKeeper = exports.OceanAgent = undefined; Object.defineProperty(exports, "OceanAgent", {
enumerable: true,
get: function get() {
return _oceanAgent.default;
}
});
Object.defineProperty(exports, "OceanKeeper", {
enumerable: true,
get: function get() {
return _oceanKeeper.default;
}
});
var _oceanAgent = require('./ocean-agent'); var _oceanAgent = _interopRequireDefault(require("./ocean-agent"));
var _oceanAgent2 = _interopRequireDefault(_oceanAgent); var _oceanKeeper = _interopRequireDefault(require("./ocean-keeper"));
var _oceanKeeper = require('./ocean-keeper');
var _oceanKeeper2 = _interopRequireDefault(_oceanKeeper);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.OceanAgent = _oceanAgent2.default;
exports.OceanKeeper = _oceanKeeper2.default;

2820
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
{ {
"name": "@oceanprotocol/squid", "name": "@oceanprotocol/squid",
"version": "0.0.4", "version": "0.0.4",
"description": "Ocean JavaScript Library", "description": "Ocean Protocol JavaScript Library",
"main": "dist/squid.js", "main": "dist/squid.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "babel src --watch --out-dir dist", "start": "babel src --watch --out-dir dist",
"build": "babel src --out-dir dist" "build": "babel src --out-dir dist"
}, },
"repository": { "repository": {
@ -13,22 +13,26 @@
"url": "git+https://github.com/oceanprotocol/squid-js.git" "url": "git+https://github.com/oceanprotocol/squid-js.git"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "Ocean Protocol <devops@oceanproocol.com>",
"license": "ISC", "license": "Apache-2.0",
"bugs": { "bugs": {
"url": "https://github.com/oceanprotocol/squid-js/issues" "url": "https://github.com/oceanprotocol/squid-js/issues"
}, },
"homepage": "https://github.com/oceanprotocol/squid-js#readme", "homepage": "https://github.com/oceanprotocol/squid-js#readme",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0",
"@oceanprotocol/keeper-contracts": "^0.1.0", "@oceanprotocol/keeper-contracts": "^0.1.0",
"truffle-contract": "^3.0.6", "truffle-contract": "^3.0.6",
"web3": "0.20.6" "web3": "0.20.6"
}, },
"devDependencies": { "devDependencies": {
"babel-cli": "^6.26.0", "@babel/cli": "^7.0.0",
"babel-core": "^6.26.3", "@babel/core": "^7.0.0",
"babel-plugin-transform-runtime": "^6.23.0", "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"babel-preset-es2015": "^6.24.1", "@babel/plugin-transform-runtime": "^7.0.0",
"babel-preset-stage-2": "^6.24.1" "@babel/preset-env": "^7.0.0"
},
"engines": {
"node": ">=8 <10"
} }
} }