Skip to content

Commit

Permalink
Add API to return evm tx, #974
Browse files Browse the repository at this point in the history
  • Loading branch information
wliyongfeng committed Nov 22, 2024
1 parent 4cd2838 commit 8eb8f2e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
32 changes: 32 additions & 0 deletions backend/packages/server/src/features/txs/controllers/tx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const {
block: { getEvmTxCol, getExtrinsicCollection },
} = require("@statescan/mongo");
const { HttpError } = require("../../../utils");

async function getTx(ctx) {
const { hash } = ctx.params;
const evmCol = await getEvmTxCol();
const evmTx = await evmCol.findOne({ hash }, { projection: { _id: 0 } });
if (evmTx) {
ctx.body = {
isEvm: true,
...evmTx,
};
return;
}

const exCol = await getExtrinsicCollection();
const extrinsic = await exCol.findOne({ hash }, { projection: { _id: 0 } });
if (!extrinsic) {
throw new HttpError(404, "extrinsic not found");
}

ctx.body = {
isEvm: false,
...extrinsic,
};
}

module.exports = {
getTx,
};
8 changes: 8 additions & 0 deletions backend/packages/server/src/features/txs/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Router = require("koa-router");
const { getTx } = require("./controllers/tx");

const router = new Router();

router.get("/txs/:hash", getTx);

module.exports = router;
1 change: 1 addition & 0 deletions backend/packages/server/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const routes = [
require("./features/runtime/routes"),
require("./features/status/routes"),
require("./features/overview/routes"),
require("./features/txs/routes"),
];

const assetsRoutes = [require("./features/assets/routes")];
Expand Down

0 comments on commit 8eb8f2e

Please sign in to comment.