Skip to content

Commit

Permalink
Fix wrong parameter name for balance endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0237h committed Dec 15, 2023
1 parent 106541b commit 116c6d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Binary file modified buffer.db
Binary file not shown.
4 changes: 2 additions & 2 deletions src/fetch/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { toJSON } from "./utils.js";

function verifyParams(searchParams: URLSearchParams) {
const chain = searchParams.get("chain");
const owner = searchParams.get("owner");
const account = searchParams.get("account");
const contract = searchParams.get("contract");

if (!chain) throw new Error("chain is required");
if (!owner && !contract) throw new Error("owner or contract is required");
if (!account && !contract) throw new Error("account or contract is required");
}

export default async function (req: Request) {
Expand Down
24 changes: 12 additions & 12 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function addTimestampBlockFilter(searchParams: URLSearchParams, where: an
["greater", ">"],
["less_or_equals", "<="],
["less", "<"],
];
];

for (const [key, operator] of operators) {
const block_number = searchParams.get(`${key}_by_block`);
Expand All @@ -24,7 +24,7 @@ export function addAmountFilter(searchParams: URLSearchParams, where: any[]) {
["greater", ">"],
["less_or_equals", "<="],
["less", "<"],
];
];

for (const [key, operator] of operators) {
const amount = searchParams.get(`amount_${key}`);
Expand Down Expand Up @@ -96,8 +96,8 @@ export function getBalanceChanges(searchParams: URLSearchParams, example?: boole
if (where.length) query += ` WHERE(${where.join(' AND ')})`;

if (contract && account) query += ` ORDER BY timestamp DESC`;
if (!contract && account) query += `GROUP BY (contract, account) ORDER BY timestamp DESC`;
if (contract && !account) query += `GROUP BY (contract, account) ORDER BY timestamp DESC`;
//if (!contract && account) query += `GROUP BY (contract, account) ORDER BY timestamp DESC`;
//if (contract && !account) query += `GROUP BY (contract, account) ORDER BY timestamp DESC`;
}

const limit = parseLimit(searchParams.get("limit"));
Expand All @@ -123,14 +123,14 @@ export function getTransfers(searchParams: URLSearchParams, example?: boolean) {
let mvContractTable = "mv_transfers_contract";

let query = `SELECT
from,
to,
value as amount,
symcode,
trx_id as transaction_id,
block_number,
timestamp,
chain`;
from,
to,
value as amount,
symcode,
trx_id as transaction_id,
block_number,
timestamp,
chain`;

/*if (contract) query += ` FROM ${mvContractTable}`
else if (!contract && from && !to) query += ` FROM ${mvFromTable}`
Expand Down

0 comments on commit 116c6d3

Please sign in to comment.