Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update msg_index by order in event and log #327

Merged
merged 19 commits into from
Sep 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/services/crawl-tx/crawl_tx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,38 @@ export default class CrawlTxService extends BullableService {
return true;
}

private checkMappingEventToLog(tx: any) {
const checkResult = tx?.tx_response?.logs?.every(
(log: any, index: number) =>
log?.events?.every((event: any) =>
peara marked this conversation as resolved.
Show resolved Hide resolved
event?.attributes?.every((attr: any) => {
const filtedEvent = tx?.tx_response?.events?.filter(
(item: any) =>
item.type === event.type && item.msg_index === index
);

return filtedEvent.some((event: any) =>
event.attributes.some((attrEncoded: any) => {
const key = attrEncoded.key
? fromUtf8(fromBase64(attrEncoded.key))
: null;
const value = attrEncoded.value
? fromUtf8(fromBase64(attrEncoded.value))
: null;
if (key === attr.key && value === attr.value) {
return true;
}
return false;
})
);
})
)
);
if (checkResult === false) {
this.logger.warn('Mapping event to log is wrong');
}
}

private setMsgIndexToEvent(tx: any) {
/*------
DO NOT USE CURRENTLY
Expand Down Expand Up @@ -492,7 +524,7 @@ export default class CrawlTxService extends BullableService {
-----------*/
// count total attribute for each message, countAttributeInEvent[i] = x mean message i has x attributes
const countAttributeInEvent: number[] = [];
tx.tx_response.logs.forEach((log: any) => {
tx?.tx_response?.logs?.forEach((log: any) => {
const countAttribute = log.events.reduce(
(acc: number, curr: any) => acc + curr.attributes.length,
0
Expand All @@ -503,7 +535,7 @@ export default class CrawlTxService extends BullableService {
let reachLastEventTypeTx = false;
let countCurrentAttribute = 0;
let currentCompareEventId = 0;
for (let i = 0; i < tx.tx_response.events.length; i += 1) {
for (let i = 0; i < tx?.tx_response?.events?.length; i += 1) {
if (tx.tx_response.events[i].type === 'tx') {
reachLastEventTypeTx = true;
}
Expand All @@ -530,6 +562,7 @@ export default class CrawlTxService extends BullableService {
}
}
}
this.checkMappingEventToLog(tx);
}

private _findAttribute(
Expand Down