feat(rpc): add server_definitions method (#4703)

Add a new RPC / WS call for `server_definitions`, which returns an
SDK-compatible `definitions.json` (binary enum definitions) generated by
the server. This enables clients/libraries to dynamically work with new
fields and features, such as ones that may become available on side
chains. Clients query `server_definitions` on a node from the network
they want to work with, and immediately know how to speak that node's
binary "language", even if new features are added to it in the future
(as long as there are no new serialized types that the software doesn't
know how to serialize/deserialize).

Example:

```js
> {"command": "server_definitions"}
< {
    "result": {
        "FIELDS": [
            [
                "Generic",
                {
                    "isSerialized": false,
                    "isSigningField": false,
                    "isVLEncoded": false,
                    "nth": 0,
                    "type": "Unknown"
                }
            ],
            [
                "Invalid",
                {
                    "isSerialized": false,
                    "isSigningField": false,
                    "isVLEncoded": false,
                    "nth": -1,
                    "type": "Unknown"
                }
            ],
            [
                "ObjectEndMarker",
                {
                    "isSerialized": false,
                    "isSigningField": true,
                    "isVLEncoded": false,
                    "nth": 1,
                    "type": "STObject"
                }
            ],
        ...
```

Close #3657

---------

Co-authored-by: Richard Holland <richard.holland@starstone.co.nz>
This commit is contained in:
Mayukha Vadari
2026-02-19 18:33:25 +09:00
committed by tequ
parent 1fde2a507c
commit d424910e81
9 changed files with 194 additions and 56 deletions

View File

@@ -100,6 +100,7 @@ Handler const handlerArray[]{
{"channel_verify", byRef(&doChannelVerify), Role::USER, NO_CONDITION},
{"connect", byRef(&doConnect), Role::ADMIN, NO_CONDITION},
{"consensus_info", byRef(&doConsensusInfo), Role::ADMIN, NO_CONDITION},
{"crawl_shards", byRef(&doCrawlShards), Role::ADMIN, NO_CONDITION},
{"deposit_authorized",
byRef(&doDepositAuthorized),
Role::USER,
@@ -114,6 +115,7 @@ Handler const handlerArray[]{
{"feature", byRef(&doFeature), Role::ADMIN, NO_CONDITION},
{"fee", byRef(&doFee), Role::USER, NEEDS_CURRENT_LEDGER},
{"fetch_info", byRef(&doFetchInfo), Role::ADMIN, NO_CONDITION},
{"inject", byRef(&doInject), Role::ADMIN, NEEDS_CURRENT_LEDGER},
{"ledger_accept",
byRef(&doLedgerAccept),
Role::ADMIN,
@@ -159,22 +161,20 @@ Handler const handlerArray[]{
Role::ADMIN,
NO_CONDITION},
{"ripple_path_find", byRef(&doRipplePathFind), Role::USER, NO_CONDITION},
{"sign", byRef(&doSign), Role::USER, NO_CONDITION},
{"sign_for", byRef(&doSignFor), Role::USER, NO_CONDITION},
{"inject", byRef(&doInject), Role::ADMIN, NEEDS_CURRENT_LEDGER},
{"submit", byRef(&doSubmit), Role::USER, NEEDS_CURRENT_LEDGER},
{"submit_multisigned",
byRef(&doSubmitMultiSigned),
Role::USER,
NEEDS_CURRENT_LEDGER},
{"server_definitions",
byRef(&doServerDefinitions),
Role::USER,
NO_CONDITION},
{"server_info", byRef(&doServerInfo), Role::USER, NO_CONDITION},
{"server_state", byRef(&doServerState), Role::USER, NO_CONDITION},
{"crawl_shards", byRef(&doCrawlShards), Role::ADMIN, NO_CONDITION},
{"sign", byRef(&doSign), Role::USER, NO_CONDITION},
{"sign_for", byRef(&doSignFor), Role::USER, NO_CONDITION},
{"stop", byRef(&doStop), Role::ADMIN, NO_CONDITION},
{"submit", byRef(&doSubmit), Role::USER, NEEDS_CURRENT_LEDGER},
{"submit_multisigned",
byRef(&doSubmitMultiSigned),
Role::USER,
NEEDS_CURRENT_LEDGER},
{"transaction_entry", byRef(&doTransactionEntry), Role::USER, NO_CONDITION},
{"tx", byRef(&doTxJson), Role::USER, NEEDS_NETWORK_CONNECTION},
{"tx_history", byRef(&doTxHistory), Role::USER, NO_CONDITION, 1, 1},