Fulcrum does this.
$ echo '{"jsonrpc": "2.0", "method": "server.ping", "params": ["04012200"], "id": "test"}' | nc fulcrum.pepipierre.fr 50001 {"error":{"code":-32602,"message":"Expected at most 0 parameters for server.ping, got 1 instead"},"id":"test","jsonrpc":"2.0"} $ echo '{"jsonrpc": "2.0", "method": "blockchain.transaction.get_height", "params": [], "id": "test"}' | nc fulcrum.pepipierre.fr 50001 {"error":{"code":-32602,"message":"Expected at least 1 parameter for blockchain.transaction.get_height, got 0 instead"},"id":"test","jsonrpc":"2.0"} $ echo '{"jsonrpc": "2.0", "method": "blockchain.transaction.get_height", "id": "test"}' | nc fulcrum.pepipierre.fr 50001 {"error":{"code":-32602,"message":"Missing required params"},"id":"test","jsonrpc":"2.0"} $ echo '{"jsonrpc": "2.0", "method": "blockchain.transaction.get", "id": "test", "params": [1, 2, 3]}' | nc fulcrum.pepipierre.fr 50001 {"error":{"code":-32602,"message":"Expected at most 2 parameters for blockchain.transaction.get, got 3 instead"},"id":"test","jsonrpc":"2.0"}
Note that we cannot match exactly fulcrum's error messages because:
- I don't want to repeat the method name in the code when calling the macro
- RPCError::InvalidParams(...) expects a string literal / static string, so we cannot provide the actual number of passed params to the error message
- the get_param macro already provides a better error message when we don't provide at least the min number of params: {"code": -32602, "message": "Missing mandatory 'txid' parameter"}
Ref T3598