(assetCid: string, blockchainInfo)
| 555 | /* TODO: Remove this function in the next feature release. |
| 556 | */ |
| 557 | async function eventLogIteratingQuery(assetCid: string, blockchainInfo) { |
| 558 | console.log(`assetCid: ${assetCid}`); |
| 559 | |
| 560 | const commitBlockNumbers = await getCommitBlockNumbers(assetCid, blockchainInfo); |
| 561 | const commitAmount = commitBlockNumbers.length; |
| 562 | console.log(`Commit block numbers (${commitBlockNumbers.length}):`); |
| 563 | if (commitAmount > 0) { |
| 564 | console.log(`${JSON.stringify(commitBlockNumbers)}`); |
| 565 | } else { |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | /* WORKAROUND: create filters for every commit because Avalanche |
| 570 | * only supports 2048-block range in an event log query. |
| 571 | * |
| 572 | * The query performance is more worse than eventLogRangeQuery, |
| 573 | * but it's acceptable on Avalanche. |
| 574 | */ |
| 575 | // Create event log filter |
| 576 | let filter = await blockchainInfo.contract.filters.Commit(null, assetCid); |
| 577 | const abi = [ |
| 578 | "event Commit(address indexed recorder, string indexed assetCid, string commitData)" |
| 579 | ]; |
| 580 | console.log(`Filter: ${JSON.stringify(filter, null, 2)}`); |
| 581 | for (const c of commitBlockNumbers) { |
| 582 | // Get event log by filter |
| 583 | filter.fromBlock = c; |
| 584 | filter.toBlock = c; |
| 585 | const eventLogs = await blockchainInfo.provider.getLogs(filter); |
| 586 | |
| 587 | const commitEventInterface = new ethers.utils.Interface(abi); |
| 588 | for (const eventLog of eventLogs) { |
| 589 | console.log(`\nBlock number: ${(eventLog.blockNumber)}`); |
| 590 | console.log(`${blockchainInfo.explorerBaseUrl}/${(eventLog.transactionHash)}`); |
| 591 | |
| 592 | const commitEvent = commitEventInterface.parseLog(eventLog); |
| 593 | console.log(`commitEvent: ${JSON.stringify(commitEvent, null, 2)}`); |
| 594 | |
| 595 | try { |
| 596 | const commitData = JSON.parse(commitEvent.args[2]); |
| 597 | console.log(`Commit: ${JSON.stringify(commitData, null, 2)}`); |
| 598 | } catch (error) { |
| 599 | console.error(`Failed to parse Commit, error: ${error}`); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | /*---------------------------------------------------------------------------- |
| 606 | * Ethereum Signature |
nothing calls this directly
no test coverage detected