giveth-bridge
Version:
Mainnet -> sidechain Giveth Bridge.
74 lines (59 loc) • 2.81 kB
JavaScript
;
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 _winston = require('winston');
var _winston2 = _interopRequireDefault(_winston);
var _contracts = require('./contracts');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _class = function () {
function _class(web3, address) {
_classCallCheck(this, _class);
this.web3 = web3;
this.bridge = new _contracts.ForeignGivethBridge(web3, address);
// passing wrong web3 instance here b/c it doesn't matter
// only using this object to generate the call data to the
// homeBridge
this.homeBridge = new _contracts.GivethBridge(web3).$contract;
}
_createClass(_class, [{
key: 'getRelayTransactions',
value: function getRelayTransactions(fromBlock, toBlock) {
var _this = this;
if (toBlock < fromBlock) {
_winston2.default.debug('ForeignGivethBridge -> toBlock: ' + toBlock + ' < fromBlock: ' + fromBlock + ' ... ignoring fetch getRelayTransactions request');
return Promise.resolve([]);
}
return this.bridge.$contract.getPastEvents('Withdraw', { fromBlock: fromBlock, toBlock: toBlock }).then(function (events) {
return events.map(function (e) {
return _this.eventToTx(e);
});
}).then(function (promises) {
return Promise.all(promises);
}).then(function (results) {
return results.filter(function (r) {
return r !== undefined;
});
});
}
}, {
key: 'eventToTx',
value: function eventToTx(event) {
_winston2.default.info('handling ForeignGivethBridge event: ', event);
switch (event.event) {
case 'Withdraw':
return this.web3.eth.getTransaction(event.transactionHash).then(function (tx) {
return Object.assign({}, event.returnValues, {
foreignTx: event.transactionHash
});
});
default:
return Promise.resolve(undefined);
}
}
}]);
return _class;
}();
exports.default = _class;