Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Commit 7903f23

Browse files
committed
Update exchange reports
1 parent b2871f0 commit 7903f23

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

lib/exchange-report.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ var assert = require('assert');
66
* Represents a report to a bridge regarding the result of a shard exchange
77
* @constructor
88
* @param {Object} options
9-
* @param {String} options.reporterId
10-
* @param {String} [options.farmerId]
11-
* @param {String} [options.clientId]
9+
* @param {String} options.token
10+
* @param {String} options.dataHash
1211
*/
1312
function ExchangeReport(options = {}) {
14-
/* eslint complexity: [2, 7] */
13+
/* eslint complexity: [2, 8] */
1514
if (!(this instanceof ExchangeReport)) {
1615
return new ExchangeReport(options);
1716
}
1817

19-
assert(options.reporterId, 'Invalid reporterId');
20-
2118
this._r = {
2219
dataHash: options.dataHash || null,
23-
reporterId: options.reporterId,
24-
farmerId: options.farmerId,
25-
clientId: options.clientId,
20+
token: options.token || null,
2621
exchangeStart: options.exchangeStart || null,
2722
exchangeEnd: options.exchangeEnd || null,
2823
exchangeResultCode: options.exchangeResultCode || null,

lib/network/protocol.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ Protocol.prototype.handleMirror = function(params, callback) {
382382

383383
const hasher256 = crypto.createHash('sha256');
384384
const report = new ExchangeReport({
385-
reporterId: self._network.contact.nodeID,
386-
farmerId: params.farmer.nodeID
385+
dataHash: hash,
386+
token: token
387387
});
388388
const downloader = utils.createShardDownloader(
389389
new Contact(params.farmer),

lib/network/shard-server.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ ShardServer.prototype.routeConsignment = function(req, res) {
262262
}
263263

264264
let report = new ExchangeReport({
265-
reporterId: this._nodeID,
266-
farmerId: this._nodeID
265+
dataHash: hash,
266+
token: token
267267
})
268268

269269
report.begin(hash);
@@ -393,8 +393,8 @@ ShardServer.prototype.routeRetrieval = function(req, res) {
393393
}
394394

395395
let report = new ExchangeReport({
396-
reporterId: this._nodeID,
397-
farmerId: this._nodeID
396+
dataHash: hash,
397+
token: token
398398
})
399399

400400
// eslint-disable-next-line max-statements

test/exchange-report.unit.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ describe('Exchange Report', function() {
1313
it('#toObject', function() {
1414
var report = new ExchangeReport({
1515
dataHash: 'd8e33c898eb5ccd6789b32ceaca4e1d4e8cc452f',
16-
reporterId: '538db66de92c02dc52cde37307ace5463917cbf0',
17-
farmerId: '41ff35b1fac9981685b4423f91acc11ec345cd36',
18-
clientId: '2c33e90b668313c96733b269a3f5c7b7ab2128e1',
16+
token: '5412f65e73825adb616649cfddc552e8e188edd4',
1917
exchangeStart: 1479247169809,
2018
exchangeEnd: 1479250511087,
2119
exchangeResultCode: 1000,
@@ -24,9 +22,7 @@ describe('Exchange Report', function() {
2422

2523
expect(report.toObject()).to.deep.equal({
2624
dataHash: 'd8e33c898eb5ccd6789b32ceaca4e1d4e8cc452f',
27-
reporterId: '538db66de92c02dc52cde37307ace5463917cbf0',
28-
farmerId: '41ff35b1fac9981685b4423f91acc11ec345cd36',
29-
clientId: '2c33e90b668313c96733b269a3f5c7b7ab2128e1',
25+
token: '5412f65e73825adb616649cfddc552e8e188edd4',
3026
exchangeStart: 1479247169809,
3127
exchangeEnd: 1479250511087,
3228
exchangeResultCode: 1000,
@@ -38,9 +34,7 @@ describe('Exchange Report', function() {
3834
describe('#begin/#end', function() {
3935
it('it should record start and end time', function() {
4036
var report = new ExchangeReport({
41-
reporterId: '538db66de92c02dc52cde37307ace5463917cbf0',
42-
farmerId: '41ff35b1fac9981685b4423f91acc11ec345cd36',
43-
clientId: '2c33e90b668313c96733b269a3f5c7b7ab2128e1',
37+
token: '89e1625e692c4546d6cda29231f6890cbb8c31b7'
4438
});
4539

4640
expect(report._r.exchangeStart).to.equal(null);
@@ -57,9 +51,7 @@ describe('Exchange Report', function() {
5751
expect(report._r.exchangeEnd).to.equal(1479251141714);
5852

5953
expect(report.toObject()).to.deep.equal({
60-
reporterId: '538db66de92c02dc52cde37307ace5463917cbf0',
61-
farmerId: '41ff35b1fac9981685b4423f91acc11ec345cd36',
62-
clientId: '2c33e90b668313c96733b269a3f5c7b7ab2128e1',
54+
token: '89e1625e692c4546d6cda29231f6890cbb8c31b7',
6355
dataHash: '55736f88e72c42e732defdbfda258cbe0f8be94b',
6456
exchangeStart: 1479251099379,
6557
exchangeEnd: 1479251141714,

0 commit comments

Comments
 (0)