Skip to content

Commit

Permalink
Make some methods const for appropriate downstream usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebfull committed Jan 4, 2016
1 parent 317ea1e commit 53c30e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions libzerocash/IncrementalMerkleTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace libzerocash {
// IncrementalMerkleTreeCompact class
/////////////////////////////////////////////

std::vector<unsigned char> IncrementalMerkleTreeCompact::serialize() {
std::vector<unsigned char> IncrementalMerkleTreeCompact::serialize() const {
/* Serialization format:
* treeHeight (4 bytes, big endian)
* hashList (ceil(treeHeight / 8) bytes)
Expand Down Expand Up @@ -203,15 +203,15 @@ namespace libzerocash {
}

bool
IncrementalMerkleTree::getRootValue(std::vector<bool>& r) {
IncrementalMerkleTree::getRootValue(std::vector<bool>& r) const {

// Query the root for its hash
this->root.getValue(r);
return true;
}

bool
IncrementalMerkleTree::getRootValue(std::vector<unsigned char>& r) {
IncrementalMerkleTree::getRootValue(std::vector<unsigned char>& r) const {

// Create a temporary byte vector
std::vector<bool> tempR(r.size() * 8, 0);
Expand Down
12 changes: 6 additions & 6 deletions libzerocash/IncrementalMerkleTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IncrementalMerkleTreeCompact {
std::vector< std::vector<unsigned char> > const& getHashVec() { return hashVec; }
std::vector< bool > const& getHashList() { return hashList; }

std::vector<unsigned char> serialize();
std::vector<unsigned char> serialize() const;
static IncrementalMerkleTreeCompact deserialize(const std::vector<unsigned char>& serialized);

private:
Expand Down Expand Up @@ -84,8 +84,8 @@ class IncrementalMerkleNode {
bool isPruned() const { return subtreePruned; }
bool hasFreeLeaves() const { return (!subtreeFull); }
bool hasRightChildren() const { if (!right) return false; return true; }
void getValue(std::vector<bool> &r) { r = value; }
std::vector<bool>& getValue() { return value; }
void getValue(std::vector<bool> &r) const { r = value; }
const std::vector<bool>& getValue() const { return value; }

bool checkIfNodeFull();
void updateHashValue();
Expand Down Expand Up @@ -115,12 +115,12 @@ class IncrementalMerkleTree {
bool insertElement(const std::vector<unsigned char> &hashV, std::vector<unsigned char> &index);
bool insertVector(std::vector< std::vector<bool> > &valueVector);
bool getWitness(const std::vector<bool> &index, merkle_authentication_path &witness);
bool getRootValue(std::vector<bool>& r);
bool getRootValue(std::vector<unsigned char>& r);
bool getRootValue(std::vector<bool>& r) const;
bool getRootValue(std::vector<unsigned char>& r) const;
std::vector<unsigned char>getRoot();
bool prune();
IncrementalMerkleTreeCompact getCompactRepresentation() const;
std::vector<unsigned char> serialize() {
std::vector<unsigned char> serialize() const {
auto compact = getCompactRepresentation();
return compact.serialize();
}
Expand Down

1 comment on commit 53c30e6

@nathan-at-least
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Please sign in to comment.