Skip to content

Commit

Permalink
⚡️ server: prefetch onchain data for authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Nov 1, 2024
1 parent c614347 commit 791cea5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions server/hooks/cryptomate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export default new Hono().post(
},
),
async (c) => {
const previewPromise = startSpan({ name: "query onchain state", op: "exa.preview" }, () =>
publicClient.readContract({
abi: installmentsPreviewerAbi,
address: installmentsPreviewerAddress,
functionName: "preview",
}),
);
const payload = c.req.valid("json");
setTag("cryptomate.event", payload.event_type);
setTag("cryptomate.status", payload.status);
Expand Down Expand Up @@ -133,13 +140,7 @@ export default new Hono().post(
args: [BigInt(firstMaturity), amount, BigInt(timestamp), signature],
} as const;
}
const preview = await startSpan({ name: "query onchain state", op: "exa.preview" }, () =>
publicClient.readContract({
abi: installmentsPreviewerAbi,
address: installmentsPreviewerAddress,
functionName: "preview",
}),
);
const preview = await previewPromise;
const { amounts } = startSpan({ name: "split installments", op: "exa.split" }, () =>
splitInstallments(
amount,
Expand Down

0 comments on commit 791cea5

Please sign in to comment.