Content-Length: 304929 | pFad | http://github.com/ecency/vision-api/commit/876ce930178a91d6e8d74d991247a726bf8187f8

AF simple fallback for engine nodes · ecency/vision-api@876ce93 · GitHub
Skip to content

Commit

Permalink
simple fallback for engine nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
feruzm committed Aug 12, 2024
1 parent 594a450 commit 876ce93
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions src/server/handlers/wallet-api.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,12 @@ const ENGINE_NODES = [
"https://api2.hive-engine.com/rpc"
];

const BASE_ENGINE_URL = ENGINE_NODES[0];
// min and max included
const randomIntFromInterval = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1) + min);
}

let BASE_ENGINE_URL = `${ENGINE_NODES[randomIntFromInterval(0,6)]}/contracts`;
const BASE_SPK_URL = 'https://spk.good-karma.xyz';

const ENGINE_REWARDS_URL = 'https://scot-api.hive-engine.com/';
@@ -34,7 +39,7 @@ export const PATH_CONTRACTS = 'contracts';
//client engine api requests
export const eapi = async (req: express.Request, res: express.Response) => {
const data = req.body;
pipe(engineContractsRequest(data), res);
pipe(engineContractsRequest(data, BASE_ENGINE_URL), res);
}


@@ -64,8 +69,7 @@ export const engineAccountHistory = (req: express.Request, res: express.Response


//raw engine api call
const engineContractsRequest = (data: EngineRequestPayload) => {
const url = `${BASE_ENGINE_URL}/${PATH_CONTRACTS}`;
const engineContractsRequest = (data: EngineRequestPayload, url: string) => {
const headers = { 'Content-type': 'application/json', 'User-Agent': 'Ecency' };

return baseApiRequest(url, "POST", headers, data)
@@ -80,8 +84,6 @@ const engineRewardsRequest = (username:string, params:any) => {
}




//engine contracts methods
export const fetchEngineBalances = async (account: string): Promise<TokenBalance[]> => {
const data: EngineRequestPayload = {
@@ -96,14 +98,25 @@ export const fetchEngineBalances = async (account: string): Promise<TokenBalance
},
id: EngineIds.ONE,
};
try {
const response = await engineContractsRequest(data, BASE_ENGINE_URL);

const response = await engineContractsRequest(data);
if (!response.data?.result) {
throw new Error("Failed to get engine balances")
}

if (!response.data?.result) {
throw new Error("Failed to get engine balances")
return response.data.result;
}
catch (e) {
BASE_ENGINE_URL = `${ENGINE_NODES[randomIntFromInterval(0,6)]}/contracts`;
const response = await engineContractsRequest(data, BASE_ENGINE_URL);

if (!response.data?.result) {
throw new Error("Failed to get engine balances")
}

return response.data.result;
return response.data.result;
}
};


@@ -120,14 +133,24 @@ export const fetchEngineTokens = async (tokens: string[]): Promise<Token[]> => {
},
id: EngineIds.ONE,
};
try {
const response = await engineContractsRequest(data, BASE_ENGINE_URL);

const response = await engineContractsRequest(data);
if (!response.data?.result) {
throw new Error("Failed to get engine tokens data")
}

if (!response.data?.result) {
throw new Error("Failed to get engine tokens data")
}
return response.data.result;
} catch(e) {
BASE_ENGINE_URL = `${ENGINE_NODES[randomIntFromInterval(0,6)]}/contracts`;
const response = await engineContractsRequest(data, BASE_ENGINE_URL);

return response.data.result;
if (!response.data?.result) {
throw new Error("Failed to get engine tokens data")
}

return response.data.result;
}
}


@@ -144,14 +167,23 @@ export const fetchEngineMetics = async (tokens: string[]): Promise<EngineMetric[
},
id: EngineIds.ONE,
};
try {
const response = await engineContractsRequest(data, BASE_ENGINE_URL);

const response = await engineContractsRequest(data);
if (!response.data?.result) {
throw new Error("Failed to get engine metrics data")
}

if (!response.data?.result) {
throw new Error("Failed to get engine metrics data")
}
return response.data.result;
} catch(e) {
BASE_ENGINE_URL = `${ENGINE_NODES[randomIntFromInterval(0,6)]}/contracts`;
const response = await engineContractsRequest(data, BASE_ENGINE_URL);

return response.data.result;
if (!response.data?.result) {
throw new Error("Failed to get engine metrics data")
}
return response.data.result;
}
}


0 comments on commit 876ce93

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/ecency/vision-api/commit/876ce930178a91d6e8d74d991247a726bf8187f8

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy