From ba79d7dbf26d5248c9025ea3b1a508b433e1ca44 Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Fri, 24 May 2024 16:21:07 +0800 Subject: [PATCH] Updated topMakers to return user accounts in buffer format --- src/index.ts | 6 +++++- src/utils/utils.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b3857af..1bf41a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ import { sleep, validateDlobQuery, getAccountFromId, + getRawAccountFromId, } from './utils/utils'; import FEATURE_FLAGS from './utils/featureFlags'; import { getDLOBProviderFromOrderSubscriber } from './dlobProvider'; @@ -572,7 +573,10 @@ const main = async (): Promise => { res.writeHead(200); if (accountFlag) { - const topAccounts = await getAccountFromId(userMapClient, topMakers); + const topAccounts = await getRawAccountFromId( + userMapClient, + topMakers + ); res.end(JSON.stringify(topAccounts)); return; } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b82d743..1a7c16a 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -364,6 +364,32 @@ export const getAccountFromId = async ( ).then((results) => results.filter((user) => !!user)); }; +export const getRawAccountFromId = async ( + userMapClient: RedisClient, + topMakers: string[] +): Promise< + { + userAccountPubKey: string; + accountBase64: string; + }[] +> => { + return Promise.all( + topMakers.map(async (userAccountPubKey) => { + const userAccountEncoded = await userMapClient.getRaw(userAccountPubKey); + if (userAccountEncoded) { + return { + userAccountPubKey, + accountBase64: userAccountEncoded.split('::')[1], + }; + } + return { + userAccountPubKey, + accountBase64: null, + }; + }) + ).then((results) => results.filter((user) => !!user)); +}; + export function errorHandler( err: Error, _req: Request,