HomePhabricator

[chronik] check max number of parameters for Electrum commands

Description

[chronik] check max number of parameters for Electrum commands

Summary:
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

Test Plan: ninja check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Maniphest Tasks: T3598

Differential Revision: https://reviews.bitcoinabc.org/D17364

Details

Provenance
PiRKAuthored on Tue, Dec 17, 14:06
teamcityPushed on Tue, Dec 17, 20:34
Parents
rSTAGING48a7ec65fcf9: [CI] Make sure the nobody user account isn't expired on Arch
Branches
Unknown
Tags
Unknown

Event Timeline