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

Commit

Permalink
chore(gateways): modify responses from the contract to match our curr…
Browse files Browse the repository at this point in the history
…ent strucutre

This behavior could easily be moved to the contract, there is not a specific reason why `result` has to be the response of any read interactions
  • Loading branch information
dtfiedler committed Jan 25, 2024
1 parent 5667df5 commit f80e622
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,38 @@ 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) => {
async (ctx: KoaContext) => {
ctx.params.functionName = 'gateways';
return contractReadInteractionHandler(ctx);
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,
(ctx: KoaContext) => {
async (ctx: KoaContext) => {
ctx.params.functionName = 'gateway';
ctx.query = {
...ctx.query,
target: ctx.params.address,
};
return contractReadInteractionHandler(ctx);
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(
Expand Down

0 comments on commit f80e622

Please sign in to comment.