util::Result

The util::Result class provides a standard way for functions to return either error messages or result values.

Synopsis

Declared in <util/result.h>

template<class M>
class Result;

Description

It is intended for high-level functions that need to report error strings to end users. Lower-level functions that don't need this error-reporting and that only need error-handling should avoid util::Result and instead use util::Expected, std::optional, std::variant, or custom structs and enum types to return function results.

Usage examples can be found in

general code returning util::Result<T> values is very similar to code returning std::optional<T> values. Existing functions returning std::optional<T> can be updated to return util::Result<T> and return error strings usually just replacing return std::nullopt; with `return util::Error{error_string};`.

Member Functions

NameDescription
Result [constructor]Constructors
~Result [destructor]Destroys the result and its held value or error message.
has_value std::optional methods, so functions returning optional<T> can change to return Result<T> with minimal changes to existing code, and vice versa.
operator* Dereferences the held value.
operator-> Member access to the held value.
value Accesses the held value; asserts that the result holds a value.
value_or value_or overloads
operator bool Tests whether the result holds a value.

Friends

NameDescription
util::ErrorStringExtracts the error message from a result.

Non-Member Functions

NameDescription
ErrorStringExtracts the error message from a result.
::ApplyArgsManOptionsOverlay the options set in argsman on top of corresponding members in mempool_opts. Returns an error if one was encountered.
::DecodeBase64PSBTDecode a base64-encoded PSBT into a PartiallySignedTransaction.
::DecodeRawPSBTDecode a raw binary PSBT into a PartiallySignedTransaction.
::LoadAddrmanLoads the address manager (peers.dat), creating a fresh one if needed.
::SighashFromStrParse a signature-hash type from its textual name.
::init::SetLoggingCategoriesEnables or disables the debug logging categories selected by the arguments.
::init::SetLoggingLevelSets the global logging severity level selected by the arguments.
::kernel::SanityChecksEnsure a usable environment with all necessary library support.
::node::ApplyArgsManOptionsApply block-storage options taken from the argument manager.
::node::ApplyArgsManOptionsApply chainstate-manager options taken from the argument manager.
::node::CheckMiningOptionsCheck option values for validity. Returns an error for invalid values.
::node::ReadMiningArgsRead the mining options set in args. Returns an error if one was encountered.
::wallet::AttemptSelectionAttempt to find a valid input set that preserves privacy by not mixing OutputTypes. ChooseSelectionResult() will be called on each OutputType individually and the best the solution (according to the waste metric) will be chosen. If a valid input cannot be found from any single OutputType, fallback to running ChooseSelectionResult() over all available coins.
::wallet::AutomaticCoinSelectionSelect a set of coins such that nTargetValue is met; never select unconfirmed coins if they are not ours
::wallet::ChooseSelectionResultAttempt to find a valid input set that meets the provided eligibility filter and target. Multiple coin selection algorithms will be run and the input set that produces the least waste (according to the waste metric) will be chosen.
::wallet::CoinGrinderSelect coins using the CoinGrinder deterministic search algorithm.
::wallet::CreateTransactionCreate a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also create the change output, when needed
::wallet::ExportWatchOnlyWalletMake a new watchonly wallet file containing the public descriptors from this wallet The exported watchonly wallet file will be named and placed at the path specified in 'destination'
::wallet::FetchSelectedInputsFetch and validate coin control selected inputs. Coins could be internal (from the wallet) or external.
::wallet::FundTransactionInsert additional inputs into the transaction by calling CreateTransaction();
::wallet::GetWalletPathDetermine the path that the wallet is stored in
::wallet::KnapsackSolverSelect coins using the original Knapsack approximation, used as a fallback.
::wallet::MigrateLegacyToDescriptorDo all steps to migrate a legacy wallet to a descriptor wallet
::wallet::MigrateLegacyToDescriptorRequirement: The wallet provided to this function must be isolated, with no attachment to the node's context.
::wallet::SelectCoinsSelect all coins from coin_control, and if coin_control 'm_allow_other_inputs=true', call 'AutomaticCoinSelection' to select a set of coins such that nTargetValue - pre_set_inputs.total_amount is met.
::wallet::SelectCoinsBnBSelect coins using the Branch and Bound algorithm to find a changeless solution.
::wallet::SelectCoinsSRDSelect coins by Single Random Draw (SRD). SRD selects eligible OutputGroups from a shuffled ordering until the effective value of the input set suffices to create the recipient outputs and a change output with an amount of at least CHANGE_LOWER. While the maximum selection weight is exceeded during selection, the OutputGroup with the lowest effective value is dropped from the selection before additional OutputGroups are selected. Due to this greedy approach, SRD can fail to discover possible solutions in pathological cases.