Get Orchestrator by delegator if getDelegator returns empty results

This commit is contained in:
Marco van Dijk 2022-03-07 12:33:05 +01:00
parent 3815b70f66
commit a5252eb3e9
3 changed files with 29 additions and 1 deletions

View File

@ -468,6 +468,10 @@ const parseOrchestrator = async function (reqAddr) {
`; `;
orchestratorObj = await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", orchQuery); orchestratorObj = await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", orchQuery);
orchestratorObj = orchestratorObj.transcoders[0]; orchestratorObj = orchestratorObj.transcoders[0];
// Not found
if (!orchestratorObj){
return JSON.stringify({});
}
orchestratorObj.lastGet = now; orchestratorObj.lastGet = now;
if (wasCached) { if (wasCached) {
for (var orch of orchestratorCache) { for (var orch of orchestratorCache) {
@ -493,6 +497,7 @@ apiRouter.get("/getOrchestrator", async (req, res) => {
const reqObj = await parseOrchestrator(reqOrch); const reqObj = await parseOrchestrator(reqOrch);
res.send(reqObj); res.send(reqObj);
} catch (err) { } catch (err) {
console.log(err);
res.status(400).send(err); res.status(400).send(err);
} }
}); });
@ -501,6 +506,7 @@ apiRouter.get("/getOrchestrator/:orch", async (req, res) => {
const reqObj = await parseOrchestrator(req.params.orch); const reqObj = await parseOrchestrator(req.params.orch);
res.send(reqObj); res.send(reqObj);
} catch (err) { } catch (err) {
console.log(err);
res.status(400).send(err); res.status(400).send(err);
} }
}); });
@ -509,6 +515,7 @@ apiRouter.post("/getOrchestrator", async (req, res) => {
const reqObj = await parseOrchestrator(req.body.orchAddr); const reqObj = await parseOrchestrator(req.body.orchAddr);
res.send(reqObj); res.send(reqObj);
} catch (err) { } catch (err) {
console.log(err);
res.status(400).send(err); res.status(400).send(err);
} }
}); });
@ -549,6 +556,10 @@ const parseDelegator = async function (reqAddr) {
`; `;
delegatorObj = await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", delegatorQuery); delegatorObj = await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", delegatorQuery);
delegatorObj = delegatorObj.delegators[0]; delegatorObj = delegatorObj.delegators[0];
// Not found
if (!delegatorObj){
return {};
}
delegatorObj.lastGet = now; delegatorObj.lastGet = now;
if (wasCached) { if (wasCached) {
for (var delegator of delegatorCache) { for (var delegator of delegatorCache) {

View File

@ -358,7 +358,15 @@ export const getOrchestratorInfo = (orchAddr) => async dispatch => {
const response = await apiUtil.getOrchestratorInfo(orchAddr); const response = await apiUtil.getOrchestratorInfo(orchAddr);
const data = await response.json(); const data = await response.json();
if (response.ok) { if (response.ok) {
return dispatch(setOrchestratorInfo(data)); if (data && data.id){
return dispatch(setOrchestratorInfo(data));
}else{
const response = await apiUtil.getOrchestratorByDelegator(orchAddr);
const data = await response.json();
if (response.ok) {
return dispatch(setOrchestratorInfo(data));
}
}
} }
return dispatch(receiveErrors(data)); return dispatch(receiveErrors(data));
}; };

View File

@ -44,3 +44,12 @@ export const getOrchestratorInfo = (orchAddr) => (
} }
}) })
); );
export const getOrchestratorByDelegator = (delAddr) => (
fetch("api/livepeer/getOrchestratorByDelegator/" + delAddr, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
);