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
17 changes: 3 additions & 14 deletions src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CAmount CPivStake::GetValue() const
return outputFrom.nValue;
}

bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK)
bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal)
{
std::vector<valtype> vSolutions;
txnouttype whichType;
Expand All @@ -68,25 +68,14 @@ bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmoun
if (whichType != TX_PUBKEY && whichType != TX_PUBKEYHASH && whichType != TX_COLDSTAKE)
return error("%s: type=%d (%s) not supported for scriptPubKeyKernel", __func__, whichType, GetTxnOutputType(whichType));

CScript scriptPubKey;
CKey key;
if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) {
// if P2PKH or P2CS check that we have the input private key
if (!pwallet->GetKey(CKeyID(uint160(vSolutions[0])), key))
return error("%s: Unable to get staking private key", __func__);
}

// Consensus check: P2PKH block signatures were not accepted before v5 update.
// This can be removed after v5.0 enforcement
if (whichType == TX_PUBKEYHASH && onlyP2PK) {
// convert to P2PK inputs
scriptPubKey << key.GetPubKey() << OP_CHECKSIG;
} else {
// keep the same script
scriptPubKey = scriptPubKeyKernel;
}

vout.emplace_back(0, scriptPubKey);
vout.emplace_back(0, scriptPubKeyKernel);

// Calculate if we need to split the output
if (pwallet->nStakeSplitThreshold > 0) {
Expand All @@ -98,7 +87,7 @@ bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmoun
nSplit = txSizeMax;
for (int i = nSplit; i > 1; i--) {
LogPrintf("%s: StakeSplit: nTotal = %d; adding output %d of %d\n", __func__, nTotal, (nSplit-i)+2, nSplit);
vout.emplace_back(0, scriptPubKey);
vout.emplace_back(0, scriptPubKeyKernel);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/stakeinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CStakeInput
virtual bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) = 0;
virtual bool GetTxOutFrom(CTxOut& out) const = 0;
virtual CAmount GetValue() const = 0;
virtual bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK) = 0;
virtual bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) = 0;
virtual bool IsZPIV() const = 0;
virtual CDataStream GetUniqueness() const = 0;
virtual bool ContextCheck(int nHeight, uint32_t nTime) = 0;
Expand All @@ -51,7 +51,7 @@ class CPivStake : public CStakeInput
CAmount GetValue() const override;
CDataStream GetUniqueness() const override;
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override;
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK) override;
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) override;
bool IsZPIV() const override { return false; }
bool ContextCheck(int nHeight, uint32_t nTime) override;
};
Expand Down
18 changes: 4 additions & 14 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@ CWallet::Balance CWallet::GetBalance(const int min_depth) const
return ret;
}

CAmount CWallet::loopTxsBalance(std::function<void(const uint256&, const CWalletTx&, CAmount&)> method) const
CAmount CWallet::loopTxsBalance(const std::function<void(const uint256&, const CWalletTx&, CAmount&)>& method) const
{
CAmount nTotal = 0;
{
Expand Down Expand Up @@ -3227,9 +3227,6 @@ bool CWallet::CreateCoinStake(
pStakerStatus->SetLastTip(pindexPrev);
pStakerStatus->SetLastCoins((int) availableCoins->size());

// P2PKH block signatures were not accepted before v5 update.
bool onlyP2PK = !consensus.NetworkUpgradeActive(pindexPrev->nHeight + 1, Consensus::UPGRADE_V5_0);

// Kernel Search
CAmount nCredit;
CScript scriptPubKeyKernel;
Expand All @@ -3254,13 +3251,6 @@ bool CWallet::CreateCoinStake(
continue;
}

// This should never happen
if (stakeInput.IsZPIV()) {
LogPrintf("%s: ERROR - zPOS is disabled\n", __func__);
it++;
continue;
}

nCredit = 0;

nAttempts++;
Expand All @@ -3284,7 +3274,7 @@ bool CWallet::CreateCoinStake(

// Create the output transaction(s)
std::vector<CTxOut> vout;
if (!stakeInput.CreateTxOuts(this, vout, nCredit, onlyP2PK)) {
if (!stakeInput.CreateTxOuts(this, vout, nCredit)) {
LogPrintf("%s : failed to create output\n", __func__);
it++;
continue;
Expand Down Expand Up @@ -3913,7 +3903,7 @@ std::vector<CKeyID> CWallet::GetAffectedKeys(const CScript& spk)
std::vector<CKeyID> vAffected;
CAffectedKeysVisitor(*this, vAffected).Process(spk);
for (const CKeyID& keyid : vAffected) {
ret.push_back(keyid);
ret.emplace_back(keyid);
}
return ret;
}
Expand Down Expand Up @@ -4787,7 +4777,7 @@ Optional<std::pair<
{
auto output = this->tx->sapData->vShieldedOutput[op.n];

for (auto ovk : ovks) {
for (const auto& ovk : ovks) {
auto outPt = libzcash::SaplingOutgoingPlaintext::decrypt(
output.outCiphertext,
ovk,
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
};
Balance GetBalance(int min_depth = 0) const;

CAmount loopTxsBalance(std::function<void(const uint256&, const CWalletTx&, CAmount&)>method) const;
CAmount loopTxsBalance(const std::function<void(const uint256&, const CWalletTx&, CAmount&)>&method) const;
CAmount GetAvailableBalance(bool fIncludeDelegated = true, bool fIncludeShielded = true) const;
CAmount GetAvailableBalance(isminefilter& filter, bool useCache = false, int minDepth = 1) const;
CAmount GetColdStakingBalance() const; // delegated coins for which we have the staking key
Expand Down
2 changes: 1 addition & 1 deletion src/zpiv/zpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CLegacyZPivStake : public CStakeInput
CAmount GetValue() const override;
CDataStream GetUniqueness() const override;
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override { return false; /* creation disabled */}
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK) override { return false; /* creation disabled */}
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) override { return false; /* creation disabled */}
bool GetTxOutFrom(CTxOut& out) const override { return false; /* not available */ }
virtual bool ContextCheck(int nHeight, uint32_t nTime) override;
};
Expand Down