Updated topMakers to return user accounts in buffer format

This commit is contained in:
Luke Steyn
2024-05-24 16:21:07 +08:00
parent a2c4dc44fb
commit ba79d7dbf2
2 changed files with 31 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ import {
sleep, sleep,
validateDlobQuery, validateDlobQuery,
getAccountFromId, getAccountFromId,
getRawAccountFromId,
} from './utils/utils'; } from './utils/utils';
import FEATURE_FLAGS from './utils/featureFlags'; import FEATURE_FLAGS from './utils/featureFlags';
import { getDLOBProviderFromOrderSubscriber } from './dlobProvider'; import { getDLOBProviderFromOrderSubscriber } from './dlobProvider';
@@ -572,7 +573,10 @@ const main = async (): Promise<void> => {
res.writeHead(200); res.writeHead(200);
if (accountFlag) { if (accountFlag) {
const topAccounts = await getAccountFromId(userMapClient, topMakers); const topAccounts = await getRawAccountFromId(
userMapClient,
topMakers
);
res.end(JSON.stringify(topAccounts)); res.end(JSON.stringify(topAccounts));
return; return;
} }

View File

@@ -364,6 +364,32 @@ export const getAccountFromId = async (
).then((results) => results.filter((user) => !!user)); ).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( export function errorHandler(
err: Error, err: Error,
_req: Request, _req: Request,