Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@colony/colony-js-contract-client

Package Overview
Dependencies
Maintainers
7
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colony/colony-js-contract-client - npm Package Compare versions

Comparing version 1.8.1 to 1.9.0

155

lib/classes/ContractClient.js

@@ -7,2 +7,6 @@ 'use strict';

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

@@ -16,2 +20,6 @@

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _regenerator = require('babel-runtime/regenerator');

@@ -64,5 +72,6 @@

// The contract loading query the class was constructed with
// The contract event subscription methods
// The adapter used to communicate with the blockchain
// The contract interface (as provided by the adapter)
get: function get() {

@@ -72,7 +81,9 @@ return _ContractMethodCaller2.default;

// The contract event subscription methods
// Mapping of event topics to ContractEvents
// The contract interface (as provided by the adapter)
// The contract loading query the class was constructed with
// The adapter used to communicate with the blockchain
}, {

@@ -107,2 +118,3 @@ key: 'Sender',

this.events = {};
this.eventSignatures = {};

@@ -255,2 +267,95 @@ this.adapter = adapter;

/**
* Get logs with filter, and return parsed event logs.
*/
}, {
key: 'getEvents',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
var filter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var logs;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return this.getLogs(filter);
case 2:
logs = _context5.sent;
return _context5.abrupt('return', this.parseLogs(logs));
case 4:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function getEvents() {
return _ref6.apply(this, arguments);
}
return getEvents;
}()
/**
* Get logs from the contract with filter.
*/
}, {
key: 'getLogs',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
var _this = this;
var filter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _filter$eventNames, eventNames, _filter$topics, topics, extraTopics, _topics$;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_filter$eventNames = filter.eventNames, eventNames = _filter$eventNames === undefined ? [] : _filter$eventNames, _filter$topics = filter.topics, topics = _filter$topics === undefined ? [] : _filter$topics;
// Get topics for the given eventNames
extraTopics = eventNames.reduce(function (acc, eventName) {
if (!_this.events[eventName]) throw new Error('Cannot get logs for unknown event');
return [].concat((0, _toConsumableArray3.default)(acc), (0, _toConsumableArray3.default)(_this.events[eventName].interface.topics));
}, []);
// Combine any existing topics with the extra ones
if (!topics.length) {
topics.push(extraTopics);
} else if (Array.isArray(topics[0])) {
(_topics$ = topics[0]).push.apply(_topics$, (0, _toConsumableArray3.default)(extraTopics));
} else {
topics[0] = [].concat((0, _toConsumableArray3.default)(topics[0]), (0, _toConsumableArray3.default)(extraTopics));
}
// Fetch the logs and parse
return _context6.abrupt('return', this.adapter.provider.getLogs((0, _extends4.default)({}, filter, {
topics: topics
})));
case 4:
case 'end':
return _context6.stop();
}
}
}, _callee6, this);
}));
function getLogs() {
return _ref7.apply(this, arguments);
}
return getLogs;
}()
/**
* Given a transaction receipt, decode the event logs with the contract

@@ -262,7 +367,7 @@ * interface, then use the corresponding ContractEvents to collect event data.

key: 'getReceiptEventData',
value: function getReceiptEventData(_ref6) {
var _this = this;
value: function getReceiptEventData(_ref8) {
var _this2 = this;
var _ref6$logs = _ref6.logs,
logs = _ref6$logs === undefined ? [] : _ref6$logs;
var _ref8$logs = _ref8.logs,
logs = _ref8$logs === undefined ? [] : _ref8$logs;
var events = this.contract.interface.events;

@@ -289,10 +394,10 @@

// Parse the event data and add it to a resulting object
.reduce(function (acc, _ref7) {
var eventInfo = _ref7.eventInfo,
topics = _ref7.topics,
data = _ref7.data;
.reduce(function (acc, _ref9) {
var eventInfo = _ref9.eventInfo,
topics = _ref9.topics,
data = _ref9.data;
var args = eventInfo.parse(topics, data);
var event = _this.events[eventInfo.name];
var event = _this2.events[eventInfo.name];
if (!event) throw new Error('Event ' + eventInfo.name + ' not found');

@@ -311,2 +416,18 @@

}, {
key: 'parseLogs',
value: function parseLogs(logs) {
var _this3 = this;
return logs.filter(function (_ref10) {
var _ref10$topics = (0, _slicedToArray3.default)(_ref10.topics, 1),
topic = _ref10$topics[0];
return _this3.eventSignatures[topic];
}).map(function (log) {
return (0, _extends4.default)({}, _this3.eventSignatures[log.topics[0]].parseLog(log), {
eventName: _this3.eventSignatures[log.topics[0]].eventName
});
});
}
}, {
key: 'addMethod',

@@ -346,7 +467,11 @@ value: function addMethod(Method, name, def) {

Object.assign(this.events, (0, _defineProperty3.default)({}, eventName, new _ContractEvent2.default({
var event = new _ContractEvent2.default({
eventName: eventName,
client: this,
argsDef: argsDef
})));
});
Object.assign(this.events, (0, _defineProperty3.default)({}, eventName, event));
Object.assign(this.eventSignatures, (0, _defineProperty3.default)({}, event.interface.topics[0], event));
}

@@ -353,0 +478,0 @@ }, {

@@ -7,2 +7,6 @@ 'use strict';

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

@@ -44,2 +48,4 @@

if (!this.interface) throw new Error('No such event "' + eventName + '" on this contract');
this._wrappedHandlers = new Map();

@@ -64,2 +70,35 @@ this.assertValid = (0, _colonyJsUtils.makeAssert)('Validation failed for event ' + eventName);

(0, _createClass3.default)(ContractEvent, [{
key: 'parseLogs',
/**
* Given an array of logs, filter matching topics and parse event data from them.
*/
value: function parseLogs(logs) {
var _this = this;
return logs.filter(function (_ref2) {
var _ref2$topics = (0, _slicedToArray3.default)(_ref2.topics, 1),
topic = _ref2$topics[0];
return _this.interface.topics.includes(topic);
}).map(function (log) {
return _this.parseLog(log);
});
}
/**
* Given a log, parse its event data.
*/
}, {
key: 'parseLog',
value: function parseLog(_ref3) {
var topics = _ref3.topics,
data = _ref3.data;
if (!this.interface.topics.includes(topics[0])) throw new Error('Cannot parse unknown topic');
return this.parse(this.interface.parse(topics, data));
}
}, {
key: 'parse',

@@ -105,11 +144,16 @@ value: function parse(args) {

}
}, {
key: 'interface',
get: function get() {
return this.client.contract.interface.events[this.eventName];
}
}], [{
key: 'wrapHandlerFunction',
value: function wrapHandlerFunction(handlerFunction, argsDef, assertValid) {
var _this = this;
var _this2 = this;
return function (_ref2) {
var args = _ref2.args;
return function (_ref4) {
var args = _ref4.args;
var parsedArgs = _this.parse(args, argsDef, assertValid);
var parsedArgs = _this2.parse(args, argsDef, assertValid);
handlerFunction(parsedArgs);

@@ -116,0 +160,0 @@ };

6

package.json
{
"name": "@colony/colony-js-contract-client",
"version": "1.8.1",
"version": "1.9.0",
"description": "Method-like interface for Smart Contracts",

@@ -44,3 +44,3 @@ "main": "lib/index.js",

"dependencies": {
"@colony/colony-js-adapter": "^1.8.1",
"@colony/colony-js-adapter": "^1.9.0",
"@colony/colony-js-contract-loader": "^1.8.1",

@@ -59,3 +59,3 @@ "@colony/colony-js-utils": "^1.8.1",

},
"gitHead": "9115db6fce3ef8c224f2418a0bc5eadb6c00be05"
"gitHead": "6cddb1c0f1c435013aeb97fad9e3a24315ab0622"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc