make ParseOutputType return a std::optional<OutputType> #22621

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:parse_output_type_optional changing 7 files +40 −36
  1. fanquake commented at 5:40 AM on August 4, 2021: member

    Similar to #22220. Skipped using auto here for the same reasons outlined in that PR.

  2. practicalswift commented at 5:52 AM on August 4, 2021: contributor

    Concept ACK

  3. DrahtBot added the label RPC/REST/ZMQ on Aug 4, 2021
  4. DrahtBot added the label Wallet on Aug 4, 2021
  5. in src/test/fuzz/kitchen_sink.cpp:52 in fb52c43a64 outdated
      51 | -    const bool parsed = ParseOutputType(output_type_string, output_type_parsed);
      52 | -    assert(parsed);
      53 | -    assert(output_type == output_type_parsed);
      54 | -    (void)ParseOutputType(fuzzed_data_provider.ConsumeRandomLengthString(64), output_type_parsed);
      55 | +    const std::optional<OutputType> parsed = ParseOutputType(output_type_string);
      56 | +    assert(output_type == parsed.value());
    


    jnewbery commented at 10:46 AM on August 4, 2021:

    We should assert that parsed has a value before extracting the object:

        assert(parsed);
        assert(output_type == parsed.value());
    

    fanquake commented at 11:13 AM on August 4, 2021:

    This just round-trips known values, so I don't think it can ever not have a value. However we can re-add the assert.

  6. jnewbery commented at 10:47 AM on August 4, 2021: member

    utACK fb52c43a6461c5c4fee47d7442703c48d7b91c15

  7. make ParseOutputType return a std::optional<OutputType> 32fa49a184
  8. in src/outputtype.h:32 in fb52c43a64 outdated
      28 | @@ -28,7 +29,7 @@ static constexpr auto OUTPUT_TYPES = std::array{
      29 |      OutputType::BECH32M,
      30 |  };
      31 |  
      32 | -[[nodiscard]] bool ParseOutputType(const std::string& str, OutputType& output_type);
      33 | +std::optional<OutputType> ParseOutputType(const std::string& str);
    


    jnewbery commented at 10:53 AM on August 4, 2021:

    Is there a reason for removing the [[nodiscard]] attribute?


    fanquake commented at 11:12 AM on August 4, 2021:

    I'm not sure why we'd keep it now that we're returning the result. If it's unused the compiler should emit Wunused-result ?


    jnewbery commented at 12:15 PM on August 4, 2021:

    Makes sense

  9. fanquake force-pushed on Aug 4, 2021
  10. jnewbery commented at 12:16 PM on August 4, 2021: member

    utACK 32fa49a18497a9b8c72e36a72ae96e7b23930223

  11. jonatack commented at 12:44 PM on August 4, 2021: member

    Code review ACK 32fa49a18497a9b8c72e36a72ae96e7b23930223 and debian clang 13 debug build is clean / unit tests locally are green

    nit, can ignore: parsed localvars could be declared const, e.g. as in src/test/fuzz/kitchen_sink.cpp

  12. MarcoFalke commented at 5:01 PM on August 4, 2021: member

    review ACK 32fa49a18497a9b8c72e36a72ae96e7b23930223 🍢

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    review ACK 32fa49a18497a9b8c72e36a72ae96e7b23930223 🍢
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUjxxwwAp2eMiuTSDyQF/v+XmEeFfPIBci2/mHzpaBanvLWTPpDEt4DBLcMExSyA
    kNiGFoOOZWLjW00otIdoxVvEEaspLbA4LhBKqHnnoC0S9ubQwzCvYy3X9N7PraYi
    LdSa58PASEwPwpu1XUs6ZfAdf7PmsVyeZzbnILfvx+IHp1jjAWQBNII5nSLoVZBq
    YX+KJZW1bOzWsmqbZeZ+uYtx7XEoiB8wvx7IS5Q/DRvHjt5yu+rkILvjQ+GDj5jm
    OlpD/QT02oWSHI3caS3ZPKswQ1+rSkgN7gA4JCQ5Y3G1EQgwL1HxNvp0QfYx0Zmy
    VW9xWri9iRal9lVRciMWuya/qNoBT/aJzRhg6iwi6EVTBq3+Yw9Lq6o/l2X6EPSs
    meFCAPdFMJx9CSGQYx7MPHTDbCID7gN85iSyuvuBTUnWKtNJuZbDBsja2qlPseph
    MG/bMDXwSZHxfgFFSAze6Dh9ndZOEOnR5DkXd9rdekK1d8llBSDORuBtVFoXkzfw
    OuZk3zp0
    =Qnra
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash 91c943e8fe3b8d3fba23d0d084119eabd4fe46e1ab28f6b682bc8aa124a49d61 -

    </details>

  13. MarcoFalke merged this on Aug 4, 2021
  14. MarcoFalke closed this on Aug 4, 2021

  15. sidhujag referenced this in commit 7f55ebaabc on Aug 4, 2021
  16. fanquake deleted the branch on Aug 5, 2021
  17. DrahtBot locked this on Aug 16, 2022

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