From 9e2678684a81e4d278f54c7d1154a9c0b5e44e95 Mon Sep 17 00:00:00 2001 From: Enzo Cioppettini Date: Tue, 30 Jan 2024 12:05:40 -0300 Subject: [PATCH] add more comments in the code --- .../controllers/TransactionHistoryController.ts | 16 +++++++++------- webserver/shared/models/TransactionHistory.ts | 7 ++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/webserver/server/app/controllers/TransactionHistoryController.ts b/webserver/server/app/controllers/TransactionHistoryController.ts index 9c9a1c0a..33f4297e 100644 --- a/webserver/server/app/controllers/TransactionHistoryController.ts +++ b/webserver/server/app/controllers/TransactionHistoryController.ts @@ -98,6 +98,8 @@ export class TransactionHistoryController extends Controller { let pageStartWithSlot = pageStart; + // if the slotLimits field is set, this shrinks the tx id range + // accordingly if necessary. if (requestBody.slotLimits) { const bounds = slotBounds ? slotBounds[0] : { min_tx_id: -1, max_tx_id: -2 }; @@ -105,19 +107,19 @@ export class TransactionHistoryController extends Controller { if (!pageStartWithSlot) { pageStartWithSlot = { + // block_id is not really used by this query. block_id: -1, + // if no *after* argument is provided, this starts the pagination + // from the corresponding slot. This allows skipping slots you are + // not interested in. If there is also no slotLimits specified this + // starts from the first tx because of the default of -1. tx_id: minTxId, }; } else { - if (minTxId > pageStartWithSlot.tx_id) { - pageStartWithSlot.tx_id = minTxId; - } + pageStartWithSlot.tx_id = Math.max(Number(bounds.min_tx_id), pageStartWithSlot.tx_id); } - const maxTxId = Number(bounds.max_tx_id); - if (maxTxId < until.tx_id) { - until.tx_id = maxTxId; - } + until.tx_id = Math.min(until.tx_id, Number(bounds.max_tx_id)); } const commonRequest = { diff --git a/webserver/shared/models/TransactionHistory.ts b/webserver/shared/models/TransactionHistory.ts index 39a3e863..bab38426 100644 --- a/webserver/shared/models/TransactionHistory.ts +++ b/webserver/shared/models/TransactionHistory.ts @@ -1,6 +1,5 @@ import type { Address } from "./Address"; import type { BlockSubset } from "./BlockLatest"; -import { AssetName, PolicyId } from "./PolicyIdAssetMap"; import type { Pagination, RelationFilter } from "./common"; export type TransactionHistoryRequest = { @@ -10,7 +9,11 @@ export type TransactionHistoryRequest = { /** Defaults to `ADDRESS_LIMIT.RESPONSE` */ limit?: number; + /** This limits the transactions in the result to this range of slots. + * Everything else is filtered out */ slotLimits?: SlotLimits; + /** If this is set to true, the result includes the input addresses (which are + * not part of the tx), and the metadata (if any) */ withInputContext?: boolean; } & Pagination; @@ -52,6 +55,8 @@ export type TransactionHistoryResponse = { }; export type SlotLimits = { + // this is exclusive from: number; + // this is inclusive to: number; };