Skip to content

Commit 171366e

Browse files
committed
Use bilingual_str for address fetching functions
For GetNewDestination, GetNewChangeDestination, and GetReservedDestination, use bilingual_str for errors
1 parent 9571c69 commit 171366e

File tree

10 files changed

+39
-36
lines changed

10 files changed

+39
-36
lines changed

src/test/util/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <outputtype.h>
99
#include <script/standard.h>
1010
#ifdef ENABLE_WALLET
11+
#include <util/translation.h>
1112
#include <wallet/wallet.h>
1213
#endif
1314

@@ -18,7 +19,7 @@ std::string getnewaddress(CWallet& w)
1819
{
1920
constexpr auto output_type = OutputType::BECH32;
2021
CTxDestination dest;
21-
std::string error;
22+
bilingual_str error;
2223
if (!w.GetNewDestination(output_type, "", dest, error)) assert(false);
2324

2425
return EncodeDestination(dest);

src/wallet/interfaces.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <uint256.h>
1717
#include <util/check.h>
1818
#include <util/system.h>
19+
#include <util/translation.h>
1920
#include <util/ui_change_type.h>
2021
#include <wallet/context.h>
2122
#include <wallet/feebumper.h>
@@ -130,7 +131,7 @@ class WalletImpl : public Wallet
130131
bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override
131132
{
132133
LOCK(m_wallet->cs_wallet);
133-
std::string error;
134+
bilingual_str error;
134135
return m_wallet->GetNewDestination(type, label, dest, error);
135136
}
136137
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ static RPCHelpMan getnewaddress()
275275
}
276276

277277
CTxDestination dest;
278-
std::string error;
278+
bilingual_str error;
279279
if (!pwallet->GetNewDestination(output_type, label, dest, error)) {
280-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error);
280+
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error.original);
281281
}
282282

283283
return EncodeDestination(dest);
@@ -322,9 +322,9 @@ static RPCHelpMan getrawchangeaddress()
322322
}
323323

324324
CTxDestination dest;
325-
std::string error;
325+
bilingual_str error;
326326
if (!pwallet->GetNewChangeDestination(output_type, dest, error)) {
327-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error);
327+
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error.original);
328328
}
329329
return EncodeDestination(dest);
330330
},

src/wallet/scriptpubkeyman.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
//! Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value. See BIP 32 for more details.
2121
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
2222

23-
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
23+
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error)
2424
{
2525
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
26-
error = _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types").translated;
26+
error = _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types");
2727
return false;
2828
}
2929
assert(type != OutputType::BECH32M);
@@ -34,7 +34,7 @@ bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestinat
3434
// Generate a new key that is added to wallet
3535
CPubKey new_key;
3636
if (!GetKeyFromPool(new_key, type)) {
37-
error = _("Error: Keypool ran out, please call keypoolrefill first").translated;
37+
error = _("Error: Keypool ran out, please call keypoolrefill first");
3838
return false;
3939
}
4040
LearnRelatedScripts(new_key, type);
@@ -295,22 +295,22 @@ bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBat
295295
return true;
296296
}
297297

298-
bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, std::string& error)
298+
bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error)
299299
{
300300
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
301-
error = _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types").translated;
301+
error = _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types");
302302
return false;
303303
}
304304
assert(type != OutputType::BECH32M);
305305

306306
LOCK(cs_KeyStore);
307307
if (!CanGetAddresses(internal)) {
308-
error = _("Error: Keypool ran out, please call keypoolrefill first").translated;
308+
error = _("Error: Keypool ran out, please call keypoolrefill first");
309309
return false;
310310
}
311311

312312
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
313-
error = _("Error: Keypool ran out, please call keypoolrefill first").translated;
313+
error = _("Error: Keypool ran out, please call keypoolrefill first");
314314
return false;
315315
}
316316
address = GetDestinationForKey(keypool.vchPubKey, type);
@@ -1613,11 +1613,11 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
16131613
return set_address;
16141614
}
16151615

1616-
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
1616+
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error)
16171617
{
16181618
// Returns true if this descriptor supports getting new addresses. Conditions where we may be unable to fetch them (e.g. locked) are caught later
16191619
if (!CanGetAddresses()) {
1620-
error = "No addresses available";
1620+
error = _("No addresses available");
16211621
return false;
16221622
}
16231623
{
@@ -1636,12 +1636,12 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
16361636
std::vector<CScript> scripts_temp;
16371637
if (m_wallet_descriptor.range_end <= m_max_cached_index && !TopUp(1)) {
16381638
// We can't generate anymore keys
1639-
error = "Error: Keypool ran out, please call keypoolrefill first";
1639+
error = _("Error: Keypool ran out, please call keypoolrefill first");
16401640
return false;
16411641
}
16421642
if (!m_wallet_descriptor.descriptor->ExpandFromCache(m_wallet_descriptor.next_index, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
16431643
// We can't generate anymore keys
1644-
error = "Error: Keypool ran out, please call keypoolrefill first";
1644+
error = _("Error: Keypool ran out, please call keypoolrefill first");
16451645
return false;
16461646
}
16471647

@@ -1721,7 +1721,7 @@ bool DescriptorScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, Walle
17211721
return true;
17221722
}
17231723

1724-
bool DescriptorScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, std::string& error)
1724+
bool DescriptorScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error)
17251725
{
17261726
LOCK(cs_desc_man);
17271727
bool result = GetNewDestination(type, address, error);

src/wallet/scriptpubkeyman.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ class ScriptPubKeyMan
174174
public:
175175
explicit ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {}
176176
virtual ~ScriptPubKeyMan() {};
177-
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
177+
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error) { return false; }
178178
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
179179

180180
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
181181
virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) { return false; }
182182
virtual bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) { return false; }
183183

184-
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, std::string& error) { return false; }
184+
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error) { return false; }
185185
virtual void KeepDestination(int64_t index, const OutputType& type) {}
186186
virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) {}
187187

@@ -355,13 +355,13 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
355355
public:
356356
using ScriptPubKeyMan::ScriptPubKeyMan;
357357

358-
bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) override;
358+
bool GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error) override;
359359
isminetype IsMine(const CScript& script) const override;
360360

361361
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
362362
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
363363

364-
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, std::string& error) override;
364+
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error) override;
365365
void KeepDestination(int64_t index, const OutputType& type) override;
366366
void ReturnDestination(int64_t index, bool internal, const CTxDestination&) override;
367367

@@ -559,13 +559,13 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
559559

560560
mutable RecursiveMutex cs_desc_man;
561561

562-
bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) override;
562+
bool GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error) override;
563563
isminetype IsMine(const CScript& script) const override;
564564

565565
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
566566
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
567567

568-
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, std::string& error) override;
568+
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error) override;
569569
void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) override;
570570

571571
// Tops up the descriptor cache and m_map_script_pub_keys. The cache is stored in the wallet file

src/wallet/spend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,9 @@ bool CWallet::CreateTransactionInternal(
618618
// Reserve a new key pair from key pool. If it fails, provide a dummy
619619
// destination in case we don't need change.
620620
CTxDestination dest;
621-
std::string dest_err;
621+
bilingual_str dest_err;
622622
if (!reservedest.GetReservedDestination(dest, true, dest_err)) {
623-
error = strprintf(_("Transaction needs a change address, but we can't generate it. %s"), dest_err);
623+
error = _("Transaction needs a change address, but we can't generate it.") + Untranslated(" ") + dest_err;
624624
}
625625
scriptChange = GetScriptForDestination(dest);
626626
// A valid destination implies a change script (and

src/wallet/test/coinselector_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <primitives/transaction.h>
88
#include <random.h>
99
#include <test/util/setup_common.h>
10+
#include <util/translation.h>
1011
#include <wallet/coincontrol.h>
1112
#include <wallet/coinselection.h>
1213
#include <wallet/test/wallet_test_fixture.h>
@@ -66,7 +67,7 @@ static void add_coin(CWallet& wallet, const CAmount& nValue, int nAge = 6*24, bo
6667
tx.vout[nInput].nValue = nValue;
6768
if (spendable) {
6869
CTxDestination dest;
69-
std::string error;
70+
bilingual_str error;
7071
const bool destination_ok = wallet.GetNewDestination(OutputType::BECH32, "", dest, error);
7172
assert(destination_ok);
7273
tx.vout[nInput].scriptPubKey = GetScriptForDestination(dest);

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
601601
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
602602
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
603603
CTxDestination dest;
604-
std::string error;
604+
bilingual_str error;
605605
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
606606
}
607607

src/wallet/wallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
21282128
return res;
21292129
}
21302130

2131-
bool CWallet::GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error)
2131+
bool CWallet::GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, bilingual_str& error)
21322132
{
21332133
LOCK(cs_wallet);
21342134
error.clear();
@@ -2138,7 +2138,7 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
21382138
spk_man->TopUp();
21392139
result = spk_man->GetNewDestination(type, dest, error);
21402140
} else {
2141-
error = strprintf(_("Error: No %s addresses available."), FormatOutputType(type)).translated;
2141+
error = strprintf(_("Error: No %s addresses available."), FormatOutputType(type));
21422142
}
21432143
if (result) {
21442144
SetAddressBook(dest, label, "receive");
@@ -2147,7 +2147,7 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
21472147
return result;
21482148
}
21492149

2150-
bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& dest, std::string& error)
2150+
bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& dest, bilingual_str& error)
21512151
{
21522152
LOCK(cs_wallet);
21532153
error.clear();
@@ -2200,11 +2200,11 @@ std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) co
22002200
return result;
22012201
}
22022202

2203-
bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool internal, std::string& error)
2203+
bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool internal, bilingual_str& error)
22042204
{
22052205
m_spk_man = pwallet->GetScriptPubKeyMan(type, internal);
22062206
if (!m_spk_man) {
2207-
error = strprintf(_("Error: No %s addresses available."), FormatOutputType(type)).translated;
2207+
error = strprintf(_("Error: No %s addresses available."), FormatOutputType(type));
22082208
return false;
22092209
}
22102210

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class ReserveDestination
183183
}
184184

185185
//! Reserve an address
186-
bool GetReservedDestination(CTxDestination& pubkey, bool internal, std::string& error);
186+
bool GetReservedDestination(CTxDestination& pubkey, bool internal, bilingual_str& error);
187187
//! Return reserved address
188188
void ReturnDestination();
189189
//! Keep the address. Do not return it's key to the keypool when this object goes out of scope
@@ -665,8 +665,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
665665
*/
666666
void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
667667

668-
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error);
669-
bool GetNewChangeDestination(const OutputType type, CTxDestination& dest, std::string& error);
668+
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, bilingual_str& error);
669+
bool GetNewChangeDestination(const OutputType type, CTxDestination& dest, bilingual_str& error);
670670

671671
isminetype IsMine(const CTxDestination& dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
672672
isminetype IsMine(const CScript& script) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);

0 commit comments

Comments
 (0)