@@ -53,7 +53,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
5353 TransactionRecord sub (hash, nTime, wtx.GetTotalSize ());
5454 // Check for cold stakes.
5555 if (wtx.HasP2CSOutputs ()) {
56- loadHotOrColdStake (wallet, wtx, sub);
56+ loadHotOrColdStakeOrContract (wallet, wtx, sub);
5757 parts.append (sub);
5858 return parts;
5959 }
@@ -156,6 +156,13 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
156156 sub.idx = parts.size ();
157157 parts.append (sub);
158158 }
159+ } else if (wtx.HasP2CSOutputs ()) {
160+ // Delegate tx.
161+ // TODO: Think this well..
162+ TransactionRecord sub (hash, nTime, wtx.GetTotalSize ());
163+ loadHotOrColdStakeOrContract (wallet, wtx, sub, true );
164+ parts.append (sub);
165+ return parts;
159166 } else if (nNet > 0 || wtx.IsCoinBase ()) {
160167 //
161168 // Credit
@@ -322,17 +329,40 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
322329 return parts;
323330}
324331
325- void TransactionRecord::loadHotOrColdStake (const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record)
332+ void TransactionRecord::loadHotOrColdStakeOrContract (const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record, bool isContract )
326333{
327334 record.involvesWatchAddress = false ;
328- CTxOut p2csUtxo = wtx.vout [1 ];
335+
336+ // Get the p2cs
337+ CTxOut p2csUtxo;
338+ for (unsigned int nOut = 0 ; nOut < wtx.vout .size (); nOut++) {
339+ const CTxOut &txout = wtx.vout [nOut];
340+ if (txout.scriptPubKey .IsPayToColdStaking ()) {
341+ p2csUtxo = txout;
342+ break ;
343+ }
344+ }
329345 bool isSpendable = wallet->IsMine (p2csUtxo) & ISMINE_SPENDABLE_DELEGATED;
330- if (isSpendable) {
331- record.type = TransactionRecord::StakeDelegated;
346+
347+ if (isContract) {
348+ record.type = TransactionRecord::P2CSDelegation;
349+ record.debit = wtx.nDelegatedDebitCached ;
332350 record.credit = wtx.nDelegatedCreditCached ;
351+ if (isSpendable) {
352+ // Means that this wallet can redeem the p2cs, this was a send to yourself..
353+ // TODO: add some way to represent this..
354+ }
355+
333356 } else {
334- record.type = TransactionRecord::StakeHot;
335- record.credit = wtx.nColdCreditCached ;
357+ // Stake
358+ if (isSpendable) {
359+ record.type = TransactionRecord::StakeDelegated;
360+ record.credit = wtx.nDelegatedCreditCached ;
361+ record.debit = wtx.nDelegatedDebitCached ;
362+ } else {
363+ record.type = TransactionRecord::StakeHot;
364+ record.credit = wtx.nColdCreditCached ;
365+ }
336366 }
337367
338368 CTxDestination address;
0 commit comments