Skip to content

Commit bf87eae

Browse files
committed
Implement JSON-RPC API namespace separation in documentation
1 parent 3779ff9 commit bf87eae

File tree

8 files changed

+264
-13
lines changed

8 files changed

+264
-13
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Debug Namespace
6+
7+
This page lists all JSON-RPC methods in the debug namespace.
8+
9+
- [debug_getBadBlocks](/reference/debug_getBadBlocks)
10+
- [debug_getRawBlock](/reference/debug_getRawBlock)
11+
- [debug_getRawHeader](/reference/debug_getRawHeader)
12+
- [debug_getRawReceipts](/reference/debug_getRawReceipts)
13+
- [debug_getRawTransaction](/reference/debug_getRawTransaction)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Engine Namespace
6+
7+
This page lists all JSON-RPC methods in the engine namespace.
8+
9+
- [engine_exchangeCapabilities](/reference/engine_exchangeCapabilities)
10+
- [engine_exchangeTransitionConfigurationV1](/reference/engine_exchangeTransitionConfigurationV1)
11+
- [engine_forkchoiceUpdatedV1](/reference/engine_forkchoiceUpdatedV1)
12+
- [engine_forkchoiceUpdatedV2](/reference/engine_forkchoiceUpdatedV2)
13+
- [engine_forkchoiceUpdatedV3](/reference/engine_forkchoiceUpdatedV3)
14+
- [engine_getBlobsV1](/reference/engine_getBlobsV1)
15+
- [engine_getBlobsV2](/reference/engine_getBlobsV2)
16+
- [engine_getPayloadBodiesByHashV1](/reference/engine_getPayloadBodiesByHashV1)
17+
- [engine_getPayloadBodiesByRangeV1](/reference/engine_getPayloadBodiesByRangeV1)
18+
- [engine_getPayloadV1](/reference/engine_getPayloadV1)
19+
- [engine_getPayloadV2](/reference/engine_getPayloadV2)
20+
- [engine_getPayloadV3](/reference/engine_getPayloadV3)
21+
- [engine_getPayloadV4](/reference/engine_getPayloadV4)
22+
- [engine_getPayloadV5](/reference/engine_getPayloadV5)
23+
- [engine_newPayloadV1](/reference/engine_newPayloadV1)
24+
- [engine_newPayloadV2](/reference/engine_newPayloadV2)
25+
- [engine_newPayloadV3](/reference/engine_newPayloadV3)
26+
- [engine_newPayloadV4](/reference/engine_newPayloadV4)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# ETH Namespace
6+
7+
This page lists all JSON-RPC methods in the eth namespace.
8+
9+
- [eth_accounts](/reference/eth_accounts)
10+
- [eth_blobBaseFee](/reference/eth_blobBaseFee)
11+
- [eth_blockNumber](/reference/eth_blockNumber)
12+
- [eth_call](/reference/eth_call)
13+
- [eth_chainId](/reference/eth_chainId)
14+
- [eth_coinbase](/reference/eth_coinbase)
15+
- [eth_createAccessList](/reference/eth_createAccessList)
16+
- [eth_estimateGas](/reference/eth_estimateGas)
17+
- [eth_feeHistory](/reference/eth_feeHistory)
18+
- [eth_gasPrice](/reference/eth_gasPrice)
19+
- [eth_getBalance](/reference/eth_getBalance)
20+
- [eth_getBlockByHash](/reference/eth_getBlockByHash)
21+
- [eth_getBlockByNumber](/reference/eth_getBlockByNumber)
22+
- [eth_getBlockReceipts](/reference/eth_getBlockReceipts)
23+
- [eth_getBlockTransactionCountByHash](/reference/eth_getBlockTransactionCountByHash)
24+
- [eth_getBlockTransactionCountByNumber](/reference/eth_getBlockTransactionCountByNumber)
25+
- [eth_getCode](/reference/eth_getCode)
26+
- [eth_getFilterChanges](/reference/eth_getFilterChanges)
27+
- [eth_getFilterLogs](/reference/eth_getFilterLogs)
28+
- [eth_getLogs](/reference/eth_getLogs)
29+
- [eth_getProof](/reference/eth_getProof)
30+
- [eth_getStorageAt](/reference/eth_getStorageAt)
31+
- [eth_getTransactionByBlockHashAndIndex](/reference/eth_getTransactionByBlockHashAndIndex)
32+
- [eth_getTransactionByBlockNumberAndIndex](/reference/eth_getTransactionByBlockNumberAndIndex)
33+
- [eth_getTransactionByHash](/reference/eth_getTransactionByHash)
34+
- [eth_getTransactionCount](/reference/eth_getTransactionCount)
35+
- [eth_getTransactionReceipt](/reference/eth_getTransactionReceipt)
36+
- [eth_getUncleCountByBlockHash](/reference/eth_getUncleCountByBlockHash)
37+
- [eth_getUncleCountByBlockNumber](/reference/eth_getUncleCountByBlockNumber)
38+
- [eth_maxPriorityFeePerGas](/reference/eth_maxPriorityFeePerGas)
39+
- [eth_newBlockFilter](/reference/eth_newBlockFilter)
40+
- [eth_newFilter](/reference/eth_newFilter)
41+
- [eth_newPendingTransactionFilter](/reference/eth_newPendingTransactionFilter)
42+
- [eth_sendRawTransaction](/reference/eth_sendRawTransaction)
43+
- [eth_sendTransaction](/reference/eth_sendTransaction)
44+
- [eth_sign](/reference/eth_sign)
45+
- [eth_signTransaction](/reference/eth_signTransaction)
46+
- [eth_syncing](/reference/eth_syncing)
47+
- [eth_uninstallFilter](/reference/eth_uninstallFilter)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# JSON-RPC API Introduction
6+
7+
The Ethereum JSON-RPC API is organized into several namespaces, each containing related methods:
8+
9+
- [Debug Namespace](/reference/json-rpc/debug-namespace)
10+
- [Engine Namespace](/reference/json-rpc/engine-namespace)
11+
- [Eth Namespace](/reference/json-rpc/eth-namespace)
12+
13+
Each namespace contains methods with specific functionality related to different aspects of Ethereum node operation.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
"scripts": {
77
"build": "npm run build:spec",
88
"build:spec": "node scripts/build.mjs",
9+
"build:namespaced-sidebars": "node scripts/generateNamespacedSidebars.mjs",
910
"lint": "npm run build:spec && node scripts/validate.mjs && node scripts/graphql-validate.mjs",
1011
"clean": "rm -rf build && mkdir -p build",
1112
"generate-clients": "mkdir -p build && open-rpc-generator generate -c open-rpc-generator-config.json",
1213
"graphql:schema": "node scripts/graphql.mjs",
1314
"graphql:validate": "node scripts/graphql-validate.mjs",
1415
"docusaurus": "docusaurus",
15-
"start:docs": "docusaurus start",
16-
"build:docs": "docusaurus build",
16+
"start:docs": "npm run build:spec && npm run build:namespaced-sidebars && docusaurus start",
17+
"build:docs": "npm run build:spec && npm run build:namespaced-sidebars && docusaurus build",
1718
"swizzle:docs": "docusaurus swizzle",
1819
"deploy:docs": "docusaurus deploy",
1920
"clear:docs": "docusaurus clear",

scripts/build.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,21 @@ function sortByMethodName(methods) {
1818
console.log("Loading files...\n");
1919

2020
let methods = [];
21+
// Create a separate map for method namespaces
22+
let methodNamespaces = {};
23+
2124
let methodsBase = "src/eth/";
2225
let methodFiles = fs.readdirSync(methodsBase);
2326
methodFiles.forEach(file => {
2427
console.log(file);
2528
let raw = fs.readFileSync(methodsBase + file);
2629
let parsed = yaml.load(raw);
30+
// Store namespace mapping separately
31+
parsed.forEach(method => {
32+
if (method.name) {
33+
methodNamespaces[method.name] = 'eth';
34+
}
35+
});
2736
methods = [
2837
...methods,
2938
...parsed,
@@ -36,6 +45,12 @@ methodFiles.forEach(file => {
3645
console.log(file);
3746
let raw = fs.readFileSync(methodsBase + file);
3847
let parsed = yaml.load(raw);
48+
// Store namespace mapping separately
49+
parsed.forEach(method => {
50+
if (method.name) {
51+
methodNamespaces[method.name] = 'debug';
52+
}
53+
});
3954
methods = [
4055
...methods,
4156
...parsed,
@@ -48,6 +63,12 @@ methodFiles.forEach(file => {
4863
console.log(file);
4964
let raw = fs.readFileSync(methodsBase + file);
5065
let parsed = yaml.load(raw);
66+
// Store namespace mapping separately
67+
parsed.forEach(method => {
68+
if (method.name) {
69+
methodNamespaces[method.name] = 'engine';
70+
}
71+
});
5172
methods = [
5273
...methods,
5374
...parsed,
@@ -98,6 +119,9 @@ const doc = {
98119

99120
fs.writeFileSync('refs-openrpc.json', JSON.stringify(doc, null, '\t'));
100121

122+
// Save the method namespace mapping separately
123+
fs.writeFileSync('method-namespaces.json', JSON.stringify(methodNamespaces, null, '\t'));
124+
101125
let spec = await dereferenceDocument(doc);
102126

103127
spec.components = {};
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import fs from 'fs';
2+
3+
/**
4+
* Generates a namespaced sidebar configuration based on the OpenRPC document
5+
*/
6+
async function generateNamespacedSidebars() {
7+
console.log('Generating namespaced sidebars...');
8+
9+
// Read the OpenRPC document
10+
const openrpcData = JSON.parse(fs.readFileSync('refs-openrpc.json', 'utf8'));
11+
12+
// Read the method namespaces mapping
13+
const methodNamespaces = JSON.parse(fs.readFileSync('method-namespaces.json', 'utf8'));
14+
15+
// Group methods by namespace
16+
const namespaces = {};
17+
18+
openrpcData.methods.forEach(method => {
19+
const methodName = method.name;
20+
const namespace = methodNamespaces[methodName] || extractNamespace(methodName);
21+
if (!namespaces[namespace]) {
22+
namespaces[namespace] = [];
23+
}
24+
namespaces[namespace].push(methodName);
25+
});
26+
27+
// Make sure directory exists
28+
if (!fs.existsSync('docs/reference/json-rpc')) {
29+
fs.mkdirSync('docs/reference/json-rpc', { recursive: true });
30+
}
31+
32+
// Add custom JSON-RPC reference sidebar to docs
33+
fs.writeFileSync('docs/reference/json-rpc/eth-namespace.md', generateSidebarPage('ETH Namespace', namespaces['eth'] || []));
34+
fs.writeFileSync('docs/reference/json-rpc/debug-namespace.md', generateSidebarPage('Debug Namespace', namespaces['debug'] || []));
35+
fs.writeFileSync('docs/reference/json-rpc/engine-namespace.md', generateSidebarPage('Engine Namespace', namespaces['engine'] || []));
36+
37+
// Create a sidebar introduction page
38+
fs.writeFileSync('docs/reference/json-rpc/introduction.md', generateIntroductionPage(Object.keys(namespaces)));
39+
40+
console.log('Namespaced sidebar files generated successfully!');
41+
}
42+
43+
/**
44+
* Extracts namespace from method name (e.g., eth_blockNumber -> eth)
45+
*/
46+
function extractNamespace(methodName) {
47+
if (!methodName) return 'other';
48+
49+
const parts = methodName.split('_');
50+
if (parts.length > 1) {
51+
return parts[0];
52+
}
53+
54+
return 'other';
55+
}
56+
57+
/**
58+
* Generates a markdown page for a specific namespace
59+
*/
60+
function generateSidebarPage(title, methods) {
61+
const sortedMethods = [...methods].sort();
62+
63+
return `---
64+
sidebar_position: 1
65+
---
66+
67+
# ${title}
68+
69+
This page lists all JSON-RPC methods in the ${title.toLowerCase()}.
70+
71+
${sortedMethods.map(method => `- [${method}](/reference/${method})`).join('\n')}
72+
`;
73+
}
74+
75+
/**
76+
* Generates an introduction page for JSON-RPC API
77+
*/
78+
function generateIntroductionPage(namespaces) {
79+
return `---
80+
sidebar_position: 1
81+
---
82+
83+
# JSON-RPC API Introduction
84+
85+
The Ethereum JSON-RPC API is organized into several namespaces, each containing related methods:
86+
87+
${namespaces.map(namespace => `- [${namespace.charAt(0).toUpperCase() + namespace.slice(1)} Namespace](/reference/json-rpc/${namespace}-namespace)`).join('\n')}
88+
89+
Each namespace contains methods with specific functionality related to different aspects of Ethereum node operation.
90+
`;
91+
}
92+
93+
generateNamespacedSidebars().catch(console.error);

sidebars.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,51 @@ import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';
1313
Create as many sidebars as you want.
1414
*/
1515
const sidebars: SidebarsConfig = {
16-
referenceSidebar: [{
17-
type: "category",
18-
label: "Reference",
19-
link: { type: "generated-index" },
20-
items: [
21-
{
22-
type: "autogenerated",
23-
dirName: "reference",
24-
}
25-
],
26-
},],
16+
referenceSidebar: [
17+
{
18+
type: "category",
19+
label: "Reference",
20+
link: { type: "generated-index" },
21+
items: [
22+
{
23+
type: "doc",
24+
id: "reference/intro",
25+
label: "Introduction"
26+
},
27+
{
28+
type: "doc",
29+
id: "reference/making-changes",
30+
label: "Contributors Guide"
31+
},
32+
{
33+
type: "category",
34+
label: "JSON-RPC API",
35+
items: [
36+
{
37+
type: "doc",
38+
id: "reference/json-rpc/introduction",
39+
label: "Introduction",
40+
},
41+
{
42+
type: "doc",
43+
id: "reference/json-rpc/eth-namespace",
44+
label: "ETH Namespace",
45+
},
46+
{
47+
type: "doc",
48+
id: "reference/json-rpc/debug-namespace",
49+
label: "Debug Namespace",
50+
},
51+
{
52+
type: "doc",
53+
id: "reference/json-rpc/engine-namespace",
54+
label: "Engine Namespace",
55+
}
56+
]
57+
}
58+
],
59+
},
60+
],
2761
};
2862

2963
export default sidebars;

0 commit comments

Comments
 (0)