Skip to content

Commit b8251d2

Browse files
meshcollidervijaydasmp
authored andcommitted
Merge bitcoin#22337: wallet: Use bilingual_str for errors
92993aa Change SignTransaction's input_errors to use bilingual_str (Andrew Chow) 171366e Use bilingual_str for address fetching functions (Andrew Chow) 9571c69 Add bilingual_str::clear() (Andrew Chow) Pull request description: In a couple of places in the wallet, errors are `std::string`. In order for these errors to be translated, change them to use `bilingual_str`. ACKs for top commit: hebasto: re-ACK 92993aa, only rebased since my [previous](bitcoin#22337 (review)) review, verified with klementtan: Code review ACK 92993aa meshcollider: Code review ACK 92993aa Tree-SHA512: 5400e419dd87db8c49b67ed0964de2d44b58010a566ca246f2f0760ed9ef6a9b6f6df7a6adcb211b315b74c727bfe8c7d07eb5690b5922fa5828ceef4c83461f
1 parent e9690cf commit b8251d2

23 files changed

+85
-69
lines changed

src/coinjoin/client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,14 @@ bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& acti
638638

639639
// fill values for found outpoints
640640
m_wallet.chain().findCoins(coins);
641-
std::map<int, std::string> signing_errors;
641+
std::map<int, bilingual_str> signing_errors;
642642
m_wallet.SignTransaction(finalMutableTransaction, coins, SIGHASH_ALL | SIGHASH_ANYONECANPAY, signing_errors);
643643

644644
for (const auto& [input_index, error_string] : signing_errors) {
645645
// NOTE: this is a partial signing so it's expected for SignTransaction to return
646646
// "Input not found or already spent" errors for inputs that aren't ours
647-
if (error_string != "Input not found or already spent") {
648-
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- signing input %d failed: %s!\n", __func__, input_index, error_string);
647+
if (error_string.original != "Input not found or already spent") {
648+
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- signing input %d failed: %s!\n", __func__, input_index, error_string.original);
649649
UnlockCoins();
650650
keyHolderStorage.ReturnAll();
651651
SetNull();

src/interfaces/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Chain
198198
virtual bool broadcastTransaction(const CTransactionRef& tx,
199199
const CAmount& max_tx_fee,
200200
bool relay,
201-
std::string& err_string) = 0;
201+
bilingual_str& err_string) = 0;
202202

203203
//! Calculate mempool ancestor and descendant counts for the given transaction.
204204
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0;

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ class ChainImpl : public Chain
878878
auto it = m_node.mempool->GetIter(txid);
879879
return it && (*it)->GetCountWithDescendants() > 1;
880880
}
881-
bool broadcastTransaction(const CTransactionRef& tx, const CAmount& max_tx_fee, bool relay, std::string& err_string) override
881+
bool broadcastTransaction(const CTransactionRef& tx, const CAmount& max_tx_fee, bool relay, bilingual_str& err_string) override
882882
{
883883
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback*/ false);
884884
// Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.

src/node/transaction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <validationinterface.h>
1414
#include <node/context.h>
1515
#include <node/transaction.h>
16+
#include <util/translation.h>
1617

1718
#include <future>
1819

@@ -28,7 +29,7 @@ static TransactionError HandleATMPError(const TxValidationState& state, std::str
2829
}
2930
}
3031

31-
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback, bool bypass_limits)
32+
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, bilingual_str& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback, bool bypass_limits)
3233
{
3334
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
3435
// node.peerman is assigned both before chain clients and before RPC server is accepting calls,
@@ -59,7 +60,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
5960
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx,
6061
bypass_limits, true /* test_accept */);
6162
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
62-
return HandleATMPError(result.m_state, err_string);
63+
return HandleATMPError(result.m_state, err_string.original);
6364
} else if (result.m_base_fees.value() > max_tx_fee) {
6465
return TransactionError::MAX_FEE_EXCEEDED;
6566
}
@@ -68,7 +69,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
6869
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx,
6970
bypass_limits, false /* test_accept */);
7071
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
71-
return HandleATMPError(result.m_state, err_string);
72+
return HandleATMPError(result.m_state, err_string.original);
7273
}
7374

7475
// Transaction was accepted to the mempool.

src/node/transaction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
3535
*
3636
* @param[in] node reference to node context
3737
* @param[in] tx the transaction to broadcast
38-
* @param[out] err_string reference to std::string to fill with error string if available
38+
* @param[out] err_string reference to bilingual_str to fill with error string if available
3939
* @param[in] relay flag if both mempool insertion and p2p relay are requested
4040
* @param[in] wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
4141
* return error
4242
*/
43-
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false);
43+
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, bilingual_str& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false);
4444

4545
/**
4646
* Return transaction with a given hash.

src/qt/psbtoperationsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void PSBTOperationsDialog::broadcastTransaction()
100100
}
101101

102102
CTransactionRef tx = MakeTransactionRef(mtx);
103-
std::string err_string;
103+
bilingual_str err_string;
104104
TransactionError error = BroadcastTransaction(
105105
*m_client_model->node().context(), tx, err_string, DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK(), /* relay */ true, /* await_callback */ false);
106106

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <util/moneystr.h>
4242
#include <util/strencodings.h>
4343
#include <util/string.h>
44+
#include <util/translation.h>
4445
#include <validation.h>
4546
#include <validationinterface.h>
4647
#include <util/irange.h>
@@ -1164,12 +1165,12 @@ RPCHelpMan sendrawtransaction()
11641165

11651166
bool bypass_limits = false;
11661167
if (!request.params[3].isNull()) bypass_limits = request.params[3].get_bool();
1167-
std::string err_string;
1168+
bilingual_str err_string;
11681169
AssertLockNotHeld(cs_main);
11691170
NodeContext& node = EnsureAnyNodeContext(request.context);
11701171
const TransactionError err = BroadcastTransaction(node, tx, err_string, max_raw_tx_fee, /* relay */ true, /* wait_callback */ true, bypass_limits);
11711172
if (TransactionError::OK != err) {
1172-
throw JSONRPCTransactionError(err, err_string);
1173+
throw JSONRPCTransactionError(err, err_string.original);
11731174
}
11741175

11751176
return tx->GetHash().GetHex();

src/rpc/rawtransaction_util.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <util/strencodings.h>
1919
#include <validation.h>
2020
#include <txmempool.h>
21+
#include <util/translation.h>
2122

2223
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime)
2324
{
@@ -227,22 +228,22 @@ void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
227228
int nHashType = ParseSighashString(hashType);
228229

229230
// Script verification errors
230-
std::map<int, std::string> input_errors;
231+
std::map<int, bilingual_str> input_errors;
231232

232233
bool complete = SignTransaction(mtx, keystore, coins, nHashType, input_errors);
233234
SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
234235
}
235236

236-
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, std::string>& input_errors, UniValue& result)
237+
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result)
237238
{
238239
// Make errors UniValue
239240
UniValue vErrors(UniValue::VARR);
240241
for (const auto& err_pair : input_errors) {
241-
if (err_pair.second == "Missing amount") {
242+
if (err_pair.second.original == "Missing amount") {
242243
// This particular error needs to be an exception for some reason
243244
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing amount for %s", coins.at(mtx.vin.at(err_pair.first).prevout).out.ToString()));
244245
}
245-
TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second);
246+
TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second.original);
246247
}
247248

248249
result.pushKV("hex", EncodeHexTx(CTransaction(mtx)));

src/rpc/rawtransaction_util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <map>
99
#include <string>
1010

11+
struct bilingual_str;
1112
class FillableSigningProvider;
1213
class UniValue;
1314
struct CMutableTransaction;
@@ -25,7 +26,7 @@ class SigningProvider;
2526
* @param result JSON object where signed transaction results accumulate
2627
*/
2728
void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result);
28-
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, std::string>& input_errors, UniValue& result);
29+
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result);
2930

3031
/**
3132
* Parse a prevtxs UniValue array and get the map of coins from it

src/script/sign.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <script/signingprovider.h>
1212
#include <script/standard.h>
1313
#include <uint256.h>
14+
#include <util/translation.h>
1415

1516
typedef std::vector<unsigned char> valtype;
1617

@@ -385,7 +386,7 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
385386
return false;
386387
}
387388

388-
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, int nHashType, std::map<int, std::string>& input_errors)
389+
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, int nHashType, std::map<int, bilingual_str>& input_errors)
389390
{
390391
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
391392

@@ -397,7 +398,7 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
397398
CTxIn& txin = mtx.vin[i];
398399
auto coin = coins.find(txin.prevout);
399400
if (coin == coins.end() || coin->second.IsSpent()) {
400-
input_errors[i] = "Input not found or already spent";
401+
input_errors[i] = _("Input not found or already spent");
401402
continue;
402403
}
403404
const CScript& prevPubKey = coin->second.out.scriptPubKey;
@@ -415,12 +416,12 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
415416
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount), &serror)) {
416417
if (serror == SCRIPT_ERR_INVALID_STACK_OPERATION) {
417418
// Unable to sign input and verification failed (possible attempt to partially sign).
418-
input_errors[i] = "Unable to sign input, invalid stack size (possibly missing key)";
419+
input_errors[i] = Untranslated("Unable to sign input, invalid stack size (possibly missing key)");
419420
} else if (serror == SCRIPT_ERR_SIG_NULLFAIL) {
420421
// Verification failed (possibly due to insufficient signatures).
421-
input_errors[i] = "CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)";
422+
input_errors[i] = Untranslated("CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)");
422423
} else {
423-
input_errors[i] = ScriptErrorString(serror);
424+
input_errors[i] = Untranslated(ScriptErrorString(serror));
424425
}
425426
} else {
426427
// If this input succeeds, make sure there is no error set for it

0 commit comments

Comments
 (0)