@@ -60,13 +60,18 @@ CTxIn::CTxIn(const libzerocoin::CoinSpend& spend, libzerocoin::CoinDenomination
6060 nSequence = denom;
6161}
6262
63+ bool CTxIn::IsZerocoinSpend () const
64+ {
65+ return prevout.hash == 0 && scriptSig.IsZerocoinSpend ();
66+ }
67+
6368std::string CTxIn::ToString () const
6469{
6570 std::string str;
6671 str += " CTxIn(" ;
6772 str += prevout.ToString ();
6873 if (prevout.IsNull ())
69- if (scriptSig. IsZerocoinSpend ())
74+ if (IsZerocoinSpend ())
7075 str += strprintf (" , zerocoinspend %s..." , HexStr (scriptSig).substr (0 , 25 ));
7176 else
7277 str += strprintf (" , coinbase %s" , HexStr (scriptSig));
@@ -98,6 +103,19 @@ uint256 CTxOut::GetHash() const
98103 return SerializeHash (*this );
99104}
100105
106+ bool CTxOut::IsZerocoinMint () const
107+ {
108+ return scriptPubKey.IsZerocoinMint ();
109+ }
110+
111+ CAmount CTxOut::GetZerocoinMinted () const
112+ {
113+ if (!IsZerocoinMint ())
114+ return CAmount (0 );
115+
116+ return nValue;
117+ }
118+
101119std::string CTxOut::ToString () const
102120{
103121 return strprintf (" CTxOut(nValue=%d.%08d, scriptPubKey=%s)" , nValue / COIN, nValue % COIN, scriptPubKey.ToString ().substr (0 ,30 ));
@@ -146,17 +164,35 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
146164 return *this ;
147165}
148166
167+ bool CTransaction::HasZerocoinSpendInputs () const
168+ {
169+ for (const CTxIn& txin: vin) {
170+ if (txin.IsZerocoinSpend ())
171+ return true ;
172+ }
173+ return false ;
174+ }
175+
176+ bool CTransaction::HasZerocoinMintOutputs () const
177+ {
178+ for (const CTxOut& txout : vout) {
179+ if (txout.IsZerocoinMint ())
180+ return true ;
181+ }
182+ return false ;
183+ }
184+
149185bool CTransaction::IsCoinStake () const
150186{
151187 if (vin.empty ())
152188 return false ;
153189
154190 // ppcoin: the coin stake transaction is marked with the first output empty
155- bool fAllowNull = vin[0 ].scriptSig . IsZerocoinSpend ();
191+ bool fAllowNull = vin[0 ].IsZerocoinSpend ();
156192 if (vin[0 ].prevout .IsNull () && !fAllowNull )
157193 return false ;
158194
159- return (vin. size () > 0 && vout.size () >= 2 && vout[0 ].IsEmpty ());
195+ return (vout.size () >= 2 && vout[0 ].IsEmpty ());
160196}
161197
162198CAmount CTransaction::GetValueOut () const
@@ -178,14 +214,12 @@ CAmount CTransaction::GetValueOut() const
178214
179215CAmount CTransaction::GetZerocoinMinted () const
180216{
217+ CAmount nValueOut = 0 ;
181218 for (const CTxOut& txOut : vout) {
182- if (!txOut.scriptPubKey .IsZerocoinMint ())
183- continue ;
184-
185- return txOut.nValue ;
219+ nValueOut += txOut.GetZerocoinMinted ();
186220 }
187221
188- return CAmount ( 0 ) ;
222+ return nValueOut ;
189223}
190224
191225bool CTransaction::UsesUTXO (const COutPoint out)
@@ -209,12 +243,9 @@ std::list<COutPoint> CTransaction::GetOutPoints() const
209243
210244CAmount CTransaction::GetZerocoinSpent () const
211245{
212- if (!IsZerocoinSpend ())
213- return 0 ;
214-
215246 CAmount nValueOut = 0 ;
216247 for (const CTxIn& txin : vin) {
217- if (!txin.scriptSig . IsZerocoinSpend ())
248+ if (!txin.IsZerocoinSpend ())
218249 continue ;
219250
220251 nValueOut += txin.nSequence * COIN;
@@ -227,7 +258,7 @@ int CTransaction::GetZerocoinMintCount() const
227258{
228259 int nCount = 0 ;
229260 for (const CTxOut& out : vout) {
230- if (out.scriptPubKey . IsZerocoinMint ())
261+ if (out.IsZerocoinMint ())
231262 nCount++;
232263 }
233264 return nCount;
0 commit comments