From 6e278fbc456f0206689c6a853c10d9a18564bf90 Mon Sep 17 00:00:00 2001 From: Alec Ananian <1013230+alecananian@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:24:28 -0800 Subject: [PATCH] add verify harvester endpoint --- serverless.yml | 6 ++++++ src/handlers/bridgeworld.js | 13 +++++++++++++ src/services/bridgeworld.js | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/serverless.yml b/serverless.yml index 0142899..91ec8b9 100644 --- a/serverless.yml +++ b/serverless.yml @@ -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 diff --git a/src/handlers/bridgeworld.js b/src/handlers/bridgeworld.js index d6453fe..d5c75c9 100644 --- a/src/handlers/bridgeworld.js +++ b/src/handlers/bridgeworld.js @@ -3,6 +3,7 @@ const { getMines, getLegionHolders, hasGenesisLegion, + hasHarvesterAccess, } = require("../services/bridgeworld"); exports.getCorruption = getCorruption; @@ -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), + }; +}; diff --git a/src/services/bridgeworld.js b/src/services/bridgeworld.js index d1d4276..722af56 100644 --- a/src/services/bridgeworld.js +++ b/src/services/bridgeworld.js @@ -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; +};