Skip to content

Commit

Permalink
feat: add updated registration event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrdd committed May 8, 2024
1 parent 7e019b2 commit ceb17cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/indexer/handleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Indexer } from "chainsauce";
import { Database } from "../db/index.js";
import { decodeRegistrationDataAlloStrategy } from "./decode.js";
import { abis } from "../lib/abi/index.js";

const ALLO_STRATEGY_ID =
"0xf8a14294e80ff012e54157ec9d1b2827421f1e7f6bde38c06730b1c031b3f935";
import { ALLO_STRATEGY_ID } from "../lib/constants.js";

type IndexerContext = { publicClient: PublicClient; db: Kysely<Database> };

Expand Down Expand Up @@ -142,6 +140,39 @@ async function handleEvent(
break;
}

case "UpdatedRegistration": {
const {
params: { data: encodedData },
address,
} = event;

const {
recipientId,
recipientAddress,
metadata: { pointer: metadataCid },
} = decodeRegistrationDataAlloStrategy(encodedData);

const strategyAddress = address.toLowerCase();

try {
await db
.updateTable("recipients")
.set({
recipientAddress: recipientAddress.toLowerCase(),
metadataCid,
updatedAtBlock: event.blockNumber,
})
.where("chainId", "=", chainId)
.where("strategyAddress", "=", strategyAddress)
.where("id", "=", recipientId)
.execute();
} catch (err) {
console.warn("DB write error");
}

break;
}

default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ALLO_STRATEGY_ID =
"0xf8a14294e80ff012e54157ec9d1b2827421f1e7f6bde38c06730b1c031b3f935";

0 comments on commit ceb17cd

Please sign in to comment.