Skip to content

Commit

Permalink
refactor transactions api route
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Sep 21, 2023
1 parent e1b0590 commit ce74398
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,15 @@ const parsedQueryParamsWithDefaults = queryParams => {
return params;
}

const getTransactions = async url => {
const formatTransactions = transactionData => {
// SCHEMA:
// key: 'vaultTxs:0x...'
// score: timestamp
// value: 'type:hash:blockNo:asset:amount:amountDec:minted:collateralValue'
// e.g. 'deposit:0x8ae26a528861d3e6c08d4331885eaba2d1b5b55fc540234fc9b8c9c198a0d429:124132949:PAXG:8000000000000000:18:136175000000000000000:181087962079756018667'
const schema = ['type','txHash','blockNo','asset','amount','assetDec','minted','totalCollateralValue'];

const {address, queryParams} = vaultTransactionsAddress(url);
const { page, limit, sort } = parsedQueryParamsWithDefaults(queryParams);
const start = (page - 1) * limit;
const end = start + limit - 1;
const REV = !(sort === 'asc');
const key = getTransactionsKey(address)
await redis.connect();
const transactionData = await redis.ZRANGE_WITHSCORES(key, start, end, {REV});
const count = await redis.ZCARD(key);
await redis.disconnect();
const transactions = transactionData.map(data => {
return transactionData.map(data => {
const labelledData = {
timestamp: data.score
};
Expand All @@ -62,6 +52,20 @@ const getTransactions = async url => {
}
}, labelledData);
});
}

const getTransactions = async url => {
const {address, queryParams} = vaultTransactionsAddress(url);
const { page, limit, sort } = parsedQueryParamsWithDefaults(queryParams);
const start = (page - 1) * limit;
const end = start + limit - 1;
const REV = !(sort === 'asc');
const key = getTransactionsKey(address)
await redis.connect();
const transactionData = await redis.ZRANGE_WITHSCORES(key, start, end, {REV});
const count = await redis.ZCARD(key);
await redis.disconnect();
const transactions = formatTransactions(transactionData);
return {
data: transactions,
pagination: {
Expand Down

0 comments on commit ce74398

Please sign in to comment.