-
Notifications
You must be signed in to change notification settings - Fork 12
/
inspect.ts
66 lines (62 loc) · 1.83 KB
/
inspect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Command } from "@oclif/command";
import chalk from "chalk";
import { ethers } from "ethers";
import { cancelled, get } from "../lib/prompt";
import * as requests from "../lib/requests";
import * as utils from "../lib/utils";
import { getWallet } from "../lib/wallet";
import { protocolInterfaces, protocolNames } from "@airswap/utils";
export default class Inspect extends Command {
public static description = "inspect protocols for a server";
public async run() {
try {
const wallet = await getWallet(this);
const chainId = (await wallet.provider.getNetwork()).chainId;
utils.displayDescription(this, Inspect.description, chainId);
const { locator }: any = await get({
locator: {
type: "Locator",
},
});
this.log();
requests.peerCall(locator, "getProtocols", {}, async (err, protocols) => {
if (err) {
if (err === "timeout") {
this.log(chalk.yellow("The request timed out.\n"));
} else {
cancelled(err);
}
process.exit(0);
} else {
this.log(chalk.white.bold("supported protocols and methods\n"));
const unknown = [];
for (const p in protocols) {
const interfaceId = protocols[p].interfaceId;
const functions = protocolInterfaces[interfaceId];
if (functions) {
const _interface = new ethers.utils.Interface(
protocolInterfaces[interfaceId],
);
this.log(protocolNames[interfaceId]);
for (const f in _interface.fragments) {
this.log("· ", _interface.fragments[f].name);
}
this.log();
} else {
unknown.push(interfaceId);
}
}
if (unknown.length) {
this.log(chalk.yellow("Unknown interfaces"));
for (const u in unknown) {
this.log("· ", chalk.yellow(unknown[u]));
}
}
}
this.log();
});
} catch (e) {
cancelled(e);
}
}
}