Browse Source

Add total number of commitments to getblockchaininfo

v1.0.9-lin
Jack Grigg 8 years ago
parent
commit
5d6e1aa60f
No known key found for this signature in database GPG Key ID: 6A6914DAFBEA00DA
  1. 5
      src/rpcblockchain.cpp
  2. 19
      src/zcash/IncrementalMerkleTree.cpp
  3. 2
      src/zcash/IncrementalMerkleTree.hpp

5
src/rpcblockchain.cpp

@ -533,6 +533,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
" \"commitments\": xxxxxx, (numeric) the current number of note commitments in the commitment tree\n"
" \"softforks\": [ (array) status of softforks in progress\n"
" {\n"
" \"id\": \"xxxx\", (string) name of softfork\n"
@ -564,6 +565,10 @@ Value getblockchaininfo(const Array& params, bool fHelp)
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
obj.push_back(Pair("pruned", fPruneMode));
ZCIncrementalMerkleTree tree;
pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree);
obj.push_back(Pair("commitments", tree.size()));
const Consensus::Params& consensusParams = Params().GetConsensus();
CBlockIndex* tip = chainActive.Tip();
Array softforks;

19
src/zcash/IncrementalMerkleTree.cpp

@ -81,6 +81,25 @@ Hash IncrementalMerkleTree<Depth, Hash>::last() const {
}
}
template<size_t Depth, typename Hash>
size_t IncrementalMerkleTree<Depth, Hash>::size() const {
size_t ret = 0;
if (left) {
ret++;
}
if (right) {
ret++;
}
// Treat occupation of parents array as a binary number
// (right-shifted by 1)
for (size_t i = 0; i < parents.size(); i++) {
if (parents[i]) {
ret += (1 << (i+1));
}
}
return ret;
}
template<size_t Depth, typename Hash>
void IncrementalMerkleTree<Depth, Hash>::append(Hash obj) {
if (is_complete(Depth)) {

2
src/zcash/IncrementalMerkleTree.hpp

@ -75,6 +75,8 @@ public:
parents.size() * 32; // parents
}
size_t size() const;
void append(Hash obj);
Hash root() const {
return root(Depth, std::deque<Hash>());

Loading…
Cancel
Save