-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
merge-openrpc.js
67 lines (61 loc) · 1.82 KB
/
merge-openrpc.js
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
67
const fs = require("fs");
const fetch = require("node-fetch");
const mergeOpenRPC = require("./merge-utils");
const yaml = require("js-yaml");
const MetaMaskOpenRPC = yaml.load(fs.readFileSync(__dirname + "/openrpc.yaml", "utf8"));
const TransportOpenRPC = yaml.load(fs.readFileSync(__dirname + "/multichain/openrpc.yaml", "utf8"));
const getFilteredExecutionAPIs = () => {
return fetch("https://raw.githubusercontent.com/ethereum/execution-apis/337eec34772dc15228092e032fd299042e1ece99/refs-openrpc.json")
.then(async (res) => {
return filterExecutionAPIs(await res.json());
});
}
// fetch, merge and write
getFilteredExecutionAPIs().then((EthereumOpenRPC) => {
EthereumOpenRPC.methods.forEach((method) => {
const ethereumTag = {
name: "Ethereum API",
description: "Ethereum Node JSON-RPC method",
};
const multichainTag = {
name: "Multichain API",
description: "Multichain JSON-RPC method",
};
if (method.tags) {
method.tags.push(ethereumTag, multichainTag);
} else {
method.tags = [ethereumTag, multichainTag];
}
});
fs.writeFileSync(__dirname + "/src/build/openrpc.json",
JSON.stringify(
mergeOpenRPC(MetaMaskOpenRPC, EthereumOpenRPC),
null,
4
)
);
fs.writeFileSync(__dirname + "/src/build/multichain-openrpc.json",
JSON.stringify(
TransportOpenRPC,
null,
4
)
);
});
const unneeded = [
/eth_signTransaction/,
/eth_sign/,
/debug_.*/,
/engine_.*/,
/eth_createAccessList/,
/eth_getBlockReceipts/,
/eth_maxPriorityFeePerGas/,
/eth_blobBaseFee/,
];
const filterExecutionAPIs = (openrpcDocument) => {
openrpcDocument.methods = openrpcDocument.methods.filter((method) => {
const matches = unneeded.some((regex) => regex.test(method.name));
return !matches;
});
return openrpcDocument;
};