Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelsadeeq committed Sep 5, 2024
1 parent a74bdee commit 5de2906
Show file tree
Hide file tree
Showing 28 changed files with 266 additions and 190 deletions.
3 changes: 2 additions & 1 deletion src/dummywallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ArgsManager;

namespace interfaces {
class Chain;
class Settings;
class Handler;
class Wallet;
class WalletLoader;
Expand Down Expand Up @@ -61,7 +62,7 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();

namespace interfaces {

std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args)
std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args, Settings& settings)
{
throw std::logic_error("Wallet function called in non-wallet build.");
}
Expand Down
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <index/txindex.h>
#include <init/common.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <interfaces/init.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
Expand Down Expand Up @@ -1132,6 +1133,7 @@ bool AppInitInterfaces(NodeContext& node)
{
node.chain = node.init->makeChain();
node.mining = node.init->makeMining();
node.settings = node.init->makeSettings();
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions src/init/bitcoin-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
#include <interfaces/ipc.h>
Expand All @@ -28,9 +29,10 @@ class BitcoinGuiInit : public interfaces::Init
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
std::unique_ptr<interfaces::Settings> makeSettings() override { return interfaces::MakeSettings(m_node); }
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain, interfaces::Settings& settings) override
{
return MakeWalletLoader(chain, *Assert(m_node.args));
return MakeWalletLoader(chain, *Assert(m_node.args), settings);
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); }
Expand Down
6 changes: 4 additions & 2 deletions src/init/bitcoin-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
#include <interfaces/ipc.h>
Expand All @@ -30,10 +31,11 @@ class BitcoinNodeInit : public interfaces::Init
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
std::unique_ptr<interfaces::Settings> makeSettings() override { return interfaces::MakeSettings(m_node); }
std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain, interfaces::Settings& settings) override
{
return MakeWalletLoader(chain, *Assert(m_node.args));
return MakeWalletLoader(chain, *Assert(m_node.args), settings);
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); }
Expand Down
6 changes: 4 additions & 2 deletions src/init/bitcoin-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
#include <interfaces/mining.h>
Expand All @@ -26,10 +27,11 @@ class BitcoinQtInit : public interfaces::Init
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
std::unique_ptr<interfaces::Settings> makeSettings() override { return interfaces::MakeSettings(m_node); }
std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain, interfaces::Settings& settings) override
{
return MakeWalletLoader(chain, *Assert(m_node.args));
return MakeWalletLoader(chain, *Assert(m_node.args), settings);
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
node::NodeContext m_node;
Expand Down
5 changes: 3 additions & 2 deletions src/init/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
#include <interfaces/mining.h>
Expand All @@ -29,9 +30,9 @@ class BitcoindInit : public interfaces::Init
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain, interfaces::Settings& settings) override
{
return MakeWalletLoader(chain, *Assert(m_node.args));
return MakeWalletLoader(chain, *Assert(m_node.args), settings);
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
NodeContext& m_node;
Expand Down
31 changes: 0 additions & 31 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ struct BlockInfo {
BlockInfo(const uint256& hash LIFETIMEBOUND) : hash(hash) {}
};

//! The action to be taken after updating a settings value.
//! WRITE indicates that the updated value must be written to disk,
//! while SKIP_WRITE indicates that the change will be kept in memory-only
//! without persisting it.
enum class SettingsAction {
WRITE,
SKIP_WRITE
};

using SettingsUpdate = std::function<std::optional<interfaces::SettingsAction>(common::SettingsValue&)>;

//! Interface giving clients (wallet processes, maybe other analysis tools in
//! the future) ability to access to the chain state, receive notifications,
//! estimate fees, and submit transactions.
Expand Down Expand Up @@ -346,26 +335,6 @@ class Chain
//! Run function after given number of seconds. Cancel any previous calls with same name.
virtual void rpcRunLater(const std::string& name, std::function<void()> fn, int64_t seconds) = 0;

//! Get settings value.
virtual common::SettingsValue getSetting(const std::string& arg) = 0;

//! Get list of settings values.
virtual std::vector<common::SettingsValue> getSettingsList(const std::string& arg) = 0;

//! Return <datadir>/settings.json setting value.
virtual common::SettingsValue getRwSetting(const std::string& name) = 0;

//! Updates a setting in <datadir>/settings.json.
//! Depending on the action returned by the update function, this will either
//! update the setting in memory or write the updated settings to disk.
virtual bool updateRwSetting(const std::string& name, const SettingsUpdate& update_function) = 0;

//! Replace a setting in <datadir>/settings.json with a new value.
virtual bool overwriteRwSetting(const std::string& name, common::SettingsValue& value, bool write = true) = 0;

//! Delete a given setting in <datadir>/settings.json.
virtual bool deleteRwSettings(const std::string& name, bool write = true) = 0;

//! Synchronously send transactionAddedToMempool notifications about all
//! current mempool transactions to the specified handler and return after
//! the last one is sent. These notifications aren't coordinated with async
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <interfaces/echo.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/settings.h>
#include <interfaces/wallet.h>

#include <memory>
Expand All @@ -33,8 +34,9 @@ class Init
virtual ~Init() = default;
virtual std::unique_ptr<Node> makeNode() { return nullptr; }
virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
virtual std::unique_ptr<Settings> makeSettings() { return nullptr; }
virtual std::unique_ptr<Mining> makeMining() { return nullptr; }
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain, Settings& settings) { return nullptr; }
virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
virtual Ipc* ipc() { return nullptr; }
};
Expand Down
18 changes: 0 additions & 18 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,6 @@ class Node
//! Return whether shutdown was requested.
virtual bool shutdownRequested() = 0;

//! Return whether a particular setting in <datadir>/settings.json is or
//! would be ignored because it is also specified in the command line.
virtual bool isSettingIgnored(const std::string& name) = 0;

//! Return setting value from <datadir>/settings.json or bitcoin.conf.
virtual common::SettingsValue getPersistentSetting(const std::string& name) = 0;

//! Update a setting in <datadir>/settings.json.
virtual void updateRwSetting(const std::string& name, const common::SettingsValue& value) = 0;

//! Force a setting value to be applied, overriding any other configuration
//! source, but not being persisted.
virtual void forceSetting(const std::string& name, const common::SettingsValue& value) = 0;

//! Clear all settings in <datadir>/settings.json and store a backup of
//! previous settings in <datadir>/settings.json.bak.
virtual void resetSettings() = 0;

//! Map port.
virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;

Expand Down
77 changes: 77 additions & 0 deletions src/interfaces/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2024 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_INTERFACES_SETTINGS_H
#define BITCOIN_INTERFACES_SETTINGS_H

#include <common/settings.h>

#include <memory>
#include <string>

namespace node {
struct NodeContext;
} // namespacce node
namespace interfaces {

//! The action to be taken after updating a settings value.
//! WRITE indicates that the updated value must be written to disk,
//! while SKIP_WRITE indicates that the change will be kept in memory-only
//! without persisting it.
enum class SettingsAction {
WRITE,
SKIP_WRITE
};

class Settings {
public:
virtual ~Settings() = default;

//! Get settings value.
virtual common::SettingsValue getSetting(const std::string& arg) = 0;

//! Get list of settings values.
virtual std::vector<common::SettingsValue> getSettingsList(const std::string& arg) = 0;

//! Return <datadir>/settings.json setting value.
virtual common::SettingsValue getRwSetting(const std::string& name) = 0;

//! Updates a setting in <datadir>/settings.json.
//! Depending on the action returned by the update function, this will either
//! update the setting in memory or write the updated settings to disk.
using SettingsUpdateFn =
std::function<std::optional<interfaces::SettingsAction>(common::SettingsValue&)>;
virtual bool updateRwSetting(const std::string& name, const SettingsUpdateFn& update_function) = 0;

//! Replace a setting in <datadir>/settings.json with a new value.
virtual bool overwriteRwSetting(const std::string& name, common::SettingsValue& value, bool write = true) = 0;

//! Delete a given setting in <datadir>/settings.json.
virtual bool deleteRwSettings(const std::string& name, bool write = true) = 0;

//! Clear all settings in <datadir>/settings.json and store a backup of
//! previous settings in <datadir>/settings.json.bak.
virtual void resetSettings() = 0;

//! Force a setting value to be applied, overriding any other configuration
//! source, but not being persisted.
virtual void forceSetting(const std::string& name, const common::SettingsValue& value) = 0;

//! Return whether a particular setting in <datadir>/settings.json is or
//! would be ignored because it is also specified in the command line.
virtual bool isSettingIgnored(const std::string& name) = 0;

//! Return setting value from <datadir>/settings.json or bitcoin.conf.
virtual common::SettingsValue getPersistentSetting(const std::string& name) = 0;

//! Update a setting in <datadir>/settings.json.
virtual void updateRwSetting(const std::string& name, const common::SettingsValue& value) = 0;
};

//! Return an implementation of Settings interface.
std::unique_ptr<Settings> MakeSettings(node::NodeContext& node);

} // namespace interfaces

#endif // BITCOIN_INTERFACES_SETTINGS_H
3 changes: 2 additions & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <common/signmessage.h>
#include <consensus/amount.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <pubkey.h>
#include <script/script.h>
#include <support/allocators/secure.h>
Expand Down Expand Up @@ -452,7 +453,7 @@ std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::sh

//! Return implementation of ChainClient interface for a wallet loader. This
//! function will be undefined in builds where ENABLE_WALLET is false.
std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args);
std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args, Settings& settings);

} // namespace interfaces

Expand Down
1 change: 1 addition & 0 deletions src/node/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <addrman.h>
#include <banman.h>
#include <interfaces/chain.h>
#include <interfaces/settings.h>
#include <interfaces/mining.h>
#include <kernel/context.h>
#include <key.h>
Expand Down
2 changes: 2 additions & 0 deletions src/node/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NetGroupManager;
class PeerManager;
namespace interfaces {
class Chain;
class Settings;
class ChainClient;
class Mining;
class Init;
Expand Down Expand Up @@ -71,6 +72,7 @@ struct NodeContext {
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct
std::unique_ptr<interfaces::Chain> chain;
std::unique_ptr<interfaces::Settings> settings;
//! List of all chain clients (wallet processes or other client) connected to node.
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
//! Reference to chain client that should used to load or create wallets
Expand Down
Loading

0 comments on commit 5de2906

Please sign in to comment.