fix: ignore duplicated precommitments in the events (#85)

This commit is contained in:
moebius
2025-05-25 10:55:31 -06:00
committed by GitHub
2 changed files with 13 additions and 11 deletions

View File

@@ -24,11 +24,11 @@ import { EventError } from "../errors/events.error.js";
type AccountServiceConfig =
| {
mnemonic: string;
}
mnemonic: string;
}
| {
account: PrivacyPoolAccount;
};
account: PrivacyPoolAccount;
};
/**
* Service responsible for managing privacy pool accounts and their associated commitments.
@@ -781,11 +781,11 @@ export class AccountService {
dataService: DataService,
source:
| {
mnemonic: string;
}
mnemonic: string;
}
| {
service: AccountService;
},
service: AccountService;
},
pools: PoolInfo[]
): Promise<{ account: AccountService; errors: PoolEventsError[] }> {
// Log the start of the history retrieval process
@@ -876,7 +876,9 @@ export class AccountService {
// Create a map of deposits by precommitment for efficient lookup
const depositMap = new Map<Hash, DepositEvent>();
for (const deposit of deposits) {
depositMap.set(deposit.precommitment, deposit);
if (!depositMap.has(deposit.precommitment)) {
depositMap.set(deposit.precommitment, deposit);
}
}
// Track found deposits for logging and debugging

View File

@@ -104,7 +104,7 @@ export class DataService {
_merkleRoot: precommitment,
} = log.args;
if (!depositor || !commitment || !label || !value || !precommitment || !log.blockNumber || !log.transactionHash) {
if (!depositor || !commitment || !label || !precommitment || !log.blockNumber || !log.transactionHash) {
throw DataError.invalidLog("deposit", "missing required fields");
}
@@ -112,7 +112,7 @@ export class DataService {
depositor: depositor.toLowerCase(),
commitment: commitment as Hash,
label: label as Hash,
value,
value: value || BigInt(0),
precommitment: precommitment as Hash,
blockNumber: BigInt(log.blockNumber),
transactionHash: log.transactionHash,