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

Name

Description

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

Name

Description

util::ErrorString

Extracts the error message from a result.

Non-Member Functions

Name

Description

ErrorString

Extracts the error message from a result.

::ApplyArgsManOptions

Overlay the options set in argsman on top of corresponding members in mempool_opts. Returns an error if one was encountered.

::DecodeBase64PSBT

Decode a base64‐encoded PSBT into a PartiallySignedTransaction.

::DecodeRawPSBT

Decode a raw binary PSBT into a PartiallySignedTransaction.

::LoadAddrman

Loads the address manager (peers.dat), creating a fresh one if needed.

::SighashFromStr

Parse a signature‐hash type from its textual name.

::init::SetLoggingCategories

Enables or disables the debug logging categories selected by the arguments.

::init::SetLoggingLevel

Sets the global logging severity level selected by the arguments.

::kernel::SanityChecks

Ensure a usable environment with all necessary library support.

::node::ApplyArgsManOptions

Apply block‐storage options taken from the argument manager.

::node::ApplyArgsManOptions

Apply chainstate‐manager options taken from the argument manager.

::node::CheckMiningOptions

Check option values for validity. Returns an error for invalid values.

::node::ReadMiningArgs

Read the mining options set in args. Returns an error if one was encountered.

::wallet::AttemptSelection

Attempt 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::AutomaticCoinSelection

Select a set of coins such that nTargetValue is met; never select unconfirmed coins if they are not ours

::wallet::ChooseSelectionResult

Attempt 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::CoinGrinder

Select coins using the CoinGrinder deterministic search algorithm.

::wallet::CreateTransaction

Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also create the change output, when needed

::wallet::ExportWatchOnlyWallet

Make 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::FetchSelectedInputs

Fetch and validate coin control selected inputs. Coins could be internal (from the wallet) or external.

::wallet::FundTransaction

Insert additional inputs into the transaction by calling CreateTransaction();

::wallet::GetWalletPath

Determine the path that the wallet is stored in

::wallet::KnapsackSolver

Select coins using the original Knapsack approximation, used as a fallback.

::wallet::MigrateLegacyToDescriptor

Do all steps to migrate a legacy wallet to a descriptor wallet

::wallet::MigrateLegacyToDescriptor

Requirement: The wallet provided to this function must be isolated, with no attachment to the node's context.

::wallet::SelectCoins

Select 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::SelectCoinsBnB

Select coins using the Branch and Bound algorithm to find a changeless solution.

::wallet::SelectCoinsSRD

Select 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.

Created with MrDocs