Use correct RPC port in help curl example #15181

pull domob1812 wants to merge 1 commits into bitcoin:master from domob1812:rpchelp-port changing 2 files +22 −5
  1. domob1812 commented at 5:07 PM on January 16, 2019: contributor

    Put the correct RPC port (default for the selected chain or set explicitly with -rpcport) into the RPC help text "curl" example. Previously, the port there was always reported as 8332 (default mainnet port). With this change, it will be correct for testnet/regtest or with an explicit -rpcport, so that the example can be used as-is in these situations.

    This is a simplified version of #15158, following the discussion with @laanwj.

  2. laanwj added the label RPC/REST/ZMQ on Jan 16, 2019
  3. in src/rpc/server.cpp:574 in acefa70702 outdated
     568 | @@ -567,8 +569,17 @@ std::string HelpExampleCli(const std::string& methodname, const std::string& arg
     569 |  
     570 |  std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
     571 |  {
     572 | -    return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
     573 | -        "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
     574 | +    const int rpcPort = gArgs.GetArg("-rpcport", BaseParams().RPCPort());
     575 | +
     576 | +    std::ostringstream help;
    


    practicalswift commented at 8:30 AM on January 17, 2019:

    Please choose another variable name to avoid shadowing function help :-)


    domob1812 commented at 7:02 AM on January 18, 2019:

    Fixed, another good catch! Do you have an automated script to check for those shadowing instances? :)

  4. Use correct RPC port in help curl example.
    Put the correct RPC port (default for the selected chain or set explicitly
    with -rpcport) into the RPC help text "curl" example.  Previously, the
    port there was always reported as 8332 (default mainnet port).  With this
    change, it will be correct for testnet/regtest or with an explicit
    -rpcport, so that the example can be used as-is in these situations.
    d87e40afd7
  5. domob1812 force-pushed on Jan 18, 2019
  6. laanwj commented at 10:00 AM on January 22, 2019: member

    I'm really sorry to say, but again this introduces an unwanted dependency. rpcserver is supposed to be more or less independent of bitcoin (or -coin specific stuff), which includes the chain.

  7. domob1812 commented at 2:46 PM on January 22, 2019: contributor

    I'm really sorry to say, but again this introduces an unwanted dependency. rpcserver is supposed to be more or less independent of bitcoin (or -coin specific stuff), which includes the chain.

    Well, then I guess there is no way at all to do what I'm trying to do here.

    Why do you think such a (simple) code dependency is so bad, considering that there is already a semantic dependency anyway (by having that curl example in the first place)?

  8. laanwj commented at 4:15 PM on January 22, 2019: member

    Why do you think such a (simple) code dependency is so bad, considering that there is already a semantic dependency anyway (by having that curl example in the first place)?

    Look, I'm not going to back down on keeping the architecture clean here. It should in principle be possible to copy rpc/server.cpp to another project and have it still work. A curl example would still be valid as long as there is a http frontend, but it might use a different way to determine the port to listen on than bitcoin does.

    I think it is possible to do this without introducing any new dependencies by making httprpc, which knows about both HTTP and RPC, request the port number from http and then tell the rpc_server module about which port number to use in the help.

  9. domob1812 commented at 6:34 PM on January 22, 2019: contributor

    I think it is possible to do this without introducing any new dependencies by making httprpc, which knows about both HTTP and RPC, request the port number from http and then tell the rpc_server module about which port number to use in the help.

    That seems like overengineering to me - but I'm happy to do whatever you prefer. I guess we have two remaining options:

    1. Just drop this and leave it the way it is.
    2. Do what you suggest - make the port (or perhaps bind address again) a variable that is set from the HTTP RPC server.

    Do you like 2), or is that too much complexity for little benefit? I think this is something that would be nice to fix, but I'm perfectly happy to go with 1) as well if that's what you and others prefer.

  10. laanwj commented at 3:55 PM on January 24, 2019: member

    That seems like overengineering to me - but I'm happy to do whatever you prefer. I guess we have two remaining options:

    IMO it's not over-engineering if it's simply working within the constraints of the architecture. It will become a mess if we start to add dependencies from every single thing to everything else, certainly for what is only a slight documentation improvement.

    I'm okay with both options.

  11. domob1812 commented at 9:37 AM on January 25, 2019: contributor

    Thanks for the feedback - I've implemented option 2) now in #15259.

  12. domob1812 closed this on Jan 25, 2019

  13. domob1812 deleted the branch on Jan 28, 2019
  14. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me