Skip to content

Commit

Permalink
[Cleanup] Refactor CPivStake::CreateTxIn into GetTxIn
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 3, 2021
1 parent 1f71993 commit 5f3d3ba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/stakeinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTxOut>& vout, CAmount nTotal) = 0;
Expand All @@ -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<CTxOut>& vout, CAmount nTotal) override;
bool IsZPIV() const override { return false; }
bool ContextCheck(int nHeight, uint32_t nTime) override;
Expand Down
20 changes: 6 additions & 14 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/zpiv/zpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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

0 comments on commit 5f3d3ba

Please sign in to comment.