diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -35,6 +35,7 @@ enum class OutputType; struct CRecipient; struct TxId; +struct bilingual_str; namespace interfaces { @@ -156,7 +157,7 @@ createTransaction(const std::vector &recipients, const CCoinControl &coin_control, bool sign, int &change_pos, Amount &fee, - std::string &fail_reason) = 0; + bilingual_str &fail_reason) = 0; //! Commit transaction. virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -235,7 +235,7 @@ createTransaction(const std::vector &recipients, const CCoinControl &coin_control, bool sign, int &change_pos, Amount &fee, - std::string &fail_reason) override { + bilingual_str &fail_reason) override { auto locked_chain = m_wallet->chain().lock(); LOCK(m_wallet->cs_wallet); CTransactionRef tx; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -15,6 +15,7 @@ #include #include #include // for GetBoolArg +#include #include #include @@ -197,12 +198,11 @@ Amount nFeeRequired = Amount::zero(); int nChangePosRet = -1; - std::string strFailReason; + bilingual_str error; auto &newTx = transaction.getWtx(); - newTx = - m_wallet->createTransaction(vecSend, coinControl, true /* sign */, - nChangePosRet, nFeeRequired, strFailReason); + newTx = m_wallet->createTransaction(vecSend, coinControl, true /* sign */, + nChangePosRet, nFeeRequired, error); transaction.setTransactionFee(nFeeRequired); if (fSubtractFeeFromAmount && newTx) { transaction.reassignAmounts(nChangePosRet); @@ -212,7 +212,8 @@ if (!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance) { return SendCoinsReturn(AmountWithFeeExceedsBalance); } - Q_EMIT message(tr("Send Coins"), QString::fromStdString(strFailReason), + Q_EMIT message(tr("Send Coins"), + QString::fromStdString(error.translated), CClientUIInterface::MSG_ERROR); return TransactionCreationFailed; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -377,7 +377,7 @@ // Create and send the transaction Amount nFeeRequired; - std::string strError; + bilingual_str error; std::vector vecSend; int nChangePosRet = -1; CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; @@ -386,13 +386,13 @@ CCoinControl coinControl; CTransactionRef tx; if (!pwallet->CreateTransaction(locked_chain, vecSend, tx, nFeeRequired, - nChangePosRet, strError, coinControl)) { + nChangePosRet, error, coinControl)) { if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { - strError = strprintf("Error: This transaction requires a " - "transaction fee of at least %s", - FormatMoney(nFeeRequired)); + error = strprintf(Untranslated("Error: This transaction requires a " + "transaction fee of at least %s"), + FormatMoney(nFeeRequired)); } - throw JSONRPCError(RPC_WALLET_ERROR, strError); + throw JSONRPCError(RPC_WALLET_ERROR, error.original); } pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); return tx; @@ -1065,14 +1065,14 @@ // Send Amount nFeeRequired = Amount::zero(); int nChangePosRet = -1; - std::string strFailReason; + bilingual_str error; CTransactionRef tx; CCoinControl coinControl; bool fCreated = pwallet->CreateTransaction(*locked_chain, vecSend, tx, nFeeRequired, - nChangePosRet, strFailReason, coinControl); + nChangePosRet, error, coinControl); if (!fCreated) { - throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); + throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); } pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); return tx->GetId().GetHex(); @@ -3670,12 +3670,12 @@ setSubtractFeeFromOutputs.insert(pos); } - std::string strFailReason; + bilingual_str error; - if (!pwallet->FundTransaction(tx, fee_out, change_position, strFailReason, + if (!pwallet->FundTransaction(tx, fee_out, change_position, error, lockUnspents, setSubtractFeeFromOutputs, coinControl)) { - throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); + throw JSONRPCError(RPC_WALLET_ERROR, error.original); } } diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -521,7 +522,7 @@ CTransactionRef tx; Amount fee; int changePos = -1; - std::string error; + bilingual_str error; CCoinControl dummy; { auto locked_chain = m_chain->lock(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1054,7 +1054,7 @@ * CreateTransaction(); */ bool FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, - int &nChangePosInOut, std::string &strFailReason, + int &nChangePosInOut, bilingual_str &error, bool lockUnspents, const std::set &setSubtractFeeFromOutputs, CCoinControl coinControl); @@ -1070,7 +1070,7 @@ bool CreateTransaction(interfaces::Chain::Lock &locked_chain, const std::vector &vecSend, CTransactionRef &tx, Amount &nFeeRet, - int &nChangePosInOut, std::string &strFailReason, + int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign = true); /** * Submit the transaction to the node's mempool and then relay to peers. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include