Skip to content

Commit

Permalink
feat: add pool metadata updated event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrdd committed Jun 10, 2024
1 parent 037f6b9 commit 4896513
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/indexer/events/handlePoolMetadataUpdated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { EventHandlerArgs, Indexer } from "chainsauce";
import { IndexerContext } from "../handleEvent.js";
import { fetchIpfs } from "../ipfs.js";
import { abis } from "../../lib/abi/index.js";

export async function handlePoolMetadataUpdated(
args: EventHandlerArgs<
Indexer<typeof abis, IndexerContext>,
"Allo",
"PoolMetadataUpdated"
>,
) {
const {
event,
chainId,
context: { db },
} = args;

const { params } = event;

const metadataCid = params.metadata.pointer;
const metadata = await fetchIpfs(metadataCid);

try {
db.updateTable("pools")
.set({
metadataCid,
metadata,
})
.where("chainId", "=", chainId)
.where("id", "=", params.poolId.toString())
.execute();
} catch (err) {
console.warn("DB write error");
}
}
1 change: 1 addition & 0 deletions src/indexer/events/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { handleProfileCreated } from "./handleProfileCreated.js";
export { handlePoolCreated } from "./handlePoolCreated.js";
export { handlePoolMetadataUpdated } from "./handlePoolMetadataUpdated.js";
export { handleRegistered } from "./handleRegistered.js";
export { handleUpdatedRegistration } from "./handleUpdatedRegistration.js";
export { handleReviewed } from "./handleReviewed.js";
Expand Down
7 changes: 7 additions & 0 deletions src/indexer/handleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { abis } from "../lib/abi/index.js";
import {
handleProfileCreated,
handlePoolCreated,
handlePoolMetadataUpdated,
handleRegistered,
handleUpdatedRegistration,
handleReviewed,
Expand Down Expand Up @@ -41,6 +42,12 @@ async function handleEvent(
break;
}

case "PoolMetadataUpdated": {
await handlePoolMetadataUpdated({ ...args, event });

break;
}

case "Registered": {
await handleRegistered({ ...args, event });

Expand Down

0 comments on commit 4896513

Please sign in to comment.