Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat(gateways): add REST APIs for calling gateways read interactions
Browse files Browse the repository at this point in the history
The read interactions provide additional context about the weights of each gateway, we may want to change `result` to `gateways` in the contract.
  • Loading branch information
dtfiedler committed Jan 25, 2024
1 parent 15a9c09 commit 8afc082
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const PREFETCH_CONTRACTS = process.env.PREFETCH_CONTRACTS === 'true';
export const BOOTSTRAP_CACHE = process.env.BOOTSTRAP_CACHE === 'true';
export const BLOCKLISTED_CONTRACT_IDS = process.env.BLOCKLISTED_CONTRACT_IDS
? process.env.BLOCKLISTED_CONTRACT_IDS.split(',')
: ['fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ'];
: [];
export const ARWEAVE_TX_ID_REGEX = '([a-zA-Z0-9-_s+]{43})';
export const ARNS_NAME_REGEX = '([a-zA-Z0-9-s+]{1,51})';
export const SUB_CONTRACT_EVALUATION_TIMEOUT_MS = 10_000; // 10 sec state timeout - non configurable
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const DEFAULT_PAGE_SIZE = 100;
const DEFAULT_PAGE = 1;
export const queryMiddleware = async (ctx: KoaContext, next: Next) => {
const {
blockHeight,
blockHeight = 1344484,
sortKey,
page = DEFAULT_PAGE,
pageSize = DEFAULT_PAGE_SIZE,
Expand Down
22 changes: 22 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ router.get(
blocklistMiddleware,
contractRecordFilterHandler,
);
router.get(
// calls the read interaction handler with the function name set to gateways
`/v1/contract/:contractTxId${ARWEAVE_TX_ID_REGEX}/gateways`,
blocklistMiddleware,
(ctx: KoaContext) => {
ctx.params.functionName = 'gateways';
return contractReadInteractionHandler(ctx);
},
);
router.get(
// calls the read interaction handler with the function name set to gateway and target set to the path param
`/v1/contract/:contractTxId${ARWEAVE_TX_ID_REGEX}/gateways/:address${ARWEAVE_TX_ID_REGEX}`,
blocklistMiddleware,
(ctx: KoaContext) => {
ctx.params.functionName = 'gateway';
ctx.query = {
...ctx.query,
target: ctx.params.address,
};
return contractReadInteractionHandler(ctx);
},
);
router.get(
`/v1/contract/:contractTxId${ARWEAVE_TX_ID_REGEX}/balances/:address${ARWEAVE_TX_ID_REGEX}`,
blocklistMiddleware,
Expand Down
1 change: 1 addition & 0 deletions src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const prefetchContracts = async () => {
return getContractState({
contractTxId,
warp,
blockHeight: 1344484,
logger: logger.child({ prefetch: true }),
})
.then(() => {
Expand Down

0 comments on commit 8afc082

Please sign in to comment.