Skip to content

Commit 494d4e2

Browse files
Merge pull request #641 from navcoin/aguycalled-patch-4
Add extra stats to getblock
2 parents 049978e + 74fb1c5 commit 494d4e2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
197197
result.pushKV("versionHex", strprintf("%08x", block.nVersion));
198198
result.pushKV("merkleroot", block.hashMerkleRoot.GetHex());
199199
UniValue txs(UniValue::VARR);
200+
int nCountProposalVotes = 0;
201+
int nCountPaymentRequestVotes = 0;
202+
int nCountPaymentRequestPayouts = 0;
203+
int nCountProposals = 0;
204+
int nCountPaymentRequests = 0;
205+
int nCountTransactions = 0;
206+
207+
CAmount nPOWBlockReward = block.IsProofOfWork() ? GetBlockSubsidy(blockindex->nHeight, Params().GetConsensus()) : 0;
208+
200209
for(const CTransaction&tx: block.vtx)
201210
{
202211
if(txDetails)
@@ -207,8 +216,48 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
207216
}
208217
else
209218
txs.push_back(tx.GetHash().GetHex());
219+
if (tx.IsCoinBase())
220+
{
221+
CAmount nAccValue = 0;
222+
for (auto&it: tx.vout)
223+
{
224+
nAccValue += it.nValue;
225+
if (it.IsProposalVote())
226+
{
227+
nCountProposalVotes++;
228+
}
229+
else if(it.IsPaymentRequestVote())
230+
{
231+
nCountPaymentRequestVotes++;
232+
}
233+
if(nAccValue > nPOWBlockReward && it.nValue > 0)
234+
{
235+
nCountPaymentRequestPayouts++;
236+
}
237+
}
238+
}
239+
else if(tx.IsCoinStake())
240+
{
241+
242+
}
243+
else
244+
{
245+
if (tx.nVersion == CTransaction::PROPOSAL_VERSION)
246+
nCountProposals++;
247+
else if(tx.nVersion == CTransaction::PAYMENT_REQUEST_VERSION)
248+
nCountPaymentRequests++;
249+
else
250+
nCountTransactions++;
251+
}
252+
210253
}
211254
result.pushKV("tx", txs);
255+
result.pushKV("tx_count", nCountTransactions);
256+
result.pushKV("proposal_count", nCountProposals);
257+
result.pushKV("payment_request_count", nCountPaymentRequests);
258+
result.pushKV("proposal_votes_count", nCountProposalVotes);
259+
result.pushKV("payment_request_votes_count", nCountPaymentRequestVotes);
260+
result.pushKV("payment_request_payouts_count", nCountPaymentRequestPayouts);
212261
result.pushKV("time", block.GetBlockTime());
213262
result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast());
214263
result.pushKV("nonce", (uint64_t)block.nNonce);

0 commit comments

Comments
 (0)