Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
chore: add getTransactionSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Dec 18, 2019
1 parent 861ca66 commit bf151a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/element-lib/src/sidetree-v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const {
resolve,
sync,
batchWrite,
getTransactions,
} = require('./protocol');
const { getTransactions, getTransactionSummary } = require('./protocol/getTransactions');
const BatchScheduler = require('./protocol/BatchScheduler');
const op = require('./op');
const func = require('./func');
Expand Down Expand Up @@ -35,6 +35,7 @@ class Sidetree {
this.parameters = parameters;

this.getTransactions = getTransactions(this);
this.getTransactionSummary = getTransactionSummary(this);
}
}

Expand Down
23 changes: 22 additions & 1 deletion packages/element-lib/src/sidetree-v2/protocol/getTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@ const getTransactions = sidetree => async () => {
return lastTransactionsWithTimestamp;
};

module.exports = getTransactions;
const getTransactionSummary = sidetree => async (transactionTimeHash) => {
const transaction = await sidetree.getTransactions({ transactionTimeHash });
const anchorFile = await sidetree.func.readThenWriteToCache(sidetree, transaction.anchorFileHash);
const batchFile = await sidetree.func.readThenWriteToCache(sidetree, anchorFile.batchFileHash);
let operations;
try {
operations = sidetree.func.batchFileToOperations(batchFile);
} catch (e) {
operations = [];
}
return {
transaction,
anchorFile,
batchFile,
operations,
};
};

module.exports = {
getTransactions,
getTransactionSummary,
};
2 changes: 0 additions & 2 deletions packages/element-lib/src/sidetree-v2/protocol/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const resolve = require('./resolve');
const sync = require('./sync');
const batchWrite = require('./batchWrite');
const getTransactions = require('./getTransactions');

module.exports = {
resolve,
sync,
batchWrite,
getTransactions,
};

0 comments on commit bf151a8

Please sign in to comment.