Skip to content

Commit

Permalink
add verify harvester endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Mar 7, 2024
1 parent e1dabee commit 6e278fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ functions:
- httpApi:
path: /bridgeworld/legions/verify
method: post
verifyHarvesterAccess:
handler: src/handlers/bridgeworld.verifyHarvesterAccess
events:
- httpApi:
path: /bridgeworld/harvesters/{id}/verify
method: post
13 changes: 13 additions & 0 deletions src/handlers/bridgeworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
getMines,
getLegionHolders,
hasGenesisLegion,
hasHarvesterAccess,
} = require("../services/bridgeworld");

exports.getCorruption = getCorruption;
Expand All @@ -21,3 +22,15 @@ exports.verifyGenesisLegionHolders = async (event) => {
success: await hasGenesisLegion(wallets),
};
};

exports.verifyHarvesterAccess = async (event) => {
const body = JSON.parse(event.body);
const wallets = (body.wallets || body.wallet || []).map((wallet) =>
wallet.toLowerCase()
);
const id = event.pathParameters.id.toLowerCase();
console.log("Querying Harvester access for wallets:", id, wallets);
return {
success: await hasHarvesterAccess(id, wallets),
};
};
18 changes: 18 additions & 0 deletions src/services/bridgeworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,21 @@ exports.hasGenesisLegion = async (wallets) => {
}`);
return tokens.length > 0;
};

exports.hasHarvesterAccess = async (id, wallets) => {
const { stakedTokens = [] } = await querySubgraph(`{
stakedTokens(
first: 1000
where: {
user_in: ["${wallets.join('","')}"]
harvester: "${id}"
token_: {
category: Consumable
}
}
) {
id
}
}`);
return stakedTokens.length > 0;
};

0 comments on commit 6e278fb

Please sign in to comment.