mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Merge #18699: wallet: Avoid translating RPC errors
fa2cce4391
wallet: Remove trailing whitespace from potential translation strings (MarcoFalke)fa59cc1c97
wallet: Report full error message in wallettool (MarcoFalke)fae7776690
wallet: Avoid translating RPC errors when creating txs (MarcoFalke)fae51a5c6f
wallet: Avoid translating RPC errors when loading wallets (MarcoFalke) Pull request description: Common errors and warnings should be translated when displayed in the GUI, but not translated when displayed elsewhere. The wallet method `CreateWalletFromFile` does not know its caller, so this commit changes it to return a `bilingual_str` to the caller. Fixes #17072 ACKs for top commit: laanwj: ACKfa2cce4391
, checked that no new translation messages are added compared to master. hebasto: ACKfa2cce4391
Tree-SHA512: c6a943ae9c3689ea3c48c20d26de6e4970de0257a1f1eec57a2bded67a4af9dcc5c45b2d64659d6fb4c4bc4d8103e28483ea3d14bb850df8db0ff9e8e5c77ee2
This commit is contained in:
commit
23c926d859
26 changed files with 260 additions and 221 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
class CWallet;
|
class CWallet;
|
||||||
enum class WalletCreationStatus;
|
enum class WalletCreationStatus;
|
||||||
|
struct bilingual_str;
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Chain;
|
class Chain;
|
||||||
|
@ -72,12 +73,12 @@ std::vector<std::shared_ptr<CWallet>> GetWallets()
|
||||||
throw std::logic_error("Wallet function called in non-wallet build.");
|
throw std::logic_error("Wallet function called in non-wallet build.");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings)
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings)
|
||||||
{
|
{
|
||||||
throw std::logic_error("Wallet function called in non-wallet build.");
|
throw std::logic_error("Wallet function called in non-wallet build.");
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::shared_ptr<CWallet>& result)
|
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::shared_ptr<CWallet>& result)
|
||||||
{
|
{
|
||||||
throw std::logic_error("Wallet function called in non-wallet build.");
|
throw std::logic_error("Wallet function called in non-wallet build.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,8 @@ class CWallet;
|
||||||
fs::path GetWalletDir();
|
fs::path GetWalletDir();
|
||||||
std::vector<fs::path> ListWalletDir();
|
std::vector<fs::path> ListWalletDir();
|
||||||
std::vector<std::shared_ptr<CWallet>> GetWallets();
|
std::vector<std::shared_ptr<CWallet>> GetWallets();
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings);
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
||||||
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::shared_ptr<CWallet>& result);
|
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::shared_ptr<CWallet>& result);
|
||||||
std::unique_ptr<interfaces::Handler> HandleLoadWallet(interfaces::Node::LoadWalletFn load_wallet);
|
std::unique_ptr<interfaces::Handler> HandleLoadWallet(interfaces::Node::LoadWalletFn load_wallet);
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
|
@ -259,11 +259,11 @@ public:
|
||||||
}
|
}
|
||||||
return wallets;
|
return wallets;
|
||||||
}
|
}
|
||||||
std::unique_ptr<Wallet> loadWallet(const std::string& name, std::string& error, std::vector<std::string>& warnings) override
|
std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
|
||||||
{
|
{
|
||||||
return MakeWallet(LoadWallet(*m_context.chain, name, error, warnings));
|
return MakeWallet(LoadWallet(*m_context.chain, name, error, warnings));
|
||||||
}
|
}
|
||||||
std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, WalletCreationStatus& status) override
|
std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, WalletCreationStatus& status) override
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet;
|
std::shared_ptr<CWallet> wallet;
|
||||||
status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
|
status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
|
||||||
|
|
|
@ -27,9 +27,10 @@ class Coin;
|
||||||
class RPCTimerInterface;
|
class RPCTimerInterface;
|
||||||
class UniValue;
|
class UniValue;
|
||||||
class proxyType;
|
class proxyType;
|
||||||
|
enum class WalletCreationStatus;
|
||||||
struct CNodeStateStats;
|
struct CNodeStateStats;
|
||||||
struct NodeContext;
|
struct NodeContext;
|
||||||
enum class WalletCreationStatus;
|
struct bilingual_str;
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Handler;
|
class Handler;
|
||||||
|
@ -201,10 +202,10 @@ public:
|
||||||
//! Attempts to load a wallet from file or directory.
|
//! Attempts to load a wallet from file or directory.
|
||||||
//! The loaded wallet is also notified to handlers previously registered
|
//! The loaded wallet is also notified to handlers previously registered
|
||||||
//! with handleLoadWallet.
|
//! with handleLoadWallet.
|
||||||
virtual std::unique_ptr<Wallet> loadWallet(const std::string& name, std::string& error, std::vector<std::string>& warnings) = 0;
|
virtual std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
|
||||||
|
|
||||||
//! Create a wallet from file
|
//! Create a wallet from file
|
||||||
virtual std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, WalletCreationStatus& status) = 0;
|
virtual std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, WalletCreationStatus& status) = 0;
|
||||||
|
|
||||||
//! Register handler for init messages.
|
//! Register handler for init messages.
|
||||||
using InitMessageFn = std::function<void(const std::string& message)>;
|
using InitMessageFn = std::function<void(const std::string& message)>;
|
||||||
|
|
|
@ -219,7 +219,7 @@ public:
|
||||||
bool sign,
|
bool sign,
|
||||||
int& change_pos,
|
int& change_pos,
|
||||||
CAmount& fee,
|
CAmount& fee,
|
||||||
std::string& fail_reason) override
|
bilingual_str& fail_reason) override
|
||||||
{
|
{
|
||||||
LOCK(m_wallet->cs_wallet);
|
LOCK(m_wallet->cs_wallet);
|
||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
|
@ -248,7 +248,7 @@ public:
|
||||||
}
|
}
|
||||||
bool createBumpTransaction(const uint256& txid,
|
bool createBumpTransaction(const uint256& txid,
|
||||||
const CCoinControl& coin_control,
|
const CCoinControl& coin_control,
|
||||||
std::vector<std::string>& errors,
|
std::vector<bilingual_str>& errors,
|
||||||
CAmount& old_fee,
|
CAmount& old_fee,
|
||||||
CAmount& new_fee,
|
CAmount& new_fee,
|
||||||
CMutableTransaction& mtx) override
|
CMutableTransaction& mtx) override
|
||||||
|
@ -258,7 +258,7 @@ public:
|
||||||
bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
|
bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
|
||||||
bool commitBumpTransaction(const uint256& txid,
|
bool commitBumpTransaction(const uint256& txid,
|
||||||
CMutableTransaction&& mtx,
|
CMutableTransaction&& mtx,
|
||||||
std::vector<std::string>& errors,
|
std::vector<bilingual_str>& errors,
|
||||||
uint256& bumped_txid) override
|
uint256& bumped_txid) override
|
||||||
{
|
{
|
||||||
return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
|
return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
|
||||||
|
|
|
@ -31,6 +31,7 @@ enum class TransactionError;
|
||||||
enum isminetype : unsigned int;
|
enum isminetype : unsigned int;
|
||||||
struct CRecipient;
|
struct CRecipient;
|
||||||
struct PartiallySignedTransaction;
|
struct PartiallySignedTransaction;
|
||||||
|
struct bilingual_str;
|
||||||
typedef uint8_t isminefilter;
|
typedef uint8_t isminefilter;
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
|
@ -136,7 +137,7 @@ public:
|
||||||
bool sign,
|
bool sign,
|
||||||
int& change_pos,
|
int& change_pos,
|
||||||
CAmount& fee,
|
CAmount& fee,
|
||||||
std::string& fail_reason) = 0;
|
bilingual_str& fail_reason) = 0;
|
||||||
|
|
||||||
//! Commit transaction.
|
//! Commit transaction.
|
||||||
virtual void commitTransaction(CTransactionRef tx,
|
virtual void commitTransaction(CTransactionRef tx,
|
||||||
|
@ -155,7 +156,7 @@ public:
|
||||||
//! Create bump transaction.
|
//! Create bump transaction.
|
||||||
virtual bool createBumpTransaction(const uint256& txid,
|
virtual bool createBumpTransaction(const uint256& txid,
|
||||||
const CCoinControl& coin_control,
|
const CCoinControl& coin_control,
|
||||||
std::vector<std::string>& errors,
|
std::vector<bilingual_str>& errors,
|
||||||
CAmount& old_fee,
|
CAmount& old_fee,
|
||||||
CAmount& new_fee,
|
CAmount& new_fee,
|
||||||
CMutableTransaction& mtx) = 0;
|
CMutableTransaction& mtx) = 0;
|
||||||
|
@ -166,7 +167,7 @@ public:
|
||||||
//! Commit bump transaction.
|
//! Commit bump transaction.
|
||||||
virtual bool commitBumpTransaction(const uint256& txid,
|
virtual bool commitBumpTransaction(const uint256& txid,
|
||||||
CMutableTransaction&& mtx,
|
CMutableTransaction&& mtx,
|
||||||
std::vector<std::string>& errors,
|
std::vector<bilingual_str>& errors,
|
||||||
uint256& bumped_txid) = 0;
|
uint256& bumped_txid) = 0;
|
||||||
|
|
||||||
//! Get a transaction.
|
//! Get a transaction.
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <interfaces/handler.h>
|
#include <interfaces/handler.h>
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
#include <util/translation.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -244,10 +245,10 @@ void CreateWalletActivity::finish()
|
||||||
{
|
{
|
||||||
destroyProgressDialog();
|
destroyProgressDialog();
|
||||||
|
|
||||||
if (!m_error_message.empty()) {
|
if (!m_error_message.original.empty()) {
|
||||||
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message));
|
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message.translated));
|
||||||
} else if (!m_warning_message.empty()) {
|
} else if (!m_warning_message.empty()) {
|
||||||
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), QString::fromStdString(Join(m_warning_message, "\n")));
|
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), QString::fromStdString(Join(m_warning_message, "\n", OpTranslated)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_wallet_model) Q_EMIT created(m_wallet_model);
|
if (m_wallet_model) Q_EMIT created(m_wallet_model);
|
||||||
|
@ -285,10 +286,10 @@ void OpenWalletActivity::finish()
|
||||||
{
|
{
|
||||||
destroyProgressDialog();
|
destroyProgressDialog();
|
||||||
|
|
||||||
if (!m_error_message.empty()) {
|
if (!m_error_message.original.empty()) {
|
||||||
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message));
|
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message.translated));
|
||||||
} else if (!m_warning_message.empty()) {
|
} else if (!m_warning_message.empty()) {
|
||||||
QMessageBox::warning(m_parent_widget, tr("Open wallet warning"), QString::fromStdString(Join(m_warning_message, "\n")));
|
QMessageBox::warning(m_parent_widget, tr("Open wallet warning"), QString::fromStdString(Join(m_warning_message, "\n", OpTranslated)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_wallet_model) Q_EMIT opened(m_wallet_model);
|
if (m_wallet_model) Q_EMIT opened(m_wallet_model);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <qt/sendcoinsrecipient.h>
|
#include <qt/sendcoinsrecipient.h>
|
||||||
#include <support/allocators/secure.h>
|
#include <support/allocators/secure.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -104,8 +105,8 @@ protected:
|
||||||
QWidget* const m_parent_widget;
|
QWidget* const m_parent_widget;
|
||||||
QProgressDialog* m_progress_dialog{nullptr};
|
QProgressDialog* m_progress_dialog{nullptr};
|
||||||
WalletModel* m_wallet_model{nullptr};
|
WalletModel* m_wallet_model{nullptr};
|
||||||
std::string m_error_message;
|
bilingual_str m_error_message;
|
||||||
std::vector<std::string> m_warning_message;
|
std::vector<bilingual_str> m_warning_message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <psbt.h>
|
#include <psbt.h>
|
||||||
#include <ui_interface.h>
|
#include <ui_interface.h>
|
||||||
#include <util/system.h> // for GetBoolArg
|
#include <util/system.h> // for GetBoolArg
|
||||||
|
#include <util/translation.h>
|
||||||
#include <wallet/coincontrol.h>
|
#include <wallet/coincontrol.h>
|
||||||
#include <wallet/wallet.h> // for CRecipient
|
#include <wallet/wallet.h> // for CRecipient
|
||||||
|
|
||||||
|
@ -185,10 +186,10 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
|
||||||
{
|
{
|
||||||
CAmount nFeeRequired = 0;
|
CAmount nFeeRequired = 0;
|
||||||
int nChangePosRet = -1;
|
int nChangePosRet = -1;
|
||||||
std::string strFailReason;
|
bilingual_str error;
|
||||||
|
|
||||||
auto& newTx = transaction.getWtx();
|
auto& newTx = transaction.getWtx();
|
||||||
newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason);
|
newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, error);
|
||||||
transaction.setTransactionFee(nFeeRequired);
|
transaction.setTransactionFee(nFeeRequired);
|
||||||
if (fSubtractFeeFromAmount && newTx)
|
if (fSubtractFeeFromAmount && newTx)
|
||||||
transaction.reassignAmounts(nChangePosRet);
|
transaction.reassignAmounts(nChangePosRet);
|
||||||
|
@ -199,8 +200,8 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
|
||||||
{
|
{
|
||||||
return SendCoinsReturn(AmountWithFeeExceedsBalance);
|
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);
|
CClientUIInterface::MSG_ERROR);
|
||||||
return TransactionCreationFailed;
|
return TransactionCreationFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,14 +483,14 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
|
||||||
{
|
{
|
||||||
CCoinControl coin_control;
|
CCoinControl coin_control;
|
||||||
coin_control.m_signal_bip125_rbf = true;
|
coin_control.m_signal_bip125_rbf = true;
|
||||||
std::vector<std::string> errors;
|
std::vector<bilingual_str> errors;
|
||||||
CAmount old_fee;
|
CAmount old_fee;
|
||||||
CAmount new_fee;
|
CAmount new_fee;
|
||||||
CMutableTransaction mtx;
|
CMutableTransaction mtx;
|
||||||
if (!m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
|
if (!m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
|
||||||
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +
|
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +
|
||||||
(errors.size() ? QString::fromStdString(errors[0]) : "") +")");
|
(errors.size() ? QString::fromStdString(errors[0].translated) : "") +")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool create_psbt = m_wallet->privateKeysDisabled();
|
const bool create_psbt = m_wallet->privateKeysDisabled();
|
||||||
|
@ -551,8 +552,8 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
|
||||||
// commit the bumped transaction
|
// commit the bumped transaction
|
||||||
if(!m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
|
if(!m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
|
||||||
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Could not commit transaction") + "<br />(" +
|
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Could not commit transaction") + "<br />(" +
|
||||||
QString::fromStdString(errors[0])+")");
|
QString::fromStdString(errors[0].translated)+")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,20 @@ struct bilingual_str {
|
||||||
std::string translated;
|
std::string translated;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bilingual_str operator+(const bilingual_str& lhs, const bilingual_str& rhs)
|
||||||
|
{
|
||||||
|
return bilingual_str{
|
||||||
|
lhs.original + rhs.original,
|
||||||
|
lhs.translated + rhs.translated};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mark a bilingual_str as untranslated */
|
||||||
|
inline static bilingual_str Untranslated(std::string original) { return {original, original}; }
|
||||||
|
/** Unary operator to return the original */
|
||||||
|
inline static std::string OpOriginal(const bilingual_str& b) { return b.original; }
|
||||||
|
/** Unary operator to return the translation */
|
||||||
|
inline static std::string OpTranslated(const bilingual_str& b) { return b.translated; }
|
||||||
|
|
||||||
namespace tinyformat {
|
namespace tinyformat {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
bilingual_str format(const bilingual_str& fmt, const Args&... args)
|
bilingual_str format(const bilingual_str& fmt, const Args&... args)
|
||||||
|
|
|
@ -393,7 +393,7 @@ bool BerkeleyBatch::Recover(const fs::path& file_path, void *callbackDataIn, boo
|
||||||
return fSuccess;
|
return fSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& errorStr)
|
bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, bilingual_str& errorStr)
|
||||||
{
|
{
|
||||||
std::string walletFile;
|
std::string walletFile;
|
||||||
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
|
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
|
||||||
|
@ -403,14 +403,14 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& er
|
||||||
LogPrintf("Using wallet %s\n", file_path.string());
|
LogPrintf("Using wallet %s\n", file_path.string());
|
||||||
|
|
||||||
if (!env->Open(true /* retry */)) {
|
if (!env->Open(true /* retry */)) {
|
||||||
errorStr = strprintf(_("Error initializing wallet database environment %s!").translated, walletDir);
|
errorStr = strprintf(_("Error initializing wallet database environment %s!"), walletDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<std::string>& warnings, std::string& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc)
|
bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc)
|
||||||
{
|
{
|
||||||
std::string walletFile;
|
std::string walletFile;
|
||||||
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
|
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
|
||||||
|
@ -425,12 +425,12 @@ bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<st
|
||||||
warnings.push_back(strprintf(_("Warning: Wallet file corrupt, data salvaged!"
|
warnings.push_back(strprintf(_("Warning: Wallet file corrupt, data salvaged!"
|
||||||
" Original %s saved as %s in %s; if"
|
" Original %s saved as %s in %s; if"
|
||||||
" your balance or transactions are incorrect you should"
|
" your balance or transactions are incorrect you should"
|
||||||
" restore from a backup.").translated,
|
" restore from a backup."),
|
||||||
walletFile, backup_filename, walletDir));
|
walletFile, backup_filename, walletDir));
|
||||||
}
|
}
|
||||||
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
|
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
|
||||||
{
|
{
|
||||||
errorStr = strprintf(_("%s corrupt, salvage failed").translated, walletFile);
|
errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include <db_cxx.h>
|
#include <db_cxx.h>
|
||||||
|
|
||||||
|
struct bilingual_str;
|
||||||
|
|
||||||
static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
|
static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
|
||||||
static const bool DEFAULT_WALLET_PRIVDB = true;
|
static const bool DEFAULT_WALLET_PRIVDB = true;
|
||||||
|
|
||||||
|
@ -242,9 +244,9 @@ public:
|
||||||
ideal to be called periodically */
|
ideal to be called periodically */
|
||||||
static bool PeriodicFlush(BerkeleyDatabase& database);
|
static bool PeriodicFlush(BerkeleyDatabase& database);
|
||||||
/* verifies the database environment */
|
/* verifies the database environment */
|
||||||
static bool VerifyEnvironment(const fs::path& file_path, std::string& errorStr);
|
static bool VerifyEnvironment(const fs::path& file_path, bilingual_str& errorStr);
|
||||||
/* verifies the database file */
|
/* verifies the database file */
|
||||||
static bool VerifyDatabaseFile(const fs::path& file_path, std::vector<std::string>& warnings, std::string& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc);
|
static bool VerifyDatabaseFile(const fs::path& file_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc);
|
||||||
|
|
||||||
template <typename K, typename T>
|
template <typename K, typename T>
|
||||||
bool Read(const K& key, T& value)
|
bool Read(const K& key, T& value)
|
||||||
|
|
|
@ -3,44 +3,45 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
#include <wallet/coincontrol.h>
|
|
||||||
#include <wallet/feebumper.h>
|
|
||||||
#include <wallet/fees.h>
|
|
||||||
#include <wallet/wallet.h>
|
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
#include <util/rbf.h>
|
#include <util/rbf.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
#include <util/translation.h>
|
||||||
|
#include <wallet/coincontrol.h>
|
||||||
|
#include <wallet/feebumper.h>
|
||||||
|
#include <wallet/fees.h>
|
||||||
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
//! Check whether transaction has descendant in wallet or mempool, or has been
|
//! Check whether transaction has descendant in wallet or mempool, or has been
|
||||||
//! mined, or conflicts with a mined transaction. Return a feebumper::Result.
|
//! mined, or conflicts with a mined transaction. Return a feebumper::Result.
|
||||||
static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, std::vector<std::string>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
|
static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, std::vector<bilingual_str>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
|
||||||
{
|
{
|
||||||
if (wallet.HasWalletSpend(wtx.GetHash())) {
|
if (wallet.HasWalletSpend(wtx.GetHash())) {
|
||||||
errors.push_back("Transaction has descendants in the wallet");
|
errors.push_back(Untranslated("Transaction has descendants in the wallet"));
|
||||||
return feebumper::Result::INVALID_PARAMETER;
|
return feebumper::Result::INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
if (wallet.chain().hasDescendantsInMempool(wtx.GetHash())) {
|
if (wallet.chain().hasDescendantsInMempool(wtx.GetHash())) {
|
||||||
errors.push_back("Transaction has descendants in the mempool");
|
errors.push_back(Untranslated("Transaction has descendants in the mempool"));
|
||||||
return feebumper::Result::INVALID_PARAMETER;
|
return feebumper::Result::INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wtx.GetDepthInMainChain() != 0) {
|
if (wtx.GetDepthInMainChain() != 0) {
|
||||||
errors.push_back("Transaction has been mined, or is conflicted with a mined transaction");
|
errors.push_back(Untranslated("Transaction has been mined, or is conflicted with a mined transaction"));
|
||||||
return feebumper::Result::WALLET_ERROR;
|
return feebumper::Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SignalsOptInRBF(*wtx.tx)) {
|
if (!SignalsOptInRBF(*wtx.tx)) {
|
||||||
errors.push_back("Transaction is not BIP 125 replaceable");
|
errors.push_back(Untranslated("Transaction is not BIP 125 replaceable"));
|
||||||
return feebumper::Result::WALLET_ERROR;
|
return feebumper::Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wtx.mapValue.count("replaced_by_txid")) {
|
if (wtx.mapValue.count("replaced_by_txid")) {
|
||||||
errors.push_back(strprintf("Cannot bump transaction %s which was already bumped by transaction %s", wtx.GetHash().ToString(), wtx.mapValue.at("replaced_by_txid")));
|
errors.push_back(strprintf(Untranslated("Cannot bump transaction %s which was already bumped by transaction %s"), wtx.GetHash().ToString(), wtx.mapValue.at("replaced_by_txid")));
|
||||||
return feebumper::Result::WALLET_ERROR;
|
return feebumper::Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWallet
|
||||||
// if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
|
// if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
|
||||||
isminefilter filter = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
|
isminefilter filter = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
|
||||||
if (!wallet.IsAllFromMe(*wtx.tx, filter)) {
|
if (!wallet.IsAllFromMe(*wtx.tx, filter)) {
|
||||||
errors.push_back("Transaction contains inputs that don't belong to this wallet");
|
errors.push_back(Untranslated("Transaction contains inputs that don't belong to this wallet"));
|
||||||
return feebumper::Result::WALLET_ERROR;
|
return feebumper::Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +58,8 @@ static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWallet
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Check if the user provided a valid feeRate
|
//! Check if the user provided a valid feeRate
|
||||||
static feebumper::Result CheckFeeRate(const CWallet& wallet, const CWalletTx& wtx, const CFeeRate& newFeerate, const int64_t maxTxSize, std::vector<std::string>& errors) {
|
static feebumper::Result CheckFeeRate(const CWallet& wallet, const CWalletTx& wtx, const CFeeRate& newFeerate, const int64_t maxTxSize, std::vector<bilingual_str>& errors)
|
||||||
|
{
|
||||||
// check that fee rate is higher than mempool's minimum fee
|
// check that fee rate is higher than mempool's minimum fee
|
||||||
// (no point in bumping fee if we know that the new tx won't be accepted to the mempool)
|
// (no point in bumping fee if we know that the new tx won't be accepted to the mempool)
|
||||||
// This may occur if the user set fee_rate or paytxfee too low, if fallbackfee is too low, or, perhaps,
|
// This may occur if the user set fee_rate or paytxfee too low, if fallbackfee is too low, or, perhaps,
|
||||||
|
@ -67,7 +69,7 @@ static feebumper::Result CheckFeeRate(const CWallet& wallet, const CWalletTx& wt
|
||||||
|
|
||||||
if (newFeerate.GetFeePerK() < minMempoolFeeRate.GetFeePerK()) {
|
if (newFeerate.GetFeePerK() < minMempoolFeeRate.GetFeePerK()) {
|
||||||
errors.push_back(strprintf(
|
errors.push_back(strprintf(
|
||||||
"New fee rate (%s) is lower than the minimum fee rate (%s) to get into the mempool -- ",
|
Untranslated("New fee rate (%s) is lower than the minimum fee rate (%s) to get into the mempool -- "),
|
||||||
FormatMoney(newFeerate.GetFeePerK()),
|
FormatMoney(newFeerate.GetFeePerK()),
|
||||||
FormatMoney(minMempoolFeeRate.GetFeePerK())));
|
FormatMoney(minMempoolFeeRate.GetFeePerK())));
|
||||||
return feebumper::Result::WALLET_ERROR;
|
return feebumper::Result::WALLET_ERROR;
|
||||||
|
@ -86,14 +88,14 @@ static feebumper::Result CheckFeeRate(const CWallet& wallet, const CWalletTx& wt
|
||||||
CAmount minTotalFee = nOldFeeRate.GetFee(maxTxSize) + incrementalRelayFee.GetFee(maxTxSize);
|
CAmount minTotalFee = nOldFeeRate.GetFee(maxTxSize) + incrementalRelayFee.GetFee(maxTxSize);
|
||||||
|
|
||||||
if (new_total_fee < minTotalFee) {
|
if (new_total_fee < minTotalFee) {
|
||||||
errors.push_back(strprintf("Insufficient total fee %s, must be at least %s (oldFee %s + incrementalFee %s)",
|
errors.push_back(strprintf(Untranslated("Insufficient total fee %s, must be at least %s (oldFee %s + incrementalFee %s)"),
|
||||||
FormatMoney(new_total_fee), FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxTxSize)), FormatMoney(incrementalRelayFee.GetFee(maxTxSize))));
|
FormatMoney(new_total_fee), FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxTxSize)), FormatMoney(incrementalRelayFee.GetFee(maxTxSize))));
|
||||||
return feebumper::Result::INVALID_PARAMETER;
|
return feebumper::Result::INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAmount requiredFee = GetRequiredFee(wallet, maxTxSize);
|
CAmount requiredFee = GetRequiredFee(wallet, maxTxSize);
|
||||||
if (new_total_fee < requiredFee) {
|
if (new_total_fee < requiredFee) {
|
||||||
errors.push_back(strprintf("Insufficient total fee (cannot be less than required fee %s)",
|
errors.push_back(strprintf(Untranslated("Insufficient total fee (cannot be less than required fee %s)"),
|
||||||
FormatMoney(requiredFee)));
|
FormatMoney(requiredFee)));
|
||||||
return feebumper::Result::INVALID_PARAMETER;
|
return feebumper::Result::INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
@ -101,8 +103,8 @@ static feebumper::Result CheckFeeRate(const CWallet& wallet, const CWalletTx& wt
|
||||||
// Check that in all cases the new fee doesn't violate maxTxFee
|
// Check that in all cases the new fee doesn't violate maxTxFee
|
||||||
const CAmount max_tx_fee = wallet.m_default_max_tx_fee;
|
const CAmount max_tx_fee = wallet.m_default_max_tx_fee;
|
||||||
if (new_total_fee > max_tx_fee) {
|
if (new_total_fee > max_tx_fee) {
|
||||||
errors.push_back(strprintf("Specified or calculated fee %s is too high (cannot be higher than -maxtxfee %s)",
|
errors.push_back(strprintf(Untranslated("Specified or calculated fee %s is too high (cannot be higher than -maxtxfee %s)"),
|
||||||
FormatMoney(new_total_fee), FormatMoney(max_tx_fee)));
|
FormatMoney(new_total_fee), FormatMoney(max_tx_fee)));
|
||||||
return feebumper::Result::WALLET_ERROR;
|
return feebumper::Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +146,12 @@ bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid)
|
||||||
const CWalletTx* wtx = wallet.GetWalletTx(txid);
|
const CWalletTx* wtx = wallet.GetWalletTx(txid);
|
||||||
if (wtx == nullptr) return false;
|
if (wtx == nullptr) return false;
|
||||||
|
|
||||||
std::vector<std::string> errors_dummy;
|
std::vector<bilingual_str> errors_dummy;
|
||||||
feebumper::Result res = PreconditionChecks(wallet, *wtx, errors_dummy);
|
feebumper::Result res = PreconditionChecks(wallet, *wtx, errors_dummy);
|
||||||
return res == feebumper::Result::OK;
|
return res == feebumper::Result::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCoinControl& coin_control, std::vector<std::string>& errors,
|
Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCoinControl& coin_control, std::vector<bilingual_str>& errors,
|
||||||
CAmount& old_fee, CAmount& new_fee, CMutableTransaction& mtx)
|
CAmount& old_fee, CAmount& new_fee, CMutableTransaction& mtx)
|
||||||
{
|
{
|
||||||
// We are going to modify coin control later, copy to re-use
|
// We are going to modify coin control later, copy to re-use
|
||||||
|
@ -159,7 +161,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
|
||||||
errors.clear();
|
errors.clear();
|
||||||
auto it = wallet.mapWallet.find(txid);
|
auto it = wallet.mapWallet.find(txid);
|
||||||
if (it == wallet.mapWallet.end()) {
|
if (it == wallet.mapWallet.end()) {
|
||||||
errors.push_back("Invalid or non-wallet transaction id");
|
errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
|
||||||
return Result::INVALID_ADDRESS_OR_KEY;
|
return Result::INVALID_ADDRESS_OR_KEY;
|
||||||
}
|
}
|
||||||
const CWalletTx& wtx = it->second;
|
const CWalletTx& wtx = it->second;
|
||||||
|
@ -216,9 +218,9 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
|
||||||
CTransactionRef tx_new = MakeTransactionRef();
|
CTransactionRef tx_new = MakeTransactionRef();
|
||||||
CAmount fee_ret;
|
CAmount fee_ret;
|
||||||
int change_pos_in_out = -1; // No requested location for change
|
int change_pos_in_out = -1; // No requested location for change
|
||||||
std::string fail_reason;
|
bilingual_str fail_reason;
|
||||||
if (!wallet.CreateTransaction(recipients, tx_new, fee_ret, change_pos_in_out, fail_reason, new_coin_control, false)) {
|
if (!wallet.CreateTransaction(recipients, tx_new, fee_ret, change_pos_in_out, fail_reason, new_coin_control, false)) {
|
||||||
errors.push_back("Unable to create transaction: " + fail_reason);
|
errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + fail_reason);
|
||||||
return Result::WALLET_ERROR;
|
return Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +244,7 @@ bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx) {
|
||||||
return wallet.SignTransaction(mtx);
|
return wallet.SignTransaction(mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransaction&& mtx, std::vector<std::string>& errors, uint256& bumped_txid)
|
Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransaction&& mtx, std::vector<bilingual_str>& errors, uint256& bumped_txid)
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
if (!errors.empty()) {
|
if (!errors.empty()) {
|
||||||
|
@ -250,7 +252,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
|
||||||
}
|
}
|
||||||
auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid);
|
auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid);
|
||||||
if (it == wallet.mapWallet.end()) {
|
if (it == wallet.mapWallet.end()) {
|
||||||
errors.push_back("Invalid or non-wallet transaction id");
|
errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
|
||||||
return Result::MISC_ERROR;
|
return Result::MISC_ERROR;
|
||||||
}
|
}
|
||||||
CWalletTx& oldWtx = it->second;
|
CWalletTx& oldWtx = it->second;
|
||||||
|
@ -275,7 +277,7 @@ Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransacti
|
||||||
// along with an exception. It would be good to return information about
|
// along with an exception. It would be good to return information about
|
||||||
// wtxBumped to the caller even if marking the original transaction
|
// wtxBumped to the caller even if marking the original transaction
|
||||||
// replaced does not succeed for some reason.
|
// replaced does not succeed for some reason.
|
||||||
errors.push_back("Created new bumpfee transaction but could not mark the original transaction as replaced");
|
errors.push_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced"));
|
||||||
}
|
}
|
||||||
return Result::OK;
|
return Result::OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ class CWalletTx;
|
||||||
class uint256;
|
class uint256;
|
||||||
class CCoinControl;
|
class CCoinControl;
|
||||||
enum class FeeEstimateMode;
|
enum class FeeEstimateMode;
|
||||||
|
struct bilingual_str;
|
||||||
|
|
||||||
namespace feebumper {
|
namespace feebumper {
|
||||||
|
|
||||||
|
@ -30,12 +31,12 @@ bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid);
|
||||||
|
|
||||||
//! Create bumpfee transaction based on feerate estimates.
|
//! Create bumpfee transaction based on feerate estimates.
|
||||||
Result CreateRateBumpTransaction(CWallet& wallet,
|
Result CreateRateBumpTransaction(CWallet& wallet,
|
||||||
const uint256& txid,
|
const uint256& txid,
|
||||||
const CCoinControl& coin_control,
|
const CCoinControl& coin_control,
|
||||||
std::vector<std::string>& errors,
|
std::vector<bilingual_str>& errors,
|
||||||
CAmount& old_fee,
|
CAmount& old_fee,
|
||||||
CAmount& new_fee,
|
CAmount& new_fee,
|
||||||
CMutableTransaction& mtx);
|
CMutableTransaction& mtx);
|
||||||
|
|
||||||
//! Sign the new transaction,
|
//! Sign the new transaction,
|
||||||
//! @return false if the tx couldn't be found or if it was
|
//! @return false if the tx couldn't be found or if it was
|
||||||
|
@ -47,10 +48,10 @@ bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx);
|
||||||
//! but sets errors if the tx could not be added to the mempool (will try later)
|
//! but sets errors if the tx could not be added to the mempool (will try later)
|
||||||
//! or if the old transaction could not be marked as replaced.
|
//! or if the old transaction could not be marked as replaced.
|
||||||
Result CommitTransaction(CWallet& wallet,
|
Result CommitTransaction(CWallet& wallet,
|
||||||
const uint256& txid,
|
const uint256& txid,
|
||||||
CMutableTransaction&& mtx,
|
CMutableTransaction&& mtx,
|
||||||
std::vector<std::string>& errors,
|
std::vector<bilingual_str>& errors,
|
||||||
uint256& bumped_txid);
|
uint256& bumped_txid);
|
||||||
|
|
||||||
} // namespace feebumper
|
} // namespace feebumper
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,14 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error_string;
|
bilingual_str error_string;
|
||||||
std::vector<std::string> warnings;
|
std::vector<bilingual_str> warnings;
|
||||||
bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warnings);
|
bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warnings);
|
||||||
if (!error_string.empty()) chain.initError(error_string);
|
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
|
||||||
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n"));
|
if (!verify_success) {
|
||||||
if (!verify_success) return false;
|
chain.initError(error_string.translated);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -68,12 +70,12 @@ bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& walle
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
for (const std::string& walletFile : wallet_files) {
|
for (const std::string& walletFile : wallet_files) {
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
std::vector<std::string> warnings;
|
std::vector<bilingual_str> warnings;
|
||||||
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
|
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
|
||||||
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n"));
|
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
|
||||||
if (!pwallet) {
|
if (!pwallet) {
|
||||||
chain.initError(error);
|
chain.initError(error.translated);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AddWallet(pwallet);
|
AddWallet(pwallet);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
#include <util/translation.h>
|
||||||
#include <util/url.h>
|
#include <util/url.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
#include <wallet/coincontrol.h>
|
#include <wallet/coincontrol.h>
|
||||||
|
@ -338,16 +339,16 @@ static CTransactionRef SendMoney(CWallet* const pwallet, const CTxDestination& a
|
||||||
|
|
||||||
// Create and send the transaction
|
// Create and send the transaction
|
||||||
CAmount nFeeRequired = 0;
|
CAmount nFeeRequired = 0;
|
||||||
std::string strError;
|
bilingual_str error;
|
||||||
std::vector<CRecipient> vecSend;
|
std::vector<CRecipient> vecSend;
|
||||||
int nChangePosRet = -1;
|
int nChangePosRet = -1;
|
||||||
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
|
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
|
||||||
vecSend.push_back(recipient);
|
vecSend.push_back(recipient);
|
||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
if (!pwallet->CreateTransaction(vecSend, tx, nFeeRequired, nChangePosRet, strError, coin_control)) {
|
if (!pwallet->CreateTransaction(vecSend, tx, nFeeRequired, nChangePosRet, error, coin_control)) {
|
||||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance)
|
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 */);
|
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */);
|
||||||
return tx;
|
return tx;
|
||||||
|
@ -903,11 +904,11 @@ static UniValue sendmany(const JSONRPCRequest& request)
|
||||||
// Send
|
// Send
|
||||||
CAmount nFeeRequired = 0;
|
CAmount nFeeRequired = 0;
|
||||||
int nChangePosRet = -1;
|
int nChangePosRet = -1;
|
||||||
std::string strFailReason;
|
bilingual_str error;
|
||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
bool fCreated = pwallet->CreateTransaction(vecSend, tx, nFeeRequired, nChangePosRet, strFailReason, coin_control);
|
bool fCreated = pwallet->CreateTransaction(vecSend, tx, nFeeRequired, nChangePosRet, error, coin_control);
|
||||||
if (!fCreated)
|
if (!fCreated)
|
||||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original);
|
||||||
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */);
|
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */);
|
||||||
return tx->GetHash().GetHex();
|
return tx->GetHash().GetHex();
|
||||||
}
|
}
|
||||||
|
@ -2589,14 +2590,14 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
std::vector<std::string> warning;
|
std::vector<bilingual_str> warnings;
|
||||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warning);
|
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warnings);
|
||||||
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error);
|
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("name", wallet->GetName());
|
obj.pushKV("name", wallet->GetName());
|
||||||
obj.pushKV("warning", Join(warning, "\n"));
|
obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -2705,12 +2706,12 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
SecureString passphrase;
|
SecureString passphrase;
|
||||||
passphrase.reserve(100);
|
passphrase.reserve(100);
|
||||||
std::vector<std::string> warnings;
|
std::vector<bilingual_str> warnings;
|
||||||
if (!request.params[3].isNull()) {
|
if (!request.params[3].isNull()) {
|
||||||
passphrase = request.params[3].get_str().c_str();
|
passphrase = request.params[3].get_str().c_str();
|
||||||
if (passphrase.empty()) {
|
if (passphrase.empty()) {
|
||||||
// Empty string means unencrypted
|
// Empty string means unencrypted
|
||||||
warnings.emplace_back("Empty string given as passphrase, wallet will not be encrypted.");
|
warnings.emplace_back(Untranslated("Empty string given as passphrase, wallet will not be encrypted."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2721,14 +2722,14 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||||
flags |= WALLET_FLAG_DESCRIPTORS;
|
flags |= WALLET_FLAG_DESCRIPTORS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
std::shared_ptr<CWallet> wallet;
|
std::shared_ptr<CWallet> wallet;
|
||||||
WalletCreationStatus status = CreateWallet(*g_rpc_chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
WalletCreationStatus status = CreateWallet(*g_rpc_chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case WalletCreationStatus::CREATION_FAILED:
|
case WalletCreationStatus::CREATION_FAILED:
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, error);
|
throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||||
case WalletCreationStatus::ENCRYPTION_FAILED:
|
case WalletCreationStatus::ENCRYPTION_FAILED:
|
||||||
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error);
|
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error.original);
|
||||||
case WalletCreationStatus::SUCCESS:
|
case WalletCreationStatus::SUCCESS:
|
||||||
break;
|
break;
|
||||||
// no default case, so the compiler can warn about missing cases
|
// no default case, so the compiler can warn about missing cases
|
||||||
|
@ -2736,7 +2737,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("name", wallet->GetName());
|
obj.pushKV("name", wallet->GetName());
|
||||||
obj.pushKV("warning", Join(warnings, "\n"));
|
obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -3108,10 +3109,10 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
|
||||||
setSubtractFeeFromOutputs.insert(pos);
|
setSubtractFeeFromOutputs.insert(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string strFailReason;
|
bilingual_str error;
|
||||||
|
|
||||||
if (!pwallet->FundTransaction(tx, fee_out, change_position, strFailReason, lockUnspents, setSubtractFeeFromOutputs, coinControl)) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3417,7 +3418,7 @@ static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(pwallet);
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> errors;
|
std::vector<bilingual_str> errors;
|
||||||
CAmount old_fee;
|
CAmount old_fee;
|
||||||
CAmount new_fee;
|
CAmount new_fee;
|
||||||
CMutableTransaction mtx;
|
CMutableTransaction mtx;
|
||||||
|
@ -3427,19 +3428,19 @@ static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
if (res != feebumper::Result::OK) {
|
if (res != feebumper::Result::OK) {
|
||||||
switch(res) {
|
switch(res) {
|
||||||
case feebumper::Result::INVALID_ADDRESS_OR_KEY:
|
case feebumper::Result::INVALID_ADDRESS_OR_KEY:
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errors[0]);
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errors[0].original);
|
||||||
break;
|
break;
|
||||||
case feebumper::Result::INVALID_REQUEST:
|
case feebumper::Result::INVALID_REQUEST:
|
||||||
throw JSONRPCError(RPC_INVALID_REQUEST, errors[0]);
|
throw JSONRPCError(RPC_INVALID_REQUEST, errors[0].original);
|
||||||
break;
|
break;
|
||||||
case feebumper::Result::INVALID_PARAMETER:
|
case feebumper::Result::INVALID_PARAMETER:
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, errors[0]);
|
throw JSONRPCError(RPC_INVALID_PARAMETER, errors[0].original);
|
||||||
break;
|
break;
|
||||||
case feebumper::Result::WALLET_ERROR:
|
case feebumper::Result::WALLET_ERROR:
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, errors[0]);
|
throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, errors[0]);
|
throw JSONRPCError(RPC_MISC_ERROR, errors[0].original);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3455,7 +3456,7 @@ static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
|
|
||||||
uint256 txid;
|
uint256 txid;
|
||||||
if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
|
if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, errors[0]);
|
throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.pushKV("txid", txid.GetHex());
|
result.pushKV("txid", txid.GetHex());
|
||||||
|
@ -3473,8 +3474,8 @@ static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
result.pushKV("origfee", ValueFromAmount(old_fee));
|
result.pushKV("origfee", ValueFromAmount(old_fee));
|
||||||
result.pushKV("fee", ValueFromAmount(new_fee));
|
result.pushKV("fee", ValueFromAmount(new_fee));
|
||||||
UniValue result_errors(UniValue::VARR);
|
UniValue result_errors(UniValue::VARR);
|
||||||
for (const std::string& error : errors) {
|
for (const bilingual_str& error : errors) {
|
||||||
result_errors.push_back(error);
|
result_errors.push_back(error.original);
|
||||||
}
|
}
|
||||||
result.pushKV("errors", result_errors);
|
result.pushKV("errors", result_errors);
|
||||||
|
|
||||||
|
@ -4239,12 +4240,12 @@ static UniValue upgradewallet(const JSONRPCRequest& request)
|
||||||
version = request.params[0].get_int();
|
version = request.params[0].get_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
std::vector<std::string> warnings;
|
std::vector<bilingual_str> warnings;
|
||||||
if (!pwallet->UpgradeWallet(version, error, warnings)) {
|
if (!pwallet->UpgradeWallet(version, error, warnings)) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, error);
|
throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||||
}
|
}
|
||||||
return error;
|
return error.original;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
|
UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
|
||||||
|
|
|
@ -377,10 +377,9 @@ bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) const
|
||||||
return keypool_has_keys;
|
return keypool_has_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::Upgrade(int prev_version, std::string& error)
|
bool LegacyScriptPubKeyMan::Upgrade(int prev_version, bilingual_str& error)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
error = "";
|
|
||||||
bool hd_upgrade = false;
|
bool hd_upgrade = false;
|
||||||
bool split_upgrade = false;
|
bool split_upgrade = false;
|
||||||
if (m_storage.CanSupportFeature(FEATURE_HD) && !IsHDEnabled()) {
|
if (m_storage.CanSupportFeature(FEATURE_HD) && !IsHDEnabled()) {
|
||||||
|
@ -405,7 +404,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, std::string& error)
|
||||||
// Regenerate the keypool if upgraded to HD
|
// Regenerate the keypool if upgraded to HD
|
||||||
if (hd_upgrade) {
|
if (hd_upgrade) {
|
||||||
if (!TopUp()) {
|
if (!TopUp()) {
|
||||||
error = _("Unable to generate keys").translated;
|
error = _("Unable to generate keys");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <boost/signals2/signal.hpp>
|
#include <boost/signals2/signal.hpp>
|
||||||
|
|
||||||
enum class OutputType;
|
enum class OutputType;
|
||||||
|
struct bilingual_str;
|
||||||
|
|
||||||
// Wallet storage things that ScriptPubKeyMans need in order to be able to store things to the wallet database.
|
// Wallet storage things that ScriptPubKeyMans need in order to be able to store things to the wallet database.
|
||||||
// It provides access to things that are part of the entire wallet and not specific to a ScriptPubKeyMan such as
|
// It provides access to things that are part of the entire wallet and not specific to a ScriptPubKeyMan such as
|
||||||
|
@ -191,7 +192,7 @@ public:
|
||||||
virtual bool CanGetAddresses(bool internal = false) const { return false; }
|
virtual bool CanGetAddresses(bool internal = false) const { return false; }
|
||||||
|
|
||||||
/** Upgrades the wallet to the specified version */
|
/** Upgrades the wallet to the specified version */
|
||||||
virtual bool Upgrade(int prev_version, std::string& error) { return false; }
|
virtual bool Upgrade(int prev_version, bilingual_str& error) { return false; }
|
||||||
|
|
||||||
virtual bool HavePrivateKeys() const { return false; }
|
virtual bool HavePrivateKeys() const { return false; }
|
||||||
|
|
||||||
|
@ -343,7 +344,7 @@ public:
|
||||||
|
|
||||||
bool SetupGeneration(bool force = false) override;
|
bool SetupGeneration(bool force = false) override;
|
||||||
|
|
||||||
bool Upgrade(int prev_version, std::string& error) override;
|
bool Upgrade(int prev_version, bilingual_str& error) override;
|
||||||
|
|
||||||
bool HavePrivateKeys() const override;
|
bool HavePrivateKeys() const override;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <test/util/logging.h>
|
#include <test/util/logging.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
#include <util/translation.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
#include <wallet/coincontrol.h>
|
#include <wallet/coincontrol.h>
|
||||||
#include <wallet/test/wallet_test_fixture.h>
|
#include <wallet/test/wallet_test_fixture.h>
|
||||||
|
@ -30,8 +31,8 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
|
||||||
|
|
||||||
static std::shared_ptr<CWallet> TestLoadWallet(interfaces::Chain& chain)
|
static std::shared_ptr<CWallet> TestLoadWallet(interfaces::Chain& chain)
|
||||||
{
|
{
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
std::vector<std::string> warnings;
|
std::vector<bilingual_str> warnings;
|
||||||
auto wallet = CWallet::CreateWalletFromFile(chain, WalletLocation(""), error, warnings);
|
auto wallet = CWallet::CreateWalletFromFile(chain, WalletLocation(""), error, warnings);
|
||||||
wallet->postInitProcess();
|
wallet->postInitProcess();
|
||||||
return wallet;
|
return wallet;
|
||||||
|
@ -515,7 +516,7 @@ public:
|
||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
CAmount fee;
|
CAmount fee;
|
||||||
int changePos = -1;
|
int changePos = -1;
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
CCoinControl dummy;
|
CCoinControl dummy;
|
||||||
{
|
{
|
||||||
BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, fee, changePos, error, dummy));
|
BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, fee, changePos, error, dummy));
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <util/fees.h>
|
#include <util/fees.h>
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
#include <util/rbf.h>
|
#include <util/rbf.h>
|
||||||
|
#include <util/string.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/coincontrol.h>
|
#include <wallet/coincontrol.h>
|
||||||
#include <wallet/fees.h>
|
#include <wallet/fees.h>
|
||||||
|
@ -149,34 +150,34 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings)
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!CWallet::Verify(chain, location, false, error, warnings)) {
|
if (!CWallet::Verify(chain, location, false, error, warnings)) {
|
||||||
error = "Wallet file verification failed: " + error;
|
error = Untranslated("Wallet file verification failed.") + Untranslated(" ") + error;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings);
|
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings);
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
error = "Wallet loading failed: " + error;
|
error = Untranslated("Wallet loading failed.") + Untranslated(" ") + error;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
AddWallet(wallet);
|
AddWallet(wallet);
|
||||||
wallet->postInitProcess();
|
wallet->postInitProcess();
|
||||||
return wallet;
|
return wallet;
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
error = e.what();
|
error = Untranslated(e.what());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings)
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings)
|
||||||
{
|
{
|
||||||
return LoadWallet(chain, WalletLocation(name), error, warnings);
|
return LoadWallet(chain, WalletLocation(name), error, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::shared_ptr<CWallet>& result)
|
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::shared_ptr<CWallet>& result)
|
||||||
{
|
{
|
||||||
// Indicate that the wallet is actually supposed to be blank and not just blank to make it encrypted
|
// Indicate that the wallet is actually supposed to be blank and not just blank to make it encrypted
|
||||||
bool create_blank = (wallet_creation_flags & WALLET_FLAG_BLANK_WALLET);
|
bool create_blank = (wallet_creation_flags & WALLET_FLAG_BLANK_WALLET);
|
||||||
|
@ -189,39 +190,39 @@ WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString&
|
||||||
// Check the wallet file location
|
// Check the wallet file location
|
||||||
WalletLocation location(name);
|
WalletLocation location(name);
|
||||||
if (location.Exists()) {
|
if (location.Exists()) {
|
||||||
error = "Wallet " + location.GetName() + " already exists.";
|
error = strprintf(Untranslated("Wallet %s already exists."), location.GetName());
|
||||||
return WalletCreationStatus::CREATION_FAILED;
|
return WalletCreationStatus::CREATION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wallet::Verify will check if we're trying to create a wallet with a duplicate name.
|
// Wallet::Verify will check if we're trying to create a wallet with a duplicate name.
|
||||||
if (!CWallet::Verify(chain, location, false, error, warnings)) {
|
if (!CWallet::Verify(chain, location, false, error, warnings)) {
|
||||||
error = "Wallet file verification failed: " + error;
|
error = Untranslated("Wallet file verification failed.") + Untranslated(" ") + error;
|
||||||
return WalletCreationStatus::CREATION_FAILED;
|
return WalletCreationStatus::CREATION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not allow a passphrase when private keys are disabled
|
// Do not allow a passphrase when private keys are disabled
|
||||||
if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
||||||
error = "Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.";
|
error = Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.");
|
||||||
return WalletCreationStatus::CREATION_FAILED;
|
return WalletCreationStatus::CREATION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the wallet
|
// Make the wallet
|
||||||
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings, wallet_creation_flags);
|
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings, wallet_creation_flags);
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
error = "Wallet creation failed: " + error;
|
error = Untranslated("Wallet creation failed.") + Untranslated(" ") + error;
|
||||||
return WalletCreationStatus::CREATION_FAILED;
|
return WalletCreationStatus::CREATION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encrypt the wallet
|
// Encrypt the wallet
|
||||||
if (!passphrase.empty() && !(wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
if (!passphrase.empty() && !(wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
||||||
if (!wallet->EncryptWallet(passphrase)) {
|
if (!wallet->EncryptWallet(passphrase)) {
|
||||||
error = "Error: Wallet created but failed to encrypt.";
|
error = Untranslated("Error: Wallet created but failed to encrypt.");
|
||||||
return WalletCreationStatus::ENCRYPTION_FAILED;
|
return WalletCreationStatus::ENCRYPTION_FAILED;
|
||||||
}
|
}
|
||||||
if (!create_blank) {
|
if (!create_blank) {
|
||||||
// Unlock the wallet
|
// Unlock the wallet
|
||||||
if (!wallet->Unlock(passphrase)) {
|
if (!wallet->Unlock(passphrase)) {
|
||||||
error = "Error: Wallet was encrypted but could not be unlocked";
|
error = Untranslated("Error: Wallet was encrypted but could not be unlocked");
|
||||||
return WalletCreationStatus::ENCRYPTION_FAILED;
|
return WalletCreationStatus::ENCRYPTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +234,7 @@ WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString&
|
||||||
} else {
|
} else {
|
||||||
for (auto spk_man : wallet->GetActiveScriptPubKeyMans()) {
|
for (auto spk_man : wallet->GetActiveScriptPubKeyMans()) {
|
||||||
if (!spk_man->SetupGeneration()) {
|
if (!spk_man->SetupGeneration()) {
|
||||||
error = "Unable to generate initial keys";
|
error = Untranslated("Unable to generate initial keys");
|
||||||
return WalletCreationStatus::CREATION_FAILED;
|
return WalletCreationStatus::CREATION_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2520,7 +2521,7 @@ SigningResult CWallet::SignMessage(const std::string& message, const PKHash& pkh
|
||||||
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
|
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl coinControl)
|
bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, bilingual_str& error, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl coinControl)
|
||||||
{
|
{
|
||||||
std::vector<CRecipient> vecSend;
|
std::vector<CRecipient> vecSend;
|
||||||
|
|
||||||
|
@ -2542,7 +2543,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
|
|
||||||
CTransactionRef tx_new;
|
CTransactionRef tx_new;
|
||||||
if (!CreateTransaction(vecSend, tx_new, nFeeRet, nChangePosInOut, strFailReason, coinControl, false)) {
|
if (!CreateTransaction(vecSend, tx_new, nFeeRet, nChangePosInOut, error, coinControl, false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2658,7 +2659,7 @@ OutputType CWallet::TransactionChangeType(OutputType change_type, const std::vec
|
||||||
return m_default_address_type;
|
return m_default_address_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl& coin_control, bool sign)
|
bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CAmount& nFeeRet, int& nChangePosInOut, bilingual_str& error, const CCoinControl& coin_control, bool sign)
|
||||||
{
|
{
|
||||||
CAmount nValue = 0;
|
CAmount nValue = 0;
|
||||||
const OutputType change_type = TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
|
const OutputType change_type = TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
|
||||||
|
@ -2669,7 +2670,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
{
|
{
|
||||||
if (nValue < 0 || recipient.nAmount < 0)
|
if (nValue < 0 || recipient.nAmount < 0)
|
||||||
{
|
{
|
||||||
strFailReason = _("Transaction amounts must not be negative").translated;
|
error = _("Transaction amounts must not be negative");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nValue += recipient.nAmount;
|
nValue += recipient.nAmount;
|
||||||
|
@ -2679,7 +2680,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
}
|
}
|
||||||
if (vecSend.empty())
|
if (vecSend.empty())
|
||||||
{
|
{
|
||||||
strFailReason = _("Transaction must have at least one recipient").translated;
|
error = _("Transaction must have at least one recipient");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2716,7 +2717,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
// destination in case we don't need change.
|
// destination in case we don't need change.
|
||||||
CTxDestination dest;
|
CTxDestination dest;
|
||||||
if (!reservedest.GetReservedDestination(dest, true)) {
|
if (!reservedest.GetReservedDestination(dest, true)) {
|
||||||
strFailReason = _("Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.").translated;
|
error = _("Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.");
|
||||||
}
|
}
|
||||||
scriptChange = GetScriptForDestination(dest);
|
scriptChange = GetScriptForDestination(dest);
|
||||||
assert(!dest.empty() || scriptChange.empty());
|
assert(!dest.empty() || scriptChange.empty());
|
||||||
|
@ -2778,12 +2779,12 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)
|
if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)
|
||||||
{
|
{
|
||||||
if (txout.nValue < 0)
|
if (txout.nValue < 0)
|
||||||
strFailReason = _("The transaction amount is too small to pay the fee").translated;
|
error = _("The transaction amount is too small to pay the fee");
|
||||||
else
|
else
|
||||||
strFailReason = _("The transaction amount is too small to send after the fee has been deducted").translated;
|
error = _("The transaction amount is too small to send after the fee has been deducted");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strFailReason = _("Transaction amount too small").translated;
|
error = _("Transaction amount too small");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
txNew.vout.push_back(txout);
|
txNew.vout.push_back(txout);
|
||||||
|
@ -2811,7 +2812,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strFailReason = _("Insufficient funds").translated;
|
error = _("Insufficient funds");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2842,7 +2843,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
}
|
}
|
||||||
else if ((unsigned int)nChangePosInOut > txNew.vout.size())
|
else if ((unsigned int)nChangePosInOut > txNew.vout.size())
|
||||||
{
|
{
|
||||||
strFailReason = _("Change index out of range").translated;
|
error = _("Change index out of range");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2861,14 +2862,14 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
|
|
||||||
nBytes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
|
nBytes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
|
||||||
if (nBytes < 0) {
|
if (nBytes < 0) {
|
||||||
strFailReason = _("Signing transaction failed").translated;
|
error = _("Signing transaction failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nFeeNeeded = GetMinimumFee(*this, nBytes, coin_control, &feeCalc);
|
nFeeNeeded = GetMinimumFee(*this, nBytes, coin_control, &feeCalc);
|
||||||
if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) {
|
if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) {
|
||||||
// eventually allow a fallback fee
|
// eventually allow a fallback fee
|
||||||
strFailReason = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.").translated;
|
error = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2908,7 +2909,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
// fee to pay for the new output and still meet nFeeNeeded
|
// fee to pay for the new output and still meet nFeeNeeded
|
||||||
// Or we should have just subtracted fee from recipients and
|
// Or we should have just subtracted fee from recipients and
|
||||||
// nFeeNeeded should not have changed
|
// nFeeNeeded should not have changed
|
||||||
strFailReason = _("Transaction fee and change calculation failed").translated;
|
error = _("Transaction fee and change calculation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2961,7 +2962,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sign && !SignTransaction(txNew)) {
|
if (sign && !SignTransaction(txNew)) {
|
||||||
strFailReason = _("Signing transaction failed").translated;
|
error = _("Signing transaction failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2971,20 +2972,20 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
|
||||||
// Limit size
|
// Limit size
|
||||||
if (GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT)
|
if (GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT)
|
||||||
{
|
{
|
||||||
strFailReason = _("Transaction too large").translated;
|
error = _("Transaction too large");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nFeeRet > m_default_max_tx_fee) {
|
if (nFeeRet > m_default_max_tx_fee) {
|
||||||
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
|
error = Untranslated(TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
|
if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
|
||||||
// Lastly, ensure this tx will pass the mempool's chain limits
|
// Lastly, ensure this tx will pass the mempool's chain limits
|
||||||
if (!chain().checkChainLimits(tx)) {
|
if (!chain().checkChainLimits(tx)) {
|
||||||
strFailReason = _("Transaction has too long of a mempool chain").translated;
|
error = _("Transaction has too long of a mempool chain");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3656,7 +3657,7 @@ std::vector<std::string> CWallet::GetDestValues(const std::string& prefix) const
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, bool salvage_wallet, std::string& error_string, std::vector<std::string>& warnings)
|
bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, bool salvage_wallet, bilingual_str& error_string, std::vector<bilingual_str>& warnings)
|
||||||
{
|
{
|
||||||
// Do some checking on wallet path. It should be either a:
|
// Do some checking on wallet path. It should be either a:
|
||||||
//
|
//
|
||||||
|
@ -3670,17 +3671,17 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
|
||||||
if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
|
if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
|
||||||
(path_type == fs::symlink_file && fs::is_directory(wallet_path)) ||
|
(path_type == fs::symlink_file && fs::is_directory(wallet_path)) ||
|
||||||
(path_type == fs::regular_file && fs::path(location.GetName()).filename() == location.GetName()))) {
|
(path_type == fs::regular_file && fs::path(location.GetName()).filename() == location.GetName()))) {
|
||||||
error_string = strprintf(
|
error_string = Untranslated(strprintf(
|
||||||
"Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
|
"Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
|
||||||
"database/log.?????????? files can be stored, a location where such a directory could be created, "
|
"database/log.?????????? files can be stored, a location where such a directory could be created, "
|
||||||
"or (for backwards compatibility) the name of an existing data file in -walletdir (%s)",
|
"or (for backwards compatibility) the name of an existing data file in -walletdir (%s)",
|
||||||
location.GetName(), GetWalletDir());
|
location.GetName(), GetWalletDir()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the wallet path doesn't clash with an existing wallet path
|
// Make sure that the wallet path doesn't clash with an existing wallet path
|
||||||
if (IsWalletLoaded(wallet_path)) {
|
if (IsWalletLoaded(wallet_path)) {
|
||||||
error_string = strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", location.GetName());
|
error_string = Untranslated(strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", location.GetName()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3692,7 +3693,7 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (const fs::filesystem_error& e) {
|
} catch (const fs::filesystem_error& e) {
|
||||||
error_string = strprintf("Error loading wallet %s. %s", location.GetName(), fsbridge::get_filesystem_error_message(e));
|
error_string = Untranslated(strprintf("Error loading wallet %s. %s", location.GetName(), fsbridge::get_filesystem_error_message(e)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3708,7 +3709,7 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
|
||||||
return WalletBatch::VerifyDatabaseFile(wallet_path, warnings, error_string);
|
return WalletBatch::VerifyDatabaseFile(wallet_path, warnings, error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings, uint64_t wallet_creation_flags)
|
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings, uint64_t wallet_creation_flags)
|
||||||
{
|
{
|
||||||
const std::string walletFile = WalletDataFilePath(location.GetPath()).string();
|
const std::string walletFile = WalletDataFilePath(location.GetPath()).string();
|
||||||
|
|
||||||
|
@ -3721,7 +3722,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(&chain, location, WalletDatabase::Create(location.GetPath()));
|
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(&chain, location, WalletDatabase::Create(location.GetPath()));
|
||||||
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
|
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
|
||||||
if (nZapWalletRet != DBErrors::LOAD_OK) {
|
if (nZapWalletRet != DBErrors::LOAD_OK) {
|
||||||
error = strprintf(_("Error loading %s: Wallet corrupted").translated, walletFile);
|
error = strprintf(_("Error loading %s: Wallet corrupted"), walletFile);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3736,26 +3737,26 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun);
|
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun);
|
||||||
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
||||||
if (nLoadWalletRet == DBErrors::CORRUPT) {
|
if (nLoadWalletRet == DBErrors::CORRUPT) {
|
||||||
error = strprintf(_("Error loading %s: Wallet corrupted").translated, walletFile);
|
error = strprintf(_("Error loading %s: Wallet corrupted"), walletFile);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
else if (nLoadWalletRet == DBErrors::NONCRITICAL_ERROR)
|
else if (nLoadWalletRet == DBErrors::NONCRITICAL_ERROR)
|
||||||
{
|
{
|
||||||
warnings.push_back(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
|
warnings.push_back(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
|
||||||
" or address book entries might be missing or incorrect.").translated,
|
" or address book entries might be missing or incorrect."),
|
||||||
walletFile));
|
walletFile));
|
||||||
}
|
}
|
||||||
else if (nLoadWalletRet == DBErrors::TOO_NEW) {
|
else if (nLoadWalletRet == DBErrors::TOO_NEW) {
|
||||||
error = strprintf(_("Error loading %s: Wallet requires newer version of %s").translated, walletFile, PACKAGE_NAME);
|
error = strprintf(_("Error loading %s: Wallet requires newer version of %s"), walletFile, PACKAGE_NAME);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
else if (nLoadWalletRet == DBErrors::NEED_REWRITE)
|
else if (nLoadWalletRet == DBErrors::NEED_REWRITE)
|
||||||
{
|
{
|
||||||
error = strprintf(_("Wallet needed to be rewritten: restart %s to complete").translated, PACKAGE_NAME);
|
error = strprintf(_("Wallet needed to be rewritten: restart %s to complete"), PACKAGE_NAME);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error = strprintf(_("Error loading %s").translated, walletFile);
|
error = strprintf(_("Error loading %s"), walletFile);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3781,7 +3782,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
// Legacy wallets need SetupGeneration here.
|
// Legacy wallets need SetupGeneration here.
|
||||||
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
|
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
|
||||||
if (!spk_man->SetupGeneration()) {
|
if (!spk_man->SetupGeneration()) {
|
||||||
error = _("Unable to generate initial keys").translated;
|
error = _("Unable to generate initial keys");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3791,36 +3792,36 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
walletInstance->chainStateFlushed(chain.getTipLocator());
|
walletInstance->chainStateFlushed(chain.getTipLocator());
|
||||||
} else if (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS) {
|
} else if (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS) {
|
||||||
// Make it impossible to disable private keys after creation
|
// Make it impossible to disable private keys after creation
|
||||||
error = strprintf(_("Error loading %s: Private keys can only be disabled during creation").translated, walletFile);
|
error = strprintf(_("Error loading %s: Private keys can only be disabled during creation"), walletFile);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (walletInstance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
} else if (walletInstance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
||||||
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
|
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
|
||||||
if (spk_man->HavePrivateKeys()) {
|
if (spk_man->HavePrivateKeys()) {
|
||||||
warnings.push_back(strprintf(_("Warning: Private keys detected in wallet {%s} with disabled private keys").translated, walletFile));
|
warnings.push_back(strprintf(_("Warning: Private keys detected in wallet {%s} with disabled private keys"), walletFile));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gArgs.GetArg("-addresstype", "").empty() && !ParseOutputType(gArgs.GetArg("-addresstype", ""), walletInstance->m_default_address_type)) {
|
if (!gArgs.GetArg("-addresstype", "").empty() && !ParseOutputType(gArgs.GetArg("-addresstype", ""), walletInstance->m_default_address_type)) {
|
||||||
error = strprintf(_("Unknown address type '%s'").translated, gArgs.GetArg("-addresstype", ""));
|
error = strprintf(_("Unknown address type '%s'"), gArgs.GetArg("-addresstype", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gArgs.GetArg("-changetype", "").empty() && !ParseOutputType(gArgs.GetArg("-changetype", ""), walletInstance->m_default_change_type)) {
|
if (!gArgs.GetArg("-changetype", "").empty() && !ParseOutputType(gArgs.GetArg("-changetype", ""), walletInstance->m_default_change_type)) {
|
||||||
error = strprintf(_("Unknown change type '%s'").translated, gArgs.GetArg("-changetype", ""));
|
error = strprintf(_("Unknown change type '%s'"), gArgs.GetArg("-changetype", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-mintxfee")) {
|
if (gArgs.IsArgSet("-mintxfee")) {
|
||||||
CAmount n = 0;
|
CAmount n = 0;
|
||||||
if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
|
if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
|
||||||
error = AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", "")).translated;
|
error = AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (n > HIGH_TX_FEE_PER_KB) {
|
if (n > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-mintxfee").translated + " " +
|
warnings.push_back(AmountHighWarn("-mintxfee") + Untranslated(" ") +
|
||||||
_("This is the minimum transaction fee you pay on every transaction.").translated);
|
_("This is the minimum transaction fee you pay on every transaction."));
|
||||||
}
|
}
|
||||||
walletInstance->m_min_fee = CFeeRate(n);
|
walletInstance->m_min_fee = CFeeRate(n);
|
||||||
}
|
}
|
||||||
|
@ -3828,12 +3829,12 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
if (gArgs.IsArgSet("-fallbackfee")) {
|
if (gArgs.IsArgSet("-fallbackfee")) {
|
||||||
CAmount nFeePerK = 0;
|
CAmount nFeePerK = 0;
|
||||||
if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) {
|
if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) {
|
||||||
error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'").translated, gArgs.GetArg("-fallbackfee", ""));
|
error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), gArgs.GetArg("-fallbackfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
|
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-fallbackfee").translated + " " +
|
warnings.push_back(AmountHighWarn("-fallbackfee") + Untranslated(" ") +
|
||||||
_("This is the transaction fee you may pay when fee estimates are not available.").translated);
|
_("This is the transaction fee you may pay when fee estimates are not available."));
|
||||||
}
|
}
|
||||||
walletInstance->m_fallback_fee = CFeeRate(nFeePerK);
|
walletInstance->m_fallback_fee = CFeeRate(nFeePerK);
|
||||||
}
|
}
|
||||||
|
@ -3843,28 +3844,28 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
if (gArgs.IsArgSet("-discardfee")) {
|
if (gArgs.IsArgSet("-discardfee")) {
|
||||||
CAmount nFeePerK = 0;
|
CAmount nFeePerK = 0;
|
||||||
if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) {
|
if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) {
|
||||||
error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'").translated, gArgs.GetArg("-discardfee", ""));
|
error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), gArgs.GetArg("-discardfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
|
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-discardfee").translated + " " +
|
warnings.push_back(AmountHighWarn("-discardfee") + Untranslated(" ") +
|
||||||
_("This is the transaction fee you may discard if change is smaller than dust at this level").translated);
|
_("This is the transaction fee you may discard if change is smaller than dust at this level"));
|
||||||
}
|
}
|
||||||
walletInstance->m_discard_rate = CFeeRate(nFeePerK);
|
walletInstance->m_discard_rate = CFeeRate(nFeePerK);
|
||||||
}
|
}
|
||||||
if (gArgs.IsArgSet("-paytxfee")) {
|
if (gArgs.IsArgSet("-paytxfee")) {
|
||||||
CAmount nFeePerK = 0;
|
CAmount nFeePerK = 0;
|
||||||
if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
|
if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
|
||||||
error = AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", "")).translated;
|
error = AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
|
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-paytxfee").translated + " " +
|
warnings.push_back(AmountHighWarn("-paytxfee") + Untranslated(" ") +
|
||||||
_("This is the transaction fee you will pay if you send a transaction.").translated);
|
_("This is the transaction fee you will pay if you send a transaction."));
|
||||||
}
|
}
|
||||||
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
|
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
|
||||||
if (walletInstance->m_pay_tx_fee < chain.relayMinFee()) {
|
if (walletInstance->m_pay_tx_fee < chain.relayMinFee()) {
|
||||||
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)").translated,
|
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
|
||||||
gArgs.GetArg("-paytxfee", ""), chain.relayMinFee().ToString());
|
gArgs.GetArg("-paytxfee", ""), chain.relayMinFee().ToString());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -3873,23 +3874,23 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
if (gArgs.IsArgSet("-maxtxfee")) {
|
if (gArgs.IsArgSet("-maxtxfee")) {
|
||||||
CAmount nMaxFee = 0;
|
CAmount nMaxFee = 0;
|
||||||
if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) {
|
if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) {
|
||||||
error = AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", "")).translated;
|
error = AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", ""));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nMaxFee > HIGH_MAX_TX_FEE) {
|
if (nMaxFee > HIGH_MAX_TX_FEE) {
|
||||||
warnings.push_back(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction.").translated);
|
warnings.push_back(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
|
||||||
}
|
}
|
||||||
if (CFeeRate(nMaxFee, 1000) < chain.relayMinFee()) {
|
if (CFeeRate(nMaxFee, 1000) < chain.relayMinFee()) {
|
||||||
error = strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)").translated,
|
error = strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
|
||||||
gArgs.GetArg("-maxtxfee", ""), chain.relayMinFee().ToString());
|
gArgs.GetArg("-maxtxfee", ""), chain.relayMinFee().ToString());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
walletInstance->m_default_max_tx_fee = nMaxFee;
|
walletInstance->m_default_max_tx_fee = nMaxFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chain.relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB) {
|
if (chain.relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB) {
|
||||||
warnings.push_back(AmountHighWarn("-minrelaytxfee").translated + " " +
|
warnings.push_back(AmountHighWarn("-minrelaytxfee") + Untranslated(" ") +
|
||||||
_("The wallet will avoid paying less than the minimum relay fee.").translated);
|
_("The wallet will avoid paying less than the minimum relay fee."));
|
||||||
}
|
}
|
||||||
|
|
||||||
walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
|
walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
|
||||||
|
@ -3949,7 +3950,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rescan_height != block_height) {
|
if (rescan_height != block_height) {
|
||||||
error = _("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)").translated;
|
error = _("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3974,7 +3975,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
{
|
{
|
||||||
WalletRescanReserver reserver(*walletInstance);
|
WalletRescanReserver reserver(*walletInstance);
|
||||||
if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(chain.getBlockHash(rescan_height), rescan_height, {} /* max height */, reserver, true /* update */).status)) {
|
if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(chain.getBlockHash(rescan_height), rescan_height, {} /* max height */, reserver, true /* update */).status)) {
|
||||||
error = _("Failed to rescan the wallet during initialization").translated;
|
error = _("Failed to rescan the wallet during initialization");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4034,7 +4035,7 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
|
||||||
return &address_book_it->second;
|
return &address_book_it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::UpgradeWallet(int version, std::string& error, std::vector<std::string>& warnings)
|
bool CWallet::UpgradeWallet(int version, bilingual_str& error, std::vector<bilingual_str>& warnings)
|
||||||
{
|
{
|
||||||
int prev_version = GetVersion();
|
int prev_version = GetVersion();
|
||||||
int nMaxVersion = version;
|
int nMaxVersion = version;
|
||||||
|
@ -4043,12 +4044,12 @@ bool CWallet::UpgradeWallet(int version, std::string& error, std::vector<std::st
|
||||||
WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
|
WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
|
||||||
nMaxVersion = FEATURE_LATEST;
|
nMaxVersion = FEATURE_LATEST;
|
||||||
SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
|
SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
|
WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
|
||||||
|
}
|
||||||
if (nMaxVersion < GetVersion())
|
if (nMaxVersion < GetVersion())
|
||||||
{
|
{
|
||||||
error = _("Cannot downgrade wallet").translated;
|
error = _("Cannot downgrade wallet");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SetMaxVersion(nMaxVersion);
|
SetMaxVersion(nMaxVersion);
|
||||||
|
@ -4058,7 +4059,7 @@ bool CWallet::UpgradeWallet(int version, std::string& error, std::vector<std::st
|
||||||
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
|
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
|
||||||
int max_version = GetVersion();
|
int max_version = GetVersion();
|
||||||
if (!CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
|
if (!CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
|
||||||
error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified.").translated;
|
error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
|
|
||||||
using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
|
using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
|
||||||
|
|
||||||
|
struct bilingual_str;
|
||||||
|
|
||||||
//! Explicitly unload and delete the wallet.
|
//! Explicitly unload and delete the wallet.
|
||||||
//! Blocks the current thread after signaling the unload intent so that all
|
//! Blocks the current thread after signaling the unload intent so that all
|
||||||
//! wallet clients release the wallet.
|
//! wallet clients release the wallet.
|
||||||
|
@ -52,7 +54,7 @@ bool RemoveWallet(const std::shared_ptr<CWallet>& wallet);
|
||||||
bool HasWallets();
|
bool HasWallets();
|
||||||
std::vector<std::shared_ptr<CWallet>> GetWallets();
|
std::vector<std::shared_ptr<CWallet>> GetWallets();
|
||||||
std::shared_ptr<CWallet> GetWallet(const std::string& name);
|
std::shared_ptr<CWallet> GetWallet(const std::string& name);
|
||||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings);
|
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
||||||
std::unique_ptr<interfaces::Handler> HandleLoadWallet(LoadWalletFn load_wallet);
|
std::unique_ptr<interfaces::Handler> HandleLoadWallet(LoadWalletFn load_wallet);
|
||||||
|
|
||||||
enum class WalletCreationStatus {
|
enum class WalletCreationStatus {
|
||||||
|
@ -61,7 +63,7 @@ enum class WalletCreationStatus {
|
||||||
ENCRYPTION_FAILED
|
ENCRYPTION_FAILED
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::shared_ptr<CWallet>& result);
|
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::shared_ptr<CWallet>& result);
|
||||||
|
|
||||||
//! -paytxfee default
|
//! -paytxfee default
|
||||||
constexpr CAmount DEFAULT_PAY_TX_FEE = 0;
|
constexpr CAmount DEFAULT_PAY_TX_FEE = 0;
|
||||||
|
@ -930,7 +932,7 @@ public:
|
||||||
* Insert additional inputs into the transaction by
|
* Insert additional inputs into the transaction by
|
||||||
* calling CreateTransaction();
|
* calling CreateTransaction();
|
||||||
*/
|
*/
|
||||||
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);
|
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, bilingual_str& error, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);
|
||||||
// Fetch the inputs and sign with SIGHASH_ALL.
|
// Fetch the inputs and sign with SIGHASH_ALL.
|
||||||
bool SignTransaction(CMutableTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
bool SignTransaction(CMutableTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
// Sign the tx given the input coins and sighash.
|
// Sign the tx given the input coins and sighash.
|
||||||
|
@ -961,7 +963,7 @@ public:
|
||||||
* selected by SelectCoins(); Also create the change output, when needed
|
* selected by SelectCoins(); Also create the change output, when needed
|
||||||
* @note passing nChangePosInOut as -1 will result in setting a random position
|
* @note passing nChangePosInOut as -1 will result in setting a random position
|
||||||
*/
|
*/
|
||||||
bool CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
|
bool CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CAmount& nFeeRet, 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.
|
* Submit the transaction to the node's mempool and then relay to peers.
|
||||||
* Should be called after CreateTransaction unless you want to abort
|
* Should be called after CreateTransaction unless you want to abort
|
||||||
|
@ -1124,10 +1126,10 @@ public:
|
||||||
bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
|
bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
|
||||||
|
|
||||||
//! Verify wallet naming and perform salvage on the wallet if required
|
//! Verify wallet naming and perform salvage on the wallet if required
|
||||||
static bool Verify(interfaces::Chain& chain, const WalletLocation& location, bool salvage_wallet, std::string& error_string, std::vector<std::string>& warnings);
|
static bool Verify(interfaces::Chain& chain, const WalletLocation& location, bool salvage_wallet, bilingual_str& error_string, std::vector<bilingual_str>& warnings);
|
||||||
|
|
||||||
/* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
|
/* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
|
||||||
static std::shared_ptr<CWallet> CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings, uint64_t wallet_creation_flags = 0);
|
static std::shared_ptr<CWallet> CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings, uint64_t wallet_creation_flags = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wallet post-init setup
|
* Wallet post-init setup
|
||||||
|
@ -1180,7 +1182,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Upgrade the wallet */
|
/** Upgrade the wallet */
|
||||||
bool UpgradeWallet(int version, std::string& error, std::vector<std::string>& warnings);
|
bool UpgradeWallet(int version, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
||||||
|
|
||||||
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
|
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
|
||||||
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
|
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
|
||||||
|
|
|
@ -913,12 +913,12 @@ bool WalletBatch::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, C
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WalletBatch::VerifyEnvironment(const fs::path& wallet_path, std::string& errorStr)
|
bool WalletBatch::VerifyEnvironment(const fs::path& wallet_path, bilingual_str& errorStr)
|
||||||
{
|
{
|
||||||
return BerkeleyBatch::VerifyEnvironment(wallet_path, errorStr);
|
return BerkeleyBatch::VerifyEnvironment(wallet_path, errorStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WalletBatch::VerifyDatabaseFile(const fs::path& wallet_path, std::vector<std::string>& warnings, std::string& errorStr)
|
bool WalletBatch::VerifyDatabaseFile(const fs::path& wallet_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr)
|
||||||
{
|
{
|
||||||
return BerkeleyBatch::VerifyDatabaseFile(wallet_path, warnings, errorStr, WalletBatch::Recover);
|
return BerkeleyBatch::VerifyDatabaseFile(wallet_path, warnings, errorStr, WalletBatch::Recover);
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,9 +272,9 @@ public:
|
||||||
/* Function to determine if a certain KV/key-type is a key (cryptographical key) type */
|
/* Function to determine if a certain KV/key-type is a key (cryptographical key) type */
|
||||||
static bool IsKeyType(const std::string& strType);
|
static bool IsKeyType(const std::string& strType);
|
||||||
/* verifies the database environment */
|
/* verifies the database environment */
|
||||||
static bool VerifyEnvironment(const fs::path& wallet_path, std::string& errorStr);
|
static bool VerifyEnvironment(const fs::path& wallet_path, bilingual_str& errorStr);
|
||||||
/* verifies the database file */
|
/* verifies the database file */
|
||||||
static bool VerifyDatabaseFile(const fs::path& wallet_path, std::vector<std::string>& warnings, std::string& errorStr);
|
static bool VerifyDatabaseFile(const fs::path& wallet_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr);
|
||||||
|
|
||||||
//! write the hdchain model (external chain child index counter)
|
//! write the hdchain model (external chain child index counter)
|
||||||
bool WriteHDChain(const CHDChain& chain);
|
bool WriteHDChain(const CHDChain& chain);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
#include <util/translation.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
#include <wallet/walletutil.h>
|
#include <wallet/walletutil.h>
|
||||||
|
|
||||||
|
@ -117,9 +118,9 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
|
||||||
tfm::format(std::cerr, "Error: no wallet file at %s\n", name);
|
tfm::format(std::cerr, "Error: no wallet file at %s\n", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string error;
|
bilingual_str error;
|
||||||
if (!WalletBatch::VerifyEnvironment(path, error)) {
|
if (!WalletBatch::VerifyEnvironment(path, error)) {
|
||||||
tfm::format(std::cerr, "Error loading %s. Is wallet being used by other process?\n", name);
|
tfm::format(std::cerr, "%s\nError loading %s. Is wallet being used by other process?\n", error.original, name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::shared_ptr<CWallet> wallet_instance = LoadWallet(name, path);
|
std::shared_ptr<CWallet> wallet_instance = LoadWallet(name, path);
|
||||||
|
|
|
@ -15,6 +15,7 @@ from test_framework.util import assert_equal
|
||||||
|
|
||||||
BUFFER_SIZE = 16 * 1024
|
BUFFER_SIZE = 16 * 1024
|
||||||
|
|
||||||
|
|
||||||
class ToolWalletTest(BitcoinTestFramework):
|
class ToolWalletTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
|
@ -48,7 +49,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
h = hashlib.sha1()
|
h = hashlib.sha1()
|
||||||
mv = memoryview(bytearray(BUFFER_SIZE))
|
mv = memoryview(bytearray(BUFFER_SIZE))
|
||||||
with open(self.wallet_path, 'rb', buffering=0) as f:
|
with open(self.wallet_path, 'rb', buffering=0) as f:
|
||||||
for n in iter(lambda : f.readinto(mv), 0):
|
for n in iter(lambda: f.readinto(mv), 0):
|
||||||
h.update(mv[:n])
|
h.update(mv[:n])
|
||||||
return h.hexdigest()
|
return h.hexdigest()
|
||||||
|
|
||||||
|
@ -69,7 +70,12 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
self.assert_raises_tool_error('Invalid command: help', 'help')
|
self.assert_raises_tool_error('Invalid command: help', 'help')
|
||||||
self.assert_raises_tool_error('Error: two methods provided (info and create). Only one method should be provided.', 'info', 'create')
|
self.assert_raises_tool_error('Error: two methods provided (info and create). Only one method should be provided.', 'info', 'create')
|
||||||
self.assert_raises_tool_error('Error parsing command line arguments: Invalid parameter -foo', '-foo')
|
self.assert_raises_tool_error('Error parsing command line arguments: Invalid parameter -foo', '-foo')
|
||||||
self.assert_raises_tool_error('Error loading wallet.dat. Is wallet being used by other process?', '-wallet=wallet.dat', 'info')
|
self.assert_raises_tool_error(
|
||||||
|
'Error initializing wallet database environment "{}"!\nError loading wallet.dat. Is wallet being used by other process?'
|
||||||
|
.format(os.path.join(self.nodes[0].datadir, self.chain, 'wallets')),
|
||||||
|
'-wallet=wallet.dat',
|
||||||
|
'info',
|
||||||
|
)
|
||||||
self.assert_raises_tool_error('Error: no wallet file at nonexistent.dat', '-wallet=nonexistent.dat', 'info')
|
self.assert_raises_tool_error('Error: no wallet file at nonexistent.dat', '-wallet=nonexistent.dat', 'info')
|
||||||
|
|
||||||
def test_tool_wallet_info(self):
|
def test_tool_wallet_info(self):
|
||||||
|
@ -84,7 +90,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
#
|
#
|
||||||
# self.log.debug('Setting wallet file permissions to 400 (read-only)')
|
# self.log.debug('Setting wallet file permissions to 400 (read-only)')
|
||||||
# os.chmod(self.wallet_path, stat.S_IRUSR)
|
# os.chmod(self.wallet_path, stat.S_IRUSR)
|
||||||
# assert(self.wallet_permissions() in ['400', '666']) # Sanity check. 666 because Appveyor.
|
# assert self.wallet_permissions() in ['400', '666'] # Sanity check. 666 because Appveyor.
|
||||||
# shasum_before = self.wallet_shasum()
|
# shasum_before = self.wallet_shasum()
|
||||||
timestamp_before = self.wallet_timestamp()
|
timestamp_before = self.wallet_timestamp()
|
||||||
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
|
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
|
||||||
|
@ -103,7 +109,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
|
self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
|
||||||
self.log.debug('Setting wallet file permissions back to 600 (read/write)')
|
self.log.debug('Setting wallet file permissions back to 600 (read/write)')
|
||||||
os.chmod(self.wallet_path, stat.S_IRUSR | stat.S_IWUSR)
|
os.chmod(self.wallet_path, stat.S_IRUSR | stat.S_IWUSR)
|
||||||
assert(self.wallet_permissions() in ['600', '666']) # Sanity check. 666 because Appveyor.
|
assert self.wallet_permissions() in ['600', '666'] # Sanity check. 666 because Appveyor.
|
||||||
#
|
#
|
||||||
# TODO: Wallet tool info should not write to the wallet file.
|
# TODO: Wallet tool info should not write to the wallet file.
|
||||||
# The following lines should be uncommented and the tests still succeed:
|
# The following lines should be uncommented and the tests still succeed:
|
||||||
|
|
|
@ -300,7 +300,7 @@ def test_maxtxfee_fails(self, rbf_node, dest_address):
|
||||||
self.restart_node(1, ['-maxtxfee=0.000025'] + self.extra_args[1])
|
self.restart_node(1, ['-maxtxfee=0.000025'] + self.extra_args[1])
|
||||||
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
|
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
|
||||||
rbfid = spend_one_input(rbf_node, dest_address)
|
rbfid = spend_one_input(rbf_node, dest_address)
|
||||||
assert_raises_rpc_error(-4, "Unable to create transaction: Fee exceeds maximum configured by -maxtxfee", rbf_node.bumpfee, rbfid)
|
assert_raises_rpc_error(-4, "Unable to create transaction. Fee exceeds maximum configured by -maxtxfee", rbf_node.bumpfee, rbfid)
|
||||||
self.restart_node(1, self.extra_args[1])
|
self.restart_node(1, self.extra_args[1])
|
||||||
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
|
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ def test_no_more_inputs_fails(self, rbf_node, dest_address):
|
||||||
rbf_node.generatetoaddress(1, dest_address)
|
rbf_node.generatetoaddress(1, dest_address)
|
||||||
# spend all funds, no change output
|
# spend all funds, no change output
|
||||||
rbfid = rbf_node.sendtoaddress(rbf_node.getnewaddress(), rbf_node.getbalance(), "", "", True)
|
rbfid = rbf_node.sendtoaddress(rbf_node.getnewaddress(), rbf_node.getbalance(), "", "", True)
|
||||||
assert_raises_rpc_error(-4, "Unable to create transaction: Insufficient funds", rbf_node.bumpfee, rbfid)
|
assert_raises_rpc_error(-4, "Unable to create transaction. Insufficient funds", rbf_node.bumpfee, rbfid)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -227,10 +227,10 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-18, 'Wallet wallets not found.', self.nodes[0].loadwallet, 'wallets')
|
assert_raises_rpc_error(-18, 'Wallet wallets not found.', self.nodes[0].loadwallet, 'wallets')
|
||||||
|
|
||||||
# Fail to load duplicate wallets
|
# Fail to load duplicate wallets
|
||||||
assert_raises_rpc_error(-4, 'Wallet file verification failed: Error loading wallet w1. Duplicate -wallet filename specified.', self.nodes[0].loadwallet, wallet_names[0])
|
assert_raises_rpc_error(-4, 'Wallet file verification failed. Error loading wallet w1. Duplicate -wallet filename specified.', self.nodes[0].loadwallet, wallet_names[0])
|
||||||
|
|
||||||
# Fail to load duplicate wallets by different ways (directory and filepath)
|
# Fail to load duplicate wallets by different ways (directory and filepath)
|
||||||
assert_raises_rpc_error(-4, "Wallet file verification failed: Error loading wallet wallet.dat. Duplicate -wallet filename specified.", self.nodes[0].loadwallet, 'wallet.dat')
|
assert_raises_rpc_error(-4, "Wallet file verification failed. Error loading wallet wallet.dat. Duplicate -wallet filename specified.", self.nodes[0].loadwallet, 'wallet.dat')
|
||||||
|
|
||||||
# Fail to load if one wallet is a copy of another
|
# Fail to load if one wallet is a copy of another
|
||||||
assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
||||||
|
@ -240,7 +240,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
|
|
||||||
|
|
||||||
# Fail to load if wallet file is a symlink
|
# Fail to load if wallet file is a symlink
|
||||||
assert_raises_rpc_error(-4, "Wallet file verification failed: Invalid -wallet path 'w8_symlink'", self.nodes[0].loadwallet, 'w8_symlink')
|
assert_raises_rpc_error(-4, "Wallet file verification failed. Invalid -wallet path 'w8_symlink'", self.nodes[0].loadwallet, 'w8_symlink')
|
||||||
|
|
||||||
# Fail to load if a directory is specified that doesn't contain a wallet
|
# Fail to load if a directory is specified that doesn't contain a wallet
|
||||||
os.mkdir(wallet_dir('empty_wallet_dir'))
|
os.mkdir(wallet_dir('empty_wallet_dir'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue