Skip to content

Commit 5f3d3ba

Browse files
committed
[Cleanup] Refactor CPivStake::CreateTxIn into GetTxIn
1 parent 1f71993 commit 5f3d3ba

File tree

4 files changed

+9
-20
lines changed

4 files changed

+9
-20
lines changed

src/stakeinput.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ bool CPivStake::GetTxOutFrom(CTxOut& out) const
4646
return true;
4747
}
4848

49-
bool CPivStake::CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut)
49+
CTxIn CPivStake::GetTxIn() const
5050
{
51-
txIn = CTxIn(outpointFrom.hash, outpointFrom.n);
52-
return true;
51+
return CTxIn(outpointFrom.hash, outpointFrom.n);
5352
}
5453

5554
CAmount CPivStake::GetValue() const

src/stakeinput.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class CStakeInput
2323
virtual ~CStakeInput(){};
2424
virtual bool InitFromTxIn(const CTxIn& txin) = 0;
2525
virtual const CBlockIndex* GetIndexFrom() const = 0;
26-
virtual bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) = 0;
2726
virtual bool GetTxOutFrom(CTxOut& out) const = 0;
2827
virtual CAmount GetValue() const = 0;
2928
virtual bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) = 0;
@@ -50,7 +49,7 @@ class CPivStake : public CStakeInput
5049
bool GetTxOutFrom(CTxOut& out) const override;
5150
CAmount GetValue() const override;
5251
CDataStream GetUniqueness() const override;
53-
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override;
52+
CTxIn GetTxIn() const;
5453
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) override;
5554
bool IsZPIV() const override { return false; }
5655
bool ContextCheck(int nHeight, uint32_t nTime) override;

src/wallet/wallet.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,24 +3296,16 @@ bool CWallet::CreateCoinStake(
32963296
// put the remaining on the last output (which all into the first if only one output)
32973297
txNew.vout[outputs].nValue += nRemaining;
32983298

3299-
// Limit size
3300-
unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
3301-
if (nBytes >= DEFAULT_BLOCK_MAX_SIZE / 5)
3302-
return error("%s : exceeded coinstake size limit", __func__);
3299+
// Set coinstake input
3300+
txNew.vin.emplace_back(stakeInput.GetTxIn());
33033301

33043302
// Masternode payment
33053303
FillBlockPayee(txNew, pindexPrev->nHeight + 1, true);
33063304

3307-
const uint256& hashTxOut = txNew.GetHash();
3308-
CTxIn in;
3309-
if (!stakeInput.CreateTxIn(this, in, hashTxOut)) {
3310-
LogPrintf("%s : failed to create TxIn\n", __func__);
3311-
txNew.vin.clear();
3312-
txNew.vout.clear();
3313-
it++;
3314-
continue;
3315-
}
3316-
txNew.vin.emplace_back(in);
3305+
// Limit size
3306+
unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
3307+
if (nBytes >= DEFAULT_BLOCK_MAX_SIZE / 5)
3308+
return error("%s : exceeded coinstake size limit", __func__);
33173309

33183310
break;
33193311
}

src/zpiv/zpos.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class CLegacyZPivStake : public CStakeInput
2525
const CBlockIndex* GetIndexFrom() const override;
2626
CAmount GetValue() const override;
2727
CDataStream GetUniqueness() const override;
28-
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override { return false; /* creation disabled */}
2928
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) override { return false; /* creation disabled */}
3029
bool GetTxOutFrom(CTxOut& out) const override { return false; /* not available */ }
3130
virtual bool ContextCheck(int nHeight, uint32_t nTime) override;

0 commit comments

Comments
 (0)