diff --git a/.clang-tidy b/.clang-tidy index ce12e552c4..6a967532db 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -73,7 +73,7 @@ Checks: "-*, bugprone-unhandled-self-assignment, bugprone-unique-ptr-array-mismatch, bugprone-unsafe-functions, - bugprone-use-after-move, # has issues + bugprone-use-after-move, bugprone-unused-raii, bugprone-unused-return-value, bugprone-unused-local-non-trivial-variable, @@ -106,6 +106,7 @@ Checks: "-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, + modernize-use-nodiscard, modernize-use-override, modernize-use-ranges, modernize-use-starts-ends-with, diff --git a/SECURITY.md b/SECURITY.md index 2e0c43a134..d72ddcada4 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -22,117 +22,10 @@ Responsible investigation includes, but isn't limited to, the following: - Not targeting physical security measures, or attempting to use social engineering, spam, distributed denial of service (DDOS) attacks, etc. - Investigating bugs in a way that makes a reasonable, good faith effort not to be disruptive or harmful to the XRP Ledger and the broader ecosystem. -### Responsible Disclosure - -If you discover a vulnerability or potential threat, or if you _think_ -you have, please reach out by dropping an email using the contact -information below. - -Your report should include the following: - -- Your contact information (typically, an email address); -- The description of the vulnerability; -- The attack scenario (if any); -- The steps to reproduce the vulnerability; -- Any other relevant details or artifacts, including code, scripts or patches. - -In your email, please describe the issue or potential threat. If possible, include a "repro" (code that can reproduce the issue) or describe the best way to reproduce and replicate the issue. Please make your report as detailed and comprehensive as possible. - -For more information on responsible disclosure, please read this [Wikipedia article](https://en.wikipedia.org/wiki/Responsible_disclosure). - -## Report Handling Process - -Please report the bug directly to us and limit further disclosure. If you want to prove that you knew the bug as of a given time, consider using a cryptographic pre-commitment: hash the content of your report and publish the hash on a medium of your choice (e.g. on Twitter or as a memo in a transaction) as "proof" that you had written the text at a given point in time. - -Once we receive a report, we: - -1. Assign two people to independently evaluate the report; -2. Consider their recommendations; -3. If action is necessary, formulate a plan to address the issue; -4. Communicate privately with the reporter to explain our plan. -5. Prepare, test and release a version which fixes the issue; and -6. Announce the vulnerability publicly. - -We will triage and respond to your disclosure within 24 hours. Beyond that, we will work to analyze the issue in more detail, formulate, develop and test a fix. - -While we commit to responding with 24 hours of your initial report with our triage assessment, we cannot guarantee a response time for the remaining steps. We will communicate with you throughout this process, letting you know where we are and keeping you updated on the timeframe. - ## Bug Bounty Program -[Ripple](https://ripple.com) is generously sponsoring a bug bounty program for vulnerabilities in [`xrpld`](https://github.com/XRPLF/rippled) (and other related projects, like [`xrpl.js`](https://github.com/XRPLF/xrpl.js), [`xrpl-py`](https://github.com/XRPLF/xrpl-py), [`xrpl4j`](https://github.com/XRPLF/xrpl4j)). +[Ripple](https://ripple.com) is generously sponsoring a bug bounty program for vulnerabilities in [`xrpld`](https://github.com/XRPLF/rippled) (and other related projects, like [`Clio`](https://github.com/XRPLF/clio), [`xrpl.js`](https://github.com/XRPLF/xrpl.js), [`xrpl-py`](https://github.com/XRPLF/xrpl-py), [`xrpl4j`](https://github.com/XRPLF/xrpl4j)). -This program allows us to recognize and reward individuals or groups that identify and report bugs. In summary, in order to qualify for a bounty, the bug must be: +This program allows us to recognize and reward individuals or groups that identify and report bugs. -1. **In scope**. Only bugs in software under the scope of the program qualify. Currently, that means `xrpld`, `xrpl.js`, `xrpl-py`, `xrpl4j`. -2. **Relevant**. A security issue, posing a danger to user funds, privacy, or the operation of the XRP Ledger. -3. **Original and previously unknown**. Bugs that are already known and discussed in public do not qualify. Previously reported bugs, even if publicly unknown, are not eligible. -4. **Specific**. We welcome general security advice or recommendations, but we cannot pay bounties for that. -5. **Fixable**. There has to be something we can do to permanently fix the problem. Note that bugs in other people’s software may still qualify in some cases. For example, if you find a bug in a library that we use which can compromise the security of software that is in scope and we can get it fixed, you may qualify for a bounty. -6. **Unused**. If you use the exploit to attack the XRP Ledger, you do not qualify for a bounty. If you report a vulnerability used in an ongoing or past attack and there is specific, concrete evidence that suggests you are the attacker we reserve the right not to pay a bounty. - -The amount paid varies dramatically. Vulnerabilities that are harmless on their own, but could form part of a critical exploit will usually receive a bounty. Full-blown exploits can receive much higher bounties. Please don’t hold back partial vulnerabilities while trying to construct a full-blown exploit. We will pay a bounty to anyone who reports a complete chain of vulnerabilities even if they have reported each component of the exploit separately and those vulnerabilities have been fixed in the meantime. However, to qualify for a the full bounty, you must to have been the first to report each of the partial exploits. - -### Contacting Us - -To report a qualifying bug, please send a detailed report to: - -| Email Address | bugs@ripple.com | -| :-----------: | :-------------------------------------------------- | -| Short Key ID | `0xA9F514E0` | -| Long Key ID | `0xD900855AA9F514E0` | -| Fingerprint | `B72C 0654 2F2A E250 2763 A268 D900 855A A9F5 14E0` | - -The full PGP key for this address, which is also available on several key servers (e.g. on [keyserver.ubuntu.com](https://keyserver.ubuntu.com)), is: - -``` ------BEGIN PGP PUBLIC KEY BLOCK----- -mQINBGkSZAQBEACprU199OhgdsOsygNjiQV4msuN3vDOUooehL+NwfsGfW79Tbqq -Q2u7uQ3NZjW+M2T4nsDwuhkr7pe7xSReR5W8ssaczvtUyxkvbMClilcgZ2OSCAuC -N9tzJsqOqkwBvXoNXkn//T2jnPz0ZU2wSF+NrEibq5FeuyGdoX3yXXBxq9pW9HzK -HkQll63QSl6BzVSGRQq+B6lGgaZGLwf3mzmIND9Z5VGLNK2jKynyz9z091whNG/M -kV+E7/r/bujHk7WIVId07G5/COTXmSr7kFnNEkd2Umw42dkgfiNKvlmJ9M7c1wLK -KbL9Eb4ADuW6rRc5k4s1e6GT8R4/VPliWbCl9SE32hXH8uTkqVIFZP2eyM5WRRHs -aKzitkQG9UK9gcb0kdgUkxOvvgPHAe5IuZlcHFzU4y0dBbU1VEFWVpiLU0q+IuNw -5BRemeHc59YNsngkmAZ+/9zouoShRusZmC8Wzotv75C2qVBcjijPvmjWAUz0Zunm -Lsr+O71vqHE73pERjD07wuD/ISjiYRYYE/bVrXtXLZijC7qAH4RE3nID+2ojcZyO -/2jMQvt7un56RsGH4UBHi3aBHi9bUoDGCXKiQY981cEuNaOxpou7Mh3x/ONzzSvk -sTV6nl1LOZHykN1JyKwaNbTSAiuyoN+7lOBqbV04DNYAHL88PrT21P83aQARAQAB -tB1SaXBwbGUgTGFicyA8YnVnc0ByaXBwbGUuY29tPokCTgQTAQgAOBYhBLcsBlQv -KuJQJ2OiaNkAhVqp9RTgBQJpEmQEAhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA -AAoJENkAhVqp9RTgBzgP/i7y+aDWl1maig1XMdyb+o0UGusumFSW4Hmj278wlKVv -usgLPihYgHE0PKrv6WRyKOMC1tQEcYYN93M+OeQ1vFhS2YyURq6RCMmh4zq/awXG -uZbG36OURB5NH8lGBOHiN/7O+nY0CgenBT2JWm+GW3nEOAVOVm4+r5GlpPlv+Dp1 -NPBThcKXFMnH73++NpSQoDzTfRYHPxhDAX3jkLi/moXfSanOLlR6l94XNNN0jBHW -Quao0rzf4WSXq9g6AS224xhAA5JyIcFl8TX7hzj5HaFn3VWo3COoDu4U7H+BM0fl -85yqiMQypp7EhN2gxpMMWaHY5TFM85U/bFXFYfEgihZ4/gt4uoIzsNI9jlX7mYvG -KFdDij+oTlRsuOxdIy60B3dKcwOH9nZZCz0SPsN/zlRWgKzK4gDKdGhFkU9OlvPu -94ZqscanoiWKDoZkF96+sjgfjkuHsDK7Lwc1Xi+T4drHG/3aVpkYabXox+lrKB/S -yxZjeqOIQzWPhnLgCaLyvsKo5hxKzL0w3eURu8F3IS7RgOOlljv4M+Me9sEVcdNV -aN3/tQwbaomSX1X5D5YXqhBwC3rU3wXwamsscRTGEpkV+JCX6KUqGP7nWmxCpAly -FL05XuOd5SVHJjXLeuje0JqLUpN514uL+bThWwDbDTdAdwW3oK/2WbXz7IfJRLBj -uQINBGkSZAQBEADdI3SL2F72qkrgFqXWE6HSRBu9bsAvTE5QrRPWk7ux6at537r4 -S4sIw2dOwLvbyIrDgKNq3LQ5wCK88NO/NeCOFm4AiCJSl3pJHXYnTDoUxTrrxx+o -vSRI4I3fHEql/MqzgiAb0YUezjgFdh3vYheMPp/309PFbOLhiFqEcx80Mx5h06UH -gDzu1qNj3Ec+31NLic5zwkrAkvFvD54d6bqYR3SEgMau6aYEewpGHbWBi2pLqSi2 -lQcAeOFixqGpTwDmAnYR8YtjBYepy0MojEAdTHcQQlOYSDk4q4elG+io2N8vECfU -rD6ORecN48GXdZINYWTAdslrUeanmBdgQrYkSpce8TSghgT9P01SNaXxmyaehVUO -lqI4pcg5G2oojAE8ncNS3TwDtt7daTaTC3bAdr4PXDVAzNAiewjMNZPB7xidkDGQ -Y4W1LxTMXyJVWxehYOH7tsbBRKninlfRnLgYzmtIbNRAAvNcsxU6ihv3AV0WFknN -YbSzotEv1Xq/5wk309x8zCDe+sP0cQicvbXafXmUzPAZzeqFg+VLFn7F9MP1WGlW -B1u7VIvBF1Mp9Nd3EAGBAoLRdRu+0dVWIjPTQuPIuD9cCatJA0wVaKUrjYbBMl88 -a12LixNVGeSFS9N7ADHx0/o7GNT6l88YbaLP6zggUHpUD/bR+cDN7vllIQARAQAB -iQI2BBgBCAAgFiEEtywGVC8q4lAnY6Jo2QCFWqn1FOAFAmkSZAQCGwwACgkQ2QCF -Wqn1FOAfAA/8CYq4p0p4bobY20CKEMsZrkBTFJyPDqzFwMeTjgpzqbD7Y3Qq5QCK -OBbvY02GWdiIsNOzKdBxiuam2xYP9WHZj4y7/uWEvT0qlPVmDFu+HXjoJ43oxwFd -CUp2gMuQ4cSL3X94VRJ3BkVL+tgBm8CNY0vnTLLOO3kum/R69VsGJS1JSGUWjNM+ -4qwS3mz+73xJu1HmERyN2RZF/DGIZI2PyONQQ6aH85G1Dd2ohu2/DBAkQAMBrPbj -FrbDaBLyFhODxU3kTWqnfLlaElSm2EGdIU2yx7n4BggEa//NZRMm5kyeo4vzhtlQ -YIVUMLAOLZvnEqDnsLKp+22FzNR/O+htBQC4lPywl53oYSALdhz1IQlcAC1ru5KR -XPzhIXV6IIzkcx9xNkEclZxmsuy5ERXyKEmLbIHAlzFmnrldlt2ZgXDtzaorLmxj -klKibxd5tF50qOpOivz+oPtFo7n+HmFa1nlVAMxlDCUdM0pEVeYDKI5zfVwalyhZ -NnjpakdZSXMwgc7NP/hH9buF35hKDp7EckT2y3JNYwHsDdy1icXN2q40XZw5tSIn -zkPWdu3OUY8PISohN6Pw4h0RH4ZmoX97E8sEfmdKaT58U4Hf2aAv5r9IWCSrAVqY -u5jvac29CzQR9Kal0A+8phHAXHNFD83SwzIC0syaT9ficAguwGH8X6Q= -=nGuD ------END PGP PUBLIC KEY BLOCK----- -``` +We have partnered with Bugcrowd to manage this program. It is a private program, and security researchers can participate based on invitation. If you need access to the program, please email bugs@ripple.com with your Bugcrowd handle or Bugcrowd registered email, and we will get you added to the program. Once you have been added, please submit vulnerability reports through Bugcrowd, not by email. The detailed bug bounty policy is available on the Bugcrowd website. diff --git a/cmake/XrplCompiler.cmake b/cmake/XrplCompiler.cmake index 9db754eb1d..0b77ff3525 100644 --- a/cmake/XrplCompiler.cmake +++ b/cmake/XrplCompiler.cmake @@ -118,7 +118,7 @@ if(MSVC) NOMINMAX # TODO: Resolve these warnings, don't just silence them _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS - $<$,$,$>>:_CRTDBG_MAP_ALLOC> + $<$,$>:_CRTDBG_MAP_ALLOC> ) target_link_libraries(common INTERFACE -errorreport:none -machine:X64) else() diff --git a/include/xrpl/basics/BasicConfig.h b/include/xrpl/basics/BasicConfig.h index e1b0af516f..0639fb6c4d 100644 --- a/include/xrpl/basics/BasicConfig.h +++ b/include/xrpl/basics/BasicConfig.h @@ -36,7 +36,7 @@ public: explicit Section(std::string name = ""); /** Returns the name of this section. */ - std::string const& + [[nodiscard]] std::string const& name() const { return name_; @@ -45,7 +45,7 @@ public: /** Returns all the lines in the section. This includes everything. */ - std::vector const& + [[nodiscard]] std::vector const& lines() const { return lines_; @@ -54,7 +54,7 @@ public: /** Returns all the values in the section. Values are non-empty lines which are not key/value pairs. */ - std::vector const& + [[nodiscard]] std::vector const& values() const { return values_; @@ -82,7 +82,7 @@ public: * @return The retrieved value. A section with an empty legacy value returns an empty string. */ - std::string + [[nodiscard]] std::string legacy() const { if (lines_.empty()) @@ -117,11 +117,11 @@ public: } /** Returns `true` if a key with the given name exists. */ - bool + [[nodiscard]] bool exists(std::string const& name) const; template - std::optional + [[nodiscard]] std::optional get(std::string const& name) const { auto const iter = lookup_.find(name); @@ -132,7 +132,7 @@ public: /// Returns a value if present, else another value. template - T + [[nodiscard]] T value_or(std::string const& name, T const& other) const { auto const v = get(name); @@ -141,7 +141,7 @@ public: // indicates if trailing comments were seen // during the appending of any lines/values - bool + [[nodiscard]] bool had_trailing_comments() const { return had_trailing_comments_; @@ -151,42 +151,42 @@ public: operator<<(std::ostream&, Section const& section); // Returns `true` if there are no key/value pairs. - bool + [[nodiscard]] bool empty() const { return lookup_.empty(); } // Returns the number of key/value pairs. - std::size_t + [[nodiscard]] std::size_t size() const { return lookup_.size(); } // For iteration of key/value pairs. - const_iterator + [[nodiscard]] const_iterator begin() const { return lookup_.cbegin(); } // For iteration of key/value pairs. - const_iterator + [[nodiscard]] const_iterator cbegin() const { return lookup_.cbegin(); } // For iteration of key/value pairs. - const_iterator + [[nodiscard]] const_iterator end() const { return lookup_.cend(); } // For iteration of key/value pairs. - const_iterator + [[nodiscard]] const_iterator cend() const { return lookup_.cend(); @@ -206,7 +206,7 @@ private: public: /** Returns `true` if a section with the given name exists. */ - bool + [[nodiscard]] bool exists(std::string const& name) const; /** Returns the section with the given name. @@ -216,7 +216,7 @@ public: Section& section(std::string const& name); - Section const& + [[nodiscard]] Section const& section(std::string const& name) const; Section const& @@ -264,7 +264,7 @@ public: * legacy value. * @return Contents of the legacy value. */ - std::string + [[nodiscard]] std::string legacy(std::string const& sectionName) const; friend std::ostream& @@ -272,7 +272,7 @@ public: // indicates if trailing comments were seen // in any loaded Sections - bool + [[nodiscard]] bool had_trailing_comments() const { return std::ranges::any_of(map_, [](auto s) { return s.second.had_trailing_comments(); }); diff --git a/include/xrpl/basics/Buffer.h b/include/xrpl/basics/Buffer.h index 52c092981c..59968a4fa4 100644 --- a/include/xrpl/basics/Buffer.h +++ b/include/xrpl/basics/Buffer.h @@ -101,13 +101,13 @@ public: } /** Returns the number of bytes in the buffer. */ - std::size_t + [[nodiscard]] std::size_t size() const noexcept { return size_; } - bool + [[nodiscard]] bool empty() const noexcept { return 0 == size_; @@ -125,7 +125,7 @@ public: to a single byte, to facilitate pointer arithmetic. */ /** @{ */ - std::uint8_t const* + [[nodiscard]] std::uint8_t const* data() const noexcept { return p_.get(); @@ -169,25 +169,25 @@ public: return alloc(n); } - const_iterator + [[nodiscard]] const_iterator begin() const noexcept { return p_.get(); } - const_iterator + [[nodiscard]] const_iterator cbegin() const noexcept { return p_.get(); } - const_iterator + [[nodiscard]] const_iterator end() const noexcept { return p_.get() + size_; } - const_iterator + [[nodiscard]] const_iterator cend() const noexcept { return p_.get() + size_; diff --git a/include/xrpl/basics/CountedObject.h b/include/xrpl/basics/CountedObject.h index 675d1b163b..379fd49837 100644 --- a/include/xrpl/basics/CountedObject.h +++ b/include/xrpl/basics/CountedObject.h @@ -19,7 +19,7 @@ public: using Entry = std::pair; using List = std::vector; - List + [[nodiscard]] List getCounts(int minimumThreshold) const; public: @@ -59,19 +59,19 @@ public: return --count_; } - int + [[nodiscard]] int getCount() const noexcept { return count_.load(); } - Counter* + [[nodiscard]] Counter* getNext() const noexcept { return next_; } - std::string const& + [[nodiscard]] std::string const& getName() const noexcept { return name_; diff --git a/include/xrpl/basics/Expected.h b/include/xrpl/basics/Expected.h index 6cba7106fb..f4d8e5019a 100644 --- a/include/xrpl/basics/Expected.h +++ b/include/xrpl/basics/Expected.h @@ -73,7 +73,7 @@ public: { } - constexpr E const& + [[nodiscard]] constexpr E const& value() const& { return val_; @@ -91,7 +91,7 @@ public: return std::move(val_); } - constexpr E const&& + [[nodiscard]] constexpr E const&& value() const&& { return std::move(val_); @@ -125,13 +125,13 @@ public: { } - constexpr bool + [[nodiscard]] constexpr bool has_value() const { return Base::has_value(); } - constexpr T const& + [[nodiscard]] constexpr T const& value() const { return Base::value(); @@ -143,7 +143,7 @@ public: return Base::value(); } - constexpr E const& + [[nodiscard]] constexpr E const& error() const { return Base::error(); @@ -210,7 +210,7 @@ public: { } - constexpr E const& + [[nodiscard]] constexpr E const& error() const { return Base::error(); diff --git a/include/xrpl/basics/IntrusivePointer.h b/include/xrpl/basics/IntrusivePointer.h index 230dec3ebb..019e71a727 100644 --- a/include/xrpl/basics/IntrusivePointer.h +++ b/include/xrpl/basics/IntrusivePointer.h @@ -159,11 +159,11 @@ public: reset(); /** Get the raw pointer */ - T* + [[nodiscard]] T* get() const; /** Return the strong count */ - std::size_t + [[nodiscard]] std::size_t use_count() const; template @@ -181,7 +181,7 @@ public: private: /** Return the raw pointer held by this object. */ - T* + [[nodiscard]] T* unsafeGetRawPtr() const; /** Exchange the current raw pointer held by this object with the given @@ -260,7 +260,7 @@ public: lock() const; /** Return true if the strong count is zero. */ - bool + [[nodiscard]] bool expired() const; /** Set the pointer to null and decrement the weak count. @@ -339,7 +339,7 @@ public: don't lock the weak pointer. Use the `lock` method if that's what's needed) */ - SharedIntrusive + [[nodiscard]] SharedIntrusive getStrong() const; /** Return true if this is a strong pointer and the strong pointer is @@ -357,31 +357,31 @@ public: /** If this is a strong pointer, return the raw pointer. Otherwise return null. */ - T* + [[nodiscard]] T* get() const; /** If this is a strong pointer, return the strong count. Otherwise * return 0 */ - std::size_t + [[nodiscard]] std::size_t use_count() const; /** Return true if there is a non-zero strong count. */ - bool + [[nodiscard]] bool expired() const; /** If this is a strong pointer, return the strong pointer. Otherwise attempt to lock the weak pointer. */ - SharedIntrusive + [[nodiscard]] SharedIntrusive lock() const; /** Return true is this represents a strong pointer. */ - bool + [[nodiscard]] bool isStrong() const; /** Return true is this represents a weak pointer. */ - bool + [[nodiscard]] bool isWeak() const; /** If this is a weak pointer, attempt to convert it to a strong @@ -412,7 +412,7 @@ private: private: /** Return the raw pointer held by this object. */ - T* + [[nodiscard]] T* unsafeGetRawPtr() const; enum class RefStrength { strong, weak }; diff --git a/include/xrpl/basics/IntrusiveRefCounts.h b/include/xrpl/basics/IntrusiveRefCounts.h index ea610a521e..e7c31bde93 100644 --- a/include/xrpl/basics/IntrusiveRefCounts.h +++ b/include/xrpl/basics/IntrusiveRefCounts.h @@ -207,7 +207,7 @@ private: RefCountPair(CountType s, CountType w) noexcept; /** Convert back to the packed integer form. */ - FieldType + [[nodiscard]] FieldType combinedValue() const noexcept; static constexpr CountType maxStrongValue = diff --git a/include/xrpl/basics/Log.h b/include/xrpl/basics/Log.h index 4efbec5199..58cca4f486 100644 --- a/include/xrpl/basics/Log.h +++ b/include/xrpl/basics/Log.h @@ -76,7 +76,7 @@ private: @return `true` if a system file is associated and opened for writing. */ - bool + [[nodiscard]] bool isOpen() const noexcept; /** Associate a system file with the log. diff --git a/include/xrpl/basics/Mutex.hpp b/include/xrpl/basics/Mutex.hpp index 18c57370b1..5855ee2017 100644 --- a/include/xrpl/basics/Mutex.hpp +++ b/include/xrpl/basics/Mutex.hpp @@ -44,7 +44,7 @@ public: return data_; } - ProtectedDataType const& + [[nodiscard]] ProtectedDataType const& get() const { return data_; diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index 51ade0b5ea..d14b17a042 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -252,9 +252,9 @@ public: // Assume unsigned values are... unsigned. i.e. positive explicit Number(internalrep mantissa, int exponent, normalized); - constexpr rep + [[nodiscard]] constexpr rep mantissa() const noexcept; - constexpr int + [[nodiscard]] constexpr int exponent() const noexcept; constexpr Number @@ -339,7 +339,7 @@ public: } /** Return the sign of the amount */ - constexpr int + [[nodiscard]] constexpr int signum() const noexcept { if (negative_) @@ -347,7 +347,7 @@ public: return (mantissa_ != 0u) ? 1 : 0; } - Number + [[nodiscard]] Number truncate() const noexcept; friend constexpr bool @@ -490,13 +490,13 @@ private: MantissaRange::rep const& minMantissa, MantissaRange::rep const& maxMantissa); - bool + [[nodiscard]] bool isnormal() const noexcept; // Copy the number, but modify the exponent by "exponentDelta". Because the // mantissa doesn't change, the result will be "mostly" normalized, but the // exponent could go out of range, so it will be checked. - Number + [[nodiscard]] Number shiftExponent(int exponentDelta) const; // Safely convert rep (int64) mantissa to internalrep (uint64). If the rep diff --git a/include/xrpl/basics/SHAMapHash.h b/include/xrpl/basics/SHAMapHash.h index 22f8505912..bf688be7da 100644 --- a/include/xrpl/basics/SHAMapHash.h +++ b/include/xrpl/basics/SHAMapHash.h @@ -20,7 +20,7 @@ public: { } - uint256 const& + [[nodiscard]] uint256 const& as_uint256() const { return hash_; @@ -30,17 +30,17 @@ public: { return hash_; } - bool + [[nodiscard]] bool isZero() const { return hash_.isZero(); } - bool + [[nodiscard]] bool isNonZero() const { return hash_.isNonZero(); } - int + [[nodiscard]] int signum() const { return hash_.signum(); diff --git a/include/xrpl/basics/SharedWeakCachePointer.h b/include/xrpl/basics/SharedWeakCachePointer.h index afc701ed5a..05d3891e5f 100644 --- a/include/xrpl/basics/SharedWeakCachePointer.h +++ b/include/xrpl/basics/SharedWeakCachePointer.h @@ -49,7 +49,7 @@ public: /** Return a strong pointer if this is already a strong pointer (i.e. don't lock the weak pointer. Use the `lock` method if that's what's needed) */ - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& getStrong() const; /** Return true if this is a strong pointer and the strong pointer is @@ -67,30 +67,30 @@ public: /** If this is a strong pointer, return the raw pointer. Otherwise return null. */ - T* + [[nodiscard]] T* get() const; /** If this is a strong pointer, return the strong count. Otherwise return 0 */ - std::size_t + [[nodiscard]] std::size_t use_count() const; /** Return true if there is a non-zero strong count. */ - bool + [[nodiscard]] bool expired() const; /** If this is a strong pointer, return the strong pointer. Otherwise attempt to lock the weak pointer. */ - std::shared_ptr + [[nodiscard]] std::shared_ptr lock() const; /** Return true is this represents a strong pointer. */ - bool + [[nodiscard]] bool isStrong() const; /** Return true is this represents a weak pointer. */ - bool + [[nodiscard]] bool isWeak() const; /** If this is a weak pointer, attempt to convert it to a strong pointer. diff --git a/include/xrpl/basics/SlabAllocator.h b/include/xrpl/basics/SlabAllocator.h index 5cc17858e2..39be029b42 100644 --- a/include/xrpl/basics/SlabAllocator.h +++ b/include/xrpl/basics/SlabAllocator.h @@ -180,7 +180,7 @@ public: ~SlabAllocator() = default; /** Returns the size of the memory block this allocator returns. */ - constexpr std::size_t + [[nodiscard]] constexpr std::size_t size() const noexcept { return itemSize_; diff --git a/include/xrpl/basics/Slice.h b/include/xrpl/basics/Slice.h index 08ee9464ef..4be7d9d0bb 100644 --- a/include/xrpl/basics/Slice.h +++ b/include/xrpl/basics/Slice.h @@ -74,7 +74,7 @@ public: @note The return type is guaranteed to be a pointer to a single byte, to facilitate pointer arithmetic. */ - std::uint8_t const* + [[nodiscard]] std::uint8_t const* data() const noexcept { return data_; @@ -123,25 +123,25 @@ public: size_ -= n; } - const_iterator + [[nodiscard]] const_iterator begin() const noexcept { return data_; } - const_iterator + [[nodiscard]] const_iterator cbegin() const noexcept { return data_; } - const_iterator + [[nodiscard]] const_iterator end() const noexcept { return data_ + size_; } - const_iterator + [[nodiscard]] const_iterator cend() const noexcept { return data_ + size_; @@ -158,7 +158,7 @@ public: @returns The requested subslice, if the request is valid. @throws std::out_of_range if pos > size() */ - Slice + [[nodiscard]] Slice substr(std::size_t pos, std::size_t count = std::numeric_limits::max()) const { if (pos > size()) diff --git a/include/xrpl/basics/TaggedCache.h b/include/xrpl/basics/TaggedCache.h index d20c850bad..8cb0c6bfdf 100644 --- a/include/xrpl/basics/TaggedCache.h +++ b/include/xrpl/basics/TaggedCache.h @@ -222,19 +222,19 @@ private: { } - bool + [[nodiscard]] bool isWeak() const { if (!ptr) return true; return ptr.isWeak(); } - bool + [[nodiscard]] bool isCached() const { return ptr && ptr.isStrong(); } - bool + [[nodiscard]] bool isExpired() const { return ptr.expired(); diff --git a/include/xrpl/basics/base_uint.h b/include/xrpl/basics/base_uint.h index 55b73bfb9b..b6ff5ea9c0 100644 --- a/include/xrpl/basics/base_uint.h +++ b/include/xrpl/basics/base_uint.h @@ -102,7 +102,7 @@ public: { return reinterpret_cast(data_.data()); } - const_pointer + [[nodiscard]] const_pointer data() const { return reinterpret_cast(data_.data()); @@ -118,22 +118,22 @@ public: { return data() + bytes; } - const_iterator + [[nodiscard]] const_iterator begin() const { return data(); } - const_iterator + [[nodiscard]] const_iterator end() const { return data() + bytes; } - const_iterator + [[nodiscard]] const_iterator cbegin() const { return data(); } - const_iterator + [[nodiscard]] const_iterator cend() const { return data() + bytes; @@ -310,7 +310,7 @@ public: return fromVoid(from.data()); } - constexpr int + [[nodiscard]] constexpr int signum() const { for (int i = 0; i < WIDTH; i++) @@ -433,14 +433,14 @@ public: return ret; } - base_uint + [[nodiscard]] base_uint next() const { auto ret = *this; return ++ret; } - base_uint + [[nodiscard]] base_uint prev() const { auto ret = *this; @@ -517,12 +517,12 @@ public: } // Deprecated. - bool + [[nodiscard]] bool isZero() const { return *this == beast::zero; } - bool + [[nodiscard]] bool isNonZero() const { return *this != beast::zero; diff --git a/include/xrpl/beast/asio/io_latency_probe.h b/include/xrpl/beast/asio/io_latency_probe.h index 9a8a63de4e..dccb6d24b4 100644 --- a/include/xrpl/beast/asio/io_latency_probe.h +++ b/include/xrpl/beast/asio/io_latency_probe.h @@ -49,7 +49,7 @@ public: return m_ios; } - boost::asio::io_context const& + [[nodiscard]] boost::asio::io_context const& get_io_context() const { return m_ios; diff --git a/include/xrpl/beast/clock/abstract_clock.h b/include/xrpl/beast/clock/abstract_clock.h index 41b57fdd2c..09de3f891d 100644 --- a/include/xrpl/beast/clock/abstract_clock.h +++ b/include/xrpl/beast/clock/abstract_clock.h @@ -63,7 +63,7 @@ struct abstract_clock_wrapper : public abstract_clock using typename abstract_clock::duration; using typename abstract_clock::time_point; - time_point + [[nodiscard]] time_point now() const override { return Clock::now(); diff --git a/include/xrpl/beast/clock/manual_clock.h b/include/xrpl/beast/clock/manual_clock.h index b959a95b90..3cabdc0ea8 100644 --- a/include/xrpl/beast/clock/manual_clock.h +++ b/include/xrpl/beast/clock/manual_clock.h @@ -32,7 +32,7 @@ public: { } - time_point + [[nodiscard]] time_point now() const override { return now_; diff --git a/include/xrpl/beast/container/detail/aged_container_iterator.h b/include/xrpl/beast/container/detail/aged_container_iterator.h index 3f12a5610a..ffa251b7a6 100644 --- a/include/xrpl/beast/container/detail/aged_container_iterator.h +++ b/include/xrpl/beast/container/detail/aged_container_iterator.h @@ -115,7 +115,7 @@ public: return &m_iter->value; } - time_point const& + [[nodiscard]] time_point const& when() const { return m_iter->when; @@ -136,7 +136,7 @@ private: { } - Iterator const& + [[nodiscard]] Iterator const& iterator() const { return m_iter; diff --git a/include/xrpl/beast/container/detail/aged_ordered_container.h b/include/xrpl/beast/container/detail/aged_ordered_container.h index b20639aec4..83a2882746 100644 --- a/include/xrpl/beast/container/detail/aged_ordered_container.h +++ b/include/xrpl/beast/container/detail/aged_ordered_container.h @@ -186,7 +186,7 @@ private: return *this; } - Compare const& + [[nodiscard]] Compare const& compare() const { return *this; @@ -295,7 +295,7 @@ private: return KeyValueCompare::compare(); } - Compare const& + [[nodiscard]] Compare const& compare() const { return KeyValueCompare::compare(); @@ -307,7 +307,7 @@ private: return *this; } - KeyValueCompare const& + [[nodiscard]] KeyValueCompare const& key_compare() const { return *this; @@ -319,7 +319,7 @@ private: return beast::detail::empty_base_optimization::member(); } - ElementAllocator const& + [[nodiscard]] ElementAllocator const& alloc() const { return beast::detail::empty_base_optimization::member(); diff --git a/include/xrpl/beast/container/detail/aged_unordered_container.h b/include/xrpl/beast/container/detail/aged_unordered_container.h index 15565bbada..7fe3a8b38a 100644 --- a/include/xrpl/beast/container/detail/aged_unordered_container.h +++ b/include/xrpl/beast/container/detail/aged_unordered_container.h @@ -149,7 +149,7 @@ private: return *this; } - Hash const& + [[nodiscard]] Hash const& hash_function() const { return *this; @@ -195,7 +195,7 @@ private: return *this; } - KeyEqual const& + [[nodiscard]] KeyEqual const& key_eq() const { return *this; @@ -348,7 +348,7 @@ private: return *this; } - ValueHash const& + [[nodiscard]] ValueHash const& value_hash() const { return *this; @@ -360,7 +360,7 @@ private: return ValueHash::hash_function(); } - Hash const& + [[nodiscard]] Hash const& hash_function() const { return ValueHash::hash_function(); @@ -372,7 +372,7 @@ private: return *this; } - KeyValueEqual const& + [[nodiscard]] KeyValueEqual const& key_value_equal() const { return *this; @@ -384,7 +384,7 @@ private: return key_value_equal().key_eq(); } - KeyEqual const& + [[nodiscard]] KeyEqual const& key_eq() const { return key_value_equal().key_eq(); @@ -396,7 +396,7 @@ private: return beast::detail::empty_base_optimization::member(); } - ElementAllocator const& + [[nodiscard]] ElementAllocator const& alloc() const { return beast::detail::empty_base_optimization::member(); @@ -433,7 +433,7 @@ private: m_vec.clear(); } - size_type + [[nodiscard]] size_type max_bucket_count() const { return m_vec.max_size(); @@ -445,7 +445,7 @@ private: return m_max_load_factor; } - float const& + [[nodiscard]] float const& max_load_factor() const { return m_max_load_factor; diff --git a/include/xrpl/beast/container/detail/empty_base_optimization.h b/include/xrpl/beast/container/detail/empty_base_optimization.h index 337f3cf434..230845102d 100644 --- a/include/xrpl/beast/container/detail/empty_base_optimization.h +++ b/include/xrpl/beast/container/detail/empty_base_optimization.h @@ -43,7 +43,7 @@ public: return *this; } - T const& + [[nodiscard]] T const& member() const noexcept { return *this; diff --git a/include/xrpl/beast/core/List.h b/include/xrpl/beast/core/List.h index ab88eae738..30a5166c62 100644 --- a/include/xrpl/beast/core/List.h +++ b/include/xrpl/beast/core/List.h @@ -128,7 +128,7 @@ public: } private: - reference + [[nodiscard]] reference dereference() const noexcept { return static_cast(*m_node); @@ -287,14 +287,14 @@ public: /** Determine if the list is empty. @return `true` if the list is empty. */ - bool + [[nodiscard]] bool empty() const noexcept { return size() == 0; } /** Returns the number of elements in the list. */ - size_type + [[nodiscard]] size_type size() const noexcept { return m_size; @@ -314,7 +314,7 @@ public: @invariant The list may not be empty. @return A const reference to the first element. */ - const_reference + [[nodiscard]] const_reference front() const noexcept { return element_from(m_head.m_next); @@ -334,7 +334,7 @@ public: @invariant The list may not be empty. @return A const reference to the last element. */ - const_reference + [[nodiscard]] const_reference back() const noexcept { return element_from(m_tail.m_prev); @@ -352,7 +352,7 @@ public: /** Obtain a const iterator to the beginning of the list. @return A const iterator pointing to the beginning of the list. */ - const_iterator + [[nodiscard]] const_iterator begin() const noexcept { return const_iterator(m_head.m_next); @@ -361,7 +361,7 @@ public: /** Obtain a const iterator to the beginning of the list. @return A const iterator pointing to the beginning of the list. */ - const_iterator + [[nodiscard]] const_iterator cbegin() const noexcept { return const_iterator(m_head.m_next); @@ -379,7 +379,7 @@ public: /** Obtain a const iterator to the end of the list. @return A constiterator pointing to the end of the list. */ - const_iterator + [[nodiscard]] const_iterator end() const noexcept { return const_iterator(&m_tail); @@ -388,7 +388,7 @@ public: /** Obtain a const iterator to the end of the list @return A constiterator pointing to the end of the list. */ - const_iterator + [[nodiscard]] const_iterator cend() const noexcept { return const_iterator(&m_tail); @@ -549,7 +549,7 @@ public: @param element The element to obtain an iterator for. @return A const iterator to the element. */ - const_iterator + [[nodiscard]] const_iterator const_iterator_to(T const& element) const noexcept { return const_iterator(static_cast(&element)); diff --git a/include/xrpl/beast/core/LockFreeStack.h b/include/xrpl/beast/core/LockFreeStack.h index 2c03e58f68..03598915df 100644 --- a/include/xrpl/beast/core/LockFreeStack.h +++ b/include/xrpl/beast/core/LockFreeStack.h @@ -162,7 +162,7 @@ public: operator=(LockFreeStack const&) = delete; /** Returns true if the stack is empty. */ - bool + [[nodiscard]] bool empty() const { return m_head.load() == &m_end; @@ -237,25 +237,25 @@ public: return iterator(&m_end); } - const_iterator + [[nodiscard]] const_iterator begin() const { return const_iterator(m_head.load()); } - const_iterator + [[nodiscard]] const_iterator end() const { return const_iterator(&m_end); } - const_iterator + [[nodiscard]] const_iterator cbegin() const { return const_iterator(m_head.load()); } - const_iterator + [[nodiscard]] const_iterator cend() const { return const_iterator(&m_end); diff --git a/include/xrpl/beast/core/SemanticVersion.h b/include/xrpl/beast/core/SemanticVersion.h index 244783234c..826a43d3f8 100644 --- a/include/xrpl/beast/core/SemanticVersion.h +++ b/include/xrpl/beast/core/SemanticVersion.h @@ -37,15 +37,15 @@ public: parse(std::string_view input); /** Produce a string from semantic version components. */ - std::string + [[nodiscard]] std::string print() const; - bool + [[nodiscard]] bool isRelease() const noexcept { return preReleaseIdentifiers.empty(); } - bool + [[nodiscard]] bool isPreRelease() const noexcept { return !isRelease(); diff --git a/include/xrpl/beast/insight/Event.h b/include/xrpl/beast/insight/Event.h index ada488f134..28994db956 100644 --- a/include/xrpl/beast/insight/Event.h +++ b/include/xrpl/beast/insight/Event.h @@ -45,7 +45,7 @@ public: m_impl->notify(ceil(value)); } - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& impl() const { return m_impl; diff --git a/include/xrpl/beast/insight/Gauge.h b/include/xrpl/beast/insight/Gauge.h index b75060face..8a7de33e2e 100644 --- a/include/xrpl/beast/insight/Gauge.h +++ b/include/xrpl/beast/insight/Gauge.h @@ -108,7 +108,7 @@ public: } /** @} */ - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& impl() const { return m_impl; diff --git a/include/xrpl/beast/insight/Group.h b/include/xrpl/beast/insight/Group.h index 2b0d692f25..3e0eb93452 100644 --- a/include/xrpl/beast/insight/Group.h +++ b/include/xrpl/beast/insight/Group.h @@ -14,7 +14,7 @@ public: using ptr = std::shared_ptr; /** Returns the name of this group, for diagnostics. */ - virtual std::string const& + [[nodiscard]] virtual std::string const& name() const = 0; }; diff --git a/include/xrpl/beast/insight/Hook.h b/include/xrpl/beast/insight/Hook.h index d51a5d2300..d873411390 100644 --- a/include/xrpl/beast/insight/Hook.h +++ b/include/xrpl/beast/insight/Hook.h @@ -24,7 +24,7 @@ public: { } - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& impl() const { return m_impl; diff --git a/include/xrpl/beast/insight/Meter.h b/include/xrpl/beast/insight/Meter.h index 7685a0ec90..93ae237956 100644 --- a/include/xrpl/beast/insight/Meter.h +++ b/include/xrpl/beast/insight/Meter.h @@ -63,7 +63,7 @@ public: } /** @} */ - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& impl() const { return m_impl; diff --git a/include/xrpl/beast/net/IPEndpoint.h b/include/xrpl/beast/net/IPEndpoint.h index 88f3d7669b..15d86d75fe 100644 --- a/include/xrpl/beast/net/IPEndpoint.h +++ b/include/xrpl/beast/net/IPEndpoint.h @@ -32,25 +32,25 @@ public: from_string(std::string const& s); /** Returns a string representing the endpoint. */ - std::string + [[nodiscard]] std::string to_string() const; /** Returns the port number on the endpoint. */ - Port + [[nodiscard]] Port port() const { return m_port; } /** Returns a new Endpoint with a different port. */ - Endpoint + [[nodiscard]] Endpoint at_port(Port port) const { return Endpoint(m_addr, port); } /** Returns the address portion of this endpoint. */ - Address const& + [[nodiscard]] Address const& address() const { return m_addr; @@ -58,22 +58,22 @@ public: /** Convenience accessors for the address part. */ /** @{ */ - bool + [[nodiscard]] bool is_v4() const { return m_addr.is_v4(); } - bool + [[nodiscard]] bool is_v6() const { return m_addr.is_v6(); } - AddressV4 + [[nodiscard]] AddressV4 to_v4() const { return m_addr.to_v4(); } - AddressV6 + [[nodiscard]] AddressV6 to_v6() const { return m_addr.to_v6(); diff --git a/include/xrpl/beast/unit_test/detail/const_container.h b/include/xrpl/beast/unit_test/detail/const_container.h index 6a32c61b61..a36423f0ef 100644 --- a/include/xrpl/beast/unit_test/detail/const_container.h +++ b/include/xrpl/beast/unit_test/detail/const_container.h @@ -25,7 +25,7 @@ protected: return m_cont; } - cont_type const& + [[nodiscard]] cont_type const& cont() const { return m_cont; @@ -39,14 +39,14 @@ public: using const_iterator = typename cont_type::const_iterator; /** Returns `true` if the container is empty. */ - bool + [[nodiscard]] bool empty() const { return m_cont.empty(); } /** Returns the number of items in the container. */ - size_type + [[nodiscard]] size_type size() const { return m_cont.size(); @@ -54,25 +54,25 @@ public: /** Returns forward iterators for traversal. */ /** @{ */ - const_iterator + [[nodiscard]] const_iterator begin() const { return m_cont.cbegin(); } - const_iterator + [[nodiscard]] const_iterator cbegin() const { return m_cont.cbegin(); } - const_iterator + [[nodiscard]] const_iterator end() const { return m_cont.cend(); } - const_iterator + [[nodiscard]] const_iterator cend() const { return m_cont.cend(); diff --git a/include/xrpl/beast/unit_test/recorder.h b/include/xrpl/beast/unit_test/recorder.h index f101d5318f..55305a4b70 100644 --- a/include/xrpl/beast/unit_test/recorder.h +++ b/include/xrpl/beast/unit_test/recorder.h @@ -21,7 +21,7 @@ public: recorder() = default; /** Returns a report with the results of all completed suites. */ - results const& + [[nodiscard]] results const& report() const { return m_results; diff --git a/include/xrpl/beast/unit_test/results.h b/include/xrpl/beast/unit_test/results.h index 5607071729..71c9aff47f 100644 --- a/include/xrpl/beast/unit_test/results.h +++ b/include/xrpl/beast/unit_test/results.h @@ -41,14 +41,14 @@ private: tests_t() = default; /** Returns the total number of test conditions. */ - std::size_t + [[nodiscard]] std::size_t total() const { return cont().size(); } /** Returns the number of failed test conditions. */ - std::size_t + [[nodiscard]] std::size_t failed() const { return failed_; @@ -89,7 +89,7 @@ public: } /** Returns the name of this testcase. */ - std::string const& + [[nodiscard]] std::string const& name() const { return name_; @@ -118,21 +118,21 @@ public: } /** Returns the name of this suite. */ - std::string const& + [[nodiscard]] std::string const& name() const { return name_; } /** Returns the total number of test conditions. */ - std::size_t + [[nodiscard]] std::size_t total() const { return total_; } /** Returns the number of failures. */ - std::size_t + [[nodiscard]] std::size_t failed() const { return failed_; @@ -173,21 +173,21 @@ public: results() = default; /** Returns the total number of test cases. */ - std::size_t + [[nodiscard]] std::size_t cases() const { return m_cases; } /** Returns the total number of test conditions. */ - std::size_t + [[nodiscard]] std::size_t total() const { return total_; } /** Returns the number of failures. */ - std::size_t + [[nodiscard]] std::size_t failed() const { return failed_; diff --git a/include/xrpl/beast/unit_test/runner.h b/include/xrpl/beast/unit_test/runner.h index 3443308675..2fdfbefa57 100644 --- a/include/xrpl/beast/unit_test/runner.h +++ b/include/xrpl/beast/unit_test/runner.h @@ -47,7 +47,7 @@ public: } /** Returns the argument string. */ - std::string const& + [[nodiscard]] std::string const& arg() const { return arg_; diff --git a/include/xrpl/beast/unit_test/suite.h b/include/xrpl/beast/unit_test/suite.h index 1719c519cf..a7b9d3bacb 100644 --- a/include/xrpl/beast/unit_test/suite.h +++ b/include/xrpl/beast/unit_test/suite.h @@ -57,7 +57,7 @@ private: // in the event of a failure, if the option to stop is set. struct abort_exception : public std::exception { - char const* + [[nodiscard]] char const* what() const noexcept override { return "test suite aborted"; diff --git a/include/xrpl/beast/unit_test/suite_info.h b/include/xrpl/beast/unit_test/suite_info.h index e7fa80b70e..e814d518cb 100644 --- a/include/xrpl/beast/unit_test/suite_info.h +++ b/include/xrpl/beast/unit_test/suite_info.h @@ -42,33 +42,33 @@ public: { } - std::string const& + [[nodiscard]] std::string const& name() const { return name_; } - std::string const& + [[nodiscard]] std::string const& module() const { return module_; } - std::string const& + [[nodiscard]] std::string const& library() const { return library_; } /// Returns `true` if this suite only runs manually. - bool + [[nodiscard]] bool manual() const { return manual_; } /// Return the canonical suite name as a string. - std::string + [[nodiscard]] std::string full_name() const { return library_ + "." + module_ + "." + name_; diff --git a/include/xrpl/beast/unit_test/thread.h b/include/xrpl/beast/unit_test/thread.h index cc12380b0d..aa9ff3b0d9 100644 --- a/include/xrpl/beast/unit_test/thread.h +++ b/include/xrpl/beast/unit_test/thread.h @@ -47,13 +47,13 @@ public: t_ = std::thread(&Thread::run, this, std::move(b)); } - bool + [[nodiscard]] bool joinable() const { return t_.joinable(); } - std::thread::id + [[nodiscard]] std::thread::id get_id() const { return t_.get_id(); diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index 975169cf5f..a056ce8d79 100644 --- a/include/xrpl/beast/utility/Journal.h +++ b/include/xrpl/beast/utility/Journal.h @@ -66,12 +66,12 @@ public: operator=(Sink const& lhs) = delete; /** Returns `true` if text at the passed severity produces output. */ - virtual bool + [[nodiscard]] virtual bool active(Severity level) const; /** Returns `true` if a message is also written to the Output Window * (MSVC). */ - virtual bool + [[nodiscard]] virtual bool console() const; /** Set whether messages are also written to the Output Window (MSVC). @@ -80,7 +80,7 @@ public: console(bool output); /** Returns the minimum severity level this sink will report. */ - virtual Severity + [[nodiscard]] virtual Severity threshold() const; /** Set the minimum severity this sink will report. */ @@ -204,14 +204,14 @@ public: operator=(Stream const& other) = delete; /** Returns the Sink that this Stream writes to. */ - Sink& + [[nodiscard]] Sink& sink() const { return m_sink; } /** Returns the Severity level of messages this Stream reports. */ - Severity + [[nodiscard]] Severity level() const { return m_level; @@ -219,7 +219,7 @@ public: /** Returns `true` if sink logs anything at this stream's level. */ /** @{ */ - bool + [[nodiscard]] bool active() const { return m_sink.active(m_level); @@ -267,14 +267,14 @@ public: } /** Returns the Sink associated with this Journal. */ - Sink& + [[nodiscard]] Sink& sink() const { return *m_sink; } /** Returns a stream for this sink, with the specified severity level. */ - Stream + [[nodiscard]] Stream stream(Severity level) const { return Stream(*m_sink, level); @@ -284,7 +284,7 @@ public: For a message to be logged, the severity must be at or above the sink's severity threshold. */ - bool + [[nodiscard]] bool active(Severity level) const { return m_sink->active(level); @@ -292,37 +292,37 @@ public: /** Severity stream access functions. */ /** @{ */ - Stream + [[nodiscard]] Stream trace() const { return {*m_sink, severities::kTrace}; } - Stream + [[nodiscard]] Stream debug() const { return {*m_sink, severities::kDebug}; } - Stream + [[nodiscard]] Stream info() const { return {*m_sink, severities::kInfo}; } - Stream + [[nodiscard]] Stream warn() const { return {*m_sink, severities::kWarning}; } - Stream + [[nodiscard]] Stream error() const { return {*m_sink, severities::kError}; } - Stream + [[nodiscard]] Stream fatal() const { return {*m_sink, severities::kFatal}; diff --git a/include/xrpl/beast/utility/PropertyStream.h b/include/xrpl/beast/utility/PropertyStream.h index b2bd8c7a35..39e354cc31 100644 --- a/include/xrpl/beast/utility/PropertyStream.h +++ b/include/xrpl/beast/utility/PropertyStream.h @@ -149,7 +149,7 @@ class PropertyStream::Item : public List::Node { public: explicit Item(Source* source); - Source& + [[nodiscard]] Source& source() const; Source* operator->() const; @@ -217,7 +217,7 @@ public: PropertyStream& stream(); - PropertyStream const& + [[nodiscard]] PropertyStream const& stream() const; template @@ -287,7 +287,7 @@ public: PropertyStream& stream(); - PropertyStream const& + [[nodiscard]] PropertyStream const& stream() const; template @@ -323,7 +323,7 @@ public: operator=(Source const&) = delete; /** Returns the name of this source. */ - std::string const& + [[nodiscard]] std::string const& name() const; /** Add a child source. */ diff --git a/include/xrpl/beast/utility/WrappedSink.h b/include/xrpl/beast/utility/WrappedSink.h index 7e36ce99d7..57f0a02413 100644 --- a/include/xrpl/beast/utility/WrappedSink.h +++ b/include/xrpl/beast/utility/WrappedSink.h @@ -35,13 +35,13 @@ public: prefix_ = s; } - bool + [[nodiscard]] bool active(beast::severities::Severity level) const override { return sink_.active(level); } - bool + [[nodiscard]] bool console() const override { return sink_.console(); @@ -53,7 +53,7 @@ public: sink_.console(output); } - beast::severities::Severity + [[nodiscard]] beast::severities::Severity threshold() const override { return sink_.threshold(); diff --git a/include/xrpl/beast/utility/temp_dir.h b/include/xrpl/beast/utility/temp_dir.h index 5aa7b28ac2..09e68c4e6b 100644 --- a/include/xrpl/beast/utility/temp_dir.h +++ b/include/xrpl/beast/utility/temp_dir.h @@ -43,7 +43,7 @@ public: } /// Get the native path for the temporary directory - std::string + [[nodiscard]] std::string path() const { return path_.string(); @@ -53,7 +53,7 @@ public: The file does not need to exist. */ - std::string + [[nodiscard]] std::string file(std::string const& name) const { return (path_ / name).string(); diff --git a/include/xrpl/conditions/Fulfillment.h b/include/xrpl/conditions/Fulfillment.h index 71ff9d83ef..cf28e29185 100644 --- a/include/xrpl/conditions/Fulfillment.h +++ b/include/xrpl/conditions/Fulfillment.h @@ -41,15 +41,15 @@ public: with respect to other conditions of the same type. */ - virtual Buffer + [[nodiscard]] virtual Buffer fingerprint() const = 0; /** Returns the type of this condition. */ - virtual Type + [[nodiscard]] virtual Type type() const = 0; /** Validates a fulfillment. */ - virtual bool + [[nodiscard]] virtual bool validate(Slice data) const = 0; /** Calculates the cost associated with this fulfillment. * @@ -58,7 +58,7 @@ public: type and properties of the condition and the fulfillment that the condition is generated from. */ - virtual std::uint32_t + [[nodiscard]] virtual std::uint32_t cost() const = 0; /** Returns the condition associated with the given fulfillment. @@ -67,7 +67,7 @@ public: will, if compliant, produce the identical condition for the same fulfillment. */ - virtual Condition + [[nodiscard]] virtual Condition condition() const = 0; }; diff --git a/include/xrpl/conditions/detail/PreimageSha256.h b/include/xrpl/conditions/detail/PreimageSha256.h index bfa59ab749..1e5e93eb89 100644 --- a/include/xrpl/conditions/detail/PreimageSha256.h +++ b/include/xrpl/conditions/detail/PreimageSha256.h @@ -90,13 +90,13 @@ public: { } - Type + [[nodiscard]] Type type() const override { return Type::preimageSha256; } - Buffer + [[nodiscard]] Buffer fingerprint() const override { sha256_hasher h; @@ -105,19 +105,19 @@ public: return {d.data(), d.size()}; } - std::uint32_t + [[nodiscard]] std::uint32_t cost() const override { return static_cast(payload_.size()); } - Condition + [[nodiscard]] Condition condition() const override { return {type(), cost(), fingerprint()}; } - bool + [[nodiscard]] bool validate(Slice) const override { // Perhaps counterintuitively, the message isn't diff --git a/include/xrpl/core/HashRouter.h b/include/xrpl/core/HashRouter.h index 3bc87f9524..230fc06dbc 100644 --- a/include/xrpl/core/HashRouter.h +++ b/include/xrpl/core/HashRouter.h @@ -118,7 +118,7 @@ private: peers_.insert(peer); } - HashRouterFlags + [[nodiscard]] HashRouterFlags getFlags(void) const { return flags_; @@ -138,7 +138,7 @@ private: } /** Return seated relay time point if the message has been relayed */ - std::optional + [[nodiscard]] std::optional relayed() const { return relayed_; diff --git a/include/xrpl/core/Job.h b/include/xrpl/core/Job.h index b01b4cd68b..9954fc4ba4 100644 --- a/include/xrpl/core/Job.h +++ b/include/xrpl/core/Job.h @@ -98,11 +98,11 @@ public: LoadMonitor& lm, std::function const& job); - JobType + [[nodiscard]] JobType getType() const; /** Returns the time when the job was queued. */ - clock_type::time_point const& + [[nodiscard]] clock_type::time_point const& queue_time() const; void diff --git a/include/xrpl/core/JobQueue.h b/include/xrpl/core/JobQueue.h index 3c1bde89c3..bac616470a 100644 --- a/include/xrpl/core/JobQueue.h +++ b/include/xrpl/core/JobQueue.h @@ -7,8 +7,13 @@ #include #include +// Include only the specific Boost.Coroutine2 headers actually used here. +// Avoid `boost/coroutine2/all.hpp` because it transitively pulls in +// `boost/context/pooled_fixedsize_stack.hpp`, whose `.malloc()` / `.free()` +// member calls on `boost::pool` collide with MSVC's `_CRTDBG_MAP_ALLOC` macros +// in Debug builds (see cmake/XrplCompiler.cmake). #include -#include +#include #include diff --git a/include/xrpl/core/JobTypeData.h b/include/xrpl/core/JobTypeData.h index 917f838990..20a85e04c1 100644 --- a/include/xrpl/core/JobTypeData.h +++ b/include/xrpl/core/JobTypeData.h @@ -54,13 +54,13 @@ public: JobTypeData& operator=(JobTypeData const& other) = delete; - std::string + [[nodiscard]] std::string name() const { return info.name(); } - JobType + [[nodiscard]] JobType type() const { return info.type(); diff --git a/include/xrpl/core/JobTypeInfo.h b/include/xrpl/core/JobTypeInfo.h index 537656fa1d..81c4557be2 100644 --- a/include/xrpl/core/JobTypeInfo.h +++ b/include/xrpl/core/JobTypeInfo.h @@ -40,37 +40,37 @@ public: { } - JobType + [[nodiscard]] JobType type() const { return m_type; } - std::string const& + [[nodiscard]] std::string const& name() const { return m_name; } - int + [[nodiscard]] int limit() const { return m_limit; } - bool + [[nodiscard]] bool special() const { return m_limit == 0; } - std::chrono::milliseconds + [[nodiscard]] std::chrono::milliseconds getAverageLatency() const { return m_avgLatency; } - std::chrono::milliseconds + [[nodiscard]] std::chrono::milliseconds getPeakLatency() const { return m_peakLatency; diff --git a/include/xrpl/core/JobTypes.h b/include/xrpl/core/JobTypes.h index 1fb6f61573..cc5b54fea7 100644 --- a/include/xrpl/core/JobTypes.h +++ b/include/xrpl/core/JobTypes.h @@ -113,7 +113,7 @@ public: return instance().get(jt).name(); } - JobTypeInfo const& + [[nodiscard]] JobTypeInfo const& get(JobType jt) const { Map::const_iterator const iter(m_map.find(jt)); @@ -125,37 +125,37 @@ public: return m_unknown; } - JobTypeInfo const& + [[nodiscard]] JobTypeInfo const& getInvalid() const { return m_unknown; } - Map::size_type + [[nodiscard]] Map::size_type size() const { return m_map.size(); } - const_iterator + [[nodiscard]] const_iterator begin() const { return m_map.cbegin(); } - const_iterator + [[nodiscard]] const_iterator cbegin() const { return m_map.cbegin(); } - const_iterator + [[nodiscard]] const_iterator end() const { return m_map.cend(); } - const_iterator + [[nodiscard]] const_iterator cend() const { return m_map.cend(); diff --git a/include/xrpl/core/LoadEvent.h b/include/xrpl/core/LoadEvent.h index 87d4a5563d..0536b25709 100644 --- a/include/xrpl/core/LoadEvent.h +++ b/include/xrpl/core/LoadEvent.h @@ -21,15 +21,15 @@ public: ~LoadEvent(); - std::string const& + [[nodiscard]] std::string const& name() const; // The time spent waiting. - std::chrono::steady_clock::duration + [[nodiscard]] std::chrono::steady_clock::duration waitTime() const; // The time spent running. - std::chrono::steady_clock::duration + [[nodiscard]] std::chrono::steady_clock::duration runTime() const; void diff --git a/include/xrpl/core/NetworkIDService.h b/include/xrpl/core/NetworkIDService.h index d12fa42055..009f9ba6f8 100644 --- a/include/xrpl/core/NetworkIDService.h +++ b/include/xrpl/core/NetworkIDService.h @@ -26,7 +26,7 @@ public: * * @return The network ID this server is configured for */ - virtual std::uint32_t + [[nodiscard]] virtual std::uint32_t getNetworkID() const noexcept = 0; }; diff --git a/include/xrpl/core/PeerReservationTable.h b/include/xrpl/core/PeerReservationTable.h index 3fb85e392f..0d107e879c 100644 --- a/include/xrpl/core/PeerReservationTable.h +++ b/include/xrpl/core/PeerReservationTable.h @@ -22,7 +22,7 @@ public: PublicKey nodeId; std::string description = {}; // NOLINT(readability-redundant-member-init) - auto + [[nodiscard]] auto toJson() const -> Json::Value; template diff --git a/include/xrpl/core/PerfLog.h b/include/xrpl/core/PerfLog.h index 8da6a313c8..7151d09b08 100644 --- a/include/xrpl/core/PerfLog.h +++ b/include/xrpl/core/PerfLog.h @@ -121,7 +121,7 @@ public: * * @return Counters Json object */ - virtual Json::Value + [[nodiscard]] virtual Json::Value countersJson() const = 0; /** @@ -129,7 +129,7 @@ public: * * @return Current executing jobs and RPC calls and durations */ - virtual Json::Value + [[nodiscard]] virtual Json::Value currentJson() const = 0; /** diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h index 8b7d4b4464..1d0c9e38f4 100644 --- a/include/xrpl/core/ServiceRegistry.h +++ b/include/xrpl/core/ServiceRegistry.h @@ -192,7 +192,7 @@ public: virtual OpenLedger& getOpenLedger() = 0; - virtual OpenLedger const& + [[nodiscard]] virtual OpenLedger const& getOpenLedger() const = 0; // Transaction and operation services @@ -219,7 +219,7 @@ public: getPerfLog() = 0; // Configuration and state - virtual bool + [[nodiscard]] virtual bool isStopping() const = 0; virtual beast::Journal @@ -231,7 +231,7 @@ public: virtual Logs& getLogs() = 0; - virtual std::optional const& + [[nodiscard]] virtual std::optional const& getTrapTxID() const = 0; /** Retrieve the "wallet database" */ diff --git a/include/xrpl/core/detail/Workers.h b/include/xrpl/core/detail/Workers.h index bd82f9d57b..fb9004a9b6 100644 --- a/include/xrpl/core/detail/Workers.h +++ b/include/xrpl/core/detail/Workers.h @@ -106,7 +106,7 @@ public: @note This function is not thread-safe. */ - int + [[nodiscard]] int getNumberOfThreads() const noexcept; /** Set the desired number of threads. @@ -141,7 +141,7 @@ public: While this function is thread-safe, the value may not stay accurate for very long. It's mainly for diagnostic purposes. */ - int + [[nodiscard]] int numberOfCurrentlyRunningTasks() const noexcept; //-------------------------------------------------------------------------- diff --git a/include/xrpl/json/JsonPropertyStream.h b/include/xrpl/json/JsonPropertyStream.h index 510ed72950..e0a13c4001 100644 --- a/include/xrpl/json/JsonPropertyStream.h +++ b/include/xrpl/json/JsonPropertyStream.h @@ -14,7 +14,7 @@ public: public: JsonPropertyStream(); - Json::Value const& + [[nodiscard]] Json::Value const& top() const; protected: diff --git a/include/xrpl/json/json_reader.h b/include/xrpl/json/json_reader.h index dd1be76923..d53569fb33 100644 --- a/include/xrpl/json/json_reader.h +++ b/include/xrpl/json/json_reader.h @@ -64,7 +64,7 @@ public: * their location in the parsed document. An empty string is returned if no * error occurred during parsing. */ - std::string + [[nodiscard]] std::string getFormattedErrorMessages() const; static constexpr unsigned nest_limit{25}; diff --git a/include/xrpl/json/json_value.h b/include/xrpl/json/json_value.h index ef1d0fbcb8..83b5142b27 100644 --- a/include/xrpl/json/json_value.h +++ b/include/xrpl/json/json_value.h @@ -53,7 +53,7 @@ public: return str_; } - constexpr char const* + [[nodiscard]] constexpr char const* c_str() const { return str_; @@ -158,11 +158,11 @@ private: operator<(CZString const& other) const; bool operator==(CZString const& other) const; - int + [[nodiscard]] int index() const; - char const* + [[nodiscard]] char const* c_str() const; - bool + [[nodiscard]] bool isStaticString() const; private: @@ -223,60 +223,60 @@ public: void swap(Value& other) noexcept; - ValueType + [[nodiscard]] ValueType type() const; - char const* + [[nodiscard]] char const* asCString() const; /** Returns the unquoted string value. */ - std::string + [[nodiscard]] std::string asString() const; - Int + [[nodiscard]] Int asInt() const; - UInt + [[nodiscard]] UInt asUInt() const; - double + [[nodiscard]] double asDouble() const; - bool + [[nodiscard]] bool asBool() const; /** Correct absolute value from int or unsigned int */ - UInt + [[nodiscard]] UInt asAbsUInt() const; // TODO: What is the "empty()" method this docstring mentions? /** isNull() tests to see if this field is null. Don't use this method to test for emptiness: use empty(). */ - bool + [[nodiscard]] bool isNull() const; - bool + [[nodiscard]] bool isBool() const; - bool + [[nodiscard]] bool isInt() const; - bool + [[nodiscard]] bool isUInt() const; - bool + [[nodiscard]] bool isIntegral() const; - bool + [[nodiscard]] bool isDouble() const; - bool + [[nodiscard]] bool isNumeric() const; - bool + [[nodiscard]] bool isString() const; - bool + [[nodiscard]] bool isArray() const; - bool + [[nodiscard]] bool isArrayOrNull() const; - bool + [[nodiscard]] bool isObject() const; - bool + [[nodiscard]] bool isObjectOrNull() const; - bool + [[nodiscard]] bool isConvertibleTo(ValueType other) const; /// Number of values in array or object - UInt + [[nodiscard]] UInt size() const; /** Returns false if this is an empty array, empty object, empty string, @@ -304,10 +304,10 @@ public: operator[](UInt index) const; /// If the array contains at least index+1 elements, returns the element /// value, otherwise returns defaultValue. - Value + [[nodiscard]] Value get(UInt index, Value const& defaultValue) const; /// Return true if index < size(). - bool + [[nodiscard]] bool isValidIndex(UInt index) const; /// \brief Append value to array at the end. /// @@ -355,7 +355,7 @@ public: Value get(char const* key, Value const& defaultValue) const; /// Return the member named key if it exist, defaultValue otherwise. - Value + [[nodiscard]] Value get(std::string const& key, Value const& defaultValue) const; /// \brief Remove and return the named member. @@ -374,10 +374,10 @@ public: bool isMember(char const* key) const; /// Return true if the object has a member named key. - bool + [[nodiscard]] bool isMember(std::string const& key) const; /// Return true if the object has a member named key. - bool + [[nodiscard]] bool isMember(StaticString const& key) const; /// \brief Return a list of the member names. @@ -385,15 +385,15 @@ public: /// If null, return an empty list. /// \pre type() is objectValue or nullValue /// \post if type() was nullValue, it remains nullValue - Members + [[nodiscard]] Members getMemberNames() const; - std::string + [[nodiscard]] std::string toStyledString() const; - const_iterator + [[nodiscard]] const_iterator begin() const; - const_iterator + [[nodiscard]] const_iterator end() const; iterator @@ -513,20 +513,20 @@ public: /// Return either the index or the member name of the referenced value as a /// Value. - Value + [[nodiscard]] Value key() const; /// Return the index of the referenced Value. -1 if it is not an arrayValue. - UInt + [[nodiscard]] UInt index() const; /// Return the member name of the referenced Value. "" if it is not an /// objectValue. - char const* + [[nodiscard]] char const* memberName() const; protected: - Value& + [[nodiscard]] Value& deref() const; void @@ -535,10 +535,10 @@ protected: void decrement(); - difference_type + [[nodiscard]] difference_type computeDistance(SelfType const& other) const; - bool + [[nodiscard]] bool isEqual(SelfType const& other) const; void diff --git a/include/xrpl/ledger/AcceptedLedgerTx.h b/include/xrpl/ledger/AcceptedLedgerTx.h index d07016b860..5d6d471ba0 100644 --- a/include/xrpl/ledger/AcceptedLedgerTx.h +++ b/include/xrpl/ledger/AcceptedLedgerTx.h @@ -30,47 +30,47 @@ public: std::shared_ptr const&, std::shared_ptr const&); - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& getTxn() const { return mTxn; } - TxMeta const& + [[nodiscard]] TxMeta const& getMeta() const { return mMeta; } - boost::container::flat_set const& + [[nodiscard]] boost::container::flat_set const& getAffected() const { return mAffected; } - TxID + [[nodiscard]] TxID getTransactionID() const { return mTxn->getTransactionID(); } - TxType + [[nodiscard]] TxType getTxnType() const { return mTxn->getTxnType(); } - TER + [[nodiscard]] TER getResult() const { return mMeta.getResultTER(); } - std::uint32_t + [[nodiscard]] std::uint32_t getTxnSeq() const { return mMeta.getIndex(); } - std::string + [[nodiscard]] std::string getEscMeta() const; - Json::Value const& + [[nodiscard]] Json::Value const& getJson() const { return mJson; diff --git a/include/xrpl/ledger/AmendmentTable.h b/include/xrpl/ledger/AmendmentTable.h index 8df09f74c3..8f40ccb413 100644 --- a/include/xrpl/ledger/AmendmentTable.h +++ b/include/xrpl/ledger/AmendmentTable.h @@ -36,7 +36,7 @@ public: virtual ~AmendmentTable() = default; - virtual uint256 + [[nodiscard]] virtual uint256 find(std::string const& name) const = 0; virtual bool @@ -47,9 +47,9 @@ public: virtual bool enable(uint256 const& amendment) = 0; - virtual bool + [[nodiscard]] virtual bool isEnabled(uint256 const& amendment) const = 0; - virtual bool + [[nodiscard]] virtual bool isSupported(uint256 const& amendment) const = 0; /** @@ -58,17 +58,17 @@ public: * * @return true if an unsupported feature is enabled on the network */ - virtual bool + [[nodiscard]] virtual bool hasUnsupportedEnabled() const = 0; - virtual std::optional + [[nodiscard]] virtual std::optional firstUnsupportedExpected() const = 0; - virtual Json::Value + [[nodiscard]] virtual Json::Value getJson(bool isAdmin) const = 0; /** Returns a Json::objectValue. */ - virtual Json::Value + [[nodiscard]] virtual Json::Value getJson(uint256 const& amendment, bool isAdmin) const = 0; /** Called when a new fully-validated ledger is accepted. */ @@ -87,7 +87,7 @@ public: /** Called to determine whether the amendment logic needs to process a new validated ledger. (If it could have changed things.) */ - virtual bool + [[nodiscard]] virtual bool needValidatedLedger(LedgerIndex seq) const = 0; virtual void @@ -112,14 +112,14 @@ public: // Called by the consensus code when we need to // add feature entries to a validation - virtual std::vector + [[nodiscard]] virtual std::vector doValidation(std::set const& enabled) const = 0; // The set of amendments to enable in the genesis ledger // This will return all known, non-vetoed amendments. // If we ever have two amendments that should not both be // enabled at the same time, we should ensure one is vetoed. - virtual std::vector + [[nodiscard]] virtual std::vector getDesired() const = 0; // The function below adapts the API callers expect to the diff --git a/include/xrpl/ledger/ApplyView.h b/include/xrpl/ledger/ApplyView.h index 73161453db..bd38b57a58 100644 --- a/include/xrpl/ledger/ApplyView.h +++ b/include/xrpl/ledger/ApplyView.h @@ -134,7 +134,7 @@ public: while transactions applied to the consensus ledger produce hard failures (and claim a fee). */ - virtual ApplyFlags + [[nodiscard]] virtual ApplyFlags flags() const = 0; /** Prepare to modify the SLE associated with key. diff --git a/include/xrpl/ledger/BookDirs.h b/include/xrpl/ledger/BookDirs.h index eb1cbcbfa7..4cbbbd78ce 100644 --- a/include/xrpl/ledger/BookDirs.h +++ b/include/xrpl/ledger/BookDirs.h @@ -22,10 +22,10 @@ public: BookDirs(ReadView const&, Book const&); - const_iterator + [[nodiscard]] const_iterator begin() const; - const_iterator + [[nodiscard]] const_iterator end() const; }; diff --git a/include/xrpl/ledger/CanonicalTXSet.h b/include/xrpl/ledger/CanonicalTXSet.h index 857b82a734..8653816eee 100644 --- a/include/xrpl/ledger/CanonicalTXSet.h +++ b/include/xrpl/ledger/CanonicalTXSet.h @@ -59,13 +59,13 @@ private: return !(lhs == rhs); } - uint256 const& + [[nodiscard]] uint256 const& getAccount() const { return account_; } - uint256 const& + [[nodiscard]] uint256 const& getTXID() const { return txId_; @@ -118,30 +118,30 @@ public: return map_.erase(it); } - const_iterator + [[nodiscard]] const_iterator begin() const { return map_.begin(); } - const_iterator + [[nodiscard]] const_iterator end() const { return map_.end(); } - size_t + [[nodiscard]] size_t size() const { return map_.size(); } - bool + [[nodiscard]] bool empty() const { return map_.empty(); } - uint256 const& + [[nodiscard]] uint256 const& key() const { return salt_; diff --git a/include/xrpl/ledger/Dir.h b/include/xrpl/ledger/Dir.h index 0c2f1e3765..940107bf93 100644 --- a/include/xrpl/ledger/Dir.h +++ b/include/xrpl/ledger/Dir.h @@ -31,10 +31,10 @@ public: Dir(ReadView const&, Keylet const&); - const_iterator + [[nodiscard]] const_iterator begin() const; - const_iterator + [[nodiscard]] const_iterator end() const; }; diff --git a/include/xrpl/ledger/PaymentSandbox.h b/include/xrpl/ledger/PaymentSandbox.h index 223a3c0c5a..1cd89d9388 100644 --- a/include/xrpl/ledger/PaymentSandbox.h +++ b/include/xrpl/ledger/PaymentSandbox.h @@ -21,9 +21,8 @@ private: struct ValueIOU { explicit ValueIOU() = default; - - STAmount lowAcctCredits; - STAmount highAcctCredits; + STAmount lowAcctDebits; + STAmount highAcctDebits; STAmount lowAcctOrigBalance; }; @@ -75,10 +74,10 @@ public: // Get the adjustments for the balance between main and other. // Returns the debits, credits and the original balance - std::optional + [[nodiscard]] std::optional adjustmentsIOU(AccountID const& main, AccountID const& other, Currency const& currency) const; - std::optional + [[nodiscard]] std::optional adjustmentsMPT(MPTID const& mptID) const; void @@ -105,7 +104,7 @@ public: // Get the adjusted owner count. Since DeferredCredits is meant to be used // in payments, and payments only decrease owner counts, return the max // remembered owner count. - std::optional + [[nodiscard]] std::optional ownerCount(AccountID const& id) const; void @@ -180,15 +179,15 @@ public: } /** @} */ - STAmount + [[nodiscard]] STAmount balanceHookIOU(AccountID const& account, AccountID const& issuer, STAmount const& amount) const override; - STAmount + [[nodiscard]] STAmount balanceHookMPT(AccountID const& account, MPTIssue const& issue, std::int64_t amount) const override; - STAmount + [[nodiscard]] STAmount balanceHookSelfIssueMPT(MPTIssue const& issue, std::int64_t amount) const override; void @@ -213,7 +212,7 @@ public: void adjustOwnerCountHook(AccountID const& account, std::uint32_t cur, std::uint32_t next) override; - std::uint32_t + [[nodiscard]] std::uint32_t ownerCountHook(AccountID const& account, std::uint32_t count) const override; /** Apply changes to base view. @@ -230,14 +229,7 @@ public: apply(PaymentSandbox& to); /** @} */ - // Return a map of balance changes on trust lines. The low account is the - // first account in the key. If the two accounts are equal, the map contains - // the total changes in currency regardless of issuer. This is useful to get - // the total change in XRP balances. - std::map, STAmount> - balanceChanges(ReadView const& view) const; - - XRPAmount + [[nodiscard]] XRPAmount xrpDestroyed() const; private: diff --git a/include/xrpl/ledger/ReadView.h b/include/xrpl/ledger/ReadView.h index debf01e85f..bb0aa56507 100644 --- a/include/xrpl/ledger/ReadView.h +++ b/include/xrpl/ledger/ReadView.h @@ -39,22 +39,22 @@ public: struct sles_type : detail::ReadViewFwdRange> { explicit sles_type(ReadView const& view); - iterator + [[nodiscard]] iterator begin() const; - iterator + [[nodiscard]] iterator end() const; - iterator + [[nodiscard]] iterator upper_bound(key_type const& key) const; }; struct txs_type : detail::ReadViewFwdRange { explicit txs_type(ReadView const& view); - bool + [[nodiscard]] bool empty() const; - iterator + [[nodiscard]] iterator begin() const; - iterator + [[nodiscard]] iterator end() const; }; @@ -78,33 +78,33 @@ public: } /** Returns information about the ledger. */ - virtual LedgerHeader const& + [[nodiscard]] virtual LedgerHeader const& header() const = 0; /** Returns true if this reflects an open ledger. */ - virtual bool + [[nodiscard]] virtual bool open() const = 0; /** Returns the close time of the previous ledger. */ - NetClock::time_point + [[nodiscard]] NetClock::time_point parentCloseTime() const { return header().parentCloseTime; } /** Returns the sequence number of the base ledger. */ - LedgerIndex + [[nodiscard]] LedgerIndex seq() const { return header().seq; } /** Returns the fees for the base ledger. */ - virtual Fees const& + [[nodiscard]] virtual Fees const& fees() const = 0; /** Returns the tx processing rules. */ - virtual Rules const& + [[nodiscard]] virtual Rules const& rules() const = 0; /** Determine if a state item exists. @@ -114,7 +114,7 @@ public: @return `true` if a SLE is associated with the specified key. */ - virtual bool + [[nodiscard]] virtual bool exists(Keylet const& k) const = 0; /** Return the key of the next state item. @@ -127,7 +127,7 @@ public: the key returned would be outside the open interval (key, last). */ - virtual std::optional + [[nodiscard]] virtual std::optional succ(key_type const& key, std::optional const& last = std::nullopt) const = 0; /** Return the state item associated with a key. @@ -143,7 +143,7 @@ public: @return `nullptr` if the key is not present or if the type does not match. */ - virtual std::shared_ptr + [[nodiscard]] virtual std::shared_ptr read(Keylet const& k) const = 0; // Accounts in a payment are not allowed to use assets acquired during that @@ -151,7 +151,7 @@ public: // changes that accounts make during a payment. `balanceHookIOU` adjusts // balances so newly acquired assets are not counted toward the balance. // This is required to support PaymentSandbox. - virtual STAmount + [[nodiscard]] virtual STAmount balanceHookIOU(AccountID const& account, AccountID const& issuer, STAmount const& amount) const { XRPL_ASSERT(amount.holds(), "balanceHookIOU: amount is for Issue"); @@ -161,7 +161,7 @@ public: // balanceHookMPT adjusts balances so newly acquired assets are not counted // toward the balance. - virtual STAmount + [[nodiscard]] virtual STAmount balanceHookMPT(AccountID const& account, MPTIssue const& issue, std::int64_t amount) const { return STAmount{issue, amount}; @@ -171,7 +171,7 @@ public: // funds available to issue, which are originally available funds less // already self sold MPT amounts (MPT sell offer). This hook is used // by issuerFundsToSelfIssue() function. - virtual STAmount + [[nodiscard]] virtual STAmount balanceHookSelfIssueMPT(MPTIssue const& issue, std::int64_t amount) const { return STAmount{issue, amount}; @@ -182,30 +182,30 @@ public: // changes that accounts make during a payment. `ownerCountHook` adjusts the // ownerCount so it returns the max value of the ownerCount so far. // This is required to support PaymentSandbox. - virtual std::uint32_t + [[nodiscard]] virtual std::uint32_t ownerCountHook(AccountID const& account, std::uint32_t count) const { return count; } // used by the implementation - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr slesBegin() const = 0; // used by the implementation - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr slesEnd() const = 0; // used by the implementation - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr slesUpperBound(key_type const& key) const = 0; // used by the implementation - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr txsBegin() const = 0; // used by the implementation - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr txsEnd() const = 0; /** Returns `true` if a tx exists in the tx map. @@ -213,7 +213,7 @@ public: A tx exists in the map if it is part of the base ledger, or if it is a newly inserted tx. */ - virtual bool + [[nodiscard]] virtual bool txExists(key_type const& key) const = 0; /** Read a transaction from the tx map. @@ -224,7 +224,7 @@ public: @return A pair of nullptr if the key is not found in the tx map. */ - virtual tx_type + [[nodiscard]] virtual tx_type txRead(key_type const& key) const = 0; // @@ -257,7 +257,7 @@ public: @return std::nullopt if the item does not exist. */ - virtual std::optional + [[nodiscard]] virtual std::optional digest(key_type const& key) const = 0; }; diff --git a/include/xrpl/ledger/detail/ApplyStateTable.h b/include/xrpl/ledger/detail/ApplyStateTable.h index 0ded0aa273..93b639f54b 100644 --- a/include/xrpl/ledger/detail/ApplyStateTable.h +++ b/include/xrpl/ledger/detail/ApplyStateTable.h @@ -54,19 +54,19 @@ public: bool isDryRun, beast::Journal j); - bool + [[nodiscard]] bool exists(ReadView const& base, Keylet const& k) const; - std::optional + [[nodiscard]] std::optional succ(ReadView const& base, key_type const& key, std::optional const& last) const; - std::shared_ptr + [[nodiscard]] std::shared_ptr read(ReadView const& base, Keylet const& k) const; std::shared_ptr peek(ReadView const& base, Keylet const& k); - std::size_t + [[nodiscard]] std::size_t size() const; void @@ -97,7 +97,7 @@ public: destroyXRP(XRPAmount const& fee); // For debugging - XRPAmount const& + [[nodiscard]] XRPAmount const& dropsDestroyed() const { return dropsDestroyed_; diff --git a/include/xrpl/ledger/detail/ApplyViewBase.h b/include/xrpl/ledger/detail/ApplyViewBase.h index 0e93ac5d2f..d6a293610a 100644 --- a/include/xrpl/ledger/detail/ApplyViewBase.h +++ b/include/xrpl/ledger/detail/ApplyViewBase.h @@ -22,51 +22,51 @@ public: ApplyViewBase(ReadView const* base, ApplyFlags flags); // ReadView - bool + [[nodiscard]] bool open() const override; - LedgerHeader const& + [[nodiscard]] LedgerHeader const& header() const override; - Fees const& + [[nodiscard]] Fees const& fees() const override; - Rules const& + [[nodiscard]] Rules const& rules() const override; - bool + [[nodiscard]] bool exists(Keylet const& k) const override; - std::optional + [[nodiscard]] std::optional succ(key_type const& key, std::optional const& last = std::nullopt) const override; - std::shared_ptr + [[nodiscard]] std::shared_ptr read(Keylet const& k) const override; - std::unique_ptr + [[nodiscard]] std::unique_ptr slesBegin() const override; - std::unique_ptr + [[nodiscard]] std::unique_ptr slesEnd() const override; - std::unique_ptr + [[nodiscard]] std::unique_ptr slesUpperBound(uint256 const& key) const override; - std::unique_ptr + [[nodiscard]] std::unique_ptr txsBegin() const override; - std::unique_ptr + [[nodiscard]] std::unique_ptr txsEnd() const override; - bool + [[nodiscard]] bool txExists(key_type const& key) const override; - tx_type + [[nodiscard]] tx_type txRead(key_type const& key) const override; // ApplyView - ApplyFlags + [[nodiscard]] ApplyFlags flags() const override; std::shared_ptr diff --git a/include/xrpl/ledger/detail/RawStateTable.h b/include/xrpl/ledger/detail/RawStateTable.h index b3307b3ea4..ec5cb05981 100644 --- a/include/xrpl/ledger/detail/RawStateTable.h +++ b/include/xrpl/ledger/detail/RawStateTable.h @@ -42,10 +42,10 @@ public: void apply(RawView& to) const; - bool + [[nodiscard]] bool exists(ReadView const& base, Keylet const& k) const; - std::optional + [[nodiscard]] std::optional succ(ReadView const& base, key_type const& key, std::optional const& last) const; void @@ -57,19 +57,19 @@ public: void replace(std::shared_ptr const& sle); - std::shared_ptr + [[nodiscard]] std::shared_ptr read(ReadView const& base, Keylet const& k) const; void destroyXRP(XRPAmount const& fee); - std::unique_ptr + [[nodiscard]] std::unique_ptr slesBegin(ReadView const& base) const; - std::unique_ptr + [[nodiscard]] std::unique_ptr slesEnd(ReadView const& base) const; - std::unique_ptr + [[nodiscard]] std::unique_ptr slesUpperBound(ReadView const& base, uint256 const& key) const; private: diff --git a/include/xrpl/ledger/detail/ReadViewFwdRange.h b/include/xrpl/ledger/detail/ReadViewFwdRange.h index 26ed22f11d..74fe0447dc 100644 --- a/include/xrpl/ledger/detail/ReadViewFwdRange.h +++ b/include/xrpl/ledger/detail/ReadViewFwdRange.h @@ -27,16 +27,16 @@ public: virtual ~ReadViewFwdIter() = default; - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr copy() const = 0; - virtual bool + [[nodiscard]] virtual bool equal(ReadViewFwdIter const& impl) const = 0; virtual void increment() = 0; - virtual value_type + [[nodiscard]] virtual value_type dereference() const = 0; }; diff --git a/include/xrpl/tx/transactors/lending/LendingHelpers.h b/include/xrpl/ledger/helpers/LendingHelpers.h similarity index 98% rename from include/xrpl/tx/transactors/lending/LendingHelpers.h rename to include/xrpl/ledger/helpers/LendingHelpers.h index 1c938bbc8a..23b87de654 100644 --- a/include/xrpl/tx/transactors/lending/LendingHelpers.h +++ b/include/xrpl/ledger/helpers/LendingHelpers.h @@ -1,15 +1,14 @@ #pragma once #include +#include #include namespace xrpl { -struct PreflightContext; - // Lending protocol has dependencies, so capture them here. bool -checkLendingProtocolDependencies(PreflightContext const& ctx); +checkLendingProtocolDependencies(Rules const& rules, STTx const& tx); static constexpr std::uint32_t secondsInYear = 365 * 24 * 60 * 60; @@ -105,7 +104,7 @@ struct LoanState Number managementFeeDue; // Interest still due to be paid by the borrower. - Number + [[nodiscard]] Number interestOutstanding() const { XRPL_ASSERT_PARTS( @@ -267,7 +266,7 @@ struct PaymentComponents // // @return The amount of tracked interest included in this payment that // will be paid to the vault. - Number + [[nodiscard]] Number trackedInterestPart() const; }; @@ -341,7 +340,7 @@ struct LoanStateDeltas /* Calculates the total change across all components. * @return The sum of principal, interest, and management fee deltas. */ - Number + [[nodiscard]] Number total() const { return principal + interest + managementFee; diff --git a/include/xrpl/net/AutoSocket.h b/include/xrpl/net/AutoSocket.h index 45e4919b8a..4dc20ffc5c 100644 --- a/include/xrpl/net/AutoSocket.h +++ b/include/xrpl/net/AutoSocket.h @@ -43,7 +43,7 @@ public: { } - bool + [[nodiscard]] bool isSecure() const { return mSecure; diff --git a/include/xrpl/net/HTTPClientSSLContext.h b/include/xrpl/net/HTTPClientSSLContext.h index d211b21afe..060746b7d8 100644 --- a/include/xrpl/net/HTTPClientSSLContext.h +++ b/include/xrpl/net/HTTPClientSSLContext.h @@ -58,7 +58,7 @@ public: return ssl_context_; } - bool + [[nodiscard]] bool sslVerify() const { return verify_; diff --git a/include/xrpl/nodestore/Backend.h b/include/xrpl/nodestore/Backend.h index d1b0ecb6dd..7f9dd172cc 100644 --- a/include/xrpl/nodestore/Backend.h +++ b/include/xrpl/nodestore/Backend.h @@ -34,7 +34,7 @@ public: /** Get the block size for backends that support it */ - virtual std::optional + [[nodiscard]] virtual std::optional getBlockSize() const { return std::nullopt; @@ -135,7 +135,7 @@ public: } /** Returns the number of file descriptors the backend expects to need. */ - virtual int + [[nodiscard]] virtual int fdRequired() const = 0; }; diff --git a/include/xrpl/nodestore/Factory.h b/include/xrpl/nodestore/Factory.h index 1656e73840..c40be62d21 100644 --- a/include/xrpl/nodestore/Factory.h +++ b/include/xrpl/nodestore/Factory.h @@ -16,7 +16,7 @@ public: virtual ~Factory() = default; /** Retrieve the name of this factory. */ - virtual std::string + [[nodiscard]] virtual std::string getName() const = 0; /** Create an instance of this factory's backend. diff --git a/include/xrpl/nodestore/NodeObject.h b/include/xrpl/nodestore/NodeObject.h index 2274fc8c38..6397ea2e4e 100644 --- a/include/xrpl/nodestore/NodeObject.h +++ b/include/xrpl/nodestore/NodeObject.h @@ -59,15 +59,15 @@ public: createObject(NodeObjectType type, Blob&& data, uint256 const& hash); /** Returns the type of this object. */ - NodeObjectType + [[nodiscard]] NodeObjectType getType() const; /** Returns the hash of the data. */ - uint256 const& + [[nodiscard]] uint256 const& getHash() const; /** Returns the underlying data. */ - Blob const& + [[nodiscard]] Blob const& getData() const; private: diff --git a/include/xrpl/nodestore/detail/DecodedBlob.h b/include/xrpl/nodestore/detail/DecodedBlob.h index 052c143009..8c75e58d48 100644 --- a/include/xrpl/nodestore/detail/DecodedBlob.h +++ b/include/xrpl/nodestore/detail/DecodedBlob.h @@ -21,7 +21,7 @@ public: DecodedBlob(void const* key, void const* value, int valueBytes); /** Determine if the decoding was successful. */ - bool + [[nodiscard]] bool wasOk() const noexcept { return m_success; diff --git a/include/xrpl/protocol/Asset.h b/include/xrpl/protocol/Asset.h index b1f0338665..920e62f2c4 100644 --- a/include/xrpl/protocol/Asset.h +++ b/include/xrpl/protocol/Asset.h @@ -68,7 +68,7 @@ public: { } - AccountID const& + [[nodiscard]] AccountID const& getIssuer() const; template @@ -80,16 +80,16 @@ public: get(); template - constexpr bool + [[nodiscard]] constexpr bool holds() const; - std::string + [[nodiscard]] std::string getText() const; - constexpr value_type const& + [[nodiscard]] constexpr value_type const& value() const; - constexpr token_type + [[nodiscard]] constexpr token_type token() const; void @@ -98,7 +98,7 @@ public: STAmount operator()(Number const&) const; - constexpr AmtType + [[nodiscard]] constexpr AmtType getAmountType() const; // Custom, generic visit implementation @@ -111,7 +111,7 @@ public: return detail::visit(issue_, std::forward(visitors)...); } - constexpr bool + [[nodiscard]] constexpr bool native() const { return visit( @@ -119,7 +119,7 @@ public: [&](MPTIssue const&) { return false; }); } - bool + [[nodiscard]] bool integral() const { return visit( @@ -169,7 +169,7 @@ Asset::holds() const } template -constexpr TIss const& +[[nodiscard]] constexpr TIss const& Asset::get() const { if (!std::holds_alternative(issue_)) diff --git a/include/xrpl/protocol/Fees.h b/include/xrpl/protocol/Fees.h index ddf4acbf67..6c398735ad 100644 --- a/include/xrpl/protocol/Fees.h +++ b/include/xrpl/protocol/Fees.h @@ -39,7 +39,7 @@ struct Fees The reserve is calculated as the reserve base plus the reserve increment times the number of increments. */ - XRPAmount + [[nodiscard]] XRPAmount accountReserve(std::size_t ownerCount) const { return reserve + ownerCount * increment; diff --git a/include/xrpl/protocol/IOUAmount.h b/include/xrpl/protocol/IOUAmount.h index 1744345a1b..1654a357f1 100644 --- a/include/xrpl/protocol/IOUAmount.h +++ b/include/xrpl/protocol/IOUAmount.h @@ -71,13 +71,13 @@ public: operator bool() const noexcept; /** Return the sign of the amount */ - int + [[nodiscard]] int signum() const noexcept; - exponent_type + [[nodiscard]] exponent_type exponent() const noexcept; - mantissa_type + [[nodiscard]] mantissa_type mantissa() const noexcept; static IOUAmount diff --git a/include/xrpl/protocol/InnerObjectFormats.h b/include/xrpl/protocol/InnerObjectFormats.h index a00e6e120b..9d07a21d1c 100644 --- a/include/xrpl/protocol/InnerObjectFormats.h +++ b/include/xrpl/protocol/InnerObjectFormats.h @@ -18,7 +18,7 @@ public: static InnerObjectFormats const& getInstance(); - SOTemplate const* + [[nodiscard]] SOTemplate const* findSOTemplateBySField(SField const& sField) const; }; diff --git a/include/xrpl/protocol/Issue.h b/include/xrpl/protocol/Issue.h index 569b01725d..fa9c4ebd1f 100644 --- a/include/xrpl/protocol/Issue.h +++ b/include/xrpl/protocol/Issue.h @@ -21,22 +21,22 @@ public: { } - AccountID const& + [[nodiscard]] AccountID const& getIssuer() const { return account; } - std::string + [[nodiscard]] std::string getText() const; void setJson(Json::Value& jv) const; - bool + [[nodiscard]] bool native() const; - bool + [[nodiscard]] bool integral() const; friend constexpr std::weak_ordering diff --git a/include/xrpl/protocol/Keylet.h b/include/xrpl/protocol/Keylet.h index 2931486ac0..6795516795 100644 --- a/include/xrpl/protocol/Keylet.h +++ b/include/xrpl/protocol/Keylet.h @@ -25,7 +25,7 @@ struct Keylet } /** Returns true if the SLE matches the type */ - bool + [[nodiscard]] bool check(STLedgerEntry const&) const; }; diff --git a/include/xrpl/protocol/KnownFormats.h b/include/xrpl/protocol/KnownFormats.h index 73bc463abe..12d900572f 100644 --- a/include/xrpl/protocol/KnownFormats.h +++ b/include/xrpl/protocol/KnownFormats.h @@ -44,7 +44,7 @@ public: /** Retrieve the name of the format. */ - std::string const& + [[nodiscard]] std::string const& getName() const { return name_; @@ -52,13 +52,13 @@ public: /** Retrieve the transaction type this format represents. */ - KeyType + [[nodiscard]] KeyType getType() const { return type_; } - SOTemplate const& + [[nodiscard]] SOTemplate const& getSOTemplate() const { return soTemplate_; @@ -96,7 +96,7 @@ public: @param name The name of the type. @return The type. */ - KeyType + [[nodiscard]] KeyType findTypeByName(std::string const& name) const { if (auto const result = findByName(name)) @@ -108,7 +108,7 @@ public: /** Retrieve a format based on its type. */ - Item const* + [[nodiscard]] Item const* findByType(KeyType type) const { auto const itr = types_.find(type); @@ -118,13 +118,13 @@ public: } // begin() and end() are provided for testing purposes. - typename std::forward_list::const_iterator + [[nodiscard]] typename std::forward_list::const_iterator begin() const { return formats_.begin(); } - typename std::forward_list::const_iterator + [[nodiscard]] typename std::forward_list::const_iterator end() const { return formats_.end(); @@ -133,7 +133,7 @@ public: protected: /** Retrieve a format based on its name. */ - Item const* + [[nodiscard]] Item const* findByName(std::string const& name) const { auto const itr = names_.find(name); diff --git a/include/xrpl/protocol/MPTAmount.h b/include/xrpl/protocol/MPTAmount.h index 4a6297cc74..9d0e0901bf 100644 --- a/include/xrpl/protocol/MPTAmount.h +++ b/include/xrpl/protocol/MPTAmount.h @@ -68,14 +68,14 @@ public: } /** Return the sign of the amount */ - constexpr int + [[nodiscard]] constexpr int signum() const noexcept; /** Returns the underlying value. Code SHOULD NOT call this function unless the type has been abstracted away, e.g. in a templated function. */ - constexpr value_type + [[nodiscard]] constexpr value_type value() const; static MPTAmount diff --git a/include/xrpl/protocol/MPTIssue.h b/include/xrpl/protocol/MPTIssue.h index 727aef9008..c467382f07 100644 --- a/include/xrpl/protocol/MPTIssue.h +++ b/include/xrpl/protocol/MPTIssue.h @@ -26,16 +26,16 @@ public: return mptID_; } - AccountID const& + [[nodiscard]] AccountID const& getIssuer() const; - constexpr MPTID const& + [[nodiscard]] constexpr MPTID const& getMptID() const { return mptID_; } - std::string + [[nodiscard]] std::string getText() const; void diff --git a/include/xrpl/protocol/MultiApiJson.h b/include/xrpl/protocol/MultiApiJson.h index 8d287767a6..6a86aa35b8 100644 --- a/include/xrpl/protocol/MultiApiJson.h +++ b/include/xrpl/protocol/MultiApiJson.h @@ -156,7 +156,7 @@ struct MultiApiJson { return visitor(*self, std::forward(args)...); }; } - auto + [[nodiscard]] auto visit() const { return [self = this](auto... args) @@ -176,7 +176,7 @@ struct MultiApiJson } template - auto + [[nodiscard]] auto visit(Args... args) const -> std::invoke_result_t requires(sizeof...(args) > 0) && requires { visitor(*this, std::forward(args)...); } diff --git a/include/xrpl/protocol/PathAsset.h b/include/xrpl/protocol/PathAsset.h index 662e568bec..67b78f2191 100644 --- a/include/xrpl/protocol/PathAsset.h +++ b/include/xrpl/protocol/PathAsset.h @@ -24,17 +24,17 @@ public: } template - constexpr bool + [[nodiscard]] constexpr bool holds() const; - constexpr bool + [[nodiscard]] constexpr bool isXRP() const; template T const& get() const; - constexpr std::variant const& + [[nodiscard]] constexpr std::variant const& value() const; // Custom, generic visit implementation diff --git a/include/xrpl/protocol/Permissions.h b/include/xrpl/protocol/Permissions.h index ea8bd77643..4d26ba7cf8 100644 --- a/include/xrpl/protocol/Permissions.h +++ b/include/xrpl/protocol/Permissions.h @@ -53,22 +53,22 @@ public: Permission& operator=(Permission const&) = delete; - std::optional + [[nodiscard]] std::optional getPermissionName(std::uint32_t const value) const; - std::optional + [[nodiscard]] std::optional getGranularValue(std::string const& name) const; - std::optional + [[nodiscard]] std::optional getGranularName(GranularPermissionType const& value) const; - std::optional + [[nodiscard]] std::optional getGranularTxType(GranularPermissionType const& gpType) const; - std::optional> + [[nodiscard]] std::optional> getTxFeature(TxType txType) const; - bool + [[nodiscard]] bool isDelegable(std::uint32_t const& permissionValue, Rules const& rules) const; // for tx level permission, permission value is equal to tx type plus one diff --git a/include/xrpl/protocol/PublicKey.h b/include/xrpl/protocol/PublicKey.h index 8325d2b1d2..9ec82dde97 100644 --- a/include/xrpl/protocol/PublicKey.h +++ b/include/xrpl/protocol/PublicKey.h @@ -63,7 +63,7 @@ public: */ explicit PublicKey(Slice const& slice); - std::uint8_t const* + [[nodiscard]] std::uint8_t const* data() const noexcept { return buf_; @@ -75,31 +75,31 @@ public: return size_; } - const_iterator + [[nodiscard]] const_iterator begin() const noexcept { return buf_; } - const_iterator + [[nodiscard]] const_iterator cbegin() const noexcept { return buf_; } - const_iterator + [[nodiscard]] const_iterator end() const noexcept { return buf_ + size_; } - const_iterator + [[nodiscard]] const_iterator cend() const noexcept { return buf_ + size_; } - Slice + [[nodiscard]] Slice slice() const noexcept { return {buf_, size_}; diff --git a/include/xrpl/protocol/Quality.h b/include/xrpl/protocol/Quality.h index b0e3e65d6c..2d4ea2f652 100644 --- a/include/xrpl/protocol/Quality.h +++ b/include/xrpl/protocol/Quality.h @@ -35,7 +35,7 @@ struct TAmounts } /** Returns `true` if either quantity is not positive. */ - bool + [[nodiscard]] bool empty() const noexcept { return in <= beast::zero || out <= beast::zero; @@ -145,7 +145,7 @@ public: /** @} */ /** Returns the quality as STAmount. */ - STAmount + [[nodiscard]] STAmount rate() const { return amountFromQuality(m_value); @@ -154,7 +154,7 @@ public: /** Returns the quality rounded up to the specified number of decimal digits. */ - Quality + [[nodiscard]] Quality round(int tickSize) const; /** Returns the scaled amount with in capped. diff --git a/include/xrpl/protocol/QualityFunction.h b/include/xrpl/protocol/QualityFunction.h index 15865a6e07..672c529c38 100644 --- a/include/xrpl/protocol/QualityFunction.h +++ b/include/xrpl/protocol/QualityFunction.h @@ -53,13 +53,13 @@ public: /** Return true if the quality function is constant */ - bool + [[nodiscard]] bool isConst() const { return quality_.has_value(); } - std::optional const& + [[nodiscard]] std::optional const& quality() const { return quality_; diff --git a/include/xrpl/protocol/Rules.h b/include/xrpl/protocol/Rules.h index 11ca8eb72a..7faf602cfd 100644 --- a/include/xrpl/protocol/Rules.h +++ b/include/xrpl/protocol/Rules.h @@ -58,12 +58,12 @@ private: std::optional const& digest, STVector256 const& amendments); - std::unordered_set> const& + [[nodiscard]] std::unordered_set> const& presets() const; public: /** Returns `true` if a feature is enabled. */ - bool + [[nodiscard]] bool enabled(uint256 const& feature) const; /** Returns `true` if two rule sets are identical. diff --git a/include/xrpl/protocol/SField.h b/include/xrpl/protocol/SField.h index cbc2c12f4e..7e42b9ec62 100644 --- a/include/xrpl/protocol/SField.h +++ b/include/xrpl/protocol/SField.h @@ -189,19 +189,19 @@ public: return getField(field_code(type, value)); } - std::string const& + [[nodiscard]] std::string const& getName() const { return fieldName; } - bool + [[nodiscard]] bool hasName() const { return fieldCode > 0; } - Json::StaticString const& + [[nodiscard]] Json::StaticString const& getJsonName() const { return jsonName; @@ -212,19 +212,19 @@ public: return jsonName; } - bool + [[nodiscard]] bool isInvalid() const { return fieldCode == -1; } - bool + [[nodiscard]] bool isUseful() const { return fieldCode > 0; } - bool + [[nodiscard]] bool isBinary() const { return fieldValue < 256; @@ -234,18 +234,18 @@ public: // should be discarded during serialization,like 'hash'. // You cannot serialize an object's hash inside that object, // but you can have it in the JSON representation. - bool + [[nodiscard]] bool isDiscardable() const { return fieldValue > 256; } - int + [[nodiscard]] int getCode() const { return fieldCode; } - int + [[nodiscard]] int getNum() const { return fieldNum; @@ -256,13 +256,13 @@ public: return num; } - bool + [[nodiscard]] bool shouldMeta(int c) const { return (fieldMeta & c) != 0; } - bool + [[nodiscard]] bool shouldInclude(bool withSigningField) const { return (fieldValue < 256) && (withSigningField || (signingField == IsSigning::yes)); diff --git a/include/xrpl/protocol/SOTemplate.h b/include/xrpl/protocol/SOTemplate.h index 41cea7936c..ca09fc3d71 100644 --- a/include/xrpl/protocol/SOTemplate.h +++ b/include/xrpl/protocol/SOTemplate.h @@ -63,19 +63,19 @@ public: init(fieldName); } - SField const& + [[nodiscard]] SField const& sField() const { return sField_.get(); } - SOEStyle + [[nodiscard]] SOEStyle style() const { return style_; } - SOETxMPTIssue + [[nodiscard]] SOETxMPTIssue supportMPT() const { return supportMpt_; @@ -110,42 +110,42 @@ public: std::initializer_list commonFields = {}); /* Provide for the enumeration of fields */ - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator begin() const { return elements_.cbegin(); } - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator cbegin() const { return begin(); } - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator end() const { return elements_.cend(); } - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator cend() const { return end(); } /** The number of entries in this template */ - std::size_t + [[nodiscard]] std::size_t size() const { return elements_.size(); } /** Retrieve the position of a named field. */ - int + [[nodiscard]] int getIndex(SField const&) const; - SOEStyle + [[nodiscard]] SOEStyle style(SField const& sf) const { return elements_[indices_[sf.getNum()]].style(); diff --git a/include/xrpl/protocol/STAccount.h b/include/xrpl/protocol/STAccount.h index b1f112fbb2..65f404d58d 100644 --- a/include/xrpl/protocol/STAccount.h +++ b/include/xrpl/protocol/STAccount.h @@ -28,25 +28,25 @@ public: STAccount(SerialIter& sit, SField const& name); STAccount(SField const& n, AccountID const& v); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getText() const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; STAccount& operator=(AccountID const& value); - AccountID const& + [[nodiscard]] AccountID const& value() const noexcept; void diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index 695bd3c0b1..06471df5c9 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -138,26 +138,26 @@ public: // //-------------------------------------------------------------------------- - int + [[nodiscard]] int exponent() const noexcept; - bool + [[nodiscard]] bool integral() const noexcept; - bool + [[nodiscard]] bool native() const noexcept; template - constexpr bool + [[nodiscard]] constexpr bool holds() const noexcept; - bool + [[nodiscard]] bool negative() const noexcept; - std::uint64_t + [[nodiscard]] std::uint64_t mantissa() const noexcept; - Asset const& + [[nodiscard]] Asset const& asset() const; template @@ -168,20 +168,20 @@ public: TIss& get(); - AccountID const& + [[nodiscard]] AccountID const& getIssuer() const; - int + [[nodiscard]] int signum() const noexcept; /** Returns a zero value with the same issuer and currency. */ - STAmount + [[nodiscard]] STAmount zeroed() const; void setJson(Json::Value&) const; - STAmount const& + [[nodiscard]] STAmount const& value() const noexcept; //-------------------------------------------------------------------------- @@ -232,31 +232,31 @@ public: // //-------------------------------------------------------------------------- - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getFullText() const override; - std::string + [[nodiscard]] std::string getText() const override; - Json::Value getJson(JsonOptions = JsonOptions::none) const override; + [[nodiscard]] Json::Value getJson(JsonOptions = JsonOptions::none) const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; - XRPAmount + [[nodiscard]] XRPAmount xrp() const; - IOUAmount + [[nodiscard]] IOUAmount iou() const; - MPTAmount + [[nodiscard]] MPTAmount mpt() const; private: @@ -462,7 +462,7 @@ STAmount::asset() const } template -constexpr TIss const& +[[nodiscard]] constexpr TIss const& STAmount::get() const { return mAsset.get(); diff --git a/include/xrpl/protocol/STArray.h b/include/xrpl/protocol/STArray.h index 045b682f88..f1ac58075b 100644 --- a/include/xrpl/protocol/STArray.h +++ b/include/xrpl/protocol/STArray.h @@ -53,7 +53,7 @@ public: STObject& back(); - STObject const& + [[nodiscard]] STObject const& back() const; template @@ -72,16 +72,16 @@ public: iterator end(); - const_iterator + [[nodiscard]] const_iterator begin() const; - const_iterator + [[nodiscard]] const_iterator end() const; - size_type + [[nodiscard]] size_type size() const; - bool + [[nodiscard]] bool empty() const; void @@ -93,13 +93,13 @@ public: void swap(STArray& a) noexcept; - std::string + [[nodiscard]] std::string getFullText() const override; - std::string + [[nodiscard]] std::string getText() const override; - Json::Value + [[nodiscard]] Json::Value getJson(JsonOptions index) const override; void @@ -126,13 +126,13 @@ public: iterator erase(const_iterator first, const_iterator last); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; private: diff --git a/include/xrpl/protocol/STBase.h b/include/xrpl/protocol/STBase.h index 8edeb26424..0beefe45f6 100644 --- a/include/xrpl/protocol/STBase.h +++ b/include/xrpl/protocol/STBase.h @@ -137,24 +137,24 @@ public: D const& downcast() const; - virtual SerializedTypeID + [[nodiscard]] virtual SerializedTypeID getSType() const; - virtual std::string + [[nodiscard]] virtual std::string getFullText() const; - virtual std::string + [[nodiscard]] virtual std::string getText() const; - virtual Json::Value getJson(JsonOptions = JsonOptions::none) const; + [[nodiscard]] virtual Json::Value getJson(JsonOptions = JsonOptions::none) const; virtual void add(Serializer& s) const; - virtual bool + [[nodiscard]] virtual bool isEquivalent(STBase const& t) const; - virtual bool + [[nodiscard]] virtual bool isDefault() const; /** A STBase is a field. @@ -163,7 +163,7 @@ public: void setFName(SField const& n); - SField const& + [[nodiscard]] SField const& getFName() const; void @@ -199,7 +199,7 @@ STBase::downcast() } template -D const& +[[nodiscard]] D const& STBase::downcast() const { D const* ptr = dynamic_cast(this); diff --git a/include/xrpl/protocol/STBitString.h b/include/xrpl/protocol/STBitString.h index de038cce32..6f2e08e401 100644 --- a/include/xrpl/protocol/STBitString.h +++ b/include/xrpl/protocol/STBitString.h @@ -29,26 +29,26 @@ public: STBitString(SField const& n, value_type const& v); STBitString(SerialIter& sit, SField const& name); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getText() const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isDefault() const override; template void setValue(base_uint const& v); - value_type const& + [[nodiscard]] value_type const& value() const; operator value_type() const; diff --git a/include/xrpl/protocol/STBlob.h b/include/xrpl/protocol/STBlob.h index b9dc78ffe4..0667c54e30 100644 --- a/include/xrpl/protocol/STBlob.h +++ b/include/xrpl/protocol/STBlob.h @@ -26,31 +26,31 @@ public: STBlob(SField const& n); STBlob(SerialIter&, SField const& name = sfGeneric); - std::size_t + [[nodiscard]] std::size_t size() const; - std::uint8_t const* + [[nodiscard]] std::uint8_t const* data() const; - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getText() const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; STBlob& operator=(Slice const& slice); - value_type + [[nodiscard]] value_type value() const noexcept; STBlob& diff --git a/include/xrpl/protocol/STCurrency.h b/include/xrpl/protocol/STCurrency.h index 5fd4c08fbb..a81b589a2c 100644 --- a/include/xrpl/protocol/STCurrency.h +++ b/include/xrpl/protocol/STCurrency.h @@ -24,30 +24,30 @@ public: explicit STCurrency(SField const& name); - Currency const& + [[nodiscard]] Currency const& currency() const; - Currency const& + [[nodiscard]] Currency const& value() const noexcept; void setCurrency(Currency const& currency); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getText() const override; - Json::Value getJson(JsonOptions) const override; + [[nodiscard]] Json::Value getJson(JsonOptions) const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; private: diff --git a/include/xrpl/protocol/STInteger.h b/include/xrpl/protocol/STInteger.h index f4bbd6e73d..5f6e8c8800 100644 --- a/include/xrpl/protocol/STInteger.h +++ b/include/xrpl/protocol/STInteger.h @@ -19,27 +19,27 @@ public: STInteger(SField const& n, Integer v = 0); STInteger(SerialIter& sit, SField const& name); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - Json::Value getJson(JsonOptions) const override; + [[nodiscard]] Json::Value getJson(JsonOptions) const override; - std::string + [[nodiscard]] std::string getText() const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isDefault() const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; STInteger& operator=(value_type const& v); - value_type + [[nodiscard]] value_type value() const noexcept; void diff --git a/include/xrpl/protocol/STIssue.h b/include/xrpl/protocol/STIssue.h index 7491e3b3ff..8a64f39336 100644 --- a/include/xrpl/protocol/STIssue.h +++ b/include/xrpl/protocol/STIssue.h @@ -34,30 +34,30 @@ public: get() const; template - bool + [[nodiscard]] bool holds() const; - value_type const& + [[nodiscard]] value_type const& value() const noexcept; void setIssue(Asset const& issue); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getText() const override; - Json::Value getJson(JsonOptions) const override; + [[nodiscard]] Json::Value getJson(JsonOptions) const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; friend constexpr bool diff --git a/include/xrpl/protocol/STLedgerEntry.h b/include/xrpl/protocol/STLedgerEntry.h index a28868cd7a..2e884bc2bf 100644 --- a/include/xrpl/protocol/STLedgerEntry.h +++ b/include/xrpl/protocol/STLedgerEntry.h @@ -28,30 +28,30 @@ public: STLedgerEntry(SerialIter&& sit, uint256 const& index); STLedgerEntry(STObject const& object, uint256 const& index); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getFullText() const override; - std::string + [[nodiscard]] std::string getText() const override; - Json::Value + [[nodiscard]] Json::Value getJson(JsonOptions options = JsonOptions::none) const override; /** Returns the 'key' (or 'index') of this item. The key identifies this entry's position in the SHAMap associative container. */ - uint256 const& + [[nodiscard]] uint256 const& key() const; - LedgerEntryType + [[nodiscard]] LedgerEntryType getType() const; // is this a ledger entry that can be threaded - bool + [[nodiscard]] bool isThreadedType(Rules const& rules) const; bool diff --git a/include/xrpl/protocol/STNumber.h b/include/xrpl/protocol/STNumber.h index 137016dfe7..802bdf671f 100644 --- a/include/xrpl/protocol/STNumber.h +++ b/include/xrpl/protocol/STNumber.h @@ -43,14 +43,14 @@ public: explicit STNumber(SField const& field, Number const& value = Number()); STNumber(SerialIter& sit, SField const& field); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - std::string + [[nodiscard]] std::string getText() const override; void add(Serializer& s) const override; - Number const& + [[nodiscard]] Number const& value() const; void setValue(Number const& v); @@ -62,9 +62,9 @@ public: return *this; } - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; void diff --git a/include/xrpl/protocol/STObject.h b/include/xrpl/protocol/STObject.h index 34bd19b9a0..d27112e17c 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -86,13 +86,13 @@ public: static STObject makeInnerObject(SField const& name); - iterator + [[nodiscard]] iterator begin() const; - iterator + [[nodiscard]] iterator end() const; - bool + [[nodiscard]] bool empty() const; void @@ -104,7 +104,7 @@ public: void applyTemplateFromSField(SField const&); - bool + [[nodiscard]] bool isFree() const; void @@ -113,81 +113,81 @@ public: bool set(SerialIter& u, int depth = 0); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; void add(Serializer& s) const override; - std::string + [[nodiscard]] std::string getFullText() const override; - std::string + [[nodiscard]] std::string getText() const override; // TODO(tom): options should be an enum. - Json::Value getJson(JsonOptions = JsonOptions::none) const override; + [[nodiscard]] Json::Value getJson(JsonOptions = JsonOptions::none) const override; void addWithoutSigningFields(Serializer& s) const; - Serializer + [[nodiscard]] Serializer getSerializer() const; template std::size_t emplace_back(Args&&... args); - int + [[nodiscard]] int getCount() const; bool setFlag(std::uint32_t); bool clearFlag(std::uint32_t); - bool + [[nodiscard]] bool isFlag(std::uint32_t) const; - std::uint32_t + [[nodiscard]] std::uint32_t getFlags() const; - uint256 + [[nodiscard]] uint256 getHash(HashPrefix prefix) const; - uint256 + [[nodiscard]] uint256 getSigningHash(HashPrefix prefix) const; - STBase const& + [[nodiscard]] STBase const& peekAtIndex(int offset) const; STBase& getIndex(int offset); - STBase const* + [[nodiscard]] STBase const* peekAtPIndex(int offset) const; STBase* getPIndex(int offset); - int + [[nodiscard]] int getFieldIndex(SField const& field) const; - SField const& + [[nodiscard]] SField const& getFieldSType(int index) const; - STBase const& + [[nodiscard]] STBase const& peekAtField(SField const& field) const; STBase& getField(SField const& field); - STBase const* + [[nodiscard]] STBase const* peekAtPField(SField const& field) const; STBase* @@ -195,44 +195,44 @@ public: // these throw if the field type doesn't match, or return default values // if the field is optional but not present - unsigned char + [[nodiscard]] unsigned char getFieldU8(SField const& field) const; - std::uint16_t + [[nodiscard]] std::uint16_t getFieldU16(SField const& field) const; - std::uint32_t + [[nodiscard]] std::uint32_t getFieldU32(SField const& field) const; - std::uint64_t + [[nodiscard]] std::uint64_t getFieldU64(SField const& field) const; - uint128 + [[nodiscard]] uint128 getFieldH128(SField const& field) const; - uint160 + [[nodiscard]] uint160 getFieldH160(SField const& field) const; - uint192 + [[nodiscard]] uint192 getFieldH192(SField const& field) const; - uint256 + [[nodiscard]] uint256 getFieldH256(SField const& field) const; - std::int32_t + [[nodiscard]] std::int32_t getFieldI32(SField const& field) const; - AccountID + [[nodiscard]] AccountID getAccountID(SField const& field) const; - Blob + [[nodiscard]] Blob getFieldVL(SField const& field) const; - STAmount const& + [[nodiscard]] STAmount const& getFieldAmount(SField const& field) const; - STPathSet const& + [[nodiscard]] STPathSet const& getFieldPathSet(SField const& field) const; - STVector256 const& + [[nodiscard]] STVector256 const& getFieldV256(SField const& field) const; // If not found, returns an object constructed with the given field - STObject + [[nodiscard]] STObject getFieldObject(SField const& field) const; - STArray const& + [[nodiscard]] STArray const& getFieldArray(SField const& field) const; - STCurrency const& + [[nodiscard]] STCurrency const& getFieldCurrency(SField const& field) const; - STNumber const& + [[nodiscard]] STNumber const& getFieldNumber(SField const& field) const; /** Get the value of a field. @@ -290,7 +290,7 @@ public: @throws STObject::FieldErr if the field is not present. */ template - typename T::value_type + [[nodiscard]] typename T::value_type at(TypedField const& f) const; /** Get the value of a field as std::optional @@ -302,7 +302,7 @@ public: the specified field. */ template - std::optional> + [[nodiscard]] std::optional> at(OptionaledField const& of) const; /** Get a modifiable field value. @@ -388,7 +388,7 @@ public: STArray& peekFieldArray(SField const& field); - bool + [[nodiscard]] bool isFieldPresent(SField const& field) const; STBase* makeFieldPresent(SField const& field); @@ -399,10 +399,10 @@ public: void delField(int index); - SOEStyle + [[nodiscard]] SOEStyle getStyle(SField const& field) const; - bool + [[nodiscard]] bool hasMatchingEntry(STBase const&) const; bool @@ -480,7 +480,7 @@ class STObject::Proxy public: using value_type = typename T::value_type; - value_type + [[nodiscard]] value_type value() const; value_type @@ -500,7 +500,7 @@ protected: Proxy(STObject* st, TypedField const* f); - T const* + [[nodiscard]] T const* find() const; template @@ -666,7 +666,7 @@ public: } // Emulate std::optional::value_or - value_type + [[nodiscard]] value_type value_or(value_type val) const; OptionalProxy& @@ -685,13 +685,13 @@ private: OptionalProxy(STObject* st, TypedField const* f); - bool + [[nodiscard]] bool engaged() const noexcept; void disengage(); - optional_type + [[nodiscard]] optional_type optional_value() const; }; @@ -1068,7 +1068,7 @@ STObject::operator[](OptionaledField const& of) -> OptionalProxy } template -typename T::value_type +[[nodiscard]] typename T::value_type STObject::at(TypedField const& f) const { auto const b = peekAtPField(f); @@ -1100,7 +1100,7 @@ STObject::at(TypedField const& f) const } template -std::optional> +[[nodiscard]] std::optional> STObject::at(OptionaledField const& of) const { auto const b = peekAtPField(*of.f); diff --git a/include/xrpl/protocol/STPathSet.h b/include/xrpl/protocol/STPathSet.h index 1d6fce5c18..38f4668b5d 100644 --- a/include/xrpl/protocol/STPathSet.h +++ b/include/xrpl/protocol/STPathSet.h @@ -59,48 +59,48 @@ public: PathAsset const& asset, AccountID const& issuer); - auto + [[nodiscard]] auto getNodeType() const; - bool + [[nodiscard]] bool isOffer() const; - bool + [[nodiscard]] bool isAccount() const; - bool + [[nodiscard]] bool hasIssuer() const; - bool + [[nodiscard]] bool hasCurrency() const; - bool + [[nodiscard]] bool hasMPT() const; - bool + [[nodiscard]] bool hasAsset() const; - bool + [[nodiscard]] bool isNone() const; // Nodes are either an account ID or a offer prefix. Offer prefixs denote a // class of offers. - AccountID const& + [[nodiscard]] AccountID const& getAccountID() const; - PathAsset const& + [[nodiscard]] PathAsset const& getPathAsset() const; - Currency const& + [[nodiscard]] Currency const& getCurrency() const; - MPTID const& + [[nodiscard]] MPTID const& getMPTID() const; - AccountID const& + [[nodiscard]] AccountID const& getIssuerID() const; - bool + [[nodiscard]] bool isType(Type const& pe) const; bool @@ -123,10 +123,10 @@ public: STPath(std::vector p); - std::vector::size_type + [[nodiscard]] std::vector::size_type size() const; - bool + [[nodiscard]] bool empty() const; void @@ -136,24 +136,24 @@ public: void emplace_back(Args&&... args); - bool + [[nodiscard]] bool hasSeen(AccountID const& account, PathAsset const& asset, AccountID const& issuer) const; - Json::Value getJson(JsonOptions) const; + [[nodiscard]] Json::Value getJson(JsonOptions) const; - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator begin() const; - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator end() const; bool operator==(STPath const& t) const; - std::vector::const_reference + [[nodiscard]] std::vector::const_reference back() const; - std::vector::const_reference + [[nodiscard]] std::vector::const_reference front() const; STPathElement& @@ -182,18 +182,18 @@ public: void add(Serializer& s) const override; - Json::Value getJson(JsonOptions) const override; + [[nodiscard]] Json::Value getJson(JsonOptions) const override; - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; bool assembleAdd(STPath const& base, STPathElement const& tail); - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; // std::vector like interface: @@ -203,16 +203,16 @@ public: std::vector::reference operator[](std::vector::size_type n); - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator begin() const; - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator end() const; - std::vector::size_type + [[nodiscard]] std::vector::size_type size() const; - bool + [[nodiscard]] bool empty() const; void diff --git a/include/xrpl/protocol/STVector256.h b/include/xrpl/protocol/STVector256.h index 69b06ec1da..c650c565ce 100644 --- a/include/xrpl/protocol/STVector256.h +++ b/include/xrpl/protocol/STVector256.h @@ -21,18 +21,18 @@ public: STVector256(SField const& n, std::vector const& vector); STVector256(SerialIter& sit, SField const& name); - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; void add(Serializer& s) const override; - Json::Value getJson(JsonOptions) const override; + [[nodiscard]] Json::Value getJson(JsonOptions) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; STVector256& @@ -48,13 +48,13 @@ public: explicit operator std::vector() const; - std::size_t + [[nodiscard]] std::size_t size() const; void resize(std::size_t n); - bool + [[nodiscard]] bool empty() const; std::vector::reference @@ -63,7 +63,7 @@ public: std::vector::const_reference operator[](std::vector::size_type n) const; - std::vector const& + [[nodiscard]] std::vector const& value() const; std::vector::iterator @@ -75,13 +75,13 @@ public: std::vector::iterator begin(); - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator begin() const; std::vector::iterator end(); - std::vector::const_iterator + [[nodiscard]] std::vector::const_iterator end() const; std::vector::iterator diff --git a/include/xrpl/protocol/STXChainBridge.h b/include/xrpl/protocol/STXChainBridge.h index f74cc02041..2dc2fbce48 100644 --- a/include/xrpl/protocol/STXChainBridge.h +++ b/include/xrpl/protocol/STXChainBridge.h @@ -54,45 +54,45 @@ public: STXChainBridge& operator=(STXChainBridge const& rhs) = default; - std::string + [[nodiscard]] std::string getText() const override; - STObject + [[nodiscard]] STObject toSTObject() const; - AccountID const& + [[nodiscard]] AccountID const& lockingChainDoor() const; - Issue const& + [[nodiscard]] Issue const& lockingChainIssue() const; - AccountID const& + [[nodiscard]] AccountID const& issuingChainDoor() const; - Issue const& + [[nodiscard]] Issue const& issuingChainIssue() const; - AccountID const& + [[nodiscard]] AccountID const& door(ChainType ct) const; - Issue const& + [[nodiscard]] Issue const& issue(ChainType ct) const; - SerializedTypeID + [[nodiscard]] SerializedTypeID getSType() const override; - Json::Value getJson(JsonOptions) const override; + [[nodiscard]] Json::Value getJson(JsonOptions) const override; void add(Serializer& s) const override; - bool + [[nodiscard]] bool isEquivalent(STBase const& t) const override; - bool + [[nodiscard]] bool isDefault() const override; - value_type const& + [[nodiscard]] value_type const& value() const noexcept; private: diff --git a/include/xrpl/protocol/SecretKey.h b/include/xrpl/protocol/SecretKey.h index c17b3984e9..462a48f4bd 100644 --- a/include/xrpl/protocol/SecretKey.h +++ b/include/xrpl/protocol/SecretKey.h @@ -40,13 +40,13 @@ public: SecretKey(std::array const& data); SecretKey(Slice const& slice); - std::uint8_t const* + [[nodiscard]] std::uint8_t const* data() const { return buf_; } - std::size_t + [[nodiscard]] std::size_t size() const { return sizeof(buf_); @@ -57,28 +57,28 @@ public: @note The operator<< function is deliberately omitted to avoid accidental exposure of secret key material. */ - std::string + [[nodiscard]] std::string to_string() const; - const_iterator + [[nodiscard]] const_iterator begin() const noexcept { return buf_; } - const_iterator + [[nodiscard]] const_iterator cbegin() const noexcept { return buf_; } - const_iterator + [[nodiscard]] const_iterator end() const noexcept { return buf_ + sizeof(buf_); } - const_iterator + [[nodiscard]] const_iterator cend() const noexcept { return buf_ + sizeof(buf_); diff --git a/include/xrpl/protocol/Seed.h b/include/xrpl/protocol/Seed.h index 04e8481c8f..0b93b84516 100644 --- a/include/xrpl/protocol/Seed.h +++ b/include/xrpl/protocol/Seed.h @@ -35,37 +35,37 @@ public: explicit Seed(uint128 const& seed); /** @} */ - std::uint8_t const* + [[nodiscard]] std::uint8_t const* data() const { return buf_.data(); } - std::size_t + [[nodiscard]] std::size_t size() const { return buf_.size(); } - const_iterator + [[nodiscard]] const_iterator begin() const noexcept { return buf_.begin(); } - const_iterator + [[nodiscard]] const_iterator cbegin() const noexcept { return buf_.cbegin(); } - const_iterator + [[nodiscard]] const_iterator end() const noexcept { return buf_.end(); } - const_iterator + [[nodiscard]] const_iterator cend() const noexcept { return buf_.cend(); diff --git a/include/xrpl/protocol/SeqProxy.h b/include/xrpl/protocol/SeqProxy.h index 563292f8b3..86742bacc1 100644 --- a/include/xrpl/protocol/SeqProxy.h +++ b/include/xrpl/protocol/SeqProxy.h @@ -58,19 +58,19 @@ public: return SeqProxy{Type::seq, v}; } - constexpr std::uint32_t + [[nodiscard]] constexpr std::uint32_t value() const { return value_; } - constexpr bool + [[nodiscard]] constexpr bool isSeq() const { return type_ == seq; } - constexpr bool + [[nodiscard]] constexpr bool isTicket() const { return type_ == ticket; diff --git a/include/xrpl/protocol/Serializer.h b/include/xrpl/protocol/Serializer.h index 6ce60022e3..e14d008cd1 100644 --- a/include/xrpl/protocol/Serializer.h +++ b/include/xrpl/protocol/Serializer.h @@ -40,19 +40,19 @@ public: } } - Slice + [[nodiscard]] Slice slice() const noexcept { return Slice(mData.data(), mData.size()); } - std::size_t + [[nodiscard]] std::size_t size() const noexcept { return mData.size(); } - void const* + [[nodiscard]] void const* data() const noexcept { return mData.data(); @@ -168,16 +168,16 @@ public: } // DEPRECATED - uint256 + [[nodiscard]] uint256 getSHA512Half() const; // totality functions - Blob const& + [[nodiscard]] Blob const& peekData() const { return mData; } - Blob + [[nodiscard]] Blob getData() const { return mData; @@ -188,12 +188,12 @@ public: return mData; } - int + [[nodiscard]] int getDataLength() const { return mData.size(); } - void const* + [[nodiscard]] void const* getDataPtr() const { return mData.data(); @@ -203,12 +203,12 @@ public: { return mData.data(); } - int + [[nodiscard]] int getLength() const { return mData.size(); } - std::string + [[nodiscard]] std::string getString() const { return std::string(static_cast(getDataPtr()), size()); @@ -232,12 +232,12 @@ public: { return mData.end(); } - Blob ::const_iterator + [[nodiscard]] Blob ::const_iterator begin() const { return mData.begin(); } - Blob ::const_iterator + [[nodiscard]] Blob ::const_iterator end() const { return mData.end(); @@ -252,7 +252,7 @@ public: { mData.resize(n); } - size_t + [[nodiscard]] size_t capacity() const { return mData.capacity(); @@ -345,7 +345,7 @@ public: void reset() noexcept; - int + [[nodiscard]] int getBytesLeft() const noexcept { return static_cast(remain_); diff --git a/include/xrpl/protocol/TxMeta.h b/include/xrpl/protocol/TxMeta.h index a295eb4569..31be3bdb47 100644 --- a/include/xrpl/protocol/TxMeta.h +++ b/include/xrpl/protocol/TxMeta.h @@ -18,27 +18,27 @@ public: TxMeta(uint256 const& txID, std::uint32_t ledger, Blob const&); TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&); - uint256 const& + [[nodiscard]] uint256 const& getTxID() const { return transactionID_; } - std::uint32_t + [[nodiscard]] std::uint32_t getLgrSeq() const { return ledgerSeq_; } - int + [[nodiscard]] int getResult() const { return result_; } - TER + [[nodiscard]] TER getResultTER() const { return TER::fromInt(result_); } - std::uint32_t + [[nodiscard]] std::uint32_t getIndex() const { return index_; @@ -52,10 +52,10 @@ public: getAffectedNode(uint256 const&); /** Return a list of accounts affected by this transaction */ - boost::container::flat_set + [[nodiscard]] boost::container::flat_set getAffectedAccounts() const; - Json::Value + [[nodiscard]] Json::Value getJson(JsonOptions p) const { return getAsObject().getJson(p); @@ -63,14 +63,14 @@ public: void addRaw(Serializer&, TER, std::uint32_t index); - STObject + [[nodiscard]] STObject getAsObject() const; STArray& getNodes() { return nodes_; } - STArray const& + [[nodiscard]] STArray const& getNodes() const { return nodes_; @@ -86,7 +86,7 @@ public: parentBatchID_ = obj.getFieldH256(sfParentBatchID); } - std::optional const& + [[nodiscard]] std::optional const& getDeliveredAmount() const { return deliveredAmount_; diff --git a/include/xrpl/protocol/Units.h b/include/xrpl/protocol/Units.h index b606ca2cdf..8faabd7138 100644 --- a/include/xrpl/protocol/Units.h +++ b/include/xrpl/protocol/Units.h @@ -264,7 +264,7 @@ public: } /** Return the sign of the amount */ - constexpr int + [[nodiscard]] constexpr int signum() const noexcept { if (value_ < 0) @@ -274,14 +274,14 @@ public: /** Returns the number of drops */ // TODO: Move this to a new class, maybe with the old "TaggedFee" name - constexpr value_type + [[nodiscard]] constexpr value_type fee() const { return value_; } template - constexpr double + [[nodiscard]] constexpr double decimalFromReference(ValueUnit reference) const { return static_cast(value_) / reference.value(); @@ -291,7 +291,7 @@ public: // known valid type tags can be converted to JSON. At the time // of implementation, that includes all known tags, but more may // be added in the future. - Json::Value + [[nodiscard]] Json::Value jsonClipped() const requires Usable { @@ -319,7 +319,7 @@ public: function unless the type has been abstracted away, e.g. in a templated function. */ - constexpr value_type + [[nodiscard]] constexpr value_type value() const { return value_; diff --git a/include/xrpl/protocol/XChainAttestations.h b/include/xrpl/protocol/XChainAttestations.h index 44a2334ca0..83bb6267a2 100644 --- a/include/xrpl/protocol/XChainAttestations.h +++ b/include/xrpl/protocol/XChainAttestations.h @@ -58,7 +58,7 @@ struct AttestationBase operator=(AttestationBase const&) = default; // verify that the signature attests to the data. - bool + [[nodiscard]] bool verify(STXChainBridge const& bridge) const; protected: @@ -285,7 +285,7 @@ struct XChainClaimAttestation explicit XChainClaimAttestation(Json::Value const& v); - AttestationMatch + [[nodiscard]] AttestationMatch match(MatchFields const& rhs) const; [[nodiscard]] STObject @@ -336,7 +336,7 @@ struct XChainCreateAccountAttestation [[nodiscard]] STObject toSTObject() const; - AttestationMatch + [[nodiscard]] AttestationMatch match(MatchFields const& rhs) const; friend bool @@ -379,10 +379,10 @@ public: [[nodiscard]] STArray toSTArray() const; - typename AttCollection::const_iterator + [[nodiscard]] typename AttCollection::const_iterator begin() const; - typename AttCollection::const_iterator + [[nodiscard]] typename AttCollection::const_iterator end() const; typename AttCollection::iterator @@ -395,13 +395,13 @@ public: std::size_t erase_if(F&& f); - std::size_t + [[nodiscard]] std::size_t size() const; - bool + [[nodiscard]] bool empty() const; - AttCollection const& + [[nodiscard]] AttCollection const& attestations() const; template diff --git a/include/xrpl/protocol/XRPAmount.h b/include/xrpl/protocol/XRPAmount.h index 0cb5121ef1..bc7ef891dc 100644 --- a/include/xrpl/protocol/XRPAmount.h +++ b/include/xrpl/protocol/XRPAmount.h @@ -146,7 +146,7 @@ public: } /** Return the sign of the amount */ - constexpr int + [[nodiscard]] constexpr int signum() const noexcept { if (drops_ < 0) @@ -155,17 +155,17 @@ public: } /** Returns the number of drops */ - constexpr value_type + [[nodiscard]] constexpr value_type drops() const { return drops_; } - constexpr double + [[nodiscard]] constexpr double decimalXRP() const; template - std::optional + [[nodiscard]] std::optional dropsAs() const { if ((drops_ > std::numeric_limits::max()) || @@ -185,7 +185,7 @@ public: } template - Dest + [[nodiscard]] Dest dropsAs(XRPAmount defaultValue) const { return dropsAs().value_or(defaultValue.drops()); @@ -195,7 +195,7 @@ public: * in contexts that don't expect the value to ever approach * the 32-bit limits (i.e. fees and reserves). */ - Json::Value + [[nodiscard]] Json::Value jsonClipped() const { static_assert( @@ -216,7 +216,7 @@ public: function unless the type has been abstracted away, e.g. in a templated function. */ - constexpr value_type + [[nodiscard]] constexpr value_type value() const { return drops_; diff --git a/include/xrpl/protocol/detail/STVar.h b/include/xrpl/protocol/detail/STVar.h index 5526aed8fa..c819740a90 100644 --- a/include/xrpl/protocol/detail/STVar.h +++ b/include/xrpl/protocol/detail/STVar.h @@ -78,7 +78,7 @@ public: { return &get(); } - STBase const& + [[nodiscard]] STBase const& get() const { return *p_; @@ -129,7 +129,7 @@ private: void constructST(SerializedTypeID id, int depth, Args&&... arg); - bool + [[nodiscard]] bool on_heap() const { return static_cast(p_) != static_cast(&d_); diff --git a/include/xrpl/protocol/detail/token_errors.h b/include/xrpl/protocol/detail/token_errors.h index 5511fb06b3..a663d145b1 100644 --- a/include/xrpl/protocol/detail/token_errors.h +++ b/include/xrpl/protocol/detail/token_errors.h @@ -30,13 +30,13 @@ class TokenCodecErrcCategory : public std::error_category { public: // Return a short descriptive name for the category - char const* + [[nodiscard]] char const* name() const noexcept final { return "TokenCodecError"; } // Return what each enum means in text - std::string + [[nodiscard]] std::string message(int c) const final { switch (static_cast(c)) diff --git a/include/xrpl/rdb/DatabaseCon.h b/include/xrpl/rdb/DatabaseCon.h index 579f30516b..08376f0e71 100644 --- a/include/xrpl/rdb/DatabaseCon.h +++ b/include/xrpl/rdb/DatabaseCon.h @@ -77,7 +77,7 @@ public: // from commonPragma() bool useGlobalPragma = false; - std::vector const* + [[nodiscard]] std::vector const* commonPragma() const { XRPL_ASSERT( @@ -92,6 +92,7 @@ public: std::array lgrPragma; }; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct CheckpointerSetup { JobQueue* jobQueue{}; diff --git a/include/xrpl/rdb/SociDB.h b/include/xrpl/rdb/SociDB.h index 43086ed931..e87aa2a182 100644 --- a/include/xrpl/rdb/SociDB.h +++ b/include/xrpl/rdb/SociDB.h @@ -43,7 +43,7 @@ class DBConfig public: DBConfig(BasicConfig const& config, std::string const& dbName); - std::string + [[nodiscard]] std::string connectionString() const; void open(soci::session& s) const; diff --git a/include/xrpl/resource/Charge.h b/include/xrpl/resource/Charge.h index 436e87e158..582688260e 100644 --- a/include/xrpl/resource/Charge.h +++ b/include/xrpl/resource/Charge.h @@ -18,15 +18,15 @@ public: Charge(value_type cost, std::string label = std::string()); /** Return the human readable label associated with the charge. */ - std::string const& + [[nodiscard]] std::string const& label() const; /** Return the cost of the charge in Resource::Manager units. */ - value_type + [[nodiscard]] value_type cost() const; /** Converts this charge into a human readable string. */ - std::string + [[nodiscard]] std::string to_string() const; bool diff --git a/include/xrpl/resource/Consumer.h b/include/xrpl/resource/Consumer.h index 21d9f9c74f..ebb214d129 100644 --- a/include/xrpl/resource/Consumer.h +++ b/include/xrpl/resource/Consumer.h @@ -25,11 +25,11 @@ public: operator=(Consumer const& other); /** Return a human readable string uniquely identifying this consumer. */ - std::string + [[nodiscard]] std::string to_string() const; /** Returns `true` if this is a privileged endpoint. */ - bool + [[nodiscard]] bool isUnlimited() const; /** Raise the Consumer's privilege level to a Named endpoint. @@ -42,7 +42,7 @@ public: This should be checked upon creation to determine if the consumer should be disconnected immediately. */ - Disposition + [[nodiscard]] Disposition disposition() const; /** Apply a load charge to the consumer. */ diff --git a/include/xrpl/resource/detail/Entry.h b/include/xrpl/resource/detail/Entry.h index 5b2d8b1ba3..89f27b2672 100644 --- a/include/xrpl/resource/detail/Entry.h +++ b/include/xrpl/resource/detail/Entry.h @@ -25,7 +25,7 @@ struct Entry : public beast::List::Node { } - std::string + [[nodiscard]] std::string to_string() const { return getFingerprint(key->address, publicKey); @@ -36,7 +36,7 @@ struct Entry : public beast::List::Node * resource limits applied--it is still possible for certain RPC commands * to be forbidden, but that depends on Role. */ - bool + [[nodiscard]] bool isUnlimited() const { return key->kind == kindUnlimited; diff --git a/include/xrpl/server/Handoff.h b/include/xrpl/server/Handoff.h index 60ed16def4..eba8c6c4de 100644 --- a/include/xrpl/server/Handoff.h +++ b/include/xrpl/server/Handoff.h @@ -26,7 +26,7 @@ struct Handoff // When set, this will be sent back std::shared_ptr response; - bool + [[nodiscard]] bool handled() const { return moved || response; diff --git a/include/xrpl/server/InfoSub.h b/include/xrpl/server/InfoSub.h index d45f4d7740..b6dff5983d 100644 --- a/include/xrpl/server/InfoSub.h +++ b/include/xrpl/server/InfoSub.h @@ -172,7 +172,7 @@ public: virtual void send(Json::Value const& jvObj, bool broadcast) = 0; - std::uint64_t + [[nodiscard]] std::uint64_t getSeq() const; void @@ -203,7 +203,7 @@ public: void setApiVersion(unsigned int apiVersion); - unsigned int + [[nodiscard]] unsigned int getApiVersion() const noexcept; protected: diff --git a/include/xrpl/server/Manifest.h b/include/xrpl/server/Manifest.h index ce97c57260..e11d5dc0da 100644 --- a/include/xrpl/server/Manifest.h +++ b/include/xrpl/server/Manifest.h @@ -102,11 +102,11 @@ struct Manifest operator=(Manifest&& other) = default; /// Returns `true` if manifest signature is valid - bool + [[nodiscard]] bool verify() const; /// Returns hash of serialized manifest data - uint256 + [[nodiscard]] uint256 hash() const; /// Returns `true` if manifest revokes master key @@ -116,15 +116,15 @@ struct Manifest revoked(std::uint32_t sequence); /// Returns `true` if manifest revokes master key - bool + [[nodiscard]] bool revoked() const; /// Returns manifest signature - std::optional + [[nodiscard]] std::optional getSignature() const; /// Returns manifest master key signature - Blob + [[nodiscard]] Blob getMasterSignature() const; }; diff --git a/include/xrpl/server/NetworkOPs.h b/include/xrpl/server/NetworkOPs.h index b8f50dcd42..c449bd283b 100644 --- a/include/xrpl/server/NetworkOPs.h +++ b/include/xrpl/server/NetworkOPs.h @@ -90,11 +90,11 @@ public: // Network information // - virtual OperatingMode + [[nodiscard]] virtual OperatingMode getOperatingMode() const = 0; - virtual std::string + [[nodiscard]] virtual std::string strOperatingMode(OperatingMode const mode, bool const admin = false) const = 0; - virtual std::string + [[nodiscard]] virtual std::string strOperatingMode(bool const admin = false) const = 0; //-------------------------------------------------------------------------- diff --git a/include/xrpl/server/Port.h b/include/xrpl/server/Port.h index 93652d422a..515846b2a8 100644 --- a/include/xrpl/server/Port.h +++ b/include/xrpl/server/Port.h @@ -53,15 +53,15 @@ struct Port std::uint16_t ws_queue_limit{}; // Returns `true` if any websocket protocols are specified - bool + [[nodiscard]] bool websockets() const; // Returns `true` if any secure protocols are specified - bool + [[nodiscard]] bool secure() const; // Returns a string containing the list of protocols - std::string + [[nodiscard]] std::string protocols() const; }; diff --git a/include/xrpl/server/WSSession.h b/include/xrpl/server/WSSession.h index 56105739e9..01032359b3 100644 --- a/include/xrpl/server/WSSession.h +++ b/include/xrpl/server/WSSession.h @@ -96,13 +96,13 @@ struct WSSession virtual void run() = 0; - virtual Port const& + [[nodiscard]] virtual Port const& port() const = 0; - virtual http_request_type const& + [[nodiscard]] virtual http_request_type const& request() const = 0; - virtual boost::asio::ip::tcp::endpoint const& + [[nodiscard]] virtual boost::asio::ip::tcp::endpoint const& remote_endpoint() const = 0; /** Send a WebSockets message. */ diff --git a/include/xrpl/server/detail/BaseWSPeer.h b/include/xrpl/server/detail/BaseWSPeer.h index 4251617262..aaa4791059 100644 --- a/include/xrpl/server/detail/BaseWSPeer.h +++ b/include/xrpl/server/detail/BaseWSPeer.h @@ -70,19 +70,19 @@ public: // WSSession // - Port const& + [[nodiscard]] Port const& port() const override { return this->port_; } - http_request_type const& + [[nodiscard]] http_request_type const& request() const override { return this->request_; } - boost::asio::ip::tcp::endpoint const& + [[nodiscard]] boost::asio::ip::tcp::endpoint const& remote_endpoint() const override { return this->remote_address_; diff --git a/include/xrpl/server/detail/Door.h b/include/xrpl/server/detail/Door.h index 346309f078..2d95a1c5aa 100644 --- a/include/xrpl/server/detail/Door.h +++ b/include/xrpl/server/detail/Door.h @@ -132,7 +132,7 @@ public: void close() override; - endpoint_type + [[nodiscard]] endpoint_type get_endpoint() const { return acceptor_.local_endpoint(); diff --git a/include/xrpl/server/detail/io_list.h b/include/xrpl/server/detail/io_list.h index ef11d3cea6..8c25a89f79 100644 --- a/include/xrpl/server/detail/io_list.h +++ b/include/xrpl/server/detail/io_list.h @@ -80,7 +80,7 @@ public: Undefined result if called concurrently with close(). */ - bool + [[nodiscard]] bool closed() const { return closed_; diff --git a/include/xrpl/shamap/Family.h b/include/xrpl/shamap/Family.h index 73887fb2dc..b9dd85443a 100644 --- a/include/xrpl/shamap/Family.h +++ b/include/xrpl/shamap/Family.h @@ -27,7 +27,7 @@ public: virtual NodeStore::Database& db() = 0; - virtual NodeStore::Database const& + [[nodiscard]] virtual NodeStore::Database const& db() const = 0; virtual beast::Journal const& diff --git a/include/xrpl/shamap/SHAMapAddNode.h b/include/xrpl/shamap/SHAMapAddNode.h index e38884e050..a560568126 100644 --- a/include/xrpl/shamap/SHAMapAddNode.h +++ b/include/xrpl/shamap/SHAMapAddNode.h @@ -22,15 +22,15 @@ public: incDuplicate(); void reset(); - int + [[nodiscard]] int getGood() const; - bool + [[nodiscard]] bool isGood() const; - bool + [[nodiscard]] bool isInvalid() const; - bool + [[nodiscard]] bool isUseful() const; - std::string + [[nodiscard]] std::string get() const; SHAMapAddNode& diff --git a/include/xrpl/shamap/SHAMapNodeID.h b/include/xrpl/shamap/SHAMapNodeID.h index 3517246f90..dbc087b356 100644 --- a/include/xrpl/shamap/SHAMapNodeID.h +++ b/include/xrpl/shamap/SHAMapNodeID.h @@ -24,29 +24,29 @@ public: SHAMapNodeID& operator=(SHAMapNodeID const& other) = default; - bool + [[nodiscard]] bool isRoot() const { return depth_ == 0; } // Get the wire format (256-bit nodeID, 1-byte depth) - std::string + [[nodiscard]] std::string getRawString() const; - unsigned int + [[nodiscard]] unsigned int getDepth() const { return depth_; } - uint256 const& + [[nodiscard]] uint256 const& getNodeID() const { return id_; } - SHAMapNodeID + [[nodiscard]] SHAMapNodeID getChildNodeID(unsigned int m) const; /** diff --git a/include/xrpl/shamap/SHAMapSyncFilter.h b/include/xrpl/shamap/SHAMapSyncFilter.h index b34d160c25..4104220a3f 100644 --- a/include/xrpl/shamap/SHAMapSyncFilter.h +++ b/include/xrpl/shamap/SHAMapSyncFilter.h @@ -25,7 +25,7 @@ public: Blob&& nodeData, SHAMapNodeType type) const = 0; - virtual std::optional + [[nodiscard]] virtual std::optional getNode(SHAMapHash const& nodeHash) const = 0; }; diff --git a/include/xrpl/shamap/detail/TaggedPointer.h b/include/xrpl/shamap/detail/TaggedPointer.h index d7adde4b05..31d5f2ba65 100644 --- a/include/xrpl/shamap/detail/TaggedPointer.h +++ b/include/xrpl/shamap/detail/TaggedPointer.h @@ -192,7 +192,7 @@ public: @param i index of the requested child */ - std::optional + [[nodiscard]] std::optional getChildIndex(std::uint16_t isBranch, int i) const; }; diff --git a/include/xrpl/tx/ApplyContext.h b/include/xrpl/tx/ApplyContext.h index 1817969978..ea936017e0 100644 --- a/include/xrpl/tx/ApplyContext.h +++ b/include/xrpl/tx/ApplyContext.h @@ -49,7 +49,7 @@ public: return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor } - ApplyView const& + [[nodiscard]] ApplyView const& view() const { return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor @@ -62,7 +62,7 @@ public: return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor } - ApplyFlags const& + [[nodiscard]] ApplyFlags const& flags() const { return flags_; diff --git a/include/xrpl/tx/Transactor.h b/include/xrpl/tx/Transactor.h index a3b0af821e..e20ac70850 100644 --- a/include/xrpl/tx/Transactor.h +++ b/include/xrpl/tx/Transactor.h @@ -135,7 +135,7 @@ public: return ctx_.view(); } - ApplyView const& + [[nodiscard]] ApplyView const& view() const { return ctx_.view(); diff --git a/include/xrpl/tx/applySteps.h b/include/xrpl/tx/applySteps.h index d42ca2c118..4f857bb7c1 100644 --- a/include/xrpl/tx/applySteps.h +++ b/include/xrpl/tx/applySteps.h @@ -89,42 +89,42 @@ public: operator=(TxConsequences&&) = default; /// Fee - XRPAmount + [[nodiscard]] XRPAmount fee() const { return fee_; } /// Potential Spend - XRPAmount const& + [[nodiscard]] XRPAmount const& potentialSpend() const { return potentialSpend_; } /// SeqProxy - SeqProxy + [[nodiscard]] SeqProxy seqProxy() const { return seqProx_; } /// Sequences consumed - std::uint32_t + [[nodiscard]] std::uint32_t sequencesConsumed() const { return sequencesConsumed_; } /// Returns true if the transaction is a blocker. - bool + [[nodiscard]] bool isBlocker() const { return isBlocker_; } // Return the SeqProxy that would follow this. - SeqProxy + [[nodiscard]] SeqProxy followingSeq() const { SeqProxy following = seqProx_; diff --git a/include/xrpl/tx/invariants/AMMInvariant.h b/include/xrpl/tx/invariants/AMMInvariant.h index b15b62cc93..43d9c5ad0a 100644 --- a/include/xrpl/tx/invariants/AMMInvariant.h +++ b/include/xrpl/tx/invariants/AMMInvariant.h @@ -28,22 +28,22 @@ public: finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&); private: - bool + [[nodiscard]] bool finalizeBid(bool enforce, beast::Journal const&) const; - bool + [[nodiscard]] bool finalizeVote(bool enforce, beast::Journal const&) const; - bool + [[nodiscard]] bool finalizeCreate(STTx const&, ReadView const&, bool enforce, beast::Journal const&) const; - bool + [[nodiscard]] bool finalizeDelete(bool enforce, TER res, beast::Journal const&) const; - bool + [[nodiscard]] bool finalizeDeposit(STTx const&, ReadView const&, bool enforce, beast::Journal const&) const; // Includes clawback - bool + [[nodiscard]] bool finalizeWithdraw(STTx const&, ReadView const&, bool enforce, beast::Journal const&) const; - bool + [[nodiscard]] bool finalizeDEX(bool enforce, beast::Journal const&) const; - bool + [[nodiscard]] bool generalInvariant(STTx const&, ReadView const&, ZeroAllowed zeroAllowed, beast::Journal const&) const; }; diff --git a/include/xrpl/tx/invariants/InvariantCheck.h b/include/xrpl/tx/invariants/InvariantCheck.h index ad4c5e16c4..028a110acd 100644 --- a/include/xrpl/tx/invariants/InvariantCheck.h +++ b/include/xrpl/tx/invariants/InvariantCheck.h @@ -132,7 +132,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -152,7 +152,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -198,7 +198,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -215,7 +215,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -233,7 +233,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -252,7 +252,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -271,7 +271,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -287,7 +287,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -307,7 +307,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -328,7 +328,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; diff --git a/include/xrpl/tx/invariants/MPTInvariant.h b/include/xrpl/tx/invariants/MPTInvariant.h index dd064af396..e3aa06016a 100644 --- a/include/xrpl/tx/invariants/MPTInvariant.h +++ b/include/xrpl/tx/invariants/MPTInvariant.h @@ -24,7 +24,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; diff --git a/include/xrpl/tx/invariants/NFTInvariant.h b/include/xrpl/tx/invariants/NFTInvariant.h index 5bb5f90437..527b0e8097 100644 --- a/include/xrpl/tx/invariants/NFTInvariant.h +++ b/include/xrpl/tx/invariants/NFTInvariant.h @@ -35,7 +35,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; @@ -63,7 +63,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + [[nodiscard]] bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const; }; diff --git a/include/xrpl/tx/paths/AMMLiquidity.h b/include/xrpl/tx/paths/AMMLiquidity.h index 128052f851..d7a62dce65 100644 --- a/include/xrpl/tx/paths/AMMLiquidity.h +++ b/include/xrpl/tx/paths/AMMLiquidity.h @@ -60,40 +60,40 @@ public: * If clobQuality is provided then AMM offer size is set based on the * quality. */ - std::optional> + [[nodiscard]] std::optional> getOffer(ReadView const& view, std::optional const& clobQuality) const; - AccountID const& + [[nodiscard]] AccountID const& ammAccount() const { return ammAccountID_; } - bool + [[nodiscard]] bool multiPath() const { return ammContext_.multiPath(); } - std::uint32_t + [[nodiscard]] std::uint32_t tradingFee() const { return tradingFee_; } - AMMContext& + [[nodiscard]] AMMContext& context() const { return ammContext_; } - Asset const& + [[nodiscard]] Asset const& assetIn() const { return assetIn_; } - Asset const& + [[nodiscard]] Asset const& assetOut() const { return assetOut_; @@ -102,7 +102,7 @@ public: private: /** Fetches current AMM balances. */ - TAmounts + [[nodiscard]] TAmounts fetchBalances(ReadView const& view) const; /** Generate AMM offers with the offer size based on Fibonacci sequence. @@ -112,7 +112,7 @@ private: * If the generated offer exceeds the pool balance then the function * throws overflow exception. */ - TAmounts + [[nodiscard]] TAmounts generateFibSeqOffer(TAmounts const& balances) const; /** Generate max offer. @@ -124,7 +124,7 @@ private: * takerPays = max input amount; * takerGets = swapIn(takerPays). */ - std::optional> + [[nodiscard]] std::optional> maxOffer(TAmounts const& balances, Rules const& rules) const; }; diff --git a/include/xrpl/tx/paths/AMMOffer.h b/include/xrpl/tx/paths/AMMOffer.h index de583a60d6..bdffec5ab9 100644 --- a/include/xrpl/tx/paths/AMMOffer.h +++ b/include/xrpl/tx/paths/AMMOffer.h @@ -47,34 +47,34 @@ public: TAmounts const& balances, Quality const& quality); - Quality + [[nodiscard]] Quality quality() const noexcept { return quality_; } - Asset const& + [[nodiscard]] Asset const& assetIn() const; - Asset const& + [[nodiscard]] Asset const& assetOut() const; - AccountID const& + [[nodiscard]] AccountID const& owner() const; - std::optional + [[nodiscard]] std::optional key() const { return std::nullopt; } - TAmounts const& + [[nodiscard]] TAmounts const& amount() const; void consume(ApplyView& view, TAmounts const& consumed); - bool + [[nodiscard]] bool fully_consumed() const { return consumed_; @@ -84,17 +84,17 @@ public: * using current balances. If multi-path then ceil_out using * current quality. */ - TAmounts + [[nodiscard]] TAmounts limitOut(TAmounts const& offerAmount, TOut const& limit, bool roundUp) const; /** Limit in of the provided offer. If one-path then swapIn * using current balances. If multi-path then ceil_in using * current quality. */ - TAmounts + [[nodiscard]] TAmounts limitIn(TAmounts const& offerAmount, TIn const& limit, bool roundUp) const; - QualityFunction + [[nodiscard]] QualityFunction getQualityFunc() const; /** Send funds without incurring the transfer fee @@ -107,7 +107,7 @@ public: std::forward(args)..., WaiveTransferFee::Yes, AllowMPTOverflow::Yes); } - bool + [[nodiscard]] bool isFunded() const { // AMM offer is fully funded by the pool @@ -124,7 +124,7 @@ public: /** Check the new pool product is greater or equal to the old pool * product or if decreases then within some threshold. */ - bool + [[nodiscard]] bool checkInvariant(TAmounts const& consumed, beast::Journal j) const; }; diff --git a/include/xrpl/tx/paths/BookTip.h b/include/xrpl/tx/paths/BookTip.h index 6a1805e83a..2d7490d144 100644 --- a/include/xrpl/tx/paths/BookTip.h +++ b/include/xrpl/tx/paths/BookTip.h @@ -28,25 +28,25 @@ public: /** Create the iterator. */ BookTip(ApplyView& view, Book const& book); - uint256 const& + [[nodiscard]] uint256 const& dir() const noexcept { return m_dir; } - uint256 const& + [[nodiscard]] uint256 const& index() const noexcept { return m_index; } - Quality const& + [[nodiscard]] Quality const& quality() const noexcept { return m_quality; } - SLE::pointer const& + [[nodiscard]] SLE::pointer const& entry() const noexcept { return m_entry; diff --git a/include/xrpl/tx/paths/Offer.h b/include/xrpl/tx/paths/Offer.h index f79f33658b..7e3eee0430 100644 --- a/include/xrpl/tx/paths/Offer.h +++ b/include/xrpl/tx/paths/Offer.h @@ -43,14 +43,14 @@ public: offer is partially filled; Subsequent partial fills will use the original quality. */ - Quality + [[nodiscard]] Quality quality() const noexcept { return m_quality; } /** Returns the account id of the offer's owner. */ - AccountID const& + [[nodiscard]] AccountID const& owner() const { return m_account; @@ -59,14 +59,14 @@ public: /** Returns the in and out amounts. Some or all of the out amount may be unfunded. */ - TAmounts const& + [[nodiscard]] TAmounts const& amount() const { return m_amounts; } /** Returns `true` if no more funds can flow through this offer. */ - bool + [[nodiscard]] bool fully_consumed() const { if (m_amounts.in <= beast::zero) @@ -91,34 +91,34 @@ public: view.update(m_entry); } - std::string + [[nodiscard]] std::string id() const { return to_string(m_entry->key()); } - std::optional + [[nodiscard]] std::optional key() const { return m_entry->key(); } - Asset const& + [[nodiscard]] Asset const& assetIn() const; - Asset const& + [[nodiscard]] Asset const& assetOut() const; - TAmounts + [[nodiscard]] TAmounts limitOut(TAmounts const& offerAmount, TOut const& limit, bool roundUp) const; - TAmounts + [[nodiscard]] TAmounts limitIn(TAmounts const& offerAmount, TIn const& limit, bool roundUp) const; template static TER send(Args&&... args); - bool + [[nodiscard]] bool isFunded() const { // Offer owner is issuer; they have unlimited funds if IOU @@ -135,7 +135,7 @@ public: /** Check any required invariant. Limit order book offer * always returns true. */ - bool + [[nodiscard]] bool checkInvariant(TAmounts const& consumed, beast::Journal j) const { if (!isFeatureEnabled(fixAMMv1_3)) diff --git a/include/xrpl/tx/paths/OfferStream.h b/include/xrpl/tx/paths/OfferStream.h index 84dbac9a60..69409b9ef7 100644 --- a/include/xrpl/tx/paths/OfferStream.h +++ b/include/xrpl/tx/paths/OfferStream.h @@ -39,7 +39,7 @@ public: count_++; return true; } - std::uint32_t + [[nodiscard]] std::uint32_t count() const { return count_; @@ -66,7 +66,7 @@ protected: template requires ValidTaker - bool + [[nodiscard]] bool shouldRmSmallIncreasedQOffer() const; public: @@ -84,7 +84,7 @@ public: Offers are always presented in decreasing quality. Only valid if step() returned `true`. */ - TOffer& + [[nodiscard]] TOffer& tip() const { return const_cast(this)->offer_; @@ -100,7 +100,7 @@ public: bool step(); - TOut + [[nodiscard]] TOut ownerFunds() const { return *ownerFunds_; // NOLINT(bugprone-unchecked-optional-access) always set after step() @@ -141,7 +141,7 @@ public: void permRmOffer(uint256 const& offerIndex) override; - boost::container::flat_set const& + [[nodiscard]] boost::container::flat_set const& permToRemove() const { return permToRemove_; diff --git a/include/xrpl/tx/paths/RippleCalc.h b/include/xrpl/tx/paths/RippleCalc.h index 55f552a61f..771467cdc7 100644 --- a/include/xrpl/tx/paths/RippleCalc.h +++ b/include/xrpl/tx/paths/RippleCalc.h @@ -53,7 +53,7 @@ public: TER calculationResult_ = temUNKNOWN; public: - TER + [[nodiscard]] TER result() const { return calculationResult_; diff --git a/include/xrpl/tx/paths/detail/FlowDebugInfo.h b/include/xrpl/tx/paths/detail/FlowDebugInfo.h index dd7a0bb9c5..36c0bd7de0 100644 --- a/include/xrpl/tx/paths/detail/FlowDebugInfo.h +++ b/include/xrpl/tx/paths/detail/FlowDebugInfo.h @@ -45,7 +45,7 @@ struct FlowDebugInfo numActive.reserve(s); } - size_t + [[nodiscard]] size_t size() const { return in.size(); @@ -92,7 +92,7 @@ struct FlowDebugInfo passInfo.reserve(64); } - auto + [[nodiscard]] auto duration(std::string const& tag) const { auto i = timePoints.find(tag); @@ -109,7 +109,7 @@ struct FlowDebugInfo return std::chrono::duration_cast>(t.second - t.first); } - std::size_t + [[nodiscard]] std::size_t count(std::string const& tag) const { auto i = counts.find(tag); @@ -158,7 +158,7 @@ struct FlowDebugInfo counts[tag] = c; } - std::size_t + [[nodiscard]] std::size_t passCount() const { return passInfo.size(); @@ -182,7 +182,7 @@ struct FlowDebugInfo passInfo.newLiquidityPass(); } - std::string + [[nodiscard]] std::string to_string(bool writePassInfo) const { std::ostringstream ostr; @@ -327,27 +327,4 @@ writeDiffs(std::ostringstream& ostr, Iter begin, Iter end) ostr << ']'; }; -using BalanceDiffs = - std::pair, STAmount>, XRPAmount>; - -inline BalanceDiffs -balanceDiffs(PaymentSandbox const& sb, ReadView const& rv) -{ - return {sb.balanceChanges(rv), sb.xrpDestroyed()}; -} - -inline std::string -balanceDiffsToString(std::optional const& bd) -{ - if (!bd) - return std::string{}; - auto const& diffs = bd->first; - auto const& xrpDestroyed = bd->second; - std::ostringstream ostr; - ostr << ", xrpDestroyed: " << to_string(xrpDestroyed); - ostr << ", balanceDiffs: "; - writeDiffs(ostr, diffs.begin(), diffs.end()); - return ostr.str(); -}; - } // namespace xrpl::path::detail diff --git a/include/xrpl/tx/paths/detail/Steps.h b/include/xrpl/tx/paths/detail/Steps.h index c46cebca88..b4d9d6e0b4 100644 --- a/include/xrpl/tx/paths/detail/Steps.h +++ b/include/xrpl/tx/paths/detail/Steps.h @@ -107,21 +107,21 @@ public: Amount of currency computed coming into the Step the last time the step ran in reverse. */ - virtual std::optional + [[nodiscard]] virtual std::optional cachedIn() const = 0; /** Amount of currency computed coming out of the Step the last time the step ran in reverse. */ - virtual std::optional + [[nodiscard]] virtual std::optional cachedOut() const = 0; /** If this step is DirectStepI (IOU->IOU direct step), return the src account. This is needed for checkNoRipple. */ - virtual std::optional + [[nodiscard]] virtual std::optional directStepSrcAcct() const { return std::nullopt; @@ -129,7 +129,7 @@ public: // for debugging. Return the src and dst accounts for a direct step // For XRP endpoints, one of src or dst will be the root account - virtual std::optional> + [[nodiscard]] virtual std::optional> directStepAccts() const { return std::nullopt; @@ -143,13 +143,13 @@ public: @param sb view with the strand's state of balances and offers @param dir reverse -> called from rev(); forward -> called from fwd(). */ - virtual DebtDirection + [[nodiscard]] virtual DebtDirection debtDirection(ReadView const& sb, StrandDirection dir) const = 0; /** If this step is a DirectStepI, return the quality in of the dst account. */ - virtual std::uint32_t + [[nodiscard]] virtual std::uint32_t lineQualityIn(ReadView const&) const { return QUALITY_ONE; @@ -168,7 +168,7 @@ public: rather than `qualityUpperBound`. It could still differ from the actual quality, but except for "dust" amounts, it should be a good estimate for the actual quality. */ - virtual std::pair, DebtDirection> + [[nodiscard]] virtual std::pair, DebtDirection> qualityUpperBound(ReadView const& v, DebtDirection prevStepDir) const = 0; /** Get QualityFunction. Used in one path optimization where @@ -178,7 +178,7 @@ public: * All steps, except for BookStep have the default * implementation. */ - virtual std::pair, DebtDirection> + [[nodiscard]] virtual std::pair, DebtDirection> getQualityFunc(ReadView const& v, DebtDirection prevStepDir) const; /** Return the number of offers consumed or partially consumed the last time @@ -188,7 +188,7 @@ public: entire payment, it is only the number the last time it ran. Offers may be partially consumed multiple times during a payment. */ - virtual std::uint32_t + [[nodiscard]] virtual std::uint32_t offersUsed() const { return 0; @@ -197,7 +197,7 @@ public: /** If this step is a BookStep, return the book. */ - virtual std::optional + [[nodiscard]] virtual std::optional bookStepBook() const { return std::nullopt; @@ -206,7 +206,7 @@ public: /** Check if amount is zero */ - virtual bool + [[nodiscard]] virtual bool isZero(EitherAmount const& out) const = 0; /** @@ -214,7 +214,7 @@ public: A strand that has additional liquidity may be marked inactive if a step has consumed too many offers. */ - virtual bool + [[nodiscard]] virtual bool inactive() const { return false; @@ -223,13 +223,13 @@ public: /** Return true if Out of lhs == Out of rhs. */ - virtual bool + [[nodiscard]] virtual bool equalOut(EitherAmount const& lhs, EitherAmount const& rhs) const = 0; /** Return true if In of lhs == In of rhs. */ - virtual bool + [[nodiscard]] virtual bool equalIn(EitherAmount const& lhs, EitherAmount const& rhs) const = 0; /** @@ -278,10 +278,10 @@ public: } private: - virtual std::string + [[nodiscard]] virtual std::string logString() const = 0; - virtual bool + [[nodiscard]] virtual bool equal(Step const& rhs) const = 0; }; @@ -457,19 +457,19 @@ public: return {EitherAmount(r.first), EitherAmount(r.second)}; } - bool + [[nodiscard]] bool isZero(EitherAmount const& out) const override { return get(out) == beast::zero; } - bool + [[nodiscard]] bool equalOut(EitherAmount const& lhs, EitherAmount const& rhs) const override { return get(lhs) == get(rhs); } - bool + [[nodiscard]] bool equalIn(EitherAmount const& lhs, EitherAmount const& rhs) const override { return get(lhs) == get(rhs); diff --git a/include/xrpl/tx/paths/detail/StrandFlow.h b/include/xrpl/tx/paths/detail/StrandFlow.h index 306a0b33e7..ee23de27b3 100644 --- a/include/xrpl/tx/paths/detail/StrandFlow.h +++ b/include/xrpl/tx/paths/detail/StrandFlow.h @@ -494,7 +494,7 @@ public: std::swap(cur_, next_); } - Strand const* + [[nodiscard]] Strand const* get(size_t i) const { if (i >= cur_.size()) @@ -522,19 +522,11 @@ public: next_.insert(next_.end(), std::next(cur_.begin(), i), cur_.end()); } - auto + [[nodiscard]] auto size() const { return cur_.size(); } - - void - removeIndex(std::size_t i) - { - if (i >= next_.size()) - return; - next_.erase(next_.begin() + i); - } }; /// @endcond @@ -661,11 +653,6 @@ flow( std::optional best; if (flowDebugInfo) flowDebugInfo->newLiquidityPass(); - // Index of strand to mark as inactive (remove from the active list) if - // the liquidity is used. This is used for strands that consume too many - // offers Constructed as `false,0` to workaround a gcc warning about - // uninitialized variables - std::optional markInactiveOnUse; for (size_t strandIndex = 0, sie = activeStrands.size(); strandIndex != sie; ++strandIndex) { Strand const* strand = activeStrands.get(strandIndex); @@ -729,11 +716,6 @@ flow( if (best) { - if (markInactiveOnUse) - { - activeStrands.removeIndex(*markInactiveOnUse); - markInactiveOnUse.reset(); - } savedIns.insert(best->in); savedOuts.insert(best->out); remainingOut = outReq - sum(savedOuts); diff --git a/include/xrpl/tx/transactors/dex/AMMContext.h b/include/xrpl/tx/transactors/dex/AMMContext.h index b0ff44c5ec..f582384e12 100644 --- a/include/xrpl/tx/transactors/dex/AMMContext.h +++ b/include/xrpl/tx/transactors/dex/AMMContext.h @@ -39,7 +39,7 @@ public: AMMContext& operator=(AMMContext const&) = delete; - bool + [[nodiscard]] bool multiPath() const { return multiPath_; @@ -65,19 +65,19 @@ public: ammUsed_ = false; } - bool + [[nodiscard]] bool maxItersReached() const { return ammIters_ >= MaxIterations; } - std::uint16_t + [[nodiscard]] std::uint16_t curIters() const { return ammIters_; } - AccountID + [[nodiscard]] AccountID account() const { return account_; diff --git a/include/xrpl/tx/transactors/lending/LoanSet.h b/include/xrpl/tx/transactors/lending/LoanSet.h index c778582ab0..3ede5adc4c 100644 --- a/include/xrpl/tx/transactors/lending/LoanSet.h +++ b/include/xrpl/tx/transactors/lending/LoanSet.h @@ -1,7 +1,7 @@ #pragma once +#include #include -#include namespace xrpl { diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index 73ab8f6307..3b2b8670cb 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -79,7 +79,7 @@ public: set_positive() noexcept; void set_negative() noexcept; - bool + [[nodiscard]] bool is_negative() const noexcept; // add a digit @@ -94,7 +94,7 @@ public: // Indicate round direction: 1 is up, -1 is down, 0 is even // This enables the client to round towards nearest, and on // tie, round towards even. - int + [[nodiscard]] int round() const noexcept; // Modify the result to the correctly rounded value diff --git a/src/libxrpl/beast/utility/beast_Journal.cpp b/src/libxrpl/beast/utility/beast_Journal.cpp index 7164fcfb06..0d0b5a0d1d 100644 --- a/src/libxrpl/beast/utility/beast_Journal.cpp +++ b/src/libxrpl/beast/utility/beast_Journal.cpp @@ -18,13 +18,13 @@ public: ~NullJournalSink() override = default; - bool + [[nodiscard]] bool active(severities::Severity) const override { return false; } - bool + [[nodiscard]] bool console() const override { return false; @@ -35,7 +35,7 @@ public: { } - severities::Severity + [[nodiscard]] severities::Severity threshold() const override { return severities::kDisabled; diff --git a/src/libxrpl/conditions/error.cpp b/src/libxrpl/conditions/error.cpp index 15ac847118..44fc17265a 100644 --- a/src/libxrpl/conditions/error.cpp +++ b/src/libxrpl/conditions/error.cpp @@ -14,13 +14,13 @@ class cryptoconditions_error_category : public std::error_category public: explicit cryptoconditions_error_category() = default; - char const* + [[nodiscard]] char const* name() const noexcept override { return "cryptoconditions"; } - std::string + [[nodiscard]] std::string message(int ev) const override { switch (safe_cast(ev)) @@ -79,19 +79,19 @@ public: } } - std::error_condition + [[nodiscard]] std::error_condition default_error_condition(int ev) const noexcept override { return std::error_condition{ev, *this}; } - bool + [[nodiscard]] bool equivalent(int ev, std::error_condition const& condition) const noexcept override { return &condition.category() == this && condition.value() == ev; } - bool + [[nodiscard]] bool equivalent(std::error_code const& error, int ev) const noexcept override { return &error.category() == this && error.value() == ev; diff --git a/src/libxrpl/json/Writer.cpp b/src/libxrpl/json/Writer.cpp index 75b5bc113c..b4a85e0170 100644 --- a/src/libxrpl/json/Writer.cpp +++ b/src/libxrpl/json/Writer.cpp @@ -72,7 +72,7 @@ public: Impl& operator=(Impl&&) = delete; - bool + [[nodiscard]] bool empty() const { return stack_.empty(); @@ -160,7 +160,7 @@ public: output_({&colon, 1}); } - bool + [[nodiscard]] bool isFinished() const { return isStarted_ && empty(); @@ -187,7 +187,7 @@ public: } } - Output const& + [[nodiscard]] Output const& getOutput() const { return output_; diff --git a/src/libxrpl/ledger/Ledger.cpp b/src/libxrpl/ledger/Ledger.cpp index ab09224914..18db482538 100644 --- a/src/libxrpl/ledger/Ledger.cpp +++ b/src/libxrpl/ledger/Ledger.cpp @@ -69,13 +69,13 @@ public: { } - std::unique_ptr + [[nodiscard]] std::unique_ptr copy() const override { return std::make_unique(*this); } - bool + [[nodiscard]] bool equal(base_type const& impl) const override { if (auto const p = dynamic_cast(&impl)) @@ -89,7 +89,7 @@ public: ++iter_; } - sles_type::value_type + [[nodiscard]] sles_type::value_type dereference() const override { SerialIter sit(iter_->slice()); @@ -116,13 +116,13 @@ public: { } - std::unique_ptr + [[nodiscard]] std::unique_ptr copy() const override { return std::make_unique(*this); } - bool + [[nodiscard]] bool equal(base_type const& impl) const override { if (auto const p = dynamic_cast(&impl)) @@ -136,7 +136,7 @@ public: ++iter_; } - txs_type::value_type + [[nodiscard]] txs_type::value_type dereference() const override { auto const& item = *iter_; diff --git a/src/libxrpl/ledger/OpenView.cpp b/src/libxrpl/ledger/OpenView.cpp index 089788d90b..28da1aedcb 100644 --- a/src/libxrpl/ledger/OpenView.cpp +++ b/src/libxrpl/ledger/OpenView.cpp @@ -36,13 +36,13 @@ public: { } - std::unique_ptr + [[nodiscard]] std::unique_ptr copy() const override { return std::make_unique(metadata_, iter_); } - bool + [[nodiscard]] bool equal(base_type const& impl) const override { if (auto const p = dynamic_cast(&impl)) @@ -56,7 +56,7 @@ public: ++iter_; } - value_type + [[nodiscard]] value_type dereference() const override { value_type result; diff --git a/src/libxrpl/ledger/PaymentSandbox.cpp b/src/libxrpl/ledger/PaymentSandbox.cpp index 6b38c4840c..ef6e4be8ad 100644 --- a/src/libxrpl/ledger/PaymentSandbox.cpp +++ b/src/libxrpl/ledger/PaymentSandbox.cpp @@ -4,20 +4,16 @@ #include #include #include -#include #include #include -#include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -58,14 +54,14 @@ DeferredCredits::creditIOU( if (sender < receiver) { - v.highAcctCredits = amount; - v.lowAcctCredits = amount.zeroed(); + v.lowAcctDebits = amount; + v.highAcctDebits = amount.zeroed(); v.lowAcctOrigBalance = preCreditSenderBalance; } else { - v.highAcctCredits = amount.zeroed(); - v.lowAcctCredits = amount; + v.lowAcctDebits = amount.zeroed(); + v.highAcctDebits = amount; v.lowAcctOrigBalance = -preCreditSenderBalance; } @@ -77,11 +73,11 @@ DeferredCredits::creditIOU( auto& v = i->second; if (sender < receiver) { - v.highAcctCredits += amount; + v.lowAcctDebits += amount; } else { - v.lowAcctCredits += amount; + v.highAcctDebits += amount; } } } @@ -212,11 +208,11 @@ DeferredCredits::adjustmentsIOU( if (main < other) { - result.emplace(v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance); + result.emplace(v.lowAcctDebits, v.highAcctDebits, v.lowAcctOrigBalance); return result; } - result.emplace(v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance); + result.emplace(v.highAcctDebits, v.lowAcctDebits, -v.lowAcctOrigBalance); return result; } @@ -239,8 +235,8 @@ DeferredCredits::apply(DeferredCredits& to) { auto& toVal = r.first->second; auto const& fromVal = i.second; - toVal.lowAcctCredits += fromVal.lowAcctCredits; - toVal.highAcctCredits += fromVal.highAcctCredits; + toVal.lowAcctDebits += fromVal.lowAcctDebits; + toVal.highAcctDebits += fromVal.highAcctDebits; // Do not update the orig balance, it's already correct } } @@ -467,131 +463,6 @@ PaymentSandbox::apply(PaymentSandbox& to) tab_.apply(to.tab_); } -std::map, STAmount> -PaymentSandbox::balanceChanges(ReadView const& view) const -{ - using key_t = std::tuple; - // Map of delta trust lines. As a special case, when both ends of the trust - // line are the same currency, then it's delta currency for that issuer. To - // get the change in XRP balance, Account == root, issuer == root, currency - // == XRP - std::map result; - - // populate a dictionary with low/high/currency/delta. This can be - // compared with the other versions payment code. - auto each = [&result]( - uint256 const& key, - bool isDelete, - std::shared_ptr const& before, - std::shared_ptr const& after) { - STAmount oldBalance; - STAmount newBalance; - AccountID lowID; - AccountID highID; - - // before is read from prev view - if (isDelete) - { - if (!before) - return; - - auto const bt = before->getType(); - switch (bt) - { - case ltACCOUNT_ROOT: - lowID = xrpAccount(); - highID = (*before)[sfAccount]; - oldBalance = (*before)[sfBalance]; - newBalance = oldBalance.zeroed(); - break; - case ltRIPPLE_STATE: - lowID = (*before)[sfLowLimit].getIssuer(); - highID = (*before)[sfHighLimit].getIssuer(); - oldBalance = (*before)[sfBalance]; - newBalance = oldBalance.zeroed(); - break; - case ltOFFER: - // TBD - break; - default: - break; - } - } - else if (!before) - { - // insert - auto const at = after->getType(); - switch (at) - { - case ltACCOUNT_ROOT: - lowID = xrpAccount(); - highID = (*after)[sfAccount]; - newBalance = (*after)[sfBalance]; - oldBalance = newBalance.zeroed(); - break; - case ltRIPPLE_STATE: - lowID = (*after)[sfLowLimit].getIssuer(); - highID = (*after)[sfHighLimit].getIssuer(); - newBalance = (*after)[sfBalance]; - oldBalance = newBalance.zeroed(); - break; - case ltOFFER: - // TBD - break; - default: - break; - } - } - else - { - // modify - auto const at = after->getType(); - XRPL_ASSERT( - at == before->getType(), - "xrpl::PaymentSandbox::balanceChanges : after and before " - "types matching"); - switch (at) - { - case ltACCOUNT_ROOT: - lowID = xrpAccount(); - highID = (*after)[sfAccount]; - oldBalance = (*before)[sfBalance]; - newBalance = (*after)[sfBalance]; - break; - case ltRIPPLE_STATE: - lowID = (*after)[sfLowLimit].getIssuer(); - highID = (*after)[sfHighLimit].getIssuer(); - oldBalance = (*before)[sfBalance]; - newBalance = (*after)[sfBalance]; - break; - case ltOFFER: - // TBD - break; - default: - break; - } - } - // The following are now set, put them in the map - auto delta = newBalance - oldBalance; - auto const cur = newBalance.get().currency; - result[std::make_tuple(lowID, highID, cur)] = delta; - auto r = result.emplace(std::make_tuple(lowID, lowID, cur), delta); - if (r.second) - { - r.first->second += delta; - } - - delta.negate(); - r = result.emplace(std::make_tuple(highID, highID, cur), delta); - if (r.second) - { - r.first->second += delta; - } - }; - items_.visit(view, each); - return result; -} - XRPAmount PaymentSandbox::xrpDestroyed() const { diff --git a/src/libxrpl/tx/transactors/lending/LendingHelpers.cpp b/src/libxrpl/ledger/helpers/LendingHelpers.cpp similarity index 99% rename from src/libxrpl/tx/transactors/lending/LendingHelpers.cpp rename to src/libxrpl/ledger/helpers/LendingHelpers.cpp index dea8dbbd34..caccca752d 100644 --- a/src/libxrpl/tx/transactors/lending/LendingHelpers.cpp +++ b/src/libxrpl/ledger/helpers/LendingHelpers.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -7,18 +7,19 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include +#include +#include #include #include -#include #include #include @@ -28,9 +29,18 @@ namespace xrpl { bool -checkLendingProtocolDependencies(PreflightContext const& ctx) +checkLendingProtocolDependencies(Rules const& rules, STTx const& tx) { - return ctx.rules.enabled(featureSingleAssetVault) && VaultCreate::checkExtraFeatures(ctx); + if (!rules.enabled(featureSingleAssetVault)) + return false; + + if (!rules.enabled(featureMPTokensV1)) + return false; + + if (tx.isFieldPresent(sfDomainID) && !rules.enabled(featurePermissionedDomains)) + return false; + + return true; } LoanPaymentParts& diff --git a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp index d47b49e910..c3987ddb03 100644 --- a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp @@ -94,7 +94,11 @@ transferRate(ReadView const& view, MPTID const& issuanceID) // which represents 50% of 1,000,000,000 if (auto const sle = view.read(keylet::mptIssuance(issuanceID)); sle && sle->isFieldPresent(sfTransferFee)) - return Rate{1'000'000'000u + (10'000 * sle->getFieldU16(sfTransferFee))}; + { + auto const fee = sle->getFieldU16(sfTransferFee); + XRPL_ASSERT(fee <= maxTransferFee, "xrpl::transferRate : fee is too large"); + return Rate{1'000'000'000u + (10'000 * fee)}; + } return parityRate; } @@ -160,7 +164,7 @@ authorizeMPToken( // When a holder wants to unauthorize/delete a MPT, the ledger must // - delete mptokenKey from owner directory // - delete the MPToken - if ((flags & tfMPTUnauthorize) != 0) + if ((flags & tfMPTUnauthorize) != 0u) { auto const mptokenKey = keylet::mptoken(mptIssuanceID, account); auto const sleMpt = view.peek(mptokenKey); @@ -242,7 +246,7 @@ authorizeMPToken( // Issuer wants to unauthorize the holder, unset lsfMPTAuthorized on // their MPToken - if ((flags & tfMPTUnauthorize) != 0) + if ((flags & tfMPTUnauthorize) != 0u) { flagsOut &= ~lsfMPTAuthorized; } diff --git a/src/libxrpl/ledger/helpers/PermissionedDEXHelpers.cpp b/src/libxrpl/ledger/helpers/PermissionedDEXHelpers.cpp index d65462f0cd..456c4e95d6 100644 --- a/src/libxrpl/ledger/helpers/PermissionedDEXHelpers.cpp +++ b/src/libxrpl/ledger/helpers/PermissionedDEXHelpers.cpp @@ -62,7 +62,8 @@ offerInDomain( if (view.rules().enabled(fixSecurity3_1_3)) { - // post-fixSecurity3_1_3: also catches empty sfAdditionalBooks (size == 0) + // post-fixSecurity3_1_3: a valid hybrid offer must have + // sfAdditionalBooks present with exactly 1 entry if (sleOffer->isFlag(lsfHybrid) && (!sleOffer->isFieldPresent(sfAdditionalBooks) || sleOffer->getFieldArray(sfAdditionalBooks).size() != 1)) @@ -74,7 +75,8 @@ offerInDomain( } else { - // pre-fixSecurity3_1_3: only check for missing sfAdditionalBooks + // pre-fixSecurity3_1_3: a valid hybrid offer must have + // sfAdditionalBooks present (size is not checked) if (sleOffer->isFlag(lsfHybrid) && !sleOffer->isFieldPresent(sfAdditionalBooks)) { JLOG(j.error()) << "Hybrid offer " << offerID << " missing AdditionalBooks field"; diff --git a/src/libxrpl/nodestore/backend/MemoryFactory.cpp b/src/libxrpl/nodestore/backend/MemoryFactory.cpp index 2f94783b8b..abf25013ce 100644 --- a/src/libxrpl/nodestore/backend/MemoryFactory.cpp +++ b/src/libxrpl/nodestore/backend/MemoryFactory.cpp @@ -45,7 +45,7 @@ private: public: explicit MemoryFactory(Manager& manager); - std::string + [[nodiscard]] std::string getName() const override; std::unique_ptr @@ -207,7 +207,7 @@ public: { } - int + [[nodiscard]] int fdRequired() const override { return 0; diff --git a/src/libxrpl/nodestore/backend/NuDBFactory.cpp b/src/libxrpl/nodestore/backend/NuDBFactory.cpp index 7fb3aec843..86540016da 100644 --- a/src/libxrpl/nodestore/backend/NuDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/NuDBFactory.cpp @@ -122,7 +122,7 @@ public: return name_; } - std::optional + [[nodiscard]] std::optional getBlockSize() const override { return blockSize_; @@ -364,7 +364,7 @@ public: Throw(ec); } - int + [[nodiscard]] int fdRequired() const override { return 3; @@ -426,7 +426,7 @@ public: manager_.insert(*this); } - std::string + [[nodiscard]] std::string getName() const override { return "NuDB"; diff --git a/src/libxrpl/nodestore/backend/NullFactory.cpp b/src/libxrpl/nodestore/backend/NullFactory.cpp index 94cd71bd11..02e6ca4dda 100644 --- a/src/libxrpl/nodestore/backend/NullFactory.cpp +++ b/src/libxrpl/nodestore/backend/NullFactory.cpp @@ -90,7 +90,7 @@ public: } /** Returns the number of file descriptors the backend expects to need */ - int + [[nodiscard]] int fdRequired() const override { return 0; @@ -112,7 +112,7 @@ public: manager_.insert(*this); } - std::string + [[nodiscard]] std::string getName() const override { return "none"; diff --git a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp index 3e0957edea..86dff9240d 100644 --- a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp @@ -443,7 +443,7 @@ public: } /** Returns the number of file descriptors the backend expects to need */ - int + [[nodiscard]] int fdRequired() const override { return fdRequired_; @@ -465,7 +465,7 @@ public: manager_.insert(*this); } - std::string + [[nodiscard]] std::string getName() const override { return "RocksDB"; diff --git a/src/libxrpl/protocol/Rules.cpp b/src/libxrpl/protocol/Rules.cpp index a09afa96d8..7a8d0144bb 100644 --- a/src/libxrpl/protocol/Rules.cpp +++ b/src/libxrpl/protocol/Rules.cpp @@ -67,13 +67,13 @@ public: set_.insert(amendments.begin(), amendments.end()); } - std::unordered_set> const& + [[nodiscard]] std::unordered_set> const& presets() const { return presets_; } - bool + [[nodiscard]] bool enabled(uint256 const& feature) const { if (presets_.contains(feature)) diff --git a/src/libxrpl/protocol/SecretKey.cpp b/src/libxrpl/protocol/SecretKey.cpp index 01d3c29f9e..19ec3267ae 100644 --- a/src/libxrpl/protocol/SecretKey.cpp +++ b/src/libxrpl/protocol/SecretKey.cpp @@ -123,7 +123,7 @@ private: uint256 root_; std::array generator_{}; - uint256 + [[nodiscard]] uint256 calculateTweak(std::uint32_t seq) const { // We fill the buffer with the generator, the provided sequence diff --git a/src/libxrpl/tx/paths/BookStep.cpp b/src/libxrpl/tx/paths/BookStep.cpp index ceab379301..49a5f48034 100644 --- a/src/libxrpl/tx/paths/BookStep.cpp +++ b/src/libxrpl/tx/paths/BookStep.cpp @@ -118,13 +118,13 @@ private: } public: - Book const& + [[nodiscard]] Book const& book() const { return book_; } - std::optional + [[nodiscard]] std::optional cachedIn() const override { if (!cache_) @@ -132,7 +132,7 @@ public: return EitherAmount(cache_->in); } - std::optional + [[nodiscard]] std::optional cachedOut() const override { if (!cache_) @@ -140,25 +140,25 @@ public: return EitherAmount(cache_->out); } - DebtDirection + [[nodiscard]] DebtDirection debtDirection(ReadView const& sb, StrandDirection dir) const override { return ownerPaysTransferFee_ ? DebtDirection::issues : DebtDirection::redeems; } - std::optional + [[nodiscard]] std::optional bookStepBook() const override { return book_; } - std::pair, DebtDirection> + [[nodiscard]] std::pair, DebtDirection> qualityUpperBound(ReadView const& v, DebtDirection prevStepDir) const override; - std::pair, DebtDirection> + [[nodiscard]] std::pair, DebtDirection> getQualityFunc(ReadView const& v, DebtDirection prevStepDir) const override; - std::uint32_t + [[nodiscard]] std::uint32_t offersUsed() const override; std::pair @@ -179,10 +179,10 @@ public: validFwd(PaymentSandbox& sb, ApplyView& afView, EitherAmount const& in) override; // Check for errors frozen constraints. - TER + [[nodiscard]] TER check(StrandContext const& ctx) const; - bool + [[nodiscard]] bool inactive() const override { return inactive_; @@ -199,7 +199,7 @@ protected: return ostr.str(); } - Rate + [[nodiscard]] Rate rate(ReadView const& view, Asset const& asset, AccountID const& dstAccount) const; private: @@ -215,7 +215,7 @@ private: return !(lhs == rhs); } - bool + [[nodiscard]] bool equal(Step const& rhs) const override; // Iterate through the offers at the best quality in a book. @@ -258,12 +258,12 @@ private: tipOfferQuality(ReadView const& view) const; // If seated then it is either AMM or CLOB quality function, // whichever is a better quality. - std::optional + [[nodiscard]] std::optional tipOfferQualityF(ReadView const& view) const; // Check that takerPays/takerGets can be transferred/traded. // Applies to MPT assets. - bool + [[nodiscard]] bool checkMPTDEX(ReadView const& view, AccountID const& owner) const; friend TDerived; @@ -307,7 +307,7 @@ public: } // A payment can look at offers of any quality - bool + [[nodiscard]] bool checkQualityThreshold(Quality const& quality) const { return true; @@ -315,7 +315,7 @@ public: // A payment doesn't use quality threshold (limitQuality) // since the strand's quality doesn't directly relate to the step's quality. - std::optional + [[nodiscard]] std::optional qualityThreshold(Quality const& lobQuality) const { return lobQuality; @@ -335,7 +335,7 @@ public: return trOut; } - Quality + [[nodiscard]] Quality adjustQualityWithFees( ReadView const& v, Quality const& ofrQ, @@ -361,7 +361,7 @@ public: return composed_quality(q1, ofrQ); } - std::string + [[nodiscard]] std::string logString() const override { return this->logStringImpl("BookPaymentStep"); @@ -455,7 +455,7 @@ public: // Offer crossing can prune the offers it needs to look at with a // quality threshold. - bool + [[nodiscard]] bool checkQualityThreshold(Quality const& quality) const { return !defaultPath_ || quality >= qualityThreshold_; @@ -471,7 +471,7 @@ public: // generates the maximum AMM offer in this case, which matches // the quality threshold. This only applies to single path scenario. // Multi-path AMM offers work the same as LOB offers. - std::optional + [[nodiscard]] std::optional qualityThreshold(Quality const& lobQuality) const { if (this->ammLiquidity_ && !this->ammLiquidity_->multiPath() && @@ -507,7 +507,7 @@ public: : trOut; // then rate = QUALITY_ONE } - Quality + [[nodiscard]] Quality adjustQualityWithFees( ReadView const& v, Quality const& ofrQ, @@ -545,7 +545,7 @@ public: return composed_quality(q1, ofrQ); } - std::string + [[nodiscard]] std::string logString() const override { return this->logStringImpl("BookOfferCrossingStep"); diff --git a/src/libxrpl/tx/paths/DirectStep.cpp b/src/libxrpl/tx/paths/DirectStep.cpp index 1692f50781..a6f74c9c9f 100644 --- a/src/libxrpl/tx/paths/DirectStep.cpp +++ b/src/libxrpl/tx/paths/DirectStep.cpp @@ -70,19 +70,19 @@ protected: // the best available quality. // return: first element is max amount that can flow, // second is the debt direction of the source w.r.t. the dst - std::pair + [[nodiscard]] std::pair maxPaymentFlow(ReadView const& sb) const; // Compute srcQOut and dstQIn when the source redeems. - std::pair + [[nodiscard]] std::pair qualitiesSrcRedeems(ReadView const& sb) const; // Compute srcQOut and dstQIn when the source issues. - std::pair + [[nodiscard]] std::pair qualitiesSrcIssues(ReadView const& sb, DebtDirection prevStepDebtDirection) const; // Returns srcQOut, dstQIn - std::pair + [[nodiscard]] std::pair qualities(ReadView const& sb, DebtDirection srcDebtDir, StrandDirection strandDir) const; private: @@ -101,23 +101,23 @@ private: } public: - AccountID const& + [[nodiscard]] AccountID const& src() const { return src_; } - AccountID const& + [[nodiscard]] AccountID const& dst() const { return dst_; } - Currency const& + [[nodiscard]] Currency const& currency() const { return currency_; } - std::optional + [[nodiscard]] std::optional cachedIn() const override { if (!cache_) @@ -125,7 +125,7 @@ public: return EitherAmount(cache_->in); } - std::optional + [[nodiscard]] std::optional cachedOut() const override { if (!cache_) @@ -133,25 +133,25 @@ public: return EitherAmount(cache_->out); } - std::optional + [[nodiscard]] std::optional directStepSrcAcct() const override { return src_; } - std::optional> + [[nodiscard]] std::optional> directStepAccts() const override { return std::make_pair(src_, dst_); } - DebtDirection + [[nodiscard]] DebtDirection debtDirection(ReadView const& sb, StrandDirection dir) const override; - std::uint32_t + [[nodiscard]] std::uint32_t lineQualityIn(ReadView const& v) const override; - std::pair, DebtDirection> + [[nodiscard]] std::pair, DebtDirection> qualityUpperBound(ReadView const& v, DebtDirection dir) const override; std::pair @@ -173,7 +173,7 @@ public: // Check for error, existing liquidity, and violations of auth/frozen // constraints. - TER + [[nodiscard]] TER check(StrandContext const& ctx) const; void @@ -206,7 +206,7 @@ protected: } private: - bool + [[nodiscard]] bool equal(Step const& rhs) const override { if (auto ds = dynamic_cast(&rhs)) @@ -256,22 +256,22 @@ public: return true; } - std::uint32_t + [[nodiscard]] std::uint32_t quality(ReadView const& sb, QualityDirection qDir) const; // Compute the maximum value that can flow from src->dst at // the best available quality. // return: first element is max amount that can flow, // second is the debt direction w.r.t. the source account - std::pair + [[nodiscard]] std::pair maxFlow(ReadView const& sb, IOUAmount const& desired) const; // Verify the consistency of the step. These checks are specific to // payments and assume that general checks were already performed. - TER + [[nodiscard]] TER check(StrandContext const& ctx, std::shared_ptr const& sleSrc) const; - std::string + [[nodiscard]] std::string logString() const override { return logStringImpl("DirectIPaymentStep"); @@ -321,7 +321,7 @@ public: // the best available quality. // return: first element is max amount that can flow, // second is the debt direction w.r.t the source - std::pair + [[nodiscard]] std::pair maxFlow(ReadView const& sb, IOUAmount const& desired) const; // Verify the consistency of the step. These checks are specific to @@ -329,7 +329,7 @@ public: static TER check(StrandContext const& ctx, std::shared_ptr const& sleSrc); - std::string + [[nodiscard]] std::string logString() const override { return logStringImpl("DirectIOfferCrossingStep"); diff --git a/src/libxrpl/tx/paths/MPTEndpointStep.cpp b/src/libxrpl/tx/paths/MPTEndpointStep.cpp index aa989b27e0..a79df25479 100644 --- a/src/libxrpl/tx/paths/MPTEndpointStep.cpp +++ b/src/libxrpl/tx/paths/MPTEndpointStep.cpp @@ -71,19 +71,19 @@ protected: // the best available quality. // return: first element is max amount that can flow, // second is the debt direction of the source w.r.t. the dst - std::pair + [[nodiscard]] std::pair maxPaymentFlow(ReadView const& sb) const; // Compute srcQOut and dstQIn when the source redeems. - std::pair + [[nodiscard]] std::pair qualitiesSrcRedeems(ReadView const& sb) const; // Compute srcQOut and dstQIn when the source issues. - std::pair + [[nodiscard]] std::pair qualitiesSrcIssues(ReadView const& sb, DebtDirection prevStepDebtDirection) const; // Returns srcQOut, dstQIn - std::pair + [[nodiscard]] std::pair qualities(ReadView const& sb, DebtDirection srcDebtDir, StrandDirection strandDir) const; void @@ -112,23 +112,23 @@ private: } public: - AccountID const& + [[nodiscard]] AccountID const& src() const { return src_; } - AccountID const& + [[nodiscard]] AccountID const& dst() const { return dst_; } - MPTID const& + [[nodiscard]] MPTID const& mptID() const { return mptIssue_.getMptID(); } - std::optional + [[nodiscard]] std::optional cachedIn() const override { if (!cache_) @@ -136,7 +136,7 @@ public: return EitherAmount(cache_->in); } - std::optional + [[nodiscard]] std::optional cachedOut() const override { if (!cache_) @@ -144,25 +144,25 @@ public: return EitherAmount(cache_->out); } - std::optional + [[nodiscard]] std::optional directStepSrcAcct() const override { return src_; } - std::optional> + [[nodiscard]] std::optional> directStepAccts() const override { return std::make_pair(src_, dst_); } - DebtDirection + [[nodiscard]] DebtDirection debtDirection(ReadView const& sb, StrandDirection dir) const override; - std::uint32_t + [[nodiscard]] std::uint32_t lineQualityIn(ReadView const& v) const override; - std::pair, DebtDirection> + [[nodiscard]] std::pair, DebtDirection> qualityUpperBound(ReadView const& v, DebtDirection dir) const override; std::pair @@ -184,7 +184,7 @@ public: // Check for error, existing liquidity, and violations of auth/frozen // constraints. - TER + [[nodiscard]] TER check(StrandContext const& ctx) const; void @@ -217,7 +217,7 @@ protected: } private: - bool + [[nodiscard]] bool equal(Step const& rhs) const override { if (auto ds = dynamic_cast(&rhs)) @@ -263,10 +263,10 @@ public: // Verify the consistency of the step. These checks are specific to // payments and assume that general checks were already performed. - TER + [[nodiscard]] TER check(StrandContext const& ctx, std::shared_ptr const& sleSrc) const; - std::string + [[nodiscard]] std::string logString() const override { return logStringImpl("MPTEndpointPaymentStep"); @@ -314,7 +314,7 @@ public: static TER check(StrandContext const& ctx, std::shared_ptr const& sleSrc); - std::string + [[nodiscard]] std::string logString() const override { return logStringImpl("MPTEndpointOfferCrossingStep"); diff --git a/src/libxrpl/tx/paths/OfferStream.cpp b/src/libxrpl/tx/paths/OfferStream.cpp index 0d003c63f7..c2f2fed25b 100644 --- a/src/libxrpl/tx/paths/OfferStream.cpp +++ b/src/libxrpl/tx/paths/OfferStream.cpp @@ -132,7 +132,7 @@ accountFundsHelper( template template requires ValidTaker -bool +[[nodiscard]] bool TOfferStreamBase::shouldRmSmallIncreasedQOffer() const { // Consider removing the offer if: diff --git a/src/libxrpl/tx/paths/XRPEndpointStep.cpp b/src/libxrpl/tx/paths/XRPEndpointStep.cpp index 6356eb8ded..95228ed158 100644 --- a/src/libxrpl/tx/paths/XRPEndpointStep.cpp +++ b/src/libxrpl/tx/paths/XRPEndpointStep.cpp @@ -45,7 +45,7 @@ private: // for cachedIn and cachedOut and only one will ever be used std::optional cache_; - std::optional + [[nodiscard]] std::optional cached() const { if (!cache_) @@ -59,13 +59,13 @@ private: } public: - AccountID const& + [[nodiscard]] AccountID const& acc() const { return acc_; } - std::optional> + [[nodiscard]] std::optional> directStepAccts() const override { if (isLast_) @@ -73,25 +73,25 @@ public: return std::make_pair(acc_, xrpAccount()); } - std::optional + [[nodiscard]] std::optional cachedIn() const override { return cached(); } - std::optional + [[nodiscard]] std::optional cachedOut() const override { return cached(); } - DebtDirection + [[nodiscard]] DebtDirection debtDirection(ReadView const& sb, StrandDirection dir) const override { return DebtDirection::issues; } - std::pair, DebtDirection> + [[nodiscard]] std::pair, DebtDirection> qualityUpperBound(ReadView const& v, DebtDirection prevStepDir) const override; std::pair @@ -112,7 +112,7 @@ public: validFwd(PaymentSandbox& sb, ApplyView& afView, EitherAmount const& in) override; // Check for errors and violations of frozen constraints. - TER + [[nodiscard]] TER check(StrandContext const& ctx) const; protected: @@ -142,7 +142,7 @@ private: return !(lhs == rhs); } - bool + [[nodiscard]] bool equal(Step const& rhs) const override { if (auto ds = dynamic_cast(&rhs)) @@ -179,7 +179,7 @@ public: ; } - std::string + [[nodiscard]] std::string logString() const override { return logStringImpl("XRPEndpointPaymentStep"); @@ -230,7 +230,7 @@ public: return xrpLiquidImpl(sb, reserveReduction_); } - std::string + [[nodiscard]] std::string logString() const override { return logStringImpl("XRPEndpointOfferCrossingStep"); diff --git a/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp b/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp index 166e42560f..461c4ee207 100644 --- a/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp +++ b/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp @@ -529,7 +529,7 @@ struct FinalizeClaimHelperResult // Helper to check for overall success. If there wasn't overall success the // individual ters can be used to decide what needs to be done. - bool + [[nodiscard]] bool isTesSuccess() const { return (!mainFundsTer || xrpl::isTesSuccess(*mainFundsTer)) && @@ -537,7 +537,7 @@ struct FinalizeClaimHelperResult (!rmSleTer || xrpl::isTesSuccess(*rmSleTer)); } - TER + [[nodiscard]] TER ter() const { if (isTesSuccess()) diff --git a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp index 2d21cebbe3..119f244185 100644 --- a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp +++ b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp @@ -631,7 +631,6 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel) return {tecEXPIRED, true}; } - bool const bOpenLedger = sb.open(); bool crossed = false; if (isTesSuccess(result)) @@ -720,7 +719,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel) stream << " out: " << format_amount(place_offer.out); } - if (result == tecFAILED_PROCESSING && bOpenLedger) + if (result == tecFAILED_PROCESSING && sb.open()) result = telFAILED_PROCESSING; if (!isTesSuccess(result)) diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp index 16f95dd357..36ff1cc2de 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include @@ -36,7 +36,7 @@ namespace xrpl { bool LoanBrokerCoverClawback::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } NotTEC diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp index 36b5cab618..9b43269ec3 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include #include @@ -21,7 +21,7 @@ namespace xrpl { bool LoanBrokerCoverDeposit::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } NotTEC diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp index c8479e941d..7061ec99c3 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include #include -#include #include @@ -26,7 +26,7 @@ namespace xrpl { bool LoanBrokerCoverWithdraw::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } NotTEC diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp index 6f774eaeae..6b1abe45aa 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #include @@ -24,7 +24,7 @@ namespace xrpl { bool LoanBrokerDelete::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } NotTEC diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp index 3322df9fe3..561890abbf 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include @@ -28,7 +28,7 @@ namespace xrpl { bool LoanBrokerSet::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } NotTEC diff --git a/src/libxrpl/tx/transactors/lending/LoanDelete.cpp b/src/libxrpl/tx/transactors/lending/LoanDelete.cpp index 28948a4139..784bef7d78 100644 --- a/src/libxrpl/tx/transactors/lending/LoanDelete.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanDelete.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include // IWYU pragma: keep @@ -14,7 +15,6 @@ #include #include #include -#include #include @@ -23,7 +23,7 @@ namespace xrpl { bool LoanDelete::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } NotTEC diff --git a/src/libxrpl/tx/transactors/lending/LoanManage.cpp b/src/libxrpl/tx/transactors/lending/LoanManage.cpp index 1b87421e71..87afc2d908 100644 --- a/src/libxrpl/tx/transactors/lending/LoanManage.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanManage.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #include #include #include -#include #include #include @@ -33,7 +33,7 @@ namespace xrpl { bool LoanManage::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } std::uint32_t diff --git a/src/libxrpl/tx/transactors/lending/LoanPay.cpp b/src/libxrpl/tx/transactors/lending/LoanPay.cpp index 8360303fd8..c08518a93e 100644 --- a/src/libxrpl/tx/transactors/lending/LoanPay.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanPay.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include @@ -36,7 +36,7 @@ namespace xrpl { bool LoanPay::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } std::uint32_t diff --git a/src/libxrpl/tx/transactors/lending/LoanSet.cpp b/src/libxrpl/tx/transactors/lending/LoanSet.cpp index 1027fdea9f..48a6005c7b 100644 --- a/src/libxrpl/tx/transactors/lending/LoanSet.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanSet.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include @@ -40,7 +40,7 @@ namespace xrpl { bool LoanSet::checkExtraFeatures(PreflightContext const& ctx) { - return checkLendingProtocolDependencies(ctx); + return checkLendingProtocolDependencies(ctx.rules, ctx.tx); } std::uint32_t diff --git a/src/libxrpl/tx/transactors/payment/Payment.cpp b/src/libxrpl/tx/transactors/payment/Payment.cpp index 644d5210c0..8ea79e0840 100644 --- a/src/libxrpl/tx/transactors/payment/Payment.cpp +++ b/src/libxrpl/tx/transactors/payment/Payment.cpp @@ -431,6 +431,7 @@ Payment::doApply() sleDst = std::make_shared(k); sleDst->setAccountID(sfAccount, dstAccountID); sleDst->setFieldU32(sfSequence, view().seq()); + sleDst->setFieldAmount(sfBalance, XRPAmount(beast::zero)); view().insert(sleDst); } diff --git a/src/test/app/FlowMPT_test.cpp b/src/test/app/FlowMPT_test.cpp index eabd239550..a94d48beb4 100644 --- a/src/test/app/FlowMPT_test.cpp +++ b/src/test/app/FlowMPT_test.cpp @@ -1679,18 +1679,18 @@ struct FlowMPT_test : public beast::unit_test::suite int expGwXRP; // whole XRP excluding the fees std::uint8_t expOffersGw; bool lastGwBuyUSD; - std::uint8_t + [[nodiscard]] std::uint8_t expOffersBob() const { return expBobSellUSD == 0 ? 1 : 0; } - std::uint8_t + [[nodiscard]] std::uint8_t expOffersEd() const { // partially crossed if < 100 return expEdBuyUSD < 100 ? 1 : 0; } - std::uint8_t + [[nodiscard]] std::uint8_t expOffersDan() const { return expDanBuyUSD == 0 ? 1 : 0; @@ -1850,7 +1850,7 @@ struct FlowMPT_test : public beast::unit_test::suite int expGwXRP; // whole XRP excluding the fees std::uint8_t expOffersGw; bool lastGwBuyUSD; - std::uint8_t + [[nodiscard]] std::uint8_t expOffersBob() const { // partially crossed if < 100 @@ -1958,7 +1958,7 @@ struct FlowMPT_test : public beast::unit_test::suite int expGwXRP; std::uint8_t expOffersGw; bool lastGwBuyUSD; - std::uint8_t + [[nodiscard]] std::uint8_t expOffersBob() const { return expBobSellUSD > 0 && expBobSellUSD < 100 ? 1 : 0; diff --git a/src/test/app/LedgerReplay_test.cpp b/src/test/app/LedgerReplay_test.cpp index aec0bec592..7766be3545 100644 --- a/src/test/app/LedgerReplay_test.cpp +++ b/src/test/app/LedgerReplay_test.cpp @@ -235,7 +235,7 @@ public: send(std::shared_ptr const& m) override { } - beast::IP::Endpoint + [[nodiscard]] beast::IP::Endpoint getRemoteAddress() const override { return {}; @@ -244,27 +244,27 @@ public: charge(Resource::Charge const& fee, std::string const& context = {}) override { } - id_t + [[nodiscard]] id_t id() const override { return 1234; } - bool + [[nodiscard]] bool cluster() const override { return false; } - bool + [[nodiscard]] bool isHighLatency() const override { return false; } - int + [[nodiscard]] int getScore(bool) const override { return 0; } - PublicKey const& + [[nodiscard]] PublicKey const& getNodePublic() const override { return nodePublicKey_; @@ -274,12 +274,12 @@ public: { return {}; } - bool + [[nodiscard]] bool supportsFeature(ProtocolFeature f) const override { return f == ProtocolFeature::LedgerReplay && ledgerReplayEnabled_; } - std::optional + [[nodiscard]] std::optional publisherListSequence(PublicKey const&) const override { return {}; @@ -288,13 +288,13 @@ public: setPublisherListSequence(PublicKey const&, std::size_t const) override { } - uint256 const& + [[nodiscard]] uint256 const& getClosedLedgerHash() const override { static uint256 const hash{}; return hash; } - bool + [[nodiscard]] bool hasLedger(uint256 const& hash, std::uint32_t seq) const override { return true; @@ -303,7 +303,7 @@ public: ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override { } - bool + [[nodiscard]] bool hasTxSet(uint256 const& hash) const override { return false; @@ -317,7 +317,7 @@ public: { return false; } - bool + [[nodiscard]] bool compressionEnabled() const override { return false; @@ -334,13 +334,13 @@ public: removeTxQueue(uint256 const&) override { } - bool + [[nodiscard]] bool txReduceRelayEnabled() const override { return false; } - std::string const& + [[nodiscard]] std::string const& fingerprint() const override { return fingerprint_; @@ -440,7 +440,7 @@ struct TestPeerSet : public PeerSet } } - std::set const& + [[nodiscard]] std::set const& getPeerIds() const override { static std::set const emptyPeers; diff --git a/src/test/app/LendingHelpers_test.cpp b/src/test/app/LendingHelpers_test.cpp index 1e43c45104..82c80f0158 100644 --- a/src/test/app/LendingHelpers_test.cpp +++ b/src/test/app/LendingHelpers_test.cpp @@ -6,8 +6,8 @@ #include #include +#include #include -#include #include #include diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index 8d919d7dd3..3fe727e368 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +56,6 @@ #include #include #include -#include #include #include @@ -151,7 +151,7 @@ protected: std::string data = {}; // NOLINT(readability-redundant-member-init) std::uint32_t flags = 0; - Number + [[nodiscard]] Number maxCoveredLoanValue(Number const& currentDebt) const { NumberRoundModeGuard const mg(Number::downward); @@ -189,18 +189,18 @@ protected: { } - Keylet + [[nodiscard]] Keylet brokerKeylet() const { return keylet::loanbroker(brokerID); } - Keylet + [[nodiscard]] Keylet vaultKeylet() const { return keylet::vault(vaultID); } - int + [[nodiscard]] int vaultScale(jtx::Env const& env) const { using namespace jtx; diff --git a/src/test/app/PayStrand_test.cpp b/src/test/app/PayStrand_test.cpp index 24efb4b155..161903ee6d 100644 --- a/src/test/app/PayStrand_test.cpp +++ b/src/test/app/PayStrand_test.cpp @@ -117,13 +117,13 @@ class ElementComboIter // some tests) bool const allowCompound_ = false; - bool + [[nodiscard]] bool has(SB s) const { return (state_ & (1 << safe_cast(s))) != 0; } - bool + [[nodiscard]] bool hasAny(std::initializer_list sb) const { for (auto const s : sb) @@ -134,7 +134,7 @@ class ElementComboIter return false; } - size_t + [[nodiscard]] size_t count(std::initializer_list sb) const { size_t result = 0; @@ -152,7 +152,7 @@ public: { } - bool + [[nodiscard]] bool valid() const { return (allowCompound_ || !(has(SB::acc) && hasAny({SB::cur, SB::iss}))) && @@ -263,7 +263,7 @@ struct ExistingElementPool size_t nextAvailCurrency = 0; using ResetState = std::tuple; - ResetState + [[nodiscard]] ResetState getResetState() const { return std::make_tuple(nextAvailAccount, nextAvailCurrency); diff --git a/src/test/app/RCLValidations_test.cpp b/src/test/app/RCLValidations_test.cpp index 164ded6138..14b9979e07 100644 --- a/src/test/app/RCLValidations_test.cpp +++ b/src/test/app/RCLValidations_test.cpp @@ -272,7 +272,7 @@ class RCLValidations_test : public beast::unit_test::suite // due to the 256 ancestry limit BEAST_EXPECT(trie.remove(ledg_258, 3)); trie.insert(ledg_259, 3); - trie.getPreferred(1); + [[maybe_unused]] auto unused1 = trie.getPreferred(1); // trie.dump(std::cout); // 000000[0,1)(T:0,B:5) // |-AB868A..37C9[1,260)(T:3,B:3) @@ -296,7 +296,7 @@ class RCLValidations_test : public beast::unit_test::suite BEAST_EXPECT(trie.remove(RCLValidatedLedger{history[257], env.journal}, 1)); trie.insert(RCLValidatedLedger{history[258], env.journal}, 1); - trie.getPreferred(1); + [[maybe_unused]] auto unused2 = trie.getPreferred(1); // trie.dump(std::cout); // 000000[0,1)(T:0,B:5) // |-AB868A..37C9[1,260)(T:4,B:4) diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index 248c8121f4..844a3cd743 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -3530,9 +3530,18 @@ public: jv.isMember(jss::load_factor_fee_reference) && jv[jss::load_factor_fee_reference] == 256; })); - - BEAST_EXPECT( - !wsc->findMsg(1s, [&](auto const& jv) { return jv[jss::type] == "serverStatus"; })); + // Drain any extra serverStatus messages that may arrive + // asynchronously from the ledger close processing. The drain + // is bounded so the test cannot hang if serverStatus keeps + // arriving (e.g. LoadManager raising/lowering fees). + auto const drainDeadline = std::chrono::steady_clock::now() + 5s; + while (std::chrono::steady_clock::now() < drainDeadline) + { + if (!wsc->findMsg(1s, [&](auto const& jv) { return jv[jss::type] == "serverStatus"; })) + { + break; + } + } auto jv = wsc->invoke("unsubscribe", stream); BEAST_EXPECT(jv[jss::status] == "success"); diff --git a/src/test/app/XChain_test.cpp b/src/test/app/XChain_test.cpp index 852bbbbb8b..3f49ab42bb 100644 --- a/src/test/app/XChain_test.cpp +++ b/src/test/app/XChain_test.cpp @@ -120,19 +120,19 @@ struct SEnv return *this; } - TER + [[nodiscard]] TER ter() const { return env_.ter(); } - STAmount + [[nodiscard]] STAmount balance(jtx::Account const& account) const { return env_.balance(account).value(); } - STAmount + [[nodiscard]] STAmount balance(jtx::Account const& account, Issue const& issue) const { return env_.balance(account, issue).value(); @@ -250,7 +250,7 @@ struct Balance startAmount = env_.balance(account_); } - STAmount + [[nodiscard]] STAmount diff() const { return env_.balance(account_) - startAmount; @@ -303,7 +303,7 @@ struct BalanceTransfer { } - bool + [[nodiscard]] bool payees_received(STAmount const& reward) const { return std::all_of(reward_accounts.begin(), reward_accounts.end(), [&](balance const& b) { @@ -3954,7 +3954,7 @@ private: spend(acct, tx_fee, times); } - bool + [[nodiscard]] bool verify() const { for (auto const& [acct, state] : accounts) @@ -4001,7 +4001,7 @@ private: { } - bool + [[nodiscard]] bool verify() const { return a_.verify() && b_.verify(); @@ -4091,7 +4091,7 @@ private: { } - bool + [[nodiscard]] bool a2b() const { return cr.a2b; @@ -4218,7 +4218,7 @@ private: { } - bool + [[nodiscard]] bool a2b() const { return xfer.a2b; diff --git a/src/test/basics/PerfLog_test.cpp b/src/test/basics/PerfLog_test.cpp index cd00b180e7..9a7d89efce 100644 --- a/src/test/basics/PerfLog_test.cpp +++ b/src/test/basics/PerfLog_test.cpp @@ -58,6 +58,17 @@ class PerfLog_test : public beast::unit_test::suite explicit Fixture(Application& app, beast::Journal j) : app_(app), j_(j) { + // Clean up any stale state from a previous test run. On + // self-hosted CI runners the temp directory persists between + // runs, so the "nasty file" test may have left a regular file + // (or a non-empty directory) at the logDir path. + // + // The error code is intentionally ignored: if the path doesn't + // exist (the common case on a clean runner) remove_all returns + // an error, and that's fine — there's nothing to clean up. + using namespace boost::filesystem; + boost::system::error_code ec; + remove_all(logDir(), ec); } ~Fixture() diff --git a/src/test/basics/hardened_hash_test.cpp b/src/test/basics/hardened_hash_test.cpp index 361a961312..10e9c87309 100644 --- a/src/test/basics/hardened_hash_test.cpp +++ b/src/test/basics/hardened_hash_test.cpp @@ -115,7 +115,7 @@ public: return &m_vec[0]; } - void const* + [[nodiscard]] void const* data() const noexcept { return &m_vec[0]; diff --git a/src/test/beast/beast_Journal_test.cpp b/src/test/beast/beast_Journal_test.cpp index 7a96a1e2aa..f37a740e57 100644 --- a/src/test/beast/beast_Journal_test.cpp +++ b/src/test/beast/beast_Journal_test.cpp @@ -18,7 +18,7 @@ public: { } - int + [[nodiscard]] int count() const { return m_count; diff --git a/src/test/beast/beast_Zero_test.cpp b/src/test/beast/beast_Zero_test.cpp index a509723773..657bea7022 100644 --- a/src/test/beast/beast_Zero_test.cpp +++ b/src/test/beast/beast_Zero_test.cpp @@ -38,7 +38,7 @@ private: { } - int + [[nodiscard]] int signum() const { return value; diff --git a/src/test/consensus/NegativeUNL_test.cpp b/src/test/consensus/NegativeUNL_test.cpp index 220ca5ef12..a3987e8136 100644 --- a/src/test/consensus/NegativeUNL_test.cpp +++ b/src/test/consensus/NegativeUNL_test.cpp @@ -673,7 +673,7 @@ struct NetworkHistory } } - std::shared_ptr + [[nodiscard]] std::shared_ptr lastLedger() const { return history.back(); diff --git a/src/test/consensus/Validations_test.cpp b/src/test/consensus/Validations_test.cpp index 2cb8ae2f6c..edb728af08 100644 --- a/src/test/consensus/Validations_test.cpp +++ b/src/test/consensus/Validations_test.cpp @@ -69,7 +69,7 @@ class Validations_test : public beast::unit_test::suite loadFee_ = fee; } - PeerID + [[nodiscard]] PeerID nodeID() const { return nodeID_; @@ -81,18 +81,18 @@ class Validations_test : public beast::unit_test::suite signIdx_++; } - PeerKey + [[nodiscard]] PeerKey currKey() const { return std::make_pair(nodeID_, signIdx_); } - PeerKey + [[nodiscard]] PeerKey masterKey() const { return std::make_pair(nodeID_, 0); } - NetClock::time_point + [[nodiscard]] NetClock::time_point now() const { return toNetClock(c_); @@ -100,7 +100,7 @@ class Validations_test : public beast::unit_test::suite // Issue a new validation with given sequence number and id and // with signing and seen times offset from the common clock - Validation + [[nodiscard]] Validation validate( Ledger::ID id, Ledger::Seq seq, @@ -122,20 +122,20 @@ class Validations_test : public beast::unit_test::suite return v; } - Validation + [[nodiscard]] Validation validate(Ledger ledger, NetClock::duration signOffset, NetClock::duration seenOffset) const { return validate(ledger.id(), ledger.seq(), signOffset, seenOffset, true); } - Validation + [[nodiscard]] Validation validate(Ledger ledger) const { return validate( ledger.id(), ledger.seq(), NetClock::duration{0}, NetClock::duration{0}, true); } - Validation + [[nodiscard]] Validation partial(Ledger ledger) const { return validate( @@ -171,7 +171,7 @@ class Validations_test : public beast::unit_test::suite { } - NetClock::time_point + [[nodiscard]] NetClock::time_point now() const { return toNetClock(c_); diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index 569a31df60..33ee5aa5ee 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -164,25 +164,25 @@ public: /* bStandalone */ false); } - Config const& + [[nodiscard]] Config const& config() const { return config_; } - std::string + [[nodiscard]] std::string configFile() const { return file().string(); } - bool + [[nodiscard]] bool dataDirExists() const { return boost::filesystem::is_directory(dataDir_); } - bool + [[nodiscard]] bool configFileExists() const { return fileExists(); @@ -254,13 +254,13 @@ public: { } - bool + [[nodiscard]] bool validatorsFileExists() const { return fileExists(); } - std::string + [[nodiscard]] std::string validatorsFile() const { return absolute(file()).string(); @@ -296,7 +296,8 @@ port_wss_admin c.loadFromString(toLoad); BEAST_EXPECT(c.legacy("ssl_verify") == "0"); - expectException([&c] { c.legacy("server"); }); // not a single line + expectException( + [&c] { [[maybe_unused]] auto _ = c.legacy("server"); }); // not a single line // set a legacy value BEAST_EXPECT(c.legacy("not_in_file").empty()); @@ -1423,7 +1424,7 @@ r.ripple.com:51235 BEAST_EXPECT(s.get("not_a_key") == std::nullopt); try { - s.get("a_string"); + [[maybe_unused]] auto _ = s.get("a_string"); fail(); } catch (boost::bad_lexical_cast&) diff --git a/src/test/core/Workers_test.cpp b/src/test/core/Workers_test.cpp index 84ff85f4ec..a5b579e810 100644 --- a/src/test/core/Workers_test.cpp +++ b/src/test/core/Workers_test.cpp @@ -54,13 +54,13 @@ class PerfLogTest : public PerfLog { } - Json::Value + [[nodiscard]] Json::Value countersJson() const override { return Json::Value(); } - Json::Value + [[nodiscard]] Json::Value currentJson() const override { return Json::Value(); diff --git a/src/test/csf/BasicNetwork.h b/src/test/csf/BasicNetwork.h index 63d85c3070..8fb48ca97d 100644 --- a/src/test/csf/BasicNetwork.h +++ b/src/test/csf/BasicNetwork.h @@ -164,7 +164,7 @@ public: /** Return the underlying digraph */ - Digraph const& + [[nodiscard]] Digraph const& graph() const { return links_; diff --git a/src/test/csf/Digraph.h b/src/test/csf/Digraph.h index a5678cc539..b9fa447133 100644 --- a/src/test/csf/Digraph.h +++ b/src/test/csf/Digraph.h @@ -94,7 +94,7 @@ public: @return optional which is std::nullopt if no edge exists */ - std::optional + [[nodiscard]] std::optional edge(Vertex source, Vertex target) const { auto it = graph_.find(source); @@ -113,7 +113,7 @@ public: @param target The target vertex @return true if the source has an out edge to target */ - bool + [[nodiscard]] bool connected(Vertex source, Vertex target) const { return edge(source, target) != std::nullopt; @@ -124,7 +124,7 @@ public: @return A boost transformed range over the vertices with out edges in the graph */ - auto + [[nodiscard]] auto outVertices() const { return boost::adaptors::transform( @@ -136,7 +136,7 @@ public: @param source The source vertex @return A boost transformed range over the target vertices of source. */ - auto + [[nodiscard]] auto outVertices(Vertex source) const { auto transform = [](typename Links::value_type const& link) { return link.first; }; @@ -162,7 +162,7 @@ public: @return A boost transformed range of Edge type for all out edges of source. */ - auto + [[nodiscard]] auto outEdges(Vertex source) const { auto transform = [source](typename Links::value_type const& link) { @@ -181,7 +181,7 @@ public: @param source The source vertex @return The number of outgoing edges from source */ - std::size_t + [[nodiscard]] std::size_t outDegree(Vertex source) const { auto it = graph_.find(source); diff --git a/src/test/csf/Histogram.h b/src/test/csf/Histogram.h index 6eef1b08c1..ad3b9fd49d 100644 --- a/src/test/csf/Histogram.h +++ b/src/test/csf/Histogram.h @@ -37,35 +37,35 @@ public: } /** The number of samples */ - std::size_t + [[nodiscard]] std::size_t size() const { return samples; } /** The number of distinct samples (bins) */ - std::size_t + [[nodiscard]] std::size_t numBins() const { return counts_.size(); } /** Minimum observed value */ - T + [[nodiscard]] T minValue() const { return counts_.empty() ? T{} : counts_.begin()->first; } /** Maximum observed value */ - T + [[nodiscard]] T maxValue() const { return counts_.empty() ? T{} : counts_.rbegin()->first; } /** Histogram average */ - T + [[nodiscard]] T avg() const { T tmp{}; @@ -86,7 +86,7 @@ public: If the percentile falls between two bins, uses the nearest bin. @return The given percentile of the distribution */ - T + [[nodiscard]] T percentile(float p) const { assert(p >= 0 && p <= 1); diff --git a/src/test/csf/Peer.h b/src/test/csf/Peer.h index 5cf2757ab1..f0b903e69e 100644 --- a/src/test/csf/Peer.h +++ b/src/test/csf/Peer.h @@ -87,13 +87,13 @@ struct Peer // Received delay is the time from receiving the message to actually // handling it. template - SimDuration + [[nodiscard]] SimDuration onReceive(M const&) const { return SimDuration{}; } - SimDuration + [[nodiscard]] SimDuration onReceive(Validation const&) const { return recvValidation; @@ -132,7 +132,7 @@ struct Peer { } - NetClock::time_point + [[nodiscard]] NetClock::time_point now() const { return p_.now(); diff --git a/src/test/csf/PeerGroup.h b/src/test/csf/PeerGroup.h index 6503ac62df..8793425534 100644 --- a/src/test/csf/PeerGroup.h +++ b/src/test/csf/PeerGroup.h @@ -56,13 +56,13 @@ public: return peers_.end(); } - const_iterator + [[nodiscard]] const_iterator begin() const { return peers_.begin(); } - const_iterator + [[nodiscard]] const_iterator end() const { return peers_.end(); @@ -87,7 +87,7 @@ public: peers_.end(); } - std::size_t + [[nodiscard]] std::size_t size() const { return peers_.size(); diff --git a/src/test/csf/Scheduler.h b/src/test/csf/Scheduler.h index 82753124d9..d3f4a1c1c3 100644 --- a/src/test/csf/Scheduler.h +++ b/src/test/csf/Scheduler.h @@ -104,7 +104,7 @@ private: ~queue_type(); - bool + [[nodiscard]] bool empty() const; iterator diff --git a/src/test/csf/TrustGraph.h b/src/test/csf/TrustGraph.h index 096104bc15..202d17a6d5 100644 --- a/src/test/csf/TrustGraph.h +++ b/src/test/csf/TrustGraph.h @@ -67,7 +67,7 @@ public: } //< Whether from trusts to - bool + [[nodiscard]] bool trusts(Peer const& from, Peer const& to) const { return graph_.connected(from, to); @@ -79,7 +79,7 @@ public: @return boost transformed range over nodes `a` trusts, i.e. the nodes in its UNL */ - auto + [[nodiscard]] auto trustedPeers(Peer const& a) const { return graph_.outVertices(a); @@ -96,7 +96,7 @@ public: }; //< Return nodes that fail the white-paper no-forking condition - std::vector + [[nodiscard]] std::vector forkablePairs(double quorum) const { // Check the forking condition by looking at intersection @@ -138,7 +138,7 @@ public: /** Check whether this trust graph satisfies the whitepaper no-forking condition */ - bool + [[nodiscard]] bool canFork(double quorum) const { return !forkablePairs(quorum).empty(); diff --git a/src/test/csf/Tx.h b/src/test/csf/Tx.h index 8e8f6ea7e4..daa663af2b 100644 --- a/src/test/csf/Tx.h +++ b/src/test/csf/Tx.h @@ -31,7 +31,7 @@ public: { } - ID const& + [[nodiscard]] ID const& id() const { return id_; @@ -104,14 +104,14 @@ public: { } - bool + [[nodiscard]] bool exists(Tx::ID const txId) const { auto it = txs_.find(Tx{txId}); return it != txs_.end(); } - Tx const* + [[nodiscard]] Tx const* find(Tx::ID const& txId) const { auto it = txs_.find(Tx{txId}); @@ -120,13 +120,13 @@ public: return nullptr; } - TxSetType const& + [[nodiscard]] TxSetType const& txs() const { return txs_; } - ID + [[nodiscard]] ID id() const { return id_; @@ -136,7 +136,7 @@ public: it was in this set and not other. False means it was in the other set and not this */ - std::map + [[nodiscard]] std::map compare(TxSet const& other) const { std::map res; diff --git a/src/test/csf/Validation.h b/src/test/csf/Validation.h index 2adf64196b..df7d1ed265 100644 --- a/src/test/csf/Validation.h +++ b/src/test/csf/Validation.h @@ -64,67 +64,67 @@ public: { } - Ledger::ID + [[nodiscard]] Ledger::ID ledgerID() const { return ledgerID_; } - Ledger::Seq + [[nodiscard]] Ledger::Seq seq() const { return seq_; } - NetClock::time_point + [[nodiscard]] NetClock::time_point signTime() const { return signTime_; } - NetClock::time_point + [[nodiscard]] NetClock::time_point seenTime() const { return seenTime_; } - PeerKey const& + [[nodiscard]] PeerKey const& key() const { return key_; } - PeerID const& + [[nodiscard]] PeerID const& nodeID() const { return nodeID_; } - bool + [[nodiscard]] bool trusted() const { return trusted_; } - bool + [[nodiscard]] bool full() const { return full_; } - std::uint64_t + [[nodiscard]] std::uint64_t cookie() const { return cookie_; } - std::optional + [[nodiscard]] std::optional loadFee() const { return loadFee_; } - Validation const& + [[nodiscard]] Validation const& unwrap() const { // For the xrpld implementation in which RCLValidation wraps @@ -133,7 +133,7 @@ public: return *this; } - auto + [[nodiscard]] auto asTie() const { // trusted is a status set by the receiver, so it is not part of the tie diff --git a/src/test/csf/collectors.h b/src/test/csf/collectors.h index 8da86cc287..9e437eaef9 100644 --- a/src/test/csf/collectors.h +++ b/src/test/csf/collectors.h @@ -226,7 +226,7 @@ struct TxCollector } // Returns the number of txs which were never accepted - std::size_t + [[nodiscard]] std::size_t orphaned() const { return std::count_if( @@ -234,7 +234,7 @@ struct TxCollector } // Returns the number of txs which were never validated - std::size_t + [[nodiscard]] std::size_t unvalidated() const { return std::count_if( @@ -454,7 +454,7 @@ struct LedgerCollector } } - std::size_t + [[nodiscard]] std::size_t unvalidated() const { return std::count_if(ledgers_.begin(), ledgers_.end(), [](auto const& it) { diff --git a/src/test/csf/ledgers.h b/src/test/csf/ledgers.h index 3869fb7bd4..14495f78a9 100644 --- a/src/test/csf/ledgers.h +++ b/src/test/csf/ledgers.h @@ -85,7 +85,7 @@ private: //! of the operators below. std::vector ancestors; - auto + [[nodiscard]] auto asTie() const { return std::tie( @@ -143,56 +143,56 @@ public: { } - ID + [[nodiscard]] ID id() const { return id_; } - Seq + [[nodiscard]] Seq seq() const { return instance_->seq; } - NetClock::duration + [[nodiscard]] NetClock::duration closeTimeResolution() const { return instance_->closeTimeResolution; } - bool + [[nodiscard]] bool closeAgree() const { return instance_->closeTimeAgree; } - NetClock::time_point + [[nodiscard]] NetClock::time_point closeTime() const { return instance_->closeTime; } - NetClock::time_point + [[nodiscard]] NetClock::time_point parentCloseTime() const { return instance_->parentCloseTime; } - ID + [[nodiscard]] ID parentID() const { return instance_->parentID; } - TxSetType const& + [[nodiscard]] TxSetType const& txs() const { return instance_->txs; } /** Determine whether ancestor is really an ancestor of this ledger */ - bool + [[nodiscard]] bool isAncestor(Ledger const& ancestor) const; /** Return the id of the ancestor with the given seq (if exists/known) @@ -205,7 +205,7 @@ public: friend Ledger::Seq mismatch(Ledger const& a, Ledger const& o); - Json::Value + [[nodiscard]] Json::Value getJson() const; friend bool @@ -232,14 +232,14 @@ class LedgerOracle InstanceMap instances_; // ID for the next unique ledger - Ledger::ID + [[nodiscard]] Ledger::ID nextID() const; public: LedgerOracle(); /** Find the ledger with the given ID */ - std::optional + [[nodiscard]] std::optional lookup(Ledger::ID const& id) const; /** Accept the given txs and generate a new ledger diff --git a/src/test/csf/submitters.h b/src/test/csf/submitters.h index be45b4ea2a..a5c494beb0 100644 --- a/src/test/csf/submitters.h +++ b/src/test/csf/submitters.h @@ -18,7 +18,7 @@ struct Rate std::size_t count; SimDuration duration; - double + [[nodiscard]] double inv() const { return duration.count() / double(count); diff --git a/src/test/jtx/AMM.h b/src/test/jtx/AMM.h index faad982bcc..2bd3da8cf5 100644 --- a/src/test/jtx/AMM.h +++ b/src/test/jtx/AMM.h @@ -31,12 +31,12 @@ public: LPToken(STAmount tokens) : tokens_(tokens), asset_(tokens.asset()) { } - STAmount + [[nodiscard]] STAmount tokens() const { return STAmount{asset_, tokens_}; } - STAmount + [[nodiscard]] STAmount tokens(Issue const& ammIssue) const { return STAmount{ammIssue, tokens_}; @@ -170,7 +170,7 @@ public: /** Send amm_info RPC command */ - Json::Value + [[nodiscard]] Json::Value ammRpcInfo( std::optional const& account = std::nullopt, std::optional const& ledgerIndex = std::nullopt, @@ -191,13 +191,13 @@ public: /** Get AMM balances for the token pair. */ - std::tuple + [[nodiscard]] std::tuple balances( Asset const& asset1, Asset const& asset2, std::optional const& account = std::nullopt) const; - std::tuple + [[nodiscard]] std::tuple balances(std::optional const& account = std::nullopt) const { return balances(asset1_.asset(), asset2_.asset(), account); @@ -340,25 +340,25 @@ public: void clawback(ClawbackArg const& arg); - AccountID const& + [[nodiscard]] AccountID const& ammAccount() const { return ammAccount_; } - Issue + [[nodiscard]] Issue lptIssue() const { return lptIssue_; } - IOUAmount + [[nodiscard]] IOUAmount tokens() const { return initialLPTokens_; } - IOUAmount + [[nodiscard]] IOUAmount getLPTokensBalance(std::optional const& account = std::nullopt) const; friend std::ostream& @@ -393,7 +393,7 @@ public: doClose_ = close; } - uint256 + [[nodiscard]] uint256 ammID() const { return ammID_; diff --git a/src/test/jtx/AbstractClient.h b/src/test/jtx/AbstractClient.h index 2002b3a7d8..eb46788c34 100644 --- a/src/test/jtx/AbstractClient.h +++ b/src/test/jtx/AbstractClient.h @@ -33,7 +33,7 @@ public: invoke(std::string const& cmd, Json::Value const& params = {}) = 0; /// Get RPC 1.0 or RPC 2.0 - virtual unsigned + [[nodiscard]] virtual unsigned version() const = 0; }; diff --git a/src/test/jtx/Account.h b/src/test/jtx/Account.h index 1e39f5a546..c702bcffec 100644 --- a/src/test/jtx/Account.h +++ b/src/test/jtx/Account.h @@ -57,21 +57,21 @@ public: Account(AcctStringType stringType, std::string base58SeedStr); /** Return the name */ - std::string const& + [[nodiscard]] std::string const& name() const { return name_; } /** Return the public key. */ - PublicKey const& + [[nodiscard]] PublicKey const& pk() const { return pk_; } /** Return the secret key. */ - SecretKey const& + [[nodiscard]] SecretKey const& sk() const { return sk_; @@ -81,14 +81,14 @@ public: The Account ID is the uint160 hash of the public key. */ - AccountID + [[nodiscard]] AccountID id() const { return id_; } /** Returns the human readable public key. */ - std::string const& + [[nodiscard]] std::string const& human() const { return human_; diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 75c0195f40..3b55e6ef09 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -264,7 +264,7 @@ public: return *bundle_.app; } - Application const& + [[nodiscard]] Application const& app() const { return *bundle_.app; @@ -331,7 +331,7 @@ public: will not be visible. */ - std::shared_ptr + [[nodiscard]] std::shared_ptr current() const { return app().getOpenLedger().current(); @@ -479,7 +479,7 @@ public: } // get rpc retries - unsigned + [[nodiscard]] unsigned retries() const { return retries_; @@ -491,55 +491,55 @@ public: /** Returns the Account given the AccountID. */ /** @{ */ - Account const& + [[nodiscard]] Account const& lookup(AccountID const& id) const; - Account const& + [[nodiscard]] Account const& lookup(std::string const& base58ID) const; /** @} */ /** Returns the XRP balance on an account. Returns 0 if the account does not exist. */ - PrettyAmount + [[nodiscard]] PrettyAmount balance(Account const& account) const; /** Returns the next sequence number on account. Exceptions: Throws if the account does not exist */ - std::uint32_t + [[nodiscard]] std::uint32_t seq(Account const& account) const; /** Return the balance on an account. Returns 0 if the trust line does not exist. */ // VFALCO NOTE This should return a unit-less amount - PrettyAmount + [[nodiscard]] PrettyAmount balance(Account const& account, Asset const& asset) const; /** Returns the IOU limit on an account. Returns 0 if the trust line does not exist. */ - PrettyAmount + [[nodiscard]] PrettyAmount limit(Account const& account, Issue const& issue) const; /** Return the number of objects owned by an account. * Returns 0 if the account does not exist. */ - std::uint32_t + [[nodiscard]] std::uint32_t ownerCount(Account const& account) const; /** Return an account root. @return empty if the account does not exist. */ - std::shared_ptr + [[nodiscard]] std::shared_ptr le(Account const& account) const; /** Return a ledger entry. @return empty if the ledger entry does not exist */ - std::shared_ptr + [[nodiscard]] std::shared_ptr le(Keylet const& k) const; /** Create a JTx from parameters. */ @@ -653,7 +653,7 @@ public: /** @} */ /** Return the TER for the last JTx. */ - TER + [[nodiscard]] TER ter() const { return ter_; @@ -684,7 +684,7 @@ public: @note Only necessary for JTx submitted with via sign-and-submit method. */ - std::shared_ptr + [[nodiscard]] std::shared_ptr tx() const; void @@ -693,7 +693,7 @@ public: void disableFeature(uint256 const feature); - bool + [[nodiscard]] bool enabled(uint256 feature) const { return current()->rules().enabled(feature); diff --git a/src/test/jtx/JTx.h b/src/test/jtx/JTx.h index a4db523ff5..4693c4e1a7 100644 --- a/src/test/jtx/JTx.h +++ b/src/test/jtx/JTx.h @@ -78,7 +78,7 @@ struct JTx } template - Prop const* + [[nodiscard]] Prop const* get() const { for (auto& prop : props_.list) diff --git a/src/test/jtx/ManualTimeKeeper.h b/src/test/jtx/ManualTimeKeeper.h index 1fd94858d6..0e9da76b52 100644 --- a/src/test/jtx/ManualTimeKeeper.h +++ b/src/test/jtx/ManualTimeKeeper.h @@ -14,7 +14,7 @@ private: public: ManualTimeKeeper() = default; - time_point + [[nodiscard]] time_point now() const override { return now_.load(); diff --git a/src/test/jtx/Oracle.h b/src/test/jtx/Oracle.h index 42376b3599..c70bce623f 100644 --- a/src/test/jtx/Oracle.h +++ b/src/test/jtx/Oracle.h @@ -126,7 +126,7 @@ public: std::optional const& trim = std::nullopt, std::optional const& timeThreshold = std::nullopt); - std::uint32_t + [[nodiscard]] std::uint32_t documentID() const { return documentID_; @@ -154,7 +154,7 @@ public: std::optional const& documentID, std::optional const& index = std::nullopt); - Json::Value + [[nodiscard]] Json::Value ledgerEntry(std::optional const& index = std::nullopt) const { return Oracle::ledgerEntry(env_, owner_, documentID_, index); diff --git a/src/test/jtx/PathSet.h b/src/test/jtx/PathSet.h index 4db3b7d62e..fc739861cb 100644 --- a/src/test/jtx/PathSet.h +++ b/src/test/jtx/PathSet.h @@ -88,7 +88,7 @@ public: push_back(jtx::Account const& acc); Path& push_back(STPathElement const& pe); - Json::Value + [[nodiscard]] Json::Value json() const; private: @@ -166,7 +166,7 @@ public: { addHelper(std::forward(first), std::forward(rest)...); } - Json::Value + [[nodiscard]] Json::Value json() const { Json::Value v; diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index 70692d1675..e3119f4c71 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -46,7 +46,7 @@ public: virtual ~JTxField() = default; - virtual OV + [[nodiscard]] virtual OV value() const = 0; virtual void @@ -94,7 +94,7 @@ public: { } - OV + [[nodiscard]] OV value() const override { return value_.time_since_epoch().count(); @@ -116,7 +116,7 @@ public: { } - OV + [[nodiscard]] OV value() const override { return to_string(value_); @@ -138,7 +138,7 @@ public: { } - OV + [[nodiscard]] OV value() const override { return toBase58(value_); @@ -160,7 +160,7 @@ public: { } - OV + [[nodiscard]] OV value() const override { return value_.getJson(JsonOptions::none); @@ -202,7 +202,7 @@ protected: public: using JTxField::JTxField; - OV + [[nodiscard]] OV value() const override { return value_.value(); diff --git a/src/test/jtx/amount.h b/src/test/jtx/amount.h index 122af2faa1..4e06392948 100644 --- a/src/test/jtx/amount.h +++ b/src/test/jtx/amount.h @@ -103,25 +103,25 @@ public: { } - std::string const& + [[nodiscard]] std::string const& name() const { return name_; } - STAmount const& + [[nodiscard]] STAmount const& value() const { return amount_; } - Number + [[nodiscard]] Number number() const { return amount_; } - int + [[nodiscard]] int signum() const { return amount_.signum(); @@ -172,7 +172,7 @@ public: { } - Asset const& + [[nodiscard]] Asset const& raw() const { return asset_; @@ -209,20 +209,20 @@ public: return {asset_}; } - bool + [[nodiscard]] bool integral() const { return asset_.integral(); } - bool + [[nodiscard]] bool native() const { return asset_.native(); } template - bool + [[nodiscard]] bool holds() const { return asset_.holds(); @@ -390,17 +390,17 @@ public: { } - Issue + [[nodiscard]] Issue issue() const { return {currency, account.id()}; } - Asset + [[nodiscard]] Asset asset() const { return issue(); } - bool + [[nodiscard]] bool integral() const { return issue().integral(); @@ -488,7 +488,7 @@ public: { } - xrpl::MPTID const& + [[nodiscard]] xrpl::MPTID const& mpt() const { return issuanceID; @@ -496,12 +496,12 @@ public: /** Explicit conversion to MPTIssue or asset. */ - xrpl::MPTIssue + [[nodiscard]] xrpl::MPTIssue mptIssue() const { return MPTIssue{issuanceID}; } - Asset + [[nodiscard]] Asset asset() const { return mptIssue(); diff --git a/src/test/jtx/basic_prop.h b/src/test/jtx/basic_prop.h index d2b4805651..16e1d8cd6d 100644 --- a/src/test/jtx/basic_prop.h +++ b/src/test/jtx/basic_prop.h @@ -7,7 +7,7 @@ namespace xrpl::test::jtx { struct basic_prop { virtual ~basic_prop() = default; - virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr clone() const = 0; virtual bool assignable(basic_prop const*) const = 0; @@ -23,7 +23,7 @@ struct prop_type : basic_prop { } - std::unique_ptr + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique>(t); diff --git a/src/test/jtx/batch.h b/src/test/jtx/batch.h index 90a7bef8cc..846adc9adc 100644 --- a/src/test/jtx/batch.h +++ b/src/test/jtx/batch.h @@ -68,7 +68,7 @@ public: txn_.removeMember(key); } - Json::Value const& + [[nodiscard]] Json::Value const& getTxn() const { return txn_; diff --git a/src/test/jtx/deposit.h b/src/test/jtx/deposit.h index d74db770c7..1d032bf1e0 100644 --- a/src/test/jtx/deposit.h +++ b/src/test/jtx/deposit.h @@ -22,7 +22,7 @@ struct AuthorizeCredentials auto operator<=>(AuthorizeCredentials const&) const = default; - Json::Value + [[nodiscard]] Json::Value toJson() const { Json::Value jv; @@ -32,7 +32,7 @@ struct AuthorizeCredentials } // "ledger_entry" uses a different naming convention - Json::Value + [[nodiscard]] Json::Value toLEJson() const { Json::Value jv; diff --git a/src/test/jtx/impl/JSONRPCClient.cpp b/src/test/jtx/impl/JSONRPCClient.cpp index c44371c13e..5b00836089 100644 --- a/src/test/jtx/impl/JSONRPCClient.cpp +++ b/src/test/jtx/impl/JSONRPCClient.cpp @@ -145,7 +145,7 @@ public: return jv; } - unsigned + [[nodiscard]] unsigned version() const override { return rpc_version_; diff --git a/src/test/jtx/impl/Oracle.cpp b/src/test/jtx/impl/Oracle.cpp index 7e49cdcd3d..d9cace5624 100644 --- a/src/test/jtx/impl/Oracle.cpp +++ b/src/test/jtx/impl/Oracle.cpp @@ -409,8 +409,8 @@ validDocumentID(AnyValue const& v) { Json::Value jv; toJson(jv, v); - jv.asUInt(); - jv.isNumeric(); + [[maybe_unused]] auto unused1 = jv.asUInt(); + [[maybe_unused]] auto unused2 = jv.isNumeric(); return true; } catch (...) diff --git a/src/test/jtx/impl/WSClient.cpp b/src/test/jtx/impl/WSClient.cpp index 617e2b8881..a7db5e4302 100644 --- a/src/test/jtx/impl/WSClient.cpp +++ b/src/test/jtx/impl/WSClient.cpp @@ -281,7 +281,7 @@ public: return std::move(m->jv); } - unsigned + [[nodiscard]] unsigned version() const override { return rpc_version_; diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index eb08de5caa..77597d795d 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -229,12 +229,12 @@ public: [[nodiscard]] bool isTransferFeePresent() const; - Account const& + [[nodiscard]] Account const& issuer() const { return issuer_; } - Account const& + [[nodiscard]] Account const& holder(std::string const& h) const; void @@ -251,10 +251,10 @@ public: std::int64_t amount, std::optional err = std::nullopt); - PrettyAmount + [[nodiscard]] PrettyAmount mpt(std::int64_t amount) const; - MPTID const& + [[nodiscard]] MPTID const& issuanceID() const { if (!env_.test.BEAST_EXPECT(id_)) @@ -262,7 +262,7 @@ public: return *id_; // NOLINT(bugprone-unchecked-optional-access) } - std::int64_t + [[nodiscard]] std::int64_t getBalance(Account const& account) const; MPT @@ -307,7 +307,7 @@ private: static std::unordered_map makeHolders(std::vector const& holders); - std::uint32_t + [[nodiscard]] std::uint32_t getFlags(std::optional const& holder) const; }; diff --git a/src/test/jtx/vault.h b/src/test/jtx/vault.h index bbd8c129cc..f8883630c4 100644 --- a/src/test/jtx/vault.h +++ b/src/test/jtx/vault.h @@ -28,7 +28,7 @@ struct Vault }; /** Return a VaultCreate transaction and the Vault's expected keylet. */ - std::tuple + [[nodiscard]] std::tuple create(CreateArgs const& args) const; struct SetArgs diff --git a/src/test/jtx/xchain_bridge.h b/src/test/jtx/xchain_bridge.h index bb01bf17ba..7b5b3db0c4 100644 --- a/src/test/jtx/xchain_bridge.h +++ b/src/test/jtx/xchain_bridge.h @@ -217,7 +217,7 @@ struct XChainBridgeObjects fromIdx); } - Json::Value + [[nodiscard]] Json::Value create_bridge( Account const& acc, Json::Value const& bridge = Json::nullValue, diff --git a/src/test/overlay/reduce_relay_test.cpp b/src/test/overlay/reduce_relay_test.cpp index 842511b860..21f3482ab5 100644 --- a/src/test/overlay/reduce_relay_test.cpp +++ b/src/test/overlay/reduce_relay_test.cpp @@ -91,7 +91,7 @@ public: send(std::shared_ptr const& m) override { } - beast::IP::Endpoint + [[nodiscard]] beast::IP::Endpoint getRemoteAddress() const override { return {}; @@ -100,22 +100,22 @@ public: charge(Resource::Charge const& fee, std::string const& context = {}) override { } - bool + [[nodiscard]] bool cluster() const override { return false; } - bool + [[nodiscard]] bool isHighLatency() const override { return false; } - int + [[nodiscard]] int getScore(bool) const override { return 0; } - PublicKey const& + [[nodiscard]] PublicKey const& getNodePublic() const override { return nodePublicKey_; @@ -125,12 +125,12 @@ public: { return {}; } - bool + [[nodiscard]] bool supportsFeature(ProtocolFeature f) const override { return false; } - std::optional + [[nodiscard]] std::optional publisherListSequence(PublicKey const&) const override { return {}; @@ -139,13 +139,13 @@ public: setPublisherListSequence(PublicKey const&, std::size_t const) override { } - uint256 const& + [[nodiscard]] uint256 const& getClosedLedgerHash() const override { static uint256 const hash{}; return hash; } - bool + [[nodiscard]] bool hasLedger(uint256 const& hash, std::uint32_t seq) const override { return false; @@ -154,7 +154,7 @@ public: ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const override { } - bool + [[nodiscard]] bool hasTxSet(uint256 const& hash) const override { return false; @@ -168,12 +168,12 @@ public: { return false; } - bool + [[nodiscard]] bool compressionEnabled() const override { return false; } - bool + [[nodiscard]] bool txReduceRelayEnabled() const override { return false; @@ -421,7 +421,7 @@ public: return message_; } - std::uint16_t + [[nodiscard]] std::uint16_t id() const { return id_; diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index 5d145fb6b1..02c9312732 100644 --- a/src/test/overlay/short_read_test.cpp +++ b/src/test/overlay/short_read_test.cpp @@ -424,7 +424,7 @@ private: wait(); } - endpoint_type const& + [[nodiscard]] endpoint_type const& endpoint() const { return endpoint_; diff --git a/src/test/rpc/DeliveredAmount_test.cpp b/src/test/rpc/DeliveredAmount_test.cpp index 133c5771b7..abbeb5c81a 100644 --- a/src/test/rpc/DeliveredAmount_test.cpp +++ b/src/test/rpc/DeliveredAmount_test.cpp @@ -91,7 +91,7 @@ public: // After all the txns are checked, all the `numExpected` variables should be // zero. The `checkTxn` function decrements these variables. - bool + [[nodiscard]] bool checkExpectedCounters() const { return (numExpectedAvailable_ == 0) && (numExpectedNotSet_ == 0) && diff --git a/src/test/shamap/FetchPack_test.cpp b/src/test/shamap/FetchPack_test.cpp index fd44423ba8..cd3bc99fa8 100644 --- a/src/test/shamap/FetchPack_test.cpp +++ b/src/test/shamap/FetchPack_test.cpp @@ -64,7 +64,7 @@ public: { } - std::optional + [[nodiscard]] std::optional getNode(SHAMapHash const& nodeHash) const override { Map::iterator const it = mMap.find(nodeHash); diff --git a/src/test/shamap/common.h b/src/test/shamap/common.h index cd942076b8..08910b5c5d 100644 --- a/src/test/shamap/common.h +++ b/src/test/shamap/common.h @@ -45,7 +45,7 @@ public: return *db_; } - NodeStore::Database const& + [[nodiscard]] NodeStore::Database const& db() const override { return *db_; diff --git a/src/test/unit_test/FileDirGuard.h b/src/test/unit_test/FileDirGuard.h index 9d4b94d8c5..20520eac3d 100644 --- a/src/test/unit_test/FileDirGuard.h +++ b/src/test/unit_test/FileDirGuard.h @@ -81,7 +81,7 @@ public: }; } - path const& + [[nodiscard]] path const& subdir() const { return subDir_; @@ -147,13 +147,13 @@ public: }; } - path const& + [[nodiscard]] path const& file() const { return file_; } - bool + [[nodiscard]] bool fileExists() const { return boost::filesystem::exists(file_); diff --git a/src/test/unit_test/SuiteJournal.h b/src/test/unit_test/SuiteJournal.h index c3820b8709..f4cbb5baa0 100644 --- a/src/test/unit_test/SuiteJournal.h +++ b/src/test/unit_test/SuiteJournal.h @@ -21,7 +21,7 @@ public: } // For unit testing, always generate logging text. - bool + [[nodiscard]] bool active(beast::severities::Severity level) const override { return true; diff --git a/src/test/unit_test/multi_runner.h b/src/test/unit_test/multi_runner.h index 86d4699017..0f675955de 100644 --- a/src/test/unit_test/multi_runner.h +++ b/src/test/unit_test/multi_runner.h @@ -175,13 +175,13 @@ public: void print_results(S& s); - bool + [[nodiscard]] bool any_failed() const; - std::size_t + [[nodiscard]] std::size_t tests() const; - std::size_t + [[nodiscard]] std::size_t suites() const; void @@ -214,13 +214,13 @@ public: multi_runner_parent(); ~multi_runner_parent(); - bool + [[nodiscard]] bool any_failed() const; - std::size_t + [[nodiscard]] std::size_t tests() const; - std::size_t + [[nodiscard]] std::size_t suites() const; void @@ -254,10 +254,10 @@ public: multi_runner_child(std::size_t num_jobs, bool quiet, bool print_log); ~multi_runner_child() override; - std::size_t + [[nodiscard]] std::size_t tests() const; - std::size_t + [[nodiscard]] std::size_t suites() const; void diff --git a/src/tests/libxrpl/json/Value.cpp b/src/tests/libxrpl/json/Value.cpp index a53d81b5e1..2790f0e963 100644 --- a/src/tests/libxrpl/json/Value.cpp +++ b/src/tests/libxrpl/json/Value.cpp @@ -660,8 +660,8 @@ TEST(json_value, edge_cases) { Json::Value intString{std::to_string(overflow)}; - EXPECT_THROW(intString.asUInt(), beast::BadLexicalCast); - EXPECT_THROW(intString.asAbsUInt(), Json::error); + EXPECT_THROW([&] { return intString.asUInt(); }(), beast::BadLexicalCast); + EXPECT_THROW([&] { return intString.asAbsUInt(); }(), Json::error); intString = "4294967295"; EXPECT_EQ(intString.asUInt(), 4294967295u); @@ -672,17 +672,17 @@ TEST(json_value, edge_cases) EXPECT_EQ(intString.asAbsUInt(), 0); intString = "-1"; - EXPECT_THROW(intString.asUInt(), beast::BadLexicalCast); + EXPECT_THROW([&] { return intString.asUInt(); }(), beast::BadLexicalCast); EXPECT_EQ(intString.asAbsUInt(), 1); intString = "-4294967295"; EXPECT_EQ(intString.asAbsUInt(), 4294967295); intString = "-4294967296"; - EXPECT_THROW(intString.asAbsUInt(), Json::error); + EXPECT_THROW([&] { return intString.asAbsUInt(); }(), Json::error); intString = "2147483648"; - EXPECT_THROW(intString.asInt(), beast::BadLexicalCast); + EXPECT_THROW([&] { return intString.asInt(); }(), beast::BadLexicalCast); EXPECT_EQ(intString.asAbsUInt(), 2147483648); intString = "2147483647"; @@ -694,14 +694,14 @@ TEST(json_value, edge_cases) EXPECT_EQ(intString.asAbsUInt(), 2147483648LL); intString = "-2147483649"; - EXPECT_THROW(intString.asInt(), beast::BadLexicalCast); + EXPECT_THROW([&] { return intString.asInt(); }(), beast::BadLexicalCast); EXPECT_EQ(intString.asAbsUInt(), 2147483649); } { Json::Value intReal{4294967297.0}; - EXPECT_THROW(intReal.asUInt(), Json::error); - EXPECT_THROW(intReal.asAbsUInt(), Json::error); + EXPECT_THROW([&] { return intReal.asUInt(); }(), Json::error); + EXPECT_THROW([&] { return intReal.asAbsUInt(); }(), Json::error); intReal = 4294967295.0; EXPECT_EQ(intReal.asUInt(), 4294967295u); @@ -712,17 +712,17 @@ TEST(json_value, edge_cases) EXPECT_EQ(intReal.asAbsUInt(), 0); intReal = -1.0; - EXPECT_THROW(intReal.asUInt(), Json::error); + EXPECT_THROW([&] { return intReal.asUInt(); }(), Json::error); EXPECT_EQ(intReal.asAbsUInt(), 1); intReal = -4294967295.0; EXPECT_EQ(intReal.asAbsUInt(), 4294967295); intReal = -4294967296.0; - EXPECT_THROW(intReal.asAbsUInt(), Json::error); + EXPECT_THROW([&] { return intReal.asAbsUInt(); }(), Json::error); intReal = 2147483648.0; - EXPECT_THROW(intReal.asInt(), Json::error); + EXPECT_THROW([&] { return intReal.asInt(); }(), Json::error); EXPECT_EQ(intReal.asAbsUInt(), 2147483648); intReal = 2147483647.0; @@ -734,7 +734,7 @@ TEST(json_value, edge_cases) EXPECT_EQ(intReal.asAbsUInt(), 2147483648LL); intReal = -2147483649.0; - EXPECT_THROW(intReal.asInt(), Json::error); + EXPECT_THROW([&] { return intReal.asInt(); }(), Json::error); EXPECT_EQ(intReal.asAbsUInt(), 2147483649); } } @@ -891,7 +891,7 @@ TEST(json_value, conversions) // val.asCString() should trigger an assertion failure EXPECT_EQ(val.asString(), "-1234"); EXPECT_EQ(val.asInt(), -1234); - EXPECT_THROW(val.asUInt(), Json::error); + EXPECT_THROW([&] { return val.asUInt(); }(), Json::error); EXPECT_EQ(val.asAbsUInt(), 1234u); EXPECT_EQ(val.asDouble(), -1234.0); EXPECT_TRUE(val.asBool()); @@ -956,7 +956,7 @@ TEST(json_value, conversions) EXPECT_EQ(val.asInt(), 54321); EXPECT_EQ(val.asUInt(), 54321u); EXPECT_EQ(val.asAbsUInt(), 54321); - EXPECT_THROW(val.asDouble(), Json::error); + EXPECT_THROW([&] { return val.asDouble(); }(), Json::error); EXPECT_TRUE(val.asBool()); EXPECT_FALSE(val.isConvertibleTo(Json::nullValue)); @@ -974,10 +974,10 @@ TEST(json_value, conversions) EXPECT_TRUE(val.isString()); EXPECT_EQ(val.asCString(), nullptr); EXPECT_EQ(val.asString(), ""); - EXPECT_THROW(val.asInt(), std::exception); - EXPECT_THROW(val.asUInt(), std::exception); - EXPECT_THROW(val.asAbsUInt(), std::exception); - EXPECT_THROW(val.asDouble(), std::exception); + EXPECT_THROW([&] { return val.asInt(); }(), std::exception); + EXPECT_THROW([&] { return val.asUInt(); }(), std::exception); + EXPECT_THROW([&] { return val.asAbsUInt(); }(), std::exception); + EXPECT_THROW([&] { return val.asDouble(); }(), std::exception); EXPECT_TRUE(val.asBool() == false); EXPECT_TRUE(val.isConvertibleTo(Json::nullValue)); @@ -1036,11 +1036,11 @@ TEST(json_value, conversions) Json::Value const val(Json::arrayValue); EXPECT_TRUE(val.isArray()); // val.asCString should trigger an assertion failure - EXPECT_THROW(val.asString(), Json::error); - EXPECT_THROW(val.asInt(), Json::error); - EXPECT_THROW(val.asUInt(), Json::error); - EXPECT_THROW(val.asAbsUInt(), Json::error); - EXPECT_THROW(val.asDouble(), Json::error); + EXPECT_THROW([&] { return val.asString(); }(), Json::error); + EXPECT_THROW([&] { return val.asInt(); }(), Json::error); + EXPECT_THROW([&] { return val.asUInt(); }(), Json::error); + EXPECT_THROW([&] { return val.asAbsUInt(); }(), Json::error); + EXPECT_THROW([&] { return val.asDouble(); }(), Json::error); EXPECT_FALSE(val.asBool()); // empty or not EXPECT_TRUE(val.isConvertibleTo(Json::nullValue)); @@ -1057,11 +1057,11 @@ TEST(json_value, conversions) Json::Value const val(Json::objectValue); EXPECT_TRUE(val.isObject()); // val.asCString should trigger an assertion failure - EXPECT_THROW(val.asString(), Json::error); - EXPECT_THROW(val.asInt(), Json::error); - EXPECT_THROW(val.asUInt(), Json::error); - EXPECT_THROW(val.asAbsUInt(), Json::error); - EXPECT_THROW(val.asDouble(), Json::error); + EXPECT_THROW([&] { return val.asString(); }(), Json::error); + EXPECT_THROW([&] { return val.asInt(); }(), Json::error); + EXPECT_THROW([&] { return val.asUInt(); }(), Json::error); + EXPECT_THROW([&] { return val.asAbsUInt(); }(), Json::error); + EXPECT_THROW([&] { return val.asDouble(); }(), Json::error); EXPECT_FALSE(val.asBool()); // empty or not EXPECT_TRUE(val.isConvertibleTo(Json::nullValue)); diff --git a/src/tests/libxrpl/net/HTTPClient.cpp b/src/tests/libxrpl/net/HTTPClient.cpp index d3dfd32361..01de5ff999 100644 --- a/src/tests/libxrpl/net/HTTPClient.cpp +++ b/src/tests/libxrpl/net/HTTPClient.cpp @@ -79,7 +79,7 @@ public: return ioc_; } - unsigned short + [[nodiscard]] unsigned short port() const { return port_; @@ -110,7 +110,7 @@ public: acceptor_.close(); } - bool + [[nodiscard]] bool finished() const { return finished_; diff --git a/src/xrpld/app/consensus/RCLCxLedger.h b/src/xrpld/app/consensus/RCLCxLedger.h index 09111ebdb6..3c5175a04d 100644 --- a/src/xrpld/app/consensus/RCLCxLedger.h +++ b/src/xrpld/app/consensus/RCLCxLedger.h @@ -37,56 +37,56 @@ public: } //! Sequence number of the ledger. - Seq const& + [[nodiscard]] Seq const& seq() const { return ledger_->header().seq; } //! Unique identifier (hash) of this ledger. - ID const& + [[nodiscard]] ID const& id() const { return ledger_->header().hash; } //! Unique identifier (hash) of this ledger's parent. - ID const& + [[nodiscard]] ID const& parentID() const { return ledger_->header().parentHash; } //! Resolution used when calculating this ledger's close time. - NetClock::duration + [[nodiscard]] NetClock::duration closeTimeResolution() const { return ledger_->header().closeTimeResolution; } //! Whether consensus process agreed on close time of the ledger. - bool + [[nodiscard]] bool closeAgree() const { return xrpl::getCloseAgree(ledger_->header()); } //! The close time of this ledger - NetClock::time_point + [[nodiscard]] NetClock::time_point closeTime() const { return ledger_->header().closeTime; } //! The close time of this ledger's parent. - NetClock::time_point + [[nodiscard]] NetClock::time_point parentCloseTime() const { return ledger_->header().parentCloseTime; } //! JSON representation of this ledger. - Json::Value + [[nodiscard]] Json::Value getJson() const { return xrpl::getJson({*ledger_, {}}); diff --git a/src/xrpld/app/consensus/RCLCxTx.h b/src/xrpld/app/consensus/RCLCxTx.h index 0af43f7477..dc99ea66e3 100644 --- a/src/xrpld/app/consensus/RCLCxTx.h +++ b/src/xrpld/app/consensus/RCLCxTx.h @@ -24,7 +24,7 @@ public: } //! The unique identifier/hash of the transaction - ID const& + [[nodiscard]] ID const& id() const { return tx_->key(); @@ -104,7 +104,7 @@ public: @param entry The ID of transaction to test. @return Whether the transaction is in the set. */ - bool + [[nodiscard]] bool exists(Tx::ID const& entry) const { return map_->hasItem(entry); @@ -121,14 +121,14 @@ public: code uses the shared_ptr semantics to know whether the find was successful and properly creates a Tx as needed. */ - boost::intrusive_ptr const& + [[nodiscard]] boost::intrusive_ptr const& find(Tx::ID const& entry) const { return map_->peekItem(entry); } //! The unique ID/hash of the transaction set - ID + [[nodiscard]] ID id() const { return map_->getHash().as_uint256(); @@ -142,7 +142,7 @@ public: is the transaction ID and the value is a bool of the transaction exists in this set. */ - std::map + [[nodiscard]] std::map compare(RCLTxSet const& j) const { SHAMap::Delta delta; diff --git a/src/xrpld/app/consensus/RCLValidations.h b/src/xrpld/app/consensus/RCLValidations.h index 8da82e6425..cddcedc224 100644 --- a/src/xrpld/app/consensus/RCLValidations.h +++ b/src/xrpld/app/consensus/RCLValidations.h @@ -37,49 +37,49 @@ public: } /// Validated ledger's hash - uint256 + [[nodiscard]] uint256 ledgerID() const { return val_->getLedgerHash(); } /// Validated ledger's sequence number (0 if none) - std::uint32_t + [[nodiscard]] std::uint32_t seq() const { return val_->getFieldU32(sfLedgerSequence); } /// Validation's signing time - NetClock::time_point + [[nodiscard]] NetClock::time_point signTime() const { return val_->getSignTime(); } /// Validated ledger's first seen time - NetClock::time_point + [[nodiscard]] NetClock::time_point seenTime() const { return val_->getSeenTime(); } /// Public key of validator that published the validation - PublicKey + [[nodiscard]] PublicKey key() const { return val_->getSignerPublic(); } /// NodeID of validator that published the validation - NodeID + [[nodiscard]] NodeID nodeID() const { return val_->getNodeID(); } /// Whether the validation is considered trusted. - bool + [[nodiscard]] bool trusted() const { return val_->isTrusted(); @@ -98,28 +98,28 @@ public: } /// Whether the validation is full (not-partial) - bool + [[nodiscard]] bool full() const { return val_->isFull(); } /// Get the load fee of the validation if it exists - std::optional + [[nodiscard]] std::optional loadFee() const { return ~(*val_)[~sfLoadFee]; } /// Get the cookie specified in the validation (0 if not set) - std::uint64_t + [[nodiscard]] std::uint64_t cookie() const { return (*val_)[sfCookie]; } /// Extract the underlying STValidation being wrapped - std::shared_ptr + [[nodiscard]] std::shared_ptr unwrap() const { return val_; @@ -150,11 +150,11 @@ public: RCLValidatedLedger(std::shared_ptr const& ledger, beast::Journal j); /// The sequence (index) of the ledger - Seq + [[nodiscard]] Seq seq() const; /// The ID (hash) of the ledger - ID + [[nodiscard]] ID id() const; /** Lookup the ID of the ancestor ledger @@ -170,7 +170,7 @@ public: friend Seq mismatch(RCLValidatedLedger const& a, RCLValidatedLedger const& b); - Seq + [[nodiscard]] Seq minSeq() const; private: @@ -197,14 +197,14 @@ public: /** Current time used to determine if validations are stale. */ - NetClock::time_point + [[nodiscard]] NetClock::time_point now() const; /** Attempt to acquire the ledger with given id from the network */ std::optional acquire(LedgerHash const& id); - beast::Journal + [[nodiscard]] beast::Journal journal() const { return j_; diff --git a/src/xrpld/app/ledger/AcceptedLedger.h b/src/xrpld/app/ledger/AcceptedLedger.h index 23cee6ce35..a024e24cb2 100644 --- a/src/xrpld/app/ledger/AcceptedLedger.h +++ b/src/xrpld/app/ledger/AcceptedLedger.h @@ -27,25 +27,25 @@ class AcceptedLedger : public CountedObject public: AcceptedLedger(std::shared_ptr const& ledger); - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& getLedger() const { return mLedger; } - std::size_t + [[nodiscard]] std::size_t size() const { return transactions_.size(); } - auto + [[nodiscard]] auto begin() const { return transactions_.begin(); } - auto + [[nodiscard]] auto end() const { return transactions_.end(); diff --git a/src/xrpld/app/ledger/AccountStateSF.h b/src/xrpld/app/ledger/AccountStateSF.h index d17f3540ea..5d00e65120 100644 --- a/src/xrpld/app/ledger/AccountStateSF.h +++ b/src/xrpld/app/ledger/AccountStateSF.h @@ -24,7 +24,7 @@ public: Blob&& nodeData, SHAMapNodeType type) const override; - std::optional + [[nodiscard]] std::optional getNode(SHAMapHash const& nodeHash) const override; private: diff --git a/src/xrpld/app/ledger/ConsensusTransSetSF.h b/src/xrpld/app/ledger/ConsensusTransSetSF.h index f439ef9cfa..b666fbf750 100644 --- a/src/xrpld/app/ledger/ConsensusTransSetSF.h +++ b/src/xrpld/app/ledger/ConsensusTransSetSF.h @@ -28,7 +28,7 @@ public: Blob&& nodeData, SHAMapNodeType type) const override; - std::optional + [[nodiscard]] std::optional getNode(SHAMapHash const& nodeHash) const override; private: diff --git a/src/xrpld/app/ledger/LedgerReplay.h b/src/xrpld/app/ledger/LedgerReplay.h index a2b2e60e8e..2dc4911ade 100644 --- a/src/xrpld/app/ledger/LedgerReplay.h +++ b/src/xrpld/app/ledger/LedgerReplay.h @@ -27,7 +27,7 @@ public: /** @return The parent of the ledger to replay */ - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& parent() const { return parent_; @@ -35,7 +35,7 @@ public: /** @return The ledger to replay */ - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& replay() const { return replay_; @@ -43,7 +43,7 @@ public: /** @return Transactions in the order they should be replayed */ - std::map> const& + [[nodiscard]] std::map> const& orderedTxns() const { return orderedTxns_; diff --git a/src/xrpld/app/ledger/LedgerReplayTask.h b/src/xrpld/app/ledger/LedgerReplayTask.h index 65c43edb2d..4eaed49d1b 100644 --- a/src/xrpld/app/ledger/LedgerReplayTask.h +++ b/src/xrpld/app/ledger/LedgerReplayTask.h @@ -60,7 +60,7 @@ public: update(uint256 const& hash, std::uint32_t seq, std::vector const& sList); /** check if this task can be merged into an existing task */ - bool + [[nodiscard]] bool canMergeInto(TaskParameter const& existingTask) const; }; diff --git a/src/xrpld/app/ledger/TransactionStateSF.h b/src/xrpld/app/ledger/TransactionStateSF.h index 9ca84c2610..c5c113be7f 100644 --- a/src/xrpld/app/ledger/TransactionStateSF.h +++ b/src/xrpld/app/ledger/TransactionStateSF.h @@ -24,7 +24,7 @@ public: Blob&& nodeData, SHAMapNodeType type) const override; - std::optional + [[nodiscard]] std::optional getNode(SHAMapHash const& nodeHash) const override; private: diff --git a/src/xrpld/app/ledger/detail/LocalTxs.cpp b/src/xrpld/app/ledger/detail/LocalTxs.cpp index 5326568e35..83d9c61c3c 100644 --- a/src/xrpld/app/ledger/detail/LocalTxs.cpp +++ b/src/xrpld/app/ledger/detail/LocalTxs.cpp @@ -57,31 +57,31 @@ public: m_expire = std::min(m_expire, txn->getFieldU32(sfLastLedgerSequence) + 1); } - uint256 const& + [[nodiscard]] uint256 const& getID() const { return m_id; } - SeqProxy + [[nodiscard]] SeqProxy getSeqProxy() const { return m_seqProxy; } - bool + [[nodiscard]] bool isExpired(LedgerIndex i) const { return i > m_expire; } - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& getTX() const { return m_txn; } - AccountID const& + [[nodiscard]] AccountID const& getAccount() const { return m_account; diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 5867f77ba0..005586eaba 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -180,7 +180,7 @@ private: } } - std::chrono::milliseconds + [[nodiscard]] std::chrono::milliseconds get() const { return lastSample_.load(); diff --git a/src/xrpld/app/main/Application.h b/src/xrpld/app/main/Application.h index d0437be9a6..aa1c789381 100644 --- a/src/xrpld/app/main/Application.h +++ b/src/xrpld/app/main/Application.h @@ -112,7 +112,7 @@ public: run() = 0; virtual void signalStop(std::string msg) = 0; - virtual bool + [[nodiscard]] virtual bool checkSigs() const = 0; virtual void checkSigs(bool) = 0; @@ -122,7 +122,7 @@ public: // /** Returns a 64-bit instance identifier, generated at startup */ - virtual std::uint64_t + [[nodiscard]] virtual std::uint64_t instanceID() const = 0; virtual Config& @@ -131,7 +131,7 @@ public: virtual std::pair const& nodeIdentity() = 0; - virtual std::optional + [[nodiscard]] virtual std::optional getValidationPublicKey() const = 0; virtual std::chrono::milliseconds @@ -141,7 +141,7 @@ public: serverOkay(std::string& reason) = 0; /* Returns the number of file descriptors the application needs */ - virtual int + [[nodiscard]] virtual int fdRequired() const = 0; /** Ensure that a newly-started validator does not sign proposals older @@ -150,7 +150,7 @@ public: getMaxDisallowedLedger() = 0; /** Returns the number of io_context (I/O worker) threads used by the application. */ - virtual size_t + [[nodiscard]] virtual size_t getNumberOfThreads() const = 0; }; diff --git a/src/xrpld/app/main/BasicApp.h b/src/xrpld/app/main/BasicApp.h index 19f07d1e5b..62757da836 100644 --- a/src/xrpld/app/main/BasicApp.h +++ b/src/xrpld/app/main/BasicApp.h @@ -24,7 +24,7 @@ public: return io_context_; } - size_t + [[nodiscard]] size_t get_number_of_threads() const { return threads_.size(); diff --git a/src/xrpld/app/main/GRPCServer.h b/src/xrpld/app/main/GRPCServer.h index 215c1e037d..489a11d24a 100644 --- a/src/xrpld/app/main/GRPCServer.h +++ b/src/xrpld/app/main/GRPCServer.h @@ -127,7 +127,7 @@ public: setupListeners(); // Obtaining actually binded endpoint (if port 0 was used for server setup). - boost::asio::ip::tcp::endpoint + [[nodiscard]] boost::asio::ip::tcp::endpoint getEndpoint() const; private: @@ -305,7 +305,7 @@ public: ~GRPCServer(); - boost::asio::ip::tcp::endpoint + [[nodiscard]] boost::asio::ip::tcp::endpoint getEndpoint() const; private: diff --git a/src/xrpld/app/main/Main.cpp b/src/xrpld/app/main/Main.cpp index 2ee2ac90cd..3da6e3a2ad 100644 --- a/src/xrpld/app/main/Main.cpp +++ b/src/xrpld/app/main/Main.cpp @@ -228,7 +228,7 @@ public: return false; } - std::size_t + [[nodiscard]] std::size_t size() const { return selectors_.size(); diff --git a/src/xrpld/app/misc/FeeVoteImpl.cpp b/src/xrpld/app/misc/FeeVoteImpl.cpp index 53e56286b8..f6c60bc572 100644 --- a/src/xrpld/app/misc/FeeVoteImpl.cpp +++ b/src/xrpld/app/misc/FeeVoteImpl.cpp @@ -58,13 +58,13 @@ public: addVote(current_); } - value_type + [[nodiscard]] value_type current() const { return current_; } - std::pair + [[nodiscard]] std::pair getVotes() const; }; diff --git a/src/xrpld/app/misc/SHAMapStore.h b/src/xrpld/app/misc/SHAMapStore.h index 6788d15392..22ba0cdbe2 100644 --- a/src/xrpld/app/misc/SHAMapStore.h +++ b/src/xrpld/app/misc/SHAMapStore.h @@ -33,7 +33,7 @@ public: virtual void stop() = 0; - virtual std::uint32_t + [[nodiscard]] virtual std::uint32_t clampFetchDepth(std::uint32_t fetch_depth) const = 0; virtual std::unique_ptr @@ -44,7 +44,7 @@ public: setCanDelete(LedgerIndex canDelete) = 0; /** Whether advisory delete is enabled. */ - virtual bool + [[nodiscard]] virtual bool advisoryDelete() const = 0; /** Maximum ledger that has been deleted, or will be deleted if @@ -58,7 +58,7 @@ public: getCanDelete() = 0; /** Returns the number of file descriptors that are needed. */ - virtual int + [[nodiscard]] virtual int fdRequired() const = 0; /** The minimum ledger to try and maintain in our database. @@ -77,7 +77,7 @@ public: @return The minimum ledger sequence to keep online based on the description above. If not set, then an unseated optional. */ - virtual std::optional + [[nodiscard]] virtual std::optional minimumOnline() const = 0; }; diff --git a/src/xrpld/app/misc/Transaction.h b/src/xrpld/app/misc/Transaction.h index 31d899d99b..40e0a3d10d 100644 --- a/src/xrpld/app/misc/Transaction.h +++ b/src/xrpld/app/misc/Transaction.h @@ -174,7 +174,7 @@ public: * @brief any Get true of any state is true * @return True if any state if true */ - bool + [[nodiscard]] bool any() const { return applied || broadcast || queued || kept; @@ -306,7 +306,7 @@ public: // Call this function first to determine the type of the contained info. // Calling the wrong getter function will throw an exception. // See documentation for the getter functions for more details - bool + [[nodiscard]] bool isFound() const { return std::holds_alternative>(locator); diff --git a/src/xrpld/app/misc/TxQ.h b/src/xrpld/app/misc/TxQ.h index 0f734f7897..ce32755db1 100644 --- a/src/xrpld/app/misc/TxQ.h +++ b/src/xrpld/app/misc/TxQ.h @@ -422,7 +422,7 @@ private: }; /// Get the current @ref Snapshot - Snapshot + [[nodiscard]] Snapshot getSnapshot() const { return {.txnsExpected = txnsExpected_, .escalationMultiplier = escalationMultiplier_}; @@ -575,7 +575,7 @@ private: /// Potential @ref TxConsequences of applying this transaction /// to the open ledger. - TxConsequences const& + [[nodiscard]] TxConsequences const& consequences() const { return pfResult->consequences; // NOLINT(bugprone-unchecked-optional-access) invariant: @@ -583,7 +583,7 @@ private: } /// Return a TxDetails based on contained information. - TxDetails + [[nodiscard]] TxDetails getTxDetails() const { return { @@ -665,21 +665,21 @@ private: explicit TxQAccount(AccountID const& account); /// Return the number of transactions currently queued for this account - std::size_t + [[nodiscard]] std::size_t getTxnCount() const { return transactions.size(); } /// Checks if this account has no transactions queued - bool + [[nodiscard]] bool empty() const { return getTxnCount() == 0u; } /// Find the entry in transactions that precedes seqProx, if one does. - TxMap::const_iterator + [[nodiscard]] TxMap::const_iterator getPrevTx(SeqProxy seqProx) const; /// Add a transaction candidate to this account for queuing diff --git a/src/xrpld/app/misc/ValidatorKeys.h b/src/xrpld/app/misc/ValidatorKeys.h index 296c63e09e..d3ce996065 100644 --- a/src/xrpld/app/misc/ValidatorKeys.h +++ b/src/xrpld/app/misc/ValidatorKeys.h @@ -43,7 +43,7 @@ public: ValidatorKeys() = delete; ValidatorKeys(Config const& config, beast::Journal j); - bool + [[nodiscard]] bool configInvalid() const { return configInvalid_; diff --git a/src/xrpld/app/misc/ValidatorList.h b/src/xrpld/app/misc/ValidatorList.h index ff5aa8c71f..2c7900465c 100644 --- a/src/xrpld/app/misc/ValidatorList.h +++ b/src/xrpld/app/misc/ValidatorList.h @@ -274,9 +274,9 @@ public: explicit PublisherListStats(ListDisposition d); PublisherListStats(ListDisposition d, PublicKey key, PublisherStatus stat, std::size_t seq); - ListDisposition + [[nodiscard]] ListDisposition bestDisposition() const; - ListDisposition + [[nodiscard]] ListDisposition worstDisposition() const; void mergeDispositions(PublisherListStats const& src); diff --git a/src/xrpld/app/misc/detail/AmendmentTable.cpp b/src/xrpld/app/misc/detail/AmendmentTable.cpp index 0698230eb2..65342dac2f 100644 --- a/src/xrpld/app/misc/detail/AmendmentTable.cpp +++ b/src/xrpld/app/misc/detail/AmendmentTable.cpp @@ -334,7 +334,7 @@ public: amendmentMajorityCalcThreshold.den)); } - bool + [[nodiscard]] bool passes(uint256 const& amendment) const { auto const& it = votes_.find(amendment); @@ -350,7 +350,7 @@ public: return it->second > threshold_; } - int + [[nodiscard]] int votes(uint256 const& amendment) const { auto const& it = votes_.find(amendment); @@ -361,13 +361,13 @@ public: return it->second; } - int + [[nodiscard]] int trustedValidations() const { return trustedValidations_; } - int + [[nodiscard]] int threshold() const { return threshold_; diff --git a/src/xrpld/consensus/Consensus.h b/src/xrpld/consensus/Consensus.h index 68ea8fb403..9edbebd429 100644 --- a/src/xrpld/consensus/Consensus.h +++ b/src/xrpld/consensus/Consensus.h @@ -295,7 +295,7 @@ class Consensus MonitoredMode(ConsensusMode m) : mode_{m} { } - ConsensusMode + [[nodiscard]] ConsensusMode get() const { return mode_; @@ -408,7 +408,7 @@ public: return prevLedgerID_; } - ConsensusPhase + [[nodiscard]] ConsensusPhase phase() const { return phase_; @@ -421,7 +421,7 @@ public: @param full True if verbose response desired. @return The Json state. */ - Json::Value + [[nodiscard]] Json::Value getJson(bool full) const; private: @@ -500,7 +500,7 @@ private: * * @return Whether to pause to wait for lagging proposers. */ - bool + [[nodiscard]] bool shouldPause(std::unique_ptr const& clog) const; // Close the open ledger and establish initial position. @@ -529,7 +529,7 @@ private: leaveConsensus(std::unique_ptr const& clog); // The rounded or effective close time estimate from a proposer - NetClock::time_point + [[nodiscard]] NetClock::time_point asCloseTime(NetClock::time_point raw) const; private: diff --git a/src/xrpld/consensus/ConsensusTypes.h b/src/xrpld/consensus/ConsensusTypes.h index 8aba48f34e..8a81211722 100644 --- a/src/xrpld/consensus/ConsensusTypes.h +++ b/src/xrpld/consensus/ConsensusTypes.h @@ -120,7 +120,7 @@ class ConsensusTimer std::chrono::milliseconds dur_{}; public: - std::chrono::milliseconds + [[nodiscard]] std::chrono::milliseconds read() const { return dur_; diff --git a/src/xrpld/consensus/DisputedTx.h b/src/xrpld/consensus/DisputedTx.h index 2172fd5d47..aff4ccae68 100644 --- a/src/xrpld/consensus/DisputedTx.h +++ b/src/xrpld/consensus/DisputedTx.h @@ -47,14 +47,14 @@ public: } //! The unique id/hash of the disputed transaction. - TxID_t const& + [[nodiscard]] TxID_t const& ID() const { return tx_.id(); } //! Our vote on whether the transaction should be included. - bool + [[nodiscard]] bool getOurVote() const { return ourVote_; @@ -62,7 +62,7 @@ public: //! Are we and our peers "stalled" where we probably won't change //! our vote? - bool + [[nodiscard]] bool stalled( ConsensusParms const& p, bool proposing, @@ -127,7 +127,7 @@ public: } //! The disputed transaction. - Tx_t const& + [[nodiscard]] Tx_t const& tx() const { return tx_; @@ -173,7 +173,7 @@ public: updateVote(int percentTime, bool proposing, ConsensusParms const& p); //! JSON representation of dispute, used for debugging - Json::Value + [[nodiscard]] Json::Value getJson() const; private: diff --git a/src/xrpld/consensus/LedgerTrie.h b/src/xrpld/consensus/LedgerTrie.h index 99ddb530df..d151802158 100644 --- a/src/xrpld/consensus/LedgerTrie.h +++ b/src/xrpld/consensus/LedgerTrie.h @@ -41,7 +41,7 @@ public: @note s must be less than or equal to the sequence number of the tip ledger */ - ID + [[nodiscard]] ID ancestor(Seq const& s) const { XRPL_ASSERT(s <= seq, "xrpl::SpanTip::ancestor : valid input"); @@ -84,34 +84,34 @@ public: Span& operator=(Span&&) = default; - Seq + [[nodiscard]] Seq start() const { return start_; } - Seq + [[nodiscard]] Seq end() const { return end_; } // Return the Span from [spot,end_) or none if no such valid span - std::optional + [[nodiscard]] std::optional from(Seq spot) const { return sub(spot, end_); } // Return the Span from [start_,spot) or none if no such valid span - std::optional + [[nodiscard]] std::optional before(Seq spot) const { return sub(start_, spot); } // Return the ID of the ledger that starts this span - ID + [[nodiscard]] ID startID() const { return ledger_[start_]; @@ -119,14 +119,14 @@ public: // Return the ledger sequence number of the first possible difference // between this span and a given ledger. - Seq + [[nodiscard]] Seq diff(Ledger const& o) const { return clamp(mismatch(ledger_, o)); } // The tip of this span - SpanTip + [[nodiscard]] SpanTip tip() const { Seq const tipSeq{end_ - Seq{1}}; @@ -140,14 +140,14 @@ private: XRPL_ASSERT(start < end, "xrpl::Span::Span : non-empty span input"); } - Seq + [[nodiscard]] Seq clamp(Seq val) const { return std::min(std::max(start_, val), end_); } // Return a span of this over the half-open interval [from,to) - std::optional + [[nodiscard]] std::optional sub(Seq from, Seq to) const { Seq const newFrom = clamp(from); @@ -219,7 +219,7 @@ struct Node return o << s.span << "(T:" << s.tipSupport << ",B:" << s.branchSupport << ")"; } - Json::Value + [[nodiscard]] Json::Value getJson() const { Json::Value res; @@ -342,7 +342,7 @@ class LedgerTrie @return Pair of the found node and the sequence number of the first ledger difference. */ - std::pair + [[nodiscard]] std::pair find(Ledger const& ledger) const { // NOLINTNEXTLINE(misc-const-correctness) @@ -567,7 +567,7 @@ public: @param ledger The ledger to lookup @return The number of entries in the trie for this *exact* ledger */ - std::uint32_t + [[nodiscard]] std::uint32_t tipSupport(Ledger const& ledger) const { if (auto const* loc = findByLedgerID(ledger)) @@ -581,7 +581,7 @@ public: @return The number of entries in the trie for this ledger or a descendant */ - std::uint32_t + [[nodiscard]] std::uint32_t branchSupport(Ledger const& ledger) const { Node const* loc = findByLedgerID(ledger); @@ -655,7 +655,7 @@ public: @return Pair with the sequence number and ID of the preferred ledger or std::nullopt if no preferred ledger exists */ - std::optional> + [[nodiscard]] std::optional> getPreferred(Seq const largestIssued) const { if (empty()) @@ -758,7 +758,7 @@ public: /** Return whether the trie is tracking any ledgers */ - bool + [[nodiscard]] bool empty() const { return !root || root->branchSupport == 0; @@ -774,7 +774,7 @@ public: /** Dump JSON representation of trie state */ - Json::Value + [[nodiscard]] Json::Value getJson() const { Json::Value res; @@ -787,7 +787,7 @@ public: /** Check the compressed trie and support invariants. */ - bool + [[nodiscard]] bool checkInvariants() const { std::map expectedSeqSupport; diff --git a/src/xrpld/consensus/Validations.h b/src/xrpld/consensus/Validations.h index 00f10f89cf..46b0ef0b32 100644 --- a/src/xrpld/consensus/Validations.h +++ b/src/xrpld/consensus/Validations.h @@ -107,7 +107,7 @@ public: return true; } - Seq + [[nodiscard]] Seq largest() const { return seq_; diff --git a/src/xrpld/core/Config.h b/src/xrpld/core/Config.h index d4d8396ba5..5dd08de74f 100644 --- a/src/xrpld/core/Config.h +++ b/src/xrpld/core/Config.h @@ -60,7 +60,7 @@ struct FeeSetup * values.) */ /** Convert to a Fees object for use with Ledger construction. */ - Fees + [[nodiscard]] Fees toFees() const { return Fees{reference_fee, account_reserve, owner_reserve}; @@ -82,7 +82,7 @@ public: static char const* const validatorsFileName; /** Returns the full path and filename of the debug log file. */ - boost::filesystem::path + [[nodiscard]] boost::filesystem::path getDebugLogFile() const; private: @@ -302,29 +302,29 @@ public: void loadFromString(std::string const& fileContents); - bool + [[nodiscard]] bool quiet() const { return QUIET; } - bool + [[nodiscard]] bool silent() const { return SILENT; } - bool + [[nodiscard]] bool standalone() const { return RUN_STANDALONE; } - bool + [[nodiscard]] bool useTxTables() const { return USE_TX_TABLES; } - bool + [[nodiscard]] bool canSign() const { return signingEnabled_; @@ -347,10 +347,10 @@ public: the underlying system; this means that we can't provide optimal defaults in the code for every case. */ - int + [[nodiscard]] int getValueFor(SizedItem item, std::optional node = std::nullopt) const; - beast::Journal + [[nodiscard]] beast::Journal journal() const { return j_; diff --git a/src/xrpld/core/NetworkIDServiceImpl.h b/src/xrpld/core/NetworkIDServiceImpl.h index 1176f8d4ac..2236a854ff 100644 --- a/src/xrpld/core/NetworkIDServiceImpl.h +++ b/src/xrpld/core/NetworkIDServiceImpl.h @@ -22,7 +22,7 @@ public: ~NetworkIDServiceImpl() override = default; - std::uint32_t + [[nodiscard]] std::uint32_t getNetworkID() const noexcept override; private: diff --git a/src/xrpld/overlay/ClusterNode.h b/src/xrpld/overlay/ClusterNode.h index 3e319ef8be..3a504a5733 100644 --- a/src/xrpld/overlay/ClusterNode.h +++ b/src/xrpld/overlay/ClusterNode.h @@ -23,25 +23,25 @@ public: { } - std::string const& + [[nodiscard]] std::string const& name() const { return name_; } - std::uint32_t + [[nodiscard]] std::uint32_t getLoadFee() const { return mLoadFee; } - NetClock::time_point + [[nodiscard]] NetClock::time_point getReportTime() const { return mReportTime; } - PublicKey const& + [[nodiscard]] PublicKey const& identity() const { return identity_; diff --git a/src/xrpld/overlay/Overlay.h b/src/xrpld/overlay/Overlay.h index 2c2371a1d1..f42ef64b9a 100644 --- a/src/xrpld/overlay/Overlay.h +++ b/src/xrpld/overlay/Overlay.h @@ -85,7 +85,7 @@ public: Active peers are only those peers that have completed the handshake and are using the peer protocol. */ - virtual std::size_t + [[nodiscard]] virtual std::size_t size() const = 0; /** Return diagnostics on the status of all peers. @@ -97,7 +97,7 @@ public: /** Returns a sequence representing the current list of peers. The snapshot is made at the time of the call. */ - virtual PeerSequence + [[nodiscard]] virtual PeerSequence getActivePeers() const = 0; /** Calls the checkTracking function on each peer @@ -107,7 +107,7 @@ public: checkTracking(std::uint32_t index) = 0; /** Returns the peer with the matching short id, or null. */ - virtual std::shared_ptr + [[nodiscard]] virtual std::shared_ptr findPeerByShortID(Peer::id_t const& id) const = 0; /** Returns the peer with the matching public key, or null. */ @@ -171,7 +171,7 @@ public: /** Increment and retrieve counter for transaction job queue overflows. */ virtual void incJqTransOverflow() = 0; - virtual std::uint64_t + [[nodiscard]] virtual std::uint64_t getJqTransOverflow() const = 0; /** Increment and retrieve counters for total peer disconnects, and @@ -179,11 +179,11 @@ public: */ virtual void incPeerDisconnect() = 0; - virtual std::uint64_t + [[nodiscard]] virtual std::uint64_t getPeerDisconnect() const = 0; virtual void incPeerDisconnectCharges() = 0; - virtual std::uint64_t + [[nodiscard]] virtual std::uint64_t getPeerDisconnectCharges() const = 0; /** Returns the ID of the network this server is configured for, if any. @@ -194,13 +194,13 @@ public: @return The numerical identifier configured by the administrator of the server. An unseated optional, otherwise. */ - virtual std::optional + [[nodiscard]] virtual std::optional networkID() const = 0; /** Returns tx reduce-relay metrics @return json value of tx reduce-relay metrics */ - virtual Json::Value + [[nodiscard]] virtual Json::Value txMetrics() const = 0; }; diff --git a/src/xrpld/overlay/Peer.h b/src/xrpld/overlay/Peer.h index df2cc5bcb7..5955c97838 100644 --- a/src/xrpld/overlay/Peer.h +++ b/src/xrpld/overlay/Peer.h @@ -41,7 +41,7 @@ public: virtual void send(std::shared_ptr const& m) = 0; - virtual beast::IP::Endpoint + [[nodiscard]] virtual beast::IP::Endpoint getRemoteAddress() const = 0; /** Send aggregated transactions' hashes. */ @@ -64,57 +64,57 @@ public: // Identity // - virtual id_t + [[nodiscard]] virtual id_t id() const = 0; /** Returns `true` if this connection is a member of the cluster. */ - virtual bool + [[nodiscard]] virtual bool cluster() const = 0; - virtual bool + [[nodiscard]] virtual bool isHighLatency() const = 0; - virtual int + [[nodiscard]] virtual int getScore(bool) const = 0; - virtual PublicKey const& + [[nodiscard]] virtual PublicKey const& getNodePublic() const = 0; virtual Json::Value json() = 0; - virtual bool + [[nodiscard]] virtual bool supportsFeature(ProtocolFeature f) const = 0; - virtual std::optional + [[nodiscard]] virtual std::optional publisherListSequence(PublicKey const&) const = 0; virtual void setPublisherListSequence(PublicKey const&, std::size_t const) = 0; - virtual std::string const& + [[nodiscard]] virtual std::string const& fingerprint() const = 0; // // Ledger // - virtual uint256 const& + [[nodiscard]] virtual uint256 const& getClosedLedgerHash() const = 0; - virtual bool + [[nodiscard]] virtual bool hasLedger(uint256 const& hash, std::uint32_t seq) const = 0; virtual void ledgerRange(std::uint32_t& minSeq, std::uint32_t& maxSeq) const = 0; - virtual bool + [[nodiscard]] virtual bool hasTxSet(uint256 const& hash) const = 0; virtual void cycleStatus() = 0; virtual bool hasRange(std::uint32_t uMin, std::uint32_t uMax) = 0; - virtual bool + [[nodiscard]] virtual bool compressionEnabled() const = 0; - virtual bool + [[nodiscard]] virtual bool txReduceRelayEnabled() const = 0; }; diff --git a/src/xrpld/overlay/PeerSet.h b/src/xrpld/overlay/PeerSet.h index b69d139b4f..83cb40d84f 100644 --- a/src/xrpld/overlay/PeerSet.h +++ b/src/xrpld/overlay/PeerSet.h @@ -48,7 +48,7 @@ public: std::shared_ptr const& peer) = 0; /** get the set of ids of previously added peers */ - virtual std::set const& + [[nodiscard]] virtual std::set const& getPeerIds() const = 0; }; diff --git a/src/xrpld/overlay/Slot.h b/src/xrpld/overlay/Slot.h index d7f3e9b4d3..896bf56659 100644 --- a/src/xrpld/overlay/Slot.h +++ b/src/xrpld/overlay/Slot.h @@ -141,35 +141,35 @@ private: deletePeer(PublicKey const& validator, id_t id, bool erase); /** Get the time of the last peer selection round */ - time_point const& + [[nodiscard]] time_point const& getLastSelected() const { return lastSelected_; } /** Return number of peers in state */ - std::uint16_t + [[nodiscard]] std::uint16_t inState(PeerState state) const; /** Return number of peers not in state */ - std::uint16_t + [[nodiscard]] std::uint16_t notInState(PeerState state) const; /** Return Slot's state */ - SlotState + [[nodiscard]] SlotState getState() const { return state_; } /** Return selected peers */ - std::set + [[nodiscard]] std::set getSelected() const; /** Get peers info. Return map of peer's state, count, squelch * expiration milsec, and last message time milsec. */ - std::unordered_map> + [[nodiscard]] std::unordered_map> getPeers() const; /** Check if peers stopped relaying messages. If a peer is @@ -609,7 +609,7 @@ public: deleteIdlePeers(); /** Return number of peers in state */ - std::optional + [[nodiscard]] std::optional inState(PublicKey const& validator, PeerState state) const { auto const& it = slots_.find(validator); @@ -619,7 +619,7 @@ public: } /** Return number of peers not in state */ - std::optional + [[nodiscard]] std::optional notInState(PublicKey const& validator, PeerState state) const { auto const& it = slots_.find(validator); @@ -629,7 +629,7 @@ public: } /** Return true if Slot is in state */ - bool + [[nodiscard]] bool inState(PublicKey const& validator, SlotState state) const { auto const& it = slots_.find(validator); diff --git a/src/xrpld/overlay/detail/PeerSet.cpp b/src/xrpld/overlay/detail/PeerSet.cpp index 8d3d79d358..a1eb41d023 100644 --- a/src/xrpld/overlay/detail/PeerSet.cpp +++ b/src/xrpld/overlay/detail/PeerSet.cpp @@ -40,7 +40,7 @@ public: protocol::MessageType type, std::shared_ptr const& peer) override; - std::set const& + [[nodiscard]] std::set const& getPeerIds() const override; private: @@ -164,7 +164,7 @@ public: JLOG(j_.error()) << "DummyPeerSet sendRequest should not be called"; } - std::set const& + [[nodiscard]] std::set const& getPeerIds() const override { static std::set const emptyPeers; diff --git a/src/xrpld/overlay/detail/TrafficCount.h b/src/xrpld/overlay/detail/TrafficCount.h index bdc0729a51..736c3b76e3 100644 --- a/src/xrpld/overlay/detail/TrafficCount.h +++ b/src/xrpld/overlay/detail/TrafficCount.h @@ -217,7 +217,7 @@ public: @return an object which satisfies the requirements of Container */ - auto const& + [[nodiscard]] auto const& getCounts() const { return counts_; diff --git a/src/xrpld/overlay/detail/ZeroCopyStream.h b/src/xrpld/overlay/detail/ZeroCopyStream.h index 034f69a8da..d8d311105d 100644 --- a/src/xrpld/overlay/detail/ZeroCopyStream.h +++ b/src/xrpld/overlay/detail/ZeroCopyStream.h @@ -37,7 +37,7 @@ public: bool Skip(int count) override; - google::protobuf::int64 + [[nodiscard]] google::protobuf::int64 ByteCount() const override { return count_; @@ -132,7 +132,7 @@ public: void BackUp(int count) override; - google::protobuf::int64 + [[nodiscard]] google::protobuf::int64 ByteCount() const override { return count_; diff --git a/src/xrpld/peerfinder/PeerfinderManager.h b/src/xrpld/peerfinder/PeerfinderManager.h index 1ceaebe04d..f5a7b044b5 100644 --- a/src/xrpld/peerfinder/PeerfinderManager.h +++ b/src/xrpld/peerfinder/PeerfinderManager.h @@ -65,7 +65,7 @@ struct Config Config(); /** Returns a suitable value for outPeers according to the rules. */ - std::size_t + [[nodiscard]] std::size_t calcOutPeers() const; /** Adjusts the values so they follow the business rules. */ diff --git a/src/xrpld/peerfinder/Slot.h b/src/xrpld/peerfinder/Slot.h index 81249f54df..5c459b25ea 100644 --- a/src/xrpld/peerfinder/Slot.h +++ b/src/xrpld/peerfinder/Slot.h @@ -18,42 +18,42 @@ public: virtual ~Slot() = 0; /** Returns `true` if this is an inbound connection. */ - virtual bool + [[nodiscard]] virtual bool inbound() const = 0; /** Returns `true` if this is a fixed connection. A connection is fixed if its remote endpoint is in the list of remote endpoints for fixed connections. */ - virtual bool + [[nodiscard]] virtual bool fixed() const = 0; /** Returns `true` if this is a reserved connection. It might be a cluster peer, or a peer with a reservation. This is only known after then handshake completes. */ - virtual bool + [[nodiscard]] virtual bool reserved() const = 0; /** Returns the state of the connection. */ - virtual State + [[nodiscard]] virtual State state() const = 0; /** The remote endpoint of socket. */ - virtual beast::IP::Endpoint const& + [[nodiscard]] virtual beast::IP::Endpoint const& remote_endpoint() const = 0; /** The local endpoint of the socket, when known. */ - virtual std::optional const& + [[nodiscard]] virtual std::optional const& local_endpoint() const = 0; - virtual std::optional + [[nodiscard]] virtual std::optional listening_port() const = 0; /** The peer's public key, when known. The public key is established when the handshake is complete. */ - virtual std::optional const& + [[nodiscard]] virtual std::optional const& public_key() const = 0; }; diff --git a/src/xrpld/peerfinder/detail/Bootcache.h b/src/xrpld/peerfinder/detail/Bootcache.h index 5405dd3432..0fc0be33db 100644 --- a/src/xrpld/peerfinder/detail/Bootcache.h +++ b/src/xrpld/peerfinder/detail/Bootcache.h @@ -45,7 +45,7 @@ private: return m_valence; } - int + [[nodiscard]] int valence() const { return m_valence; @@ -108,22 +108,22 @@ public: ~Bootcache(); /** Returns `true` if the cache is empty. */ - bool + [[nodiscard]] bool empty() const; /** Returns the number of entries in the cache. */ - map_type::size_type + [[nodiscard]] map_type::size_type size() const; /** IP::Endpoint iterators that traverse in decreasing valence. */ /** @{ */ - const_iterator + [[nodiscard]] const_iterator begin() const; - const_iterator + [[nodiscard]] const_iterator cbegin() const; - const_iterator + [[nodiscard]] const_iterator end() const; - const_iterator + [[nodiscard]] const_iterator cend() const; void clear(); diff --git a/src/xrpld/peerfinder/detail/Counts.h b/src/xrpld/peerfinder/detail/Counts.h index e3d120b414..811758b0b3 100644 --- a/src/xrpld/peerfinder/detail/Counts.h +++ b/src/xrpld/peerfinder/detail/Counts.h @@ -27,7 +27,7 @@ public: } /** Returns `true` if the slot can become active. */ - bool + [[nodiscard]] bool can_activate(Slot const& s) const { // Must be handshaked and in the right state @@ -45,7 +45,7 @@ public: } /** Returns the number of attempts needed to bring us to the max. */ - std::size_t + [[nodiscard]] std::size_t attempts_needed() const { if (m_attempts >= Tuning::maxConnectAttempts) @@ -54,14 +54,14 @@ public: } /** Returns the number of outbound connection attempts. */ - std::size_t + [[nodiscard]] std::size_t attempts() const { return m_attempts; } /** Returns the total number of outbound slots. */ - int + [[nodiscard]] int out_max() const { return m_out_max; @@ -70,21 +70,21 @@ public: /** Returns the number of outbound peers assigned an open slot. Fixed peers do not count towards outbound slots used. */ - int + [[nodiscard]] int out_active() const { return m_out_active; } /** Returns the number of fixed connections. */ - std::size_t + [[nodiscard]] std::size_t fixed() const { return m_fixed; } /** Returns the number of active fixed connections. */ - std::size_t + [[nodiscard]] std::size_t fixed_active() const { return m_fixed_active; @@ -102,42 +102,42 @@ public: } /** Returns the number of accepted connections that haven't handshaked. */ - int + [[nodiscard]] int acceptCount() const { return m_acceptCount; } /** Returns the number of connection attempts currently active. */ - int + [[nodiscard]] int connectCount() const { return m_attempts; } /** Returns the number of connections that are gracefully closing. */ - int + [[nodiscard]] int closingCount() const { return m_closingCount; } /** Returns the total number of inbound slots. */ - int + [[nodiscard]] int in_max() const { return m_in_max; } /** Returns the number of inbound peers assigned an open slot. */ - int + [[nodiscard]] int inboundActive() const { return m_in_active; } /** Returns the total number of active peers excluding fixed peers. */ - int + [[nodiscard]] int totalActive() const { return m_in_active + m_out_active; @@ -146,7 +146,7 @@ public: /** Returns the number of unused inbound slots. Fixed peers do not deduct from inbound slots or count towards totals. */ - int + [[nodiscard]] int inboundSlotsFree() const { if (m_in_active < m_in_max) @@ -157,7 +157,7 @@ public: /** Returns the number of unused outbound slots. Fixed peers do not deduct from outbound slots or count towards totals. */ - int + [[nodiscard]] int outboundSlotsFree() const { if (m_out_active < m_out_max) @@ -169,7 +169,7 @@ public: /** Returns true if the slot logic considers us "connected" to the network. */ - bool + [[nodiscard]] bool isConnectedToNetwork() const { // We will consider ourselves connected if we have reached @@ -196,7 +196,7 @@ public: } /** Records the state for diagnostics. */ - std::string + [[nodiscard]] std::string state_string() const { std::stringstream ss; diff --git a/src/xrpld/peerfinder/detail/Fixed.h b/src/xrpld/peerfinder/detail/Fixed.h index b898c6ce3f..497658fd40 100644 --- a/src/xrpld/peerfinder/detail/Fixed.h +++ b/src/xrpld/peerfinder/detail/Fixed.h @@ -15,7 +15,7 @@ public: Fixed(Fixed const&) = default; /** Returns the time after which we should allow a connection attempt. */ - clock_type::time_point const& + [[nodiscard]] clock_type::time_point const& when() const { return m_when; diff --git a/src/xrpld/peerfinder/detail/Handouts.h b/src/xrpld/peerfinder/detail/Handouts.h index 0d5eae7ef7..b93b0a32b8 100644 --- a/src/xrpld/peerfinder/detail/Handouts.h +++ b/src/xrpld/peerfinder/detail/Handouts.h @@ -85,13 +85,13 @@ public: bool try_insert(Endpoint const& ep); - bool + [[nodiscard]] bool full() const { return list_.size() >= Tuning::redirectEndpointCount; } - SlotImp::ptr const& + [[nodiscard]] SlotImp::ptr const& slot() const { return slot_; @@ -103,7 +103,7 @@ public: return list_; } - std::vector const& + [[nodiscard]] std::vector const& list() const { return list_; @@ -169,7 +169,7 @@ public: bool try_insert(Endpoint const& ep); - bool + [[nodiscard]] bool full() const { return list_.size() >= Tuning::numberOfEndpoints; @@ -181,13 +181,13 @@ public: list_.push_back(ep); } - SlotImp::ptr const& + [[nodiscard]] SlotImp::ptr const& slot() const { return slot_; } - std::vector const& + [[nodiscard]] std::vector const& list() const { return list_; @@ -265,13 +265,13 @@ public: bool try_insert(beast::IP::Endpoint const& endpoint); - bool + [[nodiscard]] bool empty() const { return m_list.empty(); } - bool + [[nodiscard]] bool full() const { return m_list.size() >= m_needed; @@ -289,7 +289,7 @@ public: return m_list; } - list_type const& + [[nodiscard]] list_type const& list() const { return m_list; diff --git a/src/xrpld/peerfinder/detail/Livecache.h b/src/xrpld/peerfinder/detail/Livecache.h index 5c5ed577af..9b177d22bc 100644 --- a/src/xrpld/peerfinder/detail/Livecache.h +++ b/src/xrpld/peerfinder/detail/Livecache.h @@ -74,49 +74,49 @@ public: using const_reverse_iterator = reverse_iterator; - iterator + [[nodiscard]] iterator begin() const { return iterator(m_list.get().cbegin(), Transform()); } - iterator + [[nodiscard]] iterator cbegin() const { return iterator(m_list.get().cbegin(), Transform()); } - iterator + [[nodiscard]] iterator end() const { return iterator(m_list.get().cend(), Transform()); } - iterator + [[nodiscard]] iterator cend() const { return iterator(m_list.get().cend(), Transform()); } - reverse_iterator + [[nodiscard]] reverse_iterator rbegin() const { return reverse_iterator(m_list.get().crbegin(), Transform()); } - reverse_iterator + [[nodiscard]] reverse_iterator crbegin() const { return reverse_iterator(m_list.get().crbegin(), Transform()); } - reverse_iterator + [[nodiscard]] reverse_iterator rend() const { return reverse_iterator(m_list.get().crend(), Transform()); } - reverse_iterator + [[nodiscard]] reverse_iterator crend() const { return reverse_iterator(m_list.get().crend(), Transform()); @@ -239,13 +239,13 @@ public: return iterator(m_lists.begin(), Transform()); } - const_iterator + [[nodiscard]] const_iterator begin() const { return const_iterator(m_lists.cbegin(), Transform()); } - const_iterator + [[nodiscard]] const_iterator cbegin() const { return const_iterator(m_lists.cbegin(), Transform()); @@ -257,13 +257,13 @@ public: return iterator(m_lists.end(), Transform()); } - const_iterator + [[nodiscard]] const_iterator end() const { return const_iterator(m_lists.cend(), Transform()); } - const_iterator + [[nodiscard]] const_iterator cend() const { return const_iterator(m_lists.cend(), Transform()); @@ -275,13 +275,13 @@ public: return reverse_iterator(m_lists.rbegin(), Transform()); } - const_reverse_iterator + [[nodiscard]] const_reverse_iterator rbegin() const { return const_reverse_iterator(m_lists.crbegin(), Transform()); } - const_reverse_iterator + [[nodiscard]] const_reverse_iterator crbegin() const { return const_reverse_iterator(m_lists.crbegin(), Transform()); @@ -293,13 +293,13 @@ public: return reverse_iterator(m_lists.rend(), Transform()); } - const_reverse_iterator + [[nodiscard]] const_reverse_iterator rend() const { return const_reverse_iterator(m_lists.crend(), Transform()); } - const_reverse_iterator + [[nodiscard]] const_reverse_iterator crend() const { return const_reverse_iterator(m_lists.crend(), Transform()); @@ -309,7 +309,7 @@ public: void shuffle(); - std::string + [[nodiscard]] std::string histogram() const; private: @@ -331,7 +331,7 @@ public: } hops; /** Returns `true` if the cache is empty. */ - bool + [[nodiscard]] bool empty() const { return m_cache.empty(); diff --git a/src/xrpld/rpc/ServerHandler.h b/src/xrpld/rpc/ServerHandler.h index 2ffdc9556b..da6e36fc33 100644 --- a/src/xrpld/rpc/ServerHandler.h +++ b/src/xrpld/rpc/ServerHandler.h @@ -115,13 +115,13 @@ public: void setup(Setup const& setup, beast::Journal journal); - Setup const& + [[nodiscard]] Setup const& setup() const { return setup_; } - Endpoints const& + [[nodiscard]] Endpoints const& endpoints() const { return endpoints_; @@ -187,7 +187,7 @@ private: std::string_view forwardedFor, std::string_view user); - Handoff + [[nodiscard]] Handoff statusResponse(http_request_type const& request) const; }; diff --git a/src/xrpld/rpc/Status.h b/src/xrpld/rpc/Status.h index f0c6d932e7..ecd4c2c058 100644 --- a/src/xrpld/rpc/Status.h +++ b/src/xrpld/rpc/Status.h @@ -50,7 +50,7 @@ public: /* Returns a representation of the integer status Code as a string. If the Status is OK, the result is an empty string. */ - std::string + [[nodiscard]] std::string codeString() const; /** Returns true if the Status is *not* OK. */ @@ -68,7 +68,7 @@ public: /** Returns the Status as a TER. This may only be called if type() == Type::TER. */ - TER + [[nodiscard]] TER toTER() const { XRPL_ASSERT(type_ == Type::TER, "xrpl::RPC::Status::toTER : type is TER"); @@ -77,7 +77,7 @@ public: /** Returns the Status as an error_code_i. This may only be called if type() == Type::error_code_i. */ - error_code_i + [[nodiscard]] error_code_i toErrorCode() const { XRPL_ASSERT(type_ == Type::error_code_i, "xrpl::RPC::Status::toTER : type is error code"); @@ -102,23 +102,23 @@ public: } } - Strings const& + [[nodiscard]] Strings const& messages() const { return messages_; } /** Return the first message, if any. */ - std::string + [[nodiscard]] std::string message() const; - Type + [[nodiscard]] Type type() const { return type_; } - std::string + [[nodiscard]] std::string toString() const; /** Fill a Json::Value with an RPC 2.0 response. diff --git a/src/xrpld/rpc/detail/AssetCache.h b/src/xrpld/rpc/detail/AssetCache.h index 0709df2c5f..0597c729f1 100644 --- a/src/xrpld/rpc/detail/AssetCache.h +++ b/src/xrpld/rpc/detail/AssetCache.h @@ -20,7 +20,7 @@ public: explicit AssetCache(std::shared_ptr const& l, beast::Journal j); ~AssetCache(); - std::shared_ptr const& + [[nodiscard]] std::shared_ptr const& getLedger() const { return ledger_; @@ -75,7 +75,7 @@ private: direction_ == lhs.direction_; } - std::size_t + [[nodiscard]] std::size_t get_hash() const { return hash_value_; diff --git a/src/xrpld/rpc/detail/LegacyPathFind.h b/src/xrpld/rpc/detail/LegacyPathFind.h index 3d45bc9cfd..c9ac08f549 100644 --- a/src/xrpld/rpc/detail/LegacyPathFind.h +++ b/src/xrpld/rpc/detail/LegacyPathFind.h @@ -14,7 +14,7 @@ public: LegacyPathFind(bool isAdmin, Application& app); ~LegacyPathFind(); - bool + [[nodiscard]] bool isOk() const { return m_isOk; diff --git a/src/xrpld/rpc/detail/MPT.h b/src/xrpld/rpc/detail/MPT.h index 61dcb8fa7d..5cf2d5490f 100644 --- a/src/xrpld/rpc/detail/MPT.h +++ b/src/xrpld/rpc/detail/MPT.h @@ -25,17 +25,17 @@ public: { return mptID_; } - MPTID const& + [[nodiscard]] MPTID const& getMptID() const { return mptID_; } - bool + [[nodiscard]] bool isZeroBalance() const { return zeroBalance_; } - bool + [[nodiscard]] bool isMaxedOut() const { return maxedOut_; diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index 92b6d73050..85d5a62efc 100644 --- a/src/xrpld/rpc/detail/TransactionSign.cpp +++ b/src/xrpld/rpc/detail/TransactionSign.cpp @@ -86,33 +86,33 @@ public: { } - bool + [[nodiscard]] bool isMultiSigning() const { return multiSigningAcctID_ != nullptr; } - bool + [[nodiscard]] bool isSingleSigning() const { return !isMultiSigning(); } // When multi-signing we should not edit the tx_json fields. - bool + [[nodiscard]] bool editFields() const { return !isMultiSigning(); } - bool + [[nodiscard]] bool validMultiSign() const { return isMultiSigning() && multiSignPublicKey_ && !multiSignature_.empty(); } // Don't call this method unless isMultiSigning() returns true. - AccountID const& + [[nodiscard]] AccountID const& getSigner() const { if (multiSigningAcctID_ == nullptr) @@ -120,7 +120,7 @@ public: return *multiSigningAcctID_; } - PublicKey const& + [[nodiscard]] PublicKey const& getPublicKey() const { if (!multiSignPublicKey_) @@ -128,13 +128,13 @@ public: return *multiSignPublicKey_; } - Buffer const& + [[nodiscard]] Buffer const& getSignature() const { return multiSignature_; } - std::optional> const& + [[nodiscard]] std::optional> const& getSignatureTarget() const { return signatureTarget_; diff --git a/src/xrpld/rpc/detail/TrustLine.h b/src/xrpld/rpc/detail/TrustLine.h index 59fa2e73f3..176bea1759 100644 --- a/src/xrpld/rpc/detail/TrustLine.h +++ b/src/xrpld/rpc/detail/TrustLine.h @@ -47,7 +47,7 @@ protected: public: /** Returns the state map key for the ledger entry. */ - uint256 const& + [[nodiscard]] uint256 const& key() const { return key_; @@ -55,96 +55,96 @@ public: // VFALCO Take off the "get" from each function name - AccountID const& + [[nodiscard]] AccountID const& getAccountID() const { return mViewLowest ? mLowLimit.getIssuer() : mHighLimit.getIssuer(); } - AccountID const& + [[nodiscard]] AccountID const& getAccountIDPeer() const { return !mViewLowest ? mLowLimit.getIssuer() : mHighLimit.getIssuer(); } // True, Provided auth to peer. - bool + [[nodiscard]] bool getAuth() const { return (mFlags & (mViewLowest ? lsfLowAuth : lsfHighAuth)) != 0u; } - bool + [[nodiscard]] bool getAuthPeer() const { return (mFlags & (!mViewLowest ? lsfLowAuth : lsfHighAuth)) != 0u; } - bool + [[nodiscard]] bool getNoRipple() const { return (mFlags & (mViewLowest ? lsfLowNoRipple : lsfHighNoRipple)) != 0u; } - bool + [[nodiscard]] bool getNoRipplePeer() const { return (mFlags & (!mViewLowest ? lsfLowNoRipple : lsfHighNoRipple)) != 0u; } - LineDirection + [[nodiscard]] LineDirection getDirection() const { return getNoRipple() ? LineDirection::incoming : LineDirection::outgoing; } - LineDirection + [[nodiscard]] LineDirection getDirectionPeer() const { return getNoRipplePeer() ? LineDirection::incoming : LineDirection::outgoing; } /** Have we set the freeze flag on our peer */ - bool + [[nodiscard]] bool getFreeze() const { return (mFlags & (mViewLowest ? lsfLowFreeze : lsfHighFreeze)) != 0u; } /** Have we set the deep freeze flag on our peer */ - bool + [[nodiscard]] bool getDeepFreeze() const { return (mFlags & (mViewLowest ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u; } /** Has the peer set the freeze flag on us */ - bool + [[nodiscard]] bool getFreezePeer() const { return (mFlags & (!mViewLowest ? lsfLowFreeze : lsfHighFreeze)) != 0u; } /** Has the peer set the deep freeze flag on us */ - bool + [[nodiscard]] bool getDeepFreezePeer() const { return (mFlags & (!mViewLowest ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u; } - STAmount const& + [[nodiscard]] STAmount const& getBalance() const { return mBalance; } - STAmount const& + [[nodiscard]] STAmount const& getLimit() const { return mViewLowest ? mLowLimit : mHighLimit; } - STAmount const& + [[nodiscard]] STAmount const& getLimitPeer() const { return !mViewLowest ? mLowLimit : mHighLimit; @@ -192,13 +192,13 @@ public: RPCTrustLine(std::shared_ptr const& sle, AccountID const& viewAccount); - Rate const& + [[nodiscard]] Rate const& getQualityIn() const { return mViewLowest ? lowQualityIn_ : highQualityIn_; } - Rate const& + [[nodiscard]] Rate const& getQualityOut() const { return mViewLowest ? lowQualityOut_ : highQualityOut_; diff --git a/src/xrpld/rpc/detail/WSInfoSub.h b/src/xrpld/rpc/detail/WSInfoSub.h index 4042cd5479..ec85262f61 100644 --- a/src/xrpld/rpc/detail/WSInfoSub.h +++ b/src/xrpld/rpc/detail/WSInfoSub.h @@ -34,13 +34,13 @@ public: } } - std::string_view + [[nodiscard]] std::string_view user() const { return user_; } - std::string_view + [[nodiscard]] std::string_view forwarded_for() const { return fwdfor_; diff --git a/src/xrpld/rpc/handlers/server_info/ServerDefinitions.cpp b/src/xrpld/rpc/handlers/server_info/ServerDefinitions.cpp index 76f123f442..673d369690 100644 --- a/src/xrpld/rpc/handlers/server_info/ServerDefinitions.cpp +++ b/src/xrpld/rpc/handlers/server_info/ServerDefinitions.cpp @@ -42,13 +42,13 @@ private: public: ServerDefinitions(); - bool + [[nodiscard]] bool hashMatches(uint256 hash) const { return defsHash_ == hash; } - Json::Value const& + [[nodiscard]] Json::Value const& get() const { return defs_; diff --git a/src/xrpld/shamap/NodeFamily.h b/src/xrpld/shamap/NodeFamily.h index 3985a8bdf8..e0655292a0 100644 --- a/src/xrpld/shamap/NodeFamily.h +++ b/src/xrpld/shamap/NodeFamily.h @@ -30,7 +30,7 @@ public: return db_; } - NodeStore::Database const& + [[nodiscard]] NodeStore::Database const& db() const override { return db_;