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

feat(gateways): add REST APIs for calling gateways read interactions #99

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,44 @@
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,
async (ctx: KoaContext) => {
ctx.params.functionName = 'gateways';
await contractReadInteractionHandler(ctx);

// map the response to the expected format
const { result, ...restOfBody } = ctx.body as any;

Check warning on line 84 in src/router.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
ctx.body = {
...restOfBody,
gateways: result,
};
},
);
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,
async (ctx: KoaContext) => {
ctx.params.functionName = 'gateway';
ctx.query = {
...ctx.query,
target: ctx.params.address,
};
await contractReadInteractionHandler(ctx);

// map the response to the expected format
const { result, ...restOfBody } = ctx.body as any;

Check warning on line 104 in src/router.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
ctx.body = {
...restOfBody,
gateway: {
[ctx.params.address]: result,
},
};
},
);
router.get(
`/v1/contract/:contractTxId${ARWEAVE_TX_ID_REGEX}/balances/:address${ARWEAVE_TX_ID_REGEX}`,
blocklistMiddleware,
Expand Down
Loading