-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tool] Document with all RPC endpoints #1256
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: RPC endpoint doc | ||
on: | ||
push: | ||
branches: | ||
- zkevm | ||
pull_request: | ||
branches: | ||
- zkevm | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.19' | ||
- name: Check RPC endpoints doc | ||
run: | | ||
cd ./docs/endpoints | ||
make check-doc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DOC_NAME:="endpoints.md" | ||
|
||
.PHONY: gen-doc | ||
gen-doc: | ||
go run main.go $(DOC_NAME) | ||
|
||
.PHONY: check-doc | ||
check-doc: | ||
go run main.go tmp$(DOC_NAME) | ||
cmp -s ./$(DOC_NAME) ./tmp$(DOC_NAME); \ | ||
RETVAL=$$?; \ | ||
rm ./tmp$(DOC_NAME); \ | ||
exit $$RETVAL |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# JSON RPC Endpoints | ||
|
||
This tool is used to generate the list of supported endpoints provided by the JSON-RPC server as a markdown document. | ||
|
||
It uses reflection to go through all API interfaces and then merge the information with the content of the [template.md](./template.md) as the base to generate the [endpoints.md](./endpoints.md) file. | ||
|
||
To generate the file ensure you have `make` and `go` installed, then run available on this directory: | ||
|
||
```bash | ||
make gen-doc | ||
``` | ||
|
||
The [endpoints.md](./endpoints.md) must always be generated when a new endpoint is added, removed or changed so we can have this file pushed to the repo for further use. | ||
|
||
There is also a command to check if the current file is compatible with the current code. This command is meant to be used in the CI do ensure the doc is updated. | ||
|
||
```bash | ||
make check-doc | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
<!-- | ||
DO NOT EDIT THIS FILE. | ||
This document was auto generated by [./main.go](./main.go) based on the interfaces the JSON-RPC server use to expose the public endpoints | ||
For more details read the [./README.md](./README.md) | ||
--> | ||
|
||
# RPC Endpoints | ||
|
||
> DO NOT EDIT THIS FILE. | ||
This document was auto generated by [./main.go](./main.go) based on the interfaces the JSON-RPC server use to expose the public endpoints | ||
For more details read the [./README.md](./README.md) | ||
|
||
Here you will find the list of all supported JSON RPC endpoints. | ||
If the endpoint is not in the list below, it means this specific endpoint is not supported yet, feel free to open an issue requesting it to be added and please explain the reason why you need it. | ||
|
||
## admin | ||
|
||
- admin_nodeInfo | ||
- admin_peers | ||
|
||
## bor | ||
|
||
- bor_getAuthor | ||
- bor_getCurrentProposer | ||
- bor_getCurrentValidators | ||
- bor_getRootHash | ||
- bor_getSigners | ||
- bor_getSignersAtHash | ||
- bor_getSnapshot | ||
- bor_getSnapshotAtHash | ||
|
||
## debug | ||
|
||
- debug_accountAt | ||
- debug_accountRange | ||
- debug_getModifiedAccountsByHash | ||
- debug_getModifiedAccountsByNumber | ||
- debug_storageRangeAt | ||
- debug_traceBlockByHash | ||
- debug_traceBlockByNumber | ||
- debug_traceCall | ||
- debug_traceTransaction | ||
- debug_traceTransactionCounters | ||
|
||
## engine | ||
|
||
- engine_exchangeTransitionConfigurationV1 | ||
- engine_forkchoiceUpdatedV1 | ||
- engine_forkchoiceUpdatedV2 | ||
- engine_getPayloadBodiesByHashV1 | ||
- engine_getPayloadBodiesByRangeV1 | ||
- engine_getPayloadV1 | ||
- engine_getPayloadV2 | ||
- engine_newPayloadV1 | ||
- engine_newPayloadV2 | ||
|
||
## erigon | ||
|
||
- erigon_blockNumber | ||
- erigon_cumulativeChainTraffic | ||
- erigon_forks | ||
- erigon_getBalanceChangesInBlock | ||
- erigon_getBlockByTimestamp | ||
- erigon_getBlockReceiptsByBlockHash | ||
- erigon_getHeaderByHash | ||
- erigon_getHeaderByNumber | ||
- erigon_getLatestLogs | ||
- erigon_getLogs | ||
- erigon_getLogsByHash | ||
- erigon_nodeInfo | ||
|
||
## eth | ||
|
||
- eth_accounts | ||
- eth_blockNumber | ||
- eth_call | ||
- eth_chainId | ||
- eth_coinbase | ||
- eth_createAccessList | ||
- eth_estimateGas | ||
- eth_gasPrice | ||
- eth_getBalance | ||
- eth_getBlockByHash | ||
- eth_getBlockByNumber | ||
- eth_getBlockReceipts | ||
- eth_getBlockTransactionCountByHash | ||
- eth_getBlockTransactionCountByNumber | ||
- eth_getCode | ||
- eth_getFilterChanges | ||
- eth_getFilterLogs | ||
- eth_getLogs | ||
- eth_getProof | ||
- eth_getRawTransactionByBlockHashAndIndex | ||
- eth_getRawTransactionByBlockNumberAndIndex | ||
- eth_getRawTransactionByHash | ||
- eth_getStorageAt | ||
- eth_getTransactionByBlockHashAndIndex | ||
- eth_getTransactionByBlockNumberAndIndex | ||
- eth_getTransactionByHash | ||
- eth_getTransactionCount | ||
- eth_getTransactionReceipt | ||
- eth_getUncleByBlockHashAndIndex | ||
- eth_getUncleByBlockNumberAndIndex | ||
- eth_getUncleCountByBlockHash | ||
- eth_getUncleCountByBlockNumber | ||
- eth_getWork | ||
- eth_hashrate | ||
- eth_mining | ||
- eth_newBlockFilter | ||
- eth_newFilter | ||
- eth_newPendingTransactionFilter | ||
- eth_protocolVersion | ||
- eth_sendRawTransaction | ||
- eth_sendTransaction | ||
- eth_sign | ||
- eth_signTransaction | ||
- eth_submitHashrate | ||
- eth_submitWork | ||
- eth_syncing | ||
- eth_uninstallFilter | ||
|
||
## graphql | ||
|
||
- graphql_getBlockDetails | ||
- graphql_getChainID | ||
|
||
## net | ||
|
||
- net_listening | ||
- net_peerCount | ||
- net_version | ||
|
||
## otterscan | ||
|
||
- otterscan_getApiLevel | ||
- otterscan_getBlockDetails | ||
- otterscan_getBlockDetailsByHash | ||
- otterscan_getBlockTransactions | ||
- otterscan_getContractCreator | ||
- otterscan_getInternalOperations | ||
- otterscan_getTransactionBySenderAndNonce | ||
- otterscan_getTransactionError | ||
- otterscan_hasCode | ||
- otterscan_searchTransactionsAfter | ||
- otterscan_searchTransactionsBefore | ||
- otterscan_traceTransaction | ||
|
||
## parity | ||
|
||
- parity_listStorageKeys | ||
|
||
## trace | ||
|
||
- trace_block | ||
- trace_call | ||
- trace_callMany | ||
- trace_filter | ||
- trace_get | ||
- trace_rawTransaction | ||
- trace_replayBlockTransactions | ||
- trace_replayTransaction | ||
- trace_transaction | ||
|
||
## txpool | ||
|
||
- txpool_content | ||
- txpool_limbo | ||
|
||
## web3 | ||
|
||
- web3_clientVersion | ||
- web3_sha3 | ||
|
||
## zkevm | ||
|
||
- zkevm_batchNumber | ||
- zkevm_batchNumberByBlockNumber | ||
- zkevm_consolidatedBlockNumber | ||
- zkevm_estimateCounters | ||
- zkevm_getBatchByNumber | ||
- zkevm_getBatchCountersByNumber | ||
- zkevm_getBatchWitness | ||
- zkevm_getBlockRangeWitness | ||
- zkevm_getExitRootTable | ||
- zkevm_getExitRootsByGER | ||
- zkevm_getForkById | ||
- zkevm_getForkId | ||
- zkevm_getForkIdByBatchNumber | ||
- zkevm_getForks | ||
- zkevm_getFullBlockByHash | ||
- zkevm_getFullBlockByNumber | ||
- zkevm_getL2BlockInfoTree | ||
- zkevm_getLatestGlobalExitRoot | ||
- zkevm_getProverInput | ||
- zkevm_getVersionHistory | ||
- zkevm_getWitness | ||
- zkevm_isBlockConsolidated | ||
- zkevm_isBlockVirtualized | ||
- zkevm_verifiedBatchNumber | ||
- zkevm_virtualBatchNumber |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"reflect" | ||
"sort" | ||
"text/template" | ||
"unicode" | ||
"unicode/utf8" | ||
|
||
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands" | ||
) | ||
|
||
const disclaimer = `DO NOT EDIT THIS FILE. | ||
This document was auto generated by [./main.go](./main.go) based on the interfaces the JSON-RPC server use to expose the public endpoints | ||
For more details read the [./README.md](./README.md)` | ||
|
||
type Document struct { | ||
Disclaimer string | ||
EndpointGroups []keyValue | ||
} | ||
|
||
type keyValue struct { | ||
Key any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to avoid using any as type. Could the |
||
Value any | ||
} | ||
|
||
func main() { | ||
apiInterfaces := []keyValue{ | ||
{"admin", (*commands.AdminAPI)(nil)}, | ||
{"bor", (*commands.BorAPI)(nil)}, | ||
{"debug", (*commands.PrivateDebugAPI)(nil)}, | ||
{"engine", (*commands.EngineAPI)(nil)}, | ||
{"erigon", (*commands.ErigonAPI)(nil)}, | ||
{"eth", (*commands.EthAPI)(nil)}, | ||
{"graphql", (*commands.GraphQLAPI)(nil)}, | ||
{"net", (*commands.NetAPI)(nil)}, | ||
{"otterscan", (*commands.OtterscanAPI)(nil)}, | ||
{"parity", (*commands.ParityAPI)(nil)}, | ||
{"trace", (*commands.TraceAPI)(nil)}, | ||
{"txpool", (*commands.TxPoolAPI)(nil)}, | ||
{"web3", (*commands.Web3API)(nil)}, | ||
{"zkevm", (*commands.ZkEvmAPI)(nil)}, | ||
} | ||
|
||
endpointGroups := []keyValue{} | ||
for _, apiInterface := range apiInterfaces { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this for loop be extracted as function for better readability? Maybe |
||
apiPrefix := apiInterface.Key | ||
apiInterfaceType := apiInterface.Value | ||
|
||
apiEndpoints := []string{} | ||
interfaceType := reflect.TypeOf(apiInterfaceType).Elem() | ||
for methodIndex := 0; methodIndex < interfaceType.NumMethod(); methodIndex++ { | ||
methodName := interfaceType.Method(methodIndex).Name | ||
methodName = firstToLower(methodName) | ||
endpointName := fmt.Sprintf("%s_%s", apiPrefix, methodName) | ||
apiEndpoints = append(apiEndpoints, endpointName) | ||
} | ||
|
||
sort.Slice(apiEndpoints, func(i, j int) bool { | ||
return apiEndpoints[i] < apiEndpoints[j] | ||
}) | ||
endpointGroup := keyValue{Key: apiPrefix, Value: apiEndpoints} | ||
|
||
endpointGroups = append(endpointGroups, endpointGroup) | ||
} | ||
|
||
fileName := "endpoints.md" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can one more function be created for getting the filename - |
||
fmt.Println(os.Args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this println needed? |
||
if len(os.Args) > 1 { | ||
fileName = os.Args[1] | ||
} | ||
|
||
f, err := createOrOpen(fileName) | ||
checkErr(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if checkErr function is needed. There aren't complex checks for error behavior. It's pretty common to use |
||
|
||
t := template.Must(template.New("template.md").ParseFiles("template.md")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move "template.md" and the default fileName to constants |
||
err = t.Execute(f, Document{disclaimer, endpointGroups}) | ||
checkErr(err) | ||
} | ||
|
||
func checkErr(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func createOrOpen(name string) (*os.File, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would personally rename this to |
||
if _, err := os.Stat(name); err == nil { | ||
os.Remove(name) | ||
} | ||
return os.Create(name) | ||
} | ||
|
||
func firstToLower(s string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be simplified to
|
||
r, size := utf8.DecodeRuneInString(s) | ||
if r == utf8.RuneError && size <= 1 { | ||
return s | ||
} | ||
lc := unicode.ToLower(r) | ||
if r == lc { | ||
return s | ||
} | ||
return string(lc) + s[size:] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- | ||
{{ .Disclaimer }} | ||
--> | ||
|
||
# RPC Endpoints | ||
|
||
> {{ .Disclaimer }} | ||
|
||
Here you will find the list of all supported JSON RPC endpoints. | ||
If the endpoint is not in the list below, it means this specific endpoint is not supported yet, feel free to open an issue requesting it to be added and please explain the reason why you need it. | ||
{{ range .EndpointGroups }} | ||
## {{ .Key }} | ||
{{ range .Value }} | ||
- {{ . }} | ||
{{- end }} | ||
{{ end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyValue seems too general name to me. Maybe use
endpointGroup
?