Skip to content

Commit

Permalink
chore(listenForStakingEvents): fix listener bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Aug 9, 2024
1 parent 27c3f56 commit 1171a3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/handler/evm/utils/listenForStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const listenForStakingEvents = (
for (const log of logs) {
const decoded = stakerInt.parseLog(log);
if (!decoded) continue;
logger.info(`found event at ${lastBlock} - ${latestBlock}`);
await cb(builder.staked(decoded.args.validatorAddressAndChainType));
}
lastBlock = latestBlock;
Expand Down
64 changes: 31 additions & 33 deletions src/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,42 +200,40 @@ export async function listenStakeEvents(
signerAddress: signerAndSignature.signer,
},
});
}

const approvalFn = async () => {
try {
const tx = await Promise.race([
(
await deps.storage.approveStake(stakerAddress, signatures)
).wait(),
setTimeout(10 * 1000),
]);
const approvalFn = async () => {
try {
const tx = await Promise.race([
(await deps.storage.approveStake(stakerAddress, signatures)).wait(),
setTimeout(10 * 1000),
]);

// @ts-ignore
if (!tx?.status) throw new Error("TxFailed");
return tx;
} catch (err) {
const err_ = err as unknown as { shortMessage: string };
if (
err_.shortMessage?.includes("Already voted for this validator")
) {
return null;
}
log.error(err_, "Error while approving stake");
throw err;
// @ts-ignore
if (!tx?.status) {
throw new Error("TxFailed");
}
};
const approved = await retry(
approvalFn,
`Approving stake ${JSON.stringify(ev, null, 2)}`,
log,
6,
);
log.info(
approved
? `Approved and Signed Data for Staking Chain at TX: ${approved.hash} for user ${stakerAddress}`
: `Already approved for ${stakerAddress}`,
);
}
return tx;
} catch (err) {
const err_ = err as unknown as { shortMessage: string };
if (err_.shortMessage?.includes("Already voted for this validator")) {
return null;
}
log.error(err_, "Error while approving stake");
throw err;
}
};
const approved = await retry(
approvalFn,
`Approving stake ${JSON.stringify(ev, null, 2)}`,
log,
6,
);
log.info(
approved
? `Approved and Signed Data for Staking Chain at TX: ${approved.hash} for user ${stakerAddress}`
: `Already approved for ${stakerAddress}`,
);
});
}

Expand Down

0 comments on commit 1171a3a

Please sign in to comment.