From 5f3d3ba82ff00a34c24311637b78aa1cba4be09f Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 26 Feb 2021 21:08:00 +0100 Subject: [PATCH] [Cleanup] Refactor CPivStake::CreateTxIn into GetTxIn --- src/stakeinput.cpp | 5 ++--- src/stakeinput.h | 3 +-- src/wallet/wallet.cpp | 20 ++++++-------------- src/zpiv/zpos.h | 1 - 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/stakeinput.cpp b/src/stakeinput.cpp index a89e4920bf877..1355808a557c3 100644 --- a/src/stakeinput.cpp +++ b/src/stakeinput.cpp @@ -46,10 +46,9 @@ bool CPivStake::GetTxOutFrom(CTxOut& out) const return true; } -bool CPivStake::CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut) +CTxIn CPivStake::GetTxIn() const { - txIn = CTxIn(outpointFrom.hash, outpointFrom.n); - return true; + return CTxIn(outpointFrom.hash, outpointFrom.n); } CAmount CPivStake::GetValue() const diff --git a/src/stakeinput.h b/src/stakeinput.h index 66b2c110bf34f..c3f5ced263d1d 100644 --- a/src/stakeinput.h +++ b/src/stakeinput.h @@ -23,7 +23,6 @@ class CStakeInput virtual ~CStakeInput(){}; virtual bool InitFromTxIn(const CTxIn& txin) = 0; virtual const CBlockIndex* GetIndexFrom() const = 0; - 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& vout, CAmount nTotal) = 0; @@ -50,7 +49,7 @@ class CPivStake : public CStakeInput bool GetTxOutFrom(CTxOut& out) const override; CAmount GetValue() const override; CDataStream GetUniqueness() const override; - bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override; + CTxIn GetTxIn() const; bool CreateTxOuts(CWallet* pwallet, std::vector& vout, CAmount nTotal) override; bool IsZPIV() const override { return false; } bool ContextCheck(int nHeight, uint32_t nTime) override; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8222975c81447..3bc581ad9ae5d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3296,24 +3296,16 @@ bool CWallet::CreateCoinStake( // put the remaining on the last output (which all into the first if only one output) txNew.vout[outputs].nValue += nRemaining; - // Limit size - unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); - if (nBytes >= DEFAULT_BLOCK_MAX_SIZE / 5) - return error("%s : exceeded coinstake size limit", __func__); + // Set coinstake input + txNew.vin.emplace_back(stakeInput.GetTxIn()); // Masternode payment FillBlockPayee(txNew, pindexPrev->nHeight + 1, true); - const uint256& hashTxOut = txNew.GetHash(); - CTxIn in; - if (!stakeInput.CreateTxIn(this, in, hashTxOut)) { - LogPrintf("%s : failed to create TxIn\n", __func__); - txNew.vin.clear(); - txNew.vout.clear(); - it++; - continue; - } - txNew.vin.emplace_back(in); + // Limit size + unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); + if (nBytes >= DEFAULT_BLOCK_MAX_SIZE / 5) + return error("%s : exceeded coinstake size limit", __func__); break; } diff --git a/src/zpiv/zpos.h b/src/zpiv/zpos.h index b8dcfd7baed05..5b51df3aa45b3 100644 --- a/src/zpiv/zpos.h +++ b/src/zpiv/zpos.h @@ -25,7 +25,6 @@ class CLegacyZPivStake : public CStakeInput const CBlockIndex* GetIndexFrom() const override; 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& 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;