Skip to content

Commit f5bd46a

Browse files
committed
Merge #20125: rpc, wallet: Expose database format in getwalletinfo
624bab0 test: add coverage for getwalletinfo format field (Jon Atack) 5e737a0 rpc, wallet: Expose database format in getwalletinfo (João Barbosa) Pull request description: Support for sqlite based wallets was added in #19077. This PR adds the `format` key in `getwalletinfo` response, that can be `bdb` or `sqlite`. ACKs for top commit: jonatack: Tested ACK 624bab0 laanwj: Code review ACK 624bab0. MarcoFalke: doesn't hurt ACK 624bab0 hebasto: ACK 624bab0, tested on Linux Mint 20 (x86_64). meshcollider: utACK 624bab0 Tree-SHA512: a81f8530f040f6381d33e073a65f281993eccfa717424ab6e651c1203cbaf27794dcb7175570459e7fdaa211565bc060d0a3ecbe70d2b6f9c49b8d5071e4441c
2 parents 4538501 + 624bab0 commit f5bd46a

File tree

7 files changed

+13
-2
lines changed

7 files changed

+13
-2
lines changed

src/wallet/bdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class BerkeleyDatabase : public WalletDatabase
146146
/** Return path to main database filename */
147147
std::string Filename() override { return (env->Directory() / strFile).string(); }
148148

149+
std::string Format() override { return "bdb"; }
149150
/**
150151
* Pointer to shared database environment.
151152
*

src/wallet/db.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class WalletDatabase
144144
/** Return path to main database file for logs and error messages. */
145145
virtual std::string Filename() = 0;
146146

147+
virtual std::string Format() = 0;
148+
147149
std::atomic<unsigned int> nUpdateCounter;
148150
unsigned int nLastSeen;
149151
unsigned int nLastFlushed;
@@ -190,6 +192,7 @@ class DummyDatabase : public WalletDatabase
190192
void IncrementUpdateCounter() override { ++nUpdateCounter; }
191193
void ReloadDbEnv() override {}
192194
std::string Filename() override { return "dummy"; }
195+
std::string Format() override { return "dummy"; }
193196
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return MakeUnique<DummyBatch>(); }
194197
};
195198

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,7 @@ static RPCHelpMan getwalletinfo()
24222422
{
24232423
{RPCResult::Type::STR, "walletname", "the wallet name"},
24242424
{RPCResult::Type::NUM, "walletversion", "the wallet version"},
2425+
{RPCResult::Type::STR, "format", "the database format (bdb or sqlite)"},
24252426
{RPCResult::Type::STR_AMOUNT, "balance", "DEPRECATED. Identical to getbalances().mine.trusted"},
24262427
{RPCResult::Type::STR_AMOUNT, "unconfirmed_balance", "DEPRECATED. Identical to getbalances().mine.untrusted_pending"},
24272428
{RPCResult::Type::STR_AMOUNT, "immature_balance", "DEPRECATED. Identical to getbalances().mine.immature"},
@@ -2465,6 +2466,7 @@ static RPCHelpMan getwalletinfo()
24652466
int64_t kp_oldest = pwallet->GetOldestKeyPoolTime();
24662467
obj.pushKV("walletname", pwallet->GetName());
24672468
obj.pushKV("walletversion", pwallet->GetVersion());
2469+
obj.pushKV("format", pwallet->GetDatabase().Format());
24682470
obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted));
24692471
obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending));
24702472
obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature));

src/wallet/scriptpubkeyman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WalletStorage
3333
public:
3434
virtual ~WalletStorage() = default;
3535
virtual const std::string GetDisplayName() const = 0;
36-
virtual WalletDatabase& GetDatabase() = 0;
36+
virtual WalletDatabase& GetDatabase() const = 0;
3737
virtual bool IsWalletFlagSet(uint64_t) const = 0;
3838
virtual void UnsetBlankWalletFlag(WalletBatch&) = 0;
3939
virtual bool CanSupportFeature(enum WalletFeature) const = 0;

src/wallet/sqlite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class SQLiteDatabase : public WalletDatabase
105105
void IncrementUpdateCounter() override { ++nUpdateCounter; }
106106

107107
std::string Filename() override { return m_file_path; }
108+
std::string Format() override { return "sqlite"; }
108109

109110
/** Make a SQLiteBatch connected to this database */
110111
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
739739
{
740740
return *database;
741741
}
742-
WalletDatabase& GetDatabase() override { return *database; }
742+
WalletDatabase& GetDatabase() const override { return *database; }
743743

744744
/**
745745
* Select a set of coins such that nValueRet >= nTargetValue and at least

test/functional/wallet_descriptor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def skip_test_if_missing_module(self):
2121
self.skip_if_no_wallet()
2222

2323
def run_test(self):
24+
wallet_info = self.nodes[0].getwalletinfo()
25+
assert_equal(wallet_info['format'], 'bdb')
26+
2427
# Make a descriptor wallet
2528
self.log.info("Making a descriptor wallet")
2629
self.nodes[0].createwallet(wallet_name="desc1", descriptors=True)
@@ -29,6 +32,7 @@ def run_test(self):
2932
# A descriptor wallet should have 100 addresses * 3 types = 300 keys
3033
self.log.info("Checking wallet info")
3134
wallet_info = self.nodes[0].getwalletinfo()
35+
assert_equal(wallet_info['format'], 'sqlite')
3236
assert_equal(wallet_info['keypoolsize'], 300)
3337
assert_equal(wallet_info['keypoolsize_hd_internal'], 300)
3438
assert 'keypoololdest' not in wallet_info

0 commit comments

Comments
 (0)