(assetCid: string, blockchainInfo, fromIndex: number = null, toIndex: number = null)
| 385 | } |
| 386 | |
| 387 | export 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 | |
| 416 | export async function getLatestCommitSummary(assetCid, blockchainInfo) { |
| 417 | const commitBlockNumbers = await getCommitBlockNumbers(assetCid, blockchainInfo); |
nothing calls this directly
no test coverage detected