MCPcopy Index your code
hub / github.com/numbersprotocol/nit / difference

Function difference

src/nit.ts:387–414  ·  view source on GitHub ↗
(assetCid: string, blockchainInfo, fromIndex: number = null, toIndex: number = null)

Source from the content-addressed store, hash-verified

385}
386
387export async function difference(assetCid: string, blockchainInfo, fromIndex: number = null, toIndex: number = null) {
388 const commitBlockNumbers = await getCommitBlockNumbers(assetCid, blockchainInfo);
389 const commitAmount = commitBlockNumbers.length;
390
391 // show the Commit diff between (latest - 1, latest)
392 if (fromIndex == null) {
393 toIndex = commitAmount;
394 fromIndex = toIndex - 2;
395 }
396
397 const commitEvents = await iterateCommitEvents(assetCid, blockchainInfo, fromIndex, fromIndex < toIndex ? toIndex : fromIndex + 1);
398 const commits = await getCommits(commitEvents);
399 const fromCommit = commits[0];
400 const toCommit = commits[commits.length - 1];
401 const fromAssetTree = JSON.parse((await ipfs.ipfsCat(fromCommit.commit.assetTreeCid)).toString());
402 const toAssetTree = JSON.parse((await ipfs.ipfsCat(toCommit.commit.assetTreeCid)).toString());
403 const commitDiff = {
404 "fromIndex": fromIndex,
405 "fromBlockNumber": fromCommit.blockNumber,
406 "fromTransactionHash": fromCommit.transactionHash,
407 "toIndex": toIndex,
408 "toBlockNumber": toCommit.blockNumber,
409 "toTransactionHash": toCommit.transactionHash,
410 "commitDiff": diff.diffJson(fromCommit.commit, toCommit.commit),
411 "assetTreeDiff": diff.diffJson(fromAssetTree, toAssetTree),
412 }
413 return commitDiff;
414}
415
416export async function getLatestCommitSummary(assetCid, blockchainInfo) {
417 const commitBlockNumbers = await getCommitBlockNumbers(assetCid, blockchainInfo);

Callers

nothing calls this directly

Calls 3

getCommitBlockNumbersFunction · 0.85
iterateCommitEventsFunction · 0.85
getCommitsFunction · 0.85

Tested by

no test coverage detected