util: change GetWarnings parameter to bool #17750

pull jnewbery wants to merge 3 commits into bitcoin:master from jnewbery:2019-12-getwarnings changing 10 files +33 −40
  1. jnewbery commented at 4:30 PM on December 15, 2019: member

    GetWarnings() changes the format of the output warning string based on a passed-in string argument that can be set to "gui" or "statusbar".

    Change the argument to a bool:

    • there are only two types of behaviour, so a bool is a more natural argument type
    • changing the name to verbose does not set any expectations for the how the calling code will use the returned string (currently, statusbar is used for RPC warnings, not a status bar)
    • removes some error-handling code for when the passed-in string is not one of the two strings expected.
  2. [qt] remove unused parameter from getWarnings() 869b6314fd
  3. util: change GetWarnings parameter to bool
    GetWarnings() changes the format of the output warning string based on a
    passed-in string argument that can be set to "gui" or "statusbar".
    Change the argument to a bool:
    
    - there are only two types of behaviour, so a bool is a more natural
    argument type
    - changing the name to 'verbose' does not set any expectations for the
    how the calling code will use the returned string (currently,
    'statusbar' is used for RPC warnings, not a status bar)
    - removes some error-handling code for when the passed-in string is not
    one of the two strings expected.
    492c6dc1e7
  4. DrahtBot added the label GUI on Dec 15, 2019
  5. DrahtBot added the label Mining on Dec 15, 2019
  6. DrahtBot added the label RPC/REST/ZMQ on Dec 15, 2019
  7. DrahtBot added the label Tests on Dec 15, 2019
  8. [style] Code style fixups in GetWarnings() 7aab8d1024
  9. jnewbery force-pushed on Dec 15, 2019
  10. promag commented at 10:01 PM on December 15, 2019: member

    Code review ACK 7aab8d1024996c7c422bd34a8226df0117b813f7.

  11. laanwj commented at 10:11 AM on December 16, 2019: member

    It was always weird to have a string argument here. I think some of the "conditional translation" code could be simplified even more with bilingual_str, but, I don't think it's necessary to do so here.

    code review ACK 7aab8d1024996c7c422bd34a8226df0117b813f7

  12. laanwj removed the label Mining on Dec 16, 2019
  13. laanwj removed the label Tests on Dec 16, 2019
  14. jnewbery commented at 11:26 AM on December 16, 2019: member

    It was always weird to have a string argument here.

    Yes, I expect Satoshi was giving himself flexibility in case other formats were needed in future. If that does happen we can always switch this to an enum.

  15. laanwj commented at 11:32 AM on December 16, 2019: member

    Yea, there was at least "rpc" which was removed in d8e9a2ac74e1071c9a92b9858b7ed3143413ee94. But a enum seemed a more obvious choice (at the time, it doesn't matter now, I don't expect the set of possibilities here to be ever expanded again). There was a previous try at this in #11412, but the concerns there no longer hold as safe mode was removed (which would disable some RPC calls when the function returned a non-empty string!).

  16. practicalswift commented at 1:29 PM on December 16, 2019: contributor

    ACK 7aab8d1024996c7c422bd34a8226df0117b813f7 -- diff looks correct :)

  17. MarcoFalke commented at 3:38 PM on December 16, 2019: member

    Not sure if this makes sense. Maybe in the future, an RPC might want to return the "verbose" warning. This would be harder with your changes, as there is no way to get the verbose warning without translation.

    As you are changing all call sites anyway, you might want to use bilingual_str, and Untranslated to denote whether a string is translated. This makes it possible for the caller (rpc or gui) to pick out the right string.

    ACK 7aab8d1024996c7c422bd34a8226df0117b813f7 otherwise.

    Edit: Untranslated might not exist on master, but you can add it with

    +/** Mark a bilingual_str as untranslated */
    +inline static bilingual_str Untranslated(std::string original) { return {original, original}; }
    
  18. in src/rpc/mining.cpp:256 in 7aab8d1024
     252 | @@ -253,7 +253,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
     253 |      obj.pushKV("networkhashps",    getnetworkhashps(request));
     254 |      obj.pushKV("pooledtx",         (uint64_t)mempool.size());
     255 |      obj.pushKV("chain",            Params().NetworkIDString());
     256 | -    obj.pushKV("warnings",         GetWarnings("statusbar"));
     257 | +    obj.pushKV("warnings",         GetWarnings(false));
    


    MarcoFalke commented at 3:39 PM on December 16, 2019:
        obj.pushKV("warnings",         GetWarnings(/* verbose */ false));
    
  19. jnewbery commented at 8:52 PM on December 16, 2019: member

    Maybe in the future, an RPC might want to return the "verbose" warning. This would be harder with your changes, as there is no way to get the verbose warning without translation.

    There's no way to get the verbose warning without translation either before or after this PR. I can't see how this is any harder after this change than before (and even if it were, I don't see "we may want to do something else in future" as a good argument against improving the code now).

    As you are changing all call sites anyway, you might want to ...

    That's not the aim of this PR. Feel free to open a follow-up.

  20. MarcoFalke commented at 9:01 PM on December 16, 2019: member

    Yes, I understand that it wasn't possible before either. However, at least the parameter was explicitly called "gui", which implies that the string might be translated. With your changes, it appears that an RPC call could just set it to verbose to get more warnings (still untranslated).

  21. MarcoFalke added the label Refactoring on Dec 16, 2019
  22. MarcoFalke referenced this in commit f9fd3a27fd on Dec 16, 2019
  23. MarcoFalke merged this on Dec 16, 2019
  24. MarcoFalke closed this on Dec 16, 2019

  25. jnewbery deleted the branch on Dec 16, 2019
  26. sidhujag referenced this in commit c5b9ba0d54 on Dec 16, 2019
  27. MarkLTZ referenced this in commit f4a2898667 on Dec 17, 2019
  28. jasonbcox referenced this in commit a891001d9e on Nov 9, 2020
  29. jasonbcox referenced this in commit 4a584f195a on Nov 9, 2020
  30. jasonbcox referenced this in commit 0f3ea8a2b3 on Nov 9, 2020
  31. sidhujag referenced this in commit 14076b0864 on Nov 10, 2020
  32. MarcoFalke 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:14 UTC

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