Skip to content

Commit

Permalink
cf-worker: add /domain-data/:domain
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed Sep 30, 2024
1 parent 7927659 commit 57a4f22
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions cf-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,26 +242,23 @@ app.get("/record-v2/:domain/:record", async (c) => {
.getRoAId()
.equals(res.retrievedRecord.getContent()) &&
res.retrievedRecord.header.rightOfAssociationValidation ===
Validation.Solana;
} else if ([
Record.ETH,
Record.BSC,
Record.Injective,
Record.BASE
].includes(record)) {
Validation.Solana;
} else if (
[Record.ETH, Record.BSC, Record.Injective, Record.BASE].includes(record)
) {
roa =
res.retrievedRecord
.getRoAId()
.equals(res.retrievedRecord.getContent()) &&
res.retrievedRecord.header.rightOfAssociationValidation ===
Validation.Ethereum;
Validation.Ethereum;
} else if ([Record.Url]) {
const guardian = GUARDIANS.get(record);
if (guardian) {
roa =
res.retrievedRecord.getRoAId().equals(guardian.toBuffer()) &&
res.retrievedRecord.header.rightOfAssociationValidation ===
Validation.Solana;
Validation.Solana;
}
}

Expand Down Expand Up @@ -684,4 +681,29 @@ app.get("/create-sub", async (c) => {
}
});

/**
* Returns the base64 encoded data of a .sol domain
*/
app.get("/domain-data/:domain", async (c) => {
try {
const { domain } = c.req.param();
const rpc = c.req.query("rpc");
const connection = getConnection(c, rpc);

const { pubkey: domainKey } = getDomainKeySync(domain);
const info = await connection.getAccountInfo(domainKey);

if (!info) {
return c.json(response(false, "Domain not found"));
}

const base64Data = info.data.toString("base64");

return c.json(response(true, base64Data));
} catch (err) {
console.log(err);
return c.json(response(false, "Error fetching domain data"));
}
});

export default app;

0 comments on commit 57a4f22

Please sign in to comment.