(assetCid: string, blockchainInfo, fromIndex, toIndex)
| 453 | } |
| 454 | |
| 455 | export async function iterateCommitEvents(assetCid: string, blockchainInfo, fromIndex, toIndex) { |
| 456 | /* Get Commit events by using low-level event logs. |
| 457 | * |
| 458 | * If a blockchain provider does not support getting events by filter, |
| 459 | * (e.g., Avalanche), you can use this function. |
| 460 | * |
| 461 | * keys in eventLog: |
| 462 | * blockNumber, blockHash, transactionIndex, removed, address, data, topics |
| 463 | * transactionHash, logIndex, |
| 464 | * keys in commitEvent: |
| 465 | * eventFragment, name, signature, args, topic, args |
| 466 | */ |
| 467 | const commitBlockNumbers = (await getCommitBlockNumbers(assetCid, blockchainInfo)).slice(fromIndex, toIndex); |
| 468 | const commitAmount = commitBlockNumbers.length; |
| 469 | |
| 470 | if (commitAmount == 0) { return []; } |
| 471 | |
| 472 | const filter = await blockchainInfo.contract.filters.Commit(null, assetCid); |
| 473 | const abi = [ |
| 474 | "event Commit(address indexed recorder, string indexed assetCid, string commitData)" |
| 475 | ]; |
| 476 | const commitEventInterface = new ethers.utils.Interface(abi); |
| 477 | |
| 478 | let events = []; |
| 479 | |
| 480 | for (const c of commitBlockNumbers) { |
| 481 | filter.fromBlock = c; |
| 482 | filter.toBlock = c; |
| 483 | const eventLogs = await blockchainInfo.provider.getLogs(filter); |
| 484 | |
| 485 | for (const eventLog of eventLogs) { |
| 486 | const commitEvent = commitEventInterface.parseLog(eventLog); |
| 487 | // merge eventLog and commitEvent |
| 488 | events.push(Object.assign({}, eventLog, commitEvent)); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | return events; |
| 493 | } |
| 494 | |
| 495 | export async function getCommits(events) { |
| 496 | const commitDataIndex = 2; |
no test coverage detected