Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTrans

LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- Signing my input %i\n", __func__, nMyInputIndex);
// TODO we're using amount=0 here but we should use the correct amount. This works because Dash ignores the amount while signing/verifying (only used in Bitcoin/Segwit)
if (!SignSignature(*mixingWallet.GetSigningProvider(), prevPubKey, finalMutableTransaction, nMyInputIndex, 0, int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))) { // changes scriptSig
if (!SignSignature(*mixingWallet.GetSigningProvider(prevPubKey), prevPubKey, finalMutableTransaction, nMyInputIndex, 0, int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))) { // changes scriptSig
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- Unable to sign my own transaction!\n", __func__);
// not sure what to do here, it will time out...?
}
Expand Down Expand Up @@ -1544,7 +1544,7 @@ bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& tx
txCollateral.vout.emplace_back(0, CScript() << OP_RETURN);
}

if (!SignSignature(*mixingWallet.GetSigningProvider(), txout.scriptPubKey, txCollateral, 0, txout.nValue, SIGHASH_ALL)) {
if (!SignSignature(*mixingWallet.GetSigningProvider(txout.scriptPubKey), txout.scriptPubKey, txCollateral, 0, txout.nValue, SIGHASH_ALL)) {
strReason = "Unable to sign collateral transaction!";
return false;
}
Expand Down
28 changes: 16 additions & 12 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,21 @@ class WalletImpl : public Wallet
std::string error;
return m_wallet->GetNewDestination(label, dest, error);
}
bool getPubKey(const CKeyID& address, CPubKey& pub_key) override {
auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
if (!spk_man) {
return false;
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
{
const SigningProvider* provider = m_wallet->GetSigningProvider(script);
if (provider) {
return provider->GetPubKey(address, pub_key);
}
return spk_man->GetPubKey(address, pub_key);
return false;
}
bool getPrivKey(const CKeyID& address, CKey& key) override {
auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
if (!spk_man) {
return false;
bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) override
{
const SigningProvider* provider = m_wallet->GetSigningProvider(script);
if (provider) {
return provider->GetKey(address, key);
}
return spk_man->GetKey(address, key);
return false;
}
bool isSpendable(const CScript& script) override { return m_wallet->IsMine(script) & ISMINE_SPENDABLE; }
bool isSpendable(const CTxDestination& dest) override { return m_wallet->IsMine(dest) & ISMINE_SPENDABLE; }
Expand Down Expand Up @@ -255,12 +257,14 @@ class WalletImpl : public Wallet
bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) override
{
LOCK(m_wallet->cs_wallet);
return m_wallet->AddDestData(dest, key, value);
WalletBatch batch{m_wallet->GetDatabase()};
return m_wallet->AddDestData(batch, dest, key, value);
}
bool eraseDestData(const CTxDestination& dest, const std::string& key) override
{
LOCK(m_wallet->cs_wallet);
return m_wallet->EraseDestData(dest, key);
WalletBatch batch{m_wallet->GetDatabase()};
return m_wallet->EraseDestData(batch, dest, key);
}
std::vector<std::string> getDestValues(const std::string& prefix) override
{
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class Wallet
virtual bool getNewDestination(const std::string label, CTxDestination& dest) = 0;

//! Get public key.
virtual bool getPubKey(const CKeyID& address, CPubKey& pub_key) = 0;
virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0;

//! Get private key.
virtual bool getPrivKey(const CKeyID& address, CKey& key) = 0;
virtual bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) = 0;

//! Return whether wallet has private key.
virtual bool isSpendable(const CScript& script) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
{
CPubKey pubkey;
CKeyID *keyid = std::get_if<CKeyID>(&address);
if (keyid && model->wallet().getPubKey(*keyid, pubkey))
if (keyid && model->wallet().getPubKey(out.txout.scriptPubKey, *keyid, pubkey))
{
nBytesInputs += (pubkey.IsCompressed() ? 148 : 180);
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/signverifymessagedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
}

CKey key;
if (!model->wallet().getPrivKey(*keyID, key))
if (!model->wallet().getPrivKey(GetScriptForDestination(destination), *keyID, key))
{
ui->statusLabel_SM->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR));
ui->statusLabel_SM->setText(tr("Private key for the entered address is not available."));
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ CPubKey HexToPubKey(const std::string& hex_in)
}

// Retrieves a public key for an address from the given FillableSigningProvider
CPubKey AddrToPubKey(FillableSigningProvider* const keystore, const std::string& addr_in)
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in)
{
CTxDestination dest = DecodeDestination(addr_in);
if (!IsValidDestination(dest)) {
Expand All @@ -200,7 +200,7 @@ CPubKey AddrToPubKey(FillableSigningProvider* const keystore, const std::string&
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("%s does not refer to a key", addr_in));
}
CPubKey vchPubKey;
if (!keystore->GetPubKey(*keyID, vchPubKey)) {
if (!keystore.GetPubKey(*keyID, vchPubKey)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("no full public key for address %s", addr_in));
}
if (!vchPubKey.IsFullyValid()) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extern std::string HelpExampleCli(const std::string& methodname, const std::stri
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);

CPubKey HexToPubKey(const std::string& hex_in);
CPubKey AddrToPubKey(FillableSigningProvider* const keystore, const std::string& addr_in);
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);
CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey>& pubkeys);

UniValue DescribeAddress(const CTxDestination& dest);
Expand Down
1 change: 0 additions & 1 deletion src/wallet/coincontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <wallet/coincontrol.h>
#include <wallet/wallet.h>

#include <util/system.h>

Expand Down
3 changes: 3 additions & 0 deletions src/wallet/coincontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ enum class CoinType
MAX_COIN_TYPE = ONLY_COINJOIN_COLLATERAL,
};

//! Default for -avoidpartialspends
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17518 what's stopping us from being able to remove this circular depends

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eliminated


/** Coin Control Features. */
class CCoinControl
{
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#include <net.h>
#include <node/context.h>
#include <univalue.h>
#include <ui_interface.h>
#include <util/check.h>
#include <util/error.h>
#include <util/system.h>
#include <util/moneystr.h>
#include <util/translation.h>
#include <validation.h>
#include <walletinitinterface.h>
#include <wallet/coincontrol.h>
#include <wallet/wallet.h>

#include <coinjoin/client.h>
Expand Down
25 changes: 23 additions & 2 deletions src/wallet/psbtwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,33 @@ TransactionError FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& ps
return TransactionError::SIGHASH_MISMATCH;
}

complete &= SignPSBTInput(HidingSigningProvider(pwallet->GetSigningProvider(), !sign, !bip32derivs), psbtx, i, sighash_type);
// Get the scriptPubKey to know which SigningProvider to use
CScript script;
if (input.non_witness_utxo) {
script = input.non_witness_utxo->vout[txin.prevout.n].scriptPubKey;
} else {
// There's no UTXO so we can just skip this now
complete = false;
continue;
}
SignatureData sigdata;
input.FillSignatureData(sigdata);
const SigningProvider* provider = pwallet->GetSigningProvider(script, sigdata);
if (!provider) {
complete = false;
continue;
}

complete &= SignPSBTInput(HidingSigningProvider(provider, !sign, !bip32derivs), psbtx, i, sighash_type);
}

// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
for (unsigned int i = 0; i < psbtx.tx->vout.size(); ++i) {
UpdatePSBTOutput(HidingSigningProvider(pwallet->GetSigningProvider(), true, !bip32derivs), psbtx, i);
const CTxOut& out = psbtx.tx->vout.at(i);
const SigningProvider* provider = pwallet->GetSigningProvider(out.scriptPubKey);
if (provider) {
UpdatePSBTOutput(HidingSigningProvider(provider, true, !bip32derivs), psbtx, i);
}
}

return TransactionError::OK;
Expand Down
24 changes: 9 additions & 15 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver,
}
}

static LegacyScriptPubKeyMan& GetLegacyScriptPubKeyMan(CWallet& wallet)
{
LegacyScriptPubKeyMan* spk_man = wallet.GetLegacyScriptPubKeyMan();
if (!spk_man) {
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
}
return *spk_man;
}

UniValue importprivkey(const JSONRPCRequest& request)
{
RPCHelpMan{"importprivkey",
Expand Down Expand Up @@ -110,7 +101,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
}

LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);

WalletBatch batch(pwallet->GetDBHandle());
WalletRescanReserver reserver(pwallet);
Expand Down Expand Up @@ -221,6 +212,7 @@ UniValue importaddress(const JSONRPCRequest& request)
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
CWallet* const pwallet = wallet.get();
EnsureLegacyScriptPubKeyMan(*pwallet);

std::string strLabel;
if (!request.params[1].isNull())
Expand Down Expand Up @@ -410,6 +402,7 @@ UniValue importpubkey(const JSONRPCRequest& request)
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
CWallet* const pwallet = wallet.get();
EnsureLegacyScriptPubKeyMan(*wallet);

std::string strLabel;
if (!request.params[1].isNull())
Expand Down Expand Up @@ -486,6 +479,7 @@ UniValue importwallet(const JSONRPCRequest& request)
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
CWallet* const pwallet = wallet.get();
EnsureLegacyScriptPubKeyMan(*wallet);

if (pwallet->chain().havePruned()) {
// Exit early and print an error.
Expand Down Expand Up @@ -653,7 +647,7 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
}

LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);

LOCK(pwallet->cs_wallet);
AssertLockHeld(spk_man.cs_wallet);
Expand Down Expand Up @@ -822,7 +816,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
if (!wallet) return NullUniValue;
CWallet* const pwallet = wallet.get();

LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);

LOCK(pwallet->cs_wallet);

Expand Down Expand Up @@ -871,7 +865,7 @@ UniValue dumphdinfo(const JSONRPCRequest& request)

EnsureWalletIsUnlocked(pwallet);

LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);
CHDChain hdChainCurrent;
if (!spk_man.GetHDChain(hdChainCurrent))
throw JSONRPCError(RPC_WALLET_ERROR, "This wallet is not a HD wallet.");
Expand Down Expand Up @@ -919,7 +913,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
if (!wallet) return NullUniValue;
CWallet* const pwallet = wallet.get();

LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);

LOCK(pwallet->cs_wallet);
AssertLockHeld(spk_man.cs_wallet);
Expand Down Expand Up @@ -1515,7 +1509,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
if (!wallet) return NullUniValue;
CWallet* const pwallet = wallet.get();

GetLegacyScriptPubKeyMan(*wallet);
EnsureLegacyScriptPubKeyMan(*wallet);

//Default options
bool fRescan = true;
Expand Down
Loading