mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
refactor: Replace std::optional<bilingual_str> with util::Result
This commit is contained in:
35
src/init.cpp
35
src/init.cpp
@@ -1023,15 +1023,17 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
|
||||
.chainparams = chainparams,
|
||||
.datadir = args.GetDataDirNet(),
|
||||
};
|
||||
if (const auto error{ApplyArgsManOptions(args, chainman_opts_dummy)}) {
|
||||
return InitError(*error);
|
||||
auto chainman_result{ApplyArgsManOptions(args, chainman_opts_dummy)};
|
||||
if (!chainman_result) {
|
||||
return InitError(util::ErrorString(chainman_result));
|
||||
}
|
||||
BlockManager::Options blockman_opts_dummy{
|
||||
.chainparams = chainman_opts_dummy.chainparams,
|
||||
.blocks_dir = args.GetBlocksDirPath(),
|
||||
};
|
||||
if (const auto error{ApplyArgsManOptions(args, blockman_opts_dummy)}) {
|
||||
return InitError(*error);
|
||||
auto blockman_result{ApplyArgsManOptions(args, blockman_opts_dummy)};
|
||||
if (!blockman_result) {
|
||||
return InitError(util::ErrorString(blockman_result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1054,8 +1056,9 @@ static bool LockDataDirectory(bool probeOnly)
|
||||
bool AppInitSanityChecks(const kernel::Context& kernel)
|
||||
{
|
||||
// ********************************************************* Step 4: sanity checks
|
||||
if (auto error = kernel::SanityChecks(kernel)) {
|
||||
InitError(*error);
|
||||
auto result{kernel::SanityChecks(kernel)};
|
||||
if (!result) {
|
||||
InitError(util::ErrorString(result));
|
||||
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
|
||||
}
|
||||
|
||||
@@ -1230,9 +1233,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// Initialize addrman
|
||||
assert(!node.addrman);
|
||||
uiInterface.InitMessage(_("Loading P2P addresses…").translated);
|
||||
if (const auto error{LoadAddrman(*node.netgroupman, args, node.addrman)}) {
|
||||
return InitError(*error);
|
||||
}
|
||||
auto addrman{LoadAddrman(*node.netgroupman, args)};
|
||||
if (!addrman) return InitError(util::ErrorString(addrman));
|
||||
node.addrman = std::move(*addrman);
|
||||
}
|
||||
|
||||
assert(!node.banman);
|
||||
@@ -1434,13 +1437,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
.datadir = args.GetDataDirNet(),
|
||||
.adjusted_time_callback = GetAdjustedTime,
|
||||
};
|
||||
Assert(!ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
|
||||
Assert(ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
|
||||
|
||||
BlockManager::Options blockman_opts{
|
||||
.chainparams = chainman_opts.chainparams,
|
||||
.blocks_dir = args.GetBlocksDirPath(),
|
||||
};
|
||||
Assert(!ApplyArgsManOptions(args, blockman_opts)); // no error can happen, already checked in AppInitParameterInteraction
|
||||
Assert(ApplyArgsManOptions(args, blockman_opts)); // no error can happen, already checked in AppInitParameterInteraction
|
||||
|
||||
// cache size calculations
|
||||
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
|
||||
@@ -1463,8 +1466,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
.estimator = node.fee_estimator.get(),
|
||||
.check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0,
|
||||
};
|
||||
if (const auto err{ApplyArgsManOptions(args, chainparams, mempool_opts)}) {
|
||||
return InitError(*err);
|
||||
auto result{ApplyArgsManOptions(args, chainparams, mempool_opts)};
|
||||
if (!result) {
|
||||
return InitError(util::ErrorString(result));
|
||||
}
|
||||
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
|
||||
|
||||
@@ -1563,8 +1567,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// If reindex-chainstate was specified, delay syncing indexes until ThreadImport has reindexed the chain
|
||||
if (!fReindexChainState) g_indexes_ready_to_sync = true;
|
||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
|
||||
if (const auto error{WITH_LOCK(cs_main, return CheckLegacyTxindex(*Assert(chainman.m_blockman.m_block_tree_db)))}) {
|
||||
return InitError(*error);
|
||||
auto result{WITH_LOCK(cs_main, return CheckLegacyTxindex(*Assert(chainman.m_blockman.m_block_tree_db)))};
|
||||
if (!result) {
|
||||
return InitError(util::ErrorString(result));
|
||||
}
|
||||
|
||||
g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, fReindex);
|
||||
|
||||
Reference in New Issue
Block a user