Skip to content

Commit

Permalink
add more comments in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Jan 30, 2024
1 parent fec0f3b commit 9e26786
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 9 additions & 7 deletions webserver/server/app/controllers/TransactionHistoryController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,28 @@ 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 };

const minTxId = Number(bounds.min_tx_id);

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 = {
Expand Down
7 changes: 6 additions & 1 deletion webserver/shared/models/TransactionHistory.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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;

Expand Down Expand Up @@ -52,6 +55,8 @@ export type TransactionHistoryResponse = {
};

export type SlotLimits = {
// this is exclusive
from: number;
// this is inclusive
to: number;
};

0 comments on commit 9e26786

Please sign in to comment.