Skip to content

Commit 08928ee

Browse files
committed
fix(decoder): count
1 parent 8a29382 commit 08928ee

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

services/decoder/decoder.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class GoldRushDecoder {
2323
private static fallbacks: Fallbacks = {};
2424
private static native_decoder: NativeDecodingFunction;
2525
private static decoding_functions: DecodingFunctions = [];
26+
private static fallback_functions: DecodingFunctions = [];
2627
private static fileExtension: "js" | "ts" =
2728
process.env.NODE_ENV !== "test" ? "js" : "ts";
2829

@@ -32,6 +33,7 @@ export class GoldRushDecoder {
3233
const protocolsDirectoryPath: string = join(__dirname, "/protocols");
3334
const protocols = readdirSync(protocolsDirectoryPath);
3435
let protocolsCount: number = 0;
36+
let configsCount: number = 0;
3537
for (const protocol of protocols) {
3638
const protocolPath = join(protocolsDirectoryPath, protocol);
3739
const files = readdirSync(protocolPath);
@@ -56,6 +58,7 @@ export class GoldRushDecoder {
5658
this.configs[chain_name][protocol_name][address] = {
5759
is_factory: is_factory,
5860
};
61+
configsCount++;
5962
}
6063
);
6164
require(join(protocolPath, decodersFile));
@@ -64,7 +67,6 @@ export class GoldRushDecoder {
6467

6568
const fallbacksDirectoryPath: string = join(__dirname, "/fallbacks");
6669
const fallbacks = readdirSync(fallbacksDirectoryPath);
67-
let fallbacksCount: number = 0;
6870
for (const fallback of fallbacks) {
6971
const fallbackPath = join(fallbacksDirectoryPath, fallback);
7072
const files = readdirSync(fallbackPath);
@@ -75,7 +77,6 @@ export class GoldRushDecoder {
7577
}
7678
});
7779
if (fallbackFile) {
78-
fallbacksCount++;
7980
require(join(fallbackPath, fallbackFile));
8081
}
8182
}
@@ -87,20 +88,10 @@ export class GoldRushDecoder {
8788
);
8889
require(join(nativeDecoderPath));
8990

90-
const decodersCount = Object.keys(this.decoding_functions).length;
91-
const configsCount = Object.values(this.configs).reduce(
92-
(chainCount, chain) => {
93-
return (
94-
chainCount +
95-
Object.values(chain).reduce((addressCount, protocol) => {
96-
return addressCount + Object.keys(protocol).length;
97-
}, 0)
98-
);
99-
},
100-
0
101-
);
91+
const decodersCount = this.decoding_functions.length;
92+
const fallbacksCount = this.fallback_functions.length;
10293

103-
console.info("native decoder added");
94+
console.info("1 native decoder added");
10495
console.info(`${protocolsCount.toLocaleString()} protocols found`);
10596
console.info(`${configsCount.toLocaleString()} configs generated`);
10697
console.info(`${decodersCount.toLocaleString()} decoders generated`);
@@ -150,10 +141,10 @@ export class GoldRushDecoder {
150141
abi: abi,
151142
eventName: event_name,
152143
});
153-
this.decoding_functions.push(decoding_function);
154-
const decoding_function_index: number =
155-
this.decoding_functions.length - 1;
156-
this.fallbacks[topic0_hash] = decoding_function_index;
144+
this.fallback_functions.push(decoding_function);
145+
const fallback_function_index: number =
146+
this.fallback_functions.length - 1;
147+
this.fallbacks[topic0_hash] = fallback_function_index;
157148
};
158149

159150
public static native = (native_decoder: NativeDecodingFunction) => {
@@ -176,18 +167,27 @@ export class GoldRushDecoder {
176167
const {
177168
raw_log_topics: [topic0_hash],
178169
sender_address: contract_address,
179-
// !ERROR: add factory_contract_address in the log_event(s)
180-
// factory_contract_address,
181170
} = log;
182171
const decoding_index =
183-
// !ERROR: add factory_contract_address in the log_event(s)
184-
// factory_contract_address ||
185172
this.decoders[chain_name]?.[contract_address]?.[topic0_hash];
186173
const fallback_index = this.fallbacks[topic0_hash];
187-
if (decoding_index !== undefined || fallback_index !== undefined) {
188-
const logEvent = await this.decoding_functions[
189-
decoding_index ?? fallback_index
190-
](log, tx, chain_name, covalent_client);
174+
let logEvent: EventType | null = null;
175+
if (decoding_index !== undefined) {
176+
logEvent = await this.decoding_functions[decoding_index](
177+
log,
178+
tx,
179+
chain_name,
180+
covalent_client
181+
);
182+
} else if (fallback_index !== undefined) {
183+
logEvent = await this.fallback_functions[fallback_index](
184+
log,
185+
tx,
186+
chain_name,
187+
covalent_client
188+
);
189+
}
190+
if (logEvent) {
191191
events.push(logEvent);
192192
}
193193
}

0 commit comments

Comments
 (0)