Skip to content

Commit

Permalink
feat: checking label's availability
Browse files Browse the repository at this point in the history
  • Loading branch information
charmful0x authored Oct 13, 2021
1 parent dbce2a2 commit c3e1498
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ async function rewardPerUser(address) {
return {};
}

async function isOwned(label) {
const contract = smartweave.contract(ANS_CONTRACT_ID).connect(jwk);

const response = await contract.viewState({
function: "isOwned",
label: `${label}`,
});

if (response.type !== "ok") {
return response.errorMessage;
}

return response.result;
}

// HELPER FUNCTIONS
async function _getState() {
const contract = smartweave.contract(ANS_CONTRACT_ID);
Expand Down Expand Up @@ -132,6 +147,13 @@ app.get("/earning/:address", async (req, res) => {
res.send(earnings);
});

app.get("/isOwned/:label", async (req, res) => {
res.setHeader("Content-Type", "application/json");
const result = await isOwned(req.params.label);

res.send(result);
});

app.listen(port, () => {
console.log(`listening at http://localhost:${port}`);
});

0 comments on commit c3e1498

Please sign in to comment.