Skip to content

Commit

Permalink
feat: getExplorers function and updated Blockscout explorer URL (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Aug 21, 2023
1 parent 0af3561 commit 5018391
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
{
"type": "explorer",
"url": "https://zetachain-athens-2.blockscout.com",
"url": "https://zetachain-athens-3.blockscout.com",
"tx": "/tx/${tx}",
"address": "/address/${address}"
}
Expand Down
30 changes: 30 additions & 0 deletions src/getExplorers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NetworksSchema } from "./types";
import networks from "./networks";

export const getExplorers = (
input: string,
inputType: "address" | "tx",
networkKey: keyof NetworksSchema
): string[] => {
const network = networks[networkKey as keyof typeof networks];
if (!network) {
throw new Error("Network not found");
}

if (!("apps" in network) || !Array.isArray(network.apps)) {
throw new Error("Explorers not available for the provided network");
}

const explorerApps = network.apps.filter((app) => app.type === "explorer");

const urls: string[] = [];
for (const app of explorerApps) {
if (inputType === "address" && app.address) {
urls.push(app.url + app.address.replace("${address}", input));
} else if (inputType === "tx" && app.tx) {
urls.push(app.url + app.tx.replace("${tx}", input));
}
}

return urls;
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./getEndpoints";
export * from "./getHardhatConfigNetworks";
export * from "./getSupportedNetworks";
export * from "./getExplorers";
export { default as networks } from "./networks";
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export type ApiType =
| "evm"
| "tendermint-rpc"
| "tendermint-http"
| "cosmos-http"
| "tendermint-ws"
| "cosmos-grpc"
Expand Down

0 comments on commit 5018391

Please sign in to comment.