rippled
SHAMapLeafNode.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/basics/contract.h>
21 #include <ripple/beast/core/LexicalCast.h>
22 #include <ripple/shamap/SHAMapLeafNode.h>
23 
24 namespace ripple {
25 
28  std::uint32_t cowid)
29  : SHAMapTreeNode(cowid), item_(std::move(item))
30 {
31  assert(item_->size() >= 12);
32 }
33 
36  std::uint32_t cowid,
37  SHAMapHash const& hash)
38  : SHAMapTreeNode(cowid, hash), item_(std::move(item))
39 {
40  assert(item_->size() >= 12);
41 }
42 
45 {
46  return item_;
47 }
48 
49 bool
51 {
52  assert(cowid_ != 0);
53  item_ = std::move(i);
54 
55  auto const oldHash = hash_;
56 
57  updateHash();
58 
59  return (oldHash != hash_);
60 }
61 
64 {
66 
67  auto const type = getType();
68 
70  ret += ",txn\n";
71  else if (type == SHAMapNodeType::tnTRANSACTION_MD)
72  ret += ",txn+md\n";
73  else if (type == SHAMapNodeType::tnACCOUNT_STATE)
74  ret += ",as\n";
75  else
76  ret += ",leaf\n";
77 
78  ret += " Tag=";
79  ret += to_string(item_->key());
80  ret += "\n Hash=";
81  ret += to_string(hash_);
82  ret += "/";
83  ret += std::to_string(item_->size());
84  return ret;
85 }
86 
87 void
89 {
90  assert(hash_.isNonZero());
91  assert(item_ != nullptr);
92 }
93 
94 } // namespace ripple
std::string
STL class.
std::shared_ptr
STL class.
ripple::SHAMapLeafNode::SHAMapLeafNode
SHAMapLeafNode(std::shared_ptr< SHAMapItem const > item, std::uint32_t cowid)
Definition: SHAMapLeafNode.cpp:26
ripple::SHAMapNodeType::tnACCOUNT_STATE
@ tnACCOUNT_STATE
ripple::SHAMapLeafNode::getString
std::string getString(SHAMapNodeID const &) const final override
Definition: SHAMapLeafNode.cpp:63
ripple::SHAMapTreeNode::cowid_
std::uint32_t cowid_
Determines the owning SHAMap, if any.
Definition: SHAMapTreeNode.h:64
ripple::SHAMapNodeID
Identifies a node inside a SHAMap.
Definition: SHAMapNodeID.h:33
ripple::SHAMapHash::isNonZero
bool isNonZero() const
Definition: SHAMapHash.h:58
ripple::SHAMapTreeNode::getString
virtual std::string getString(SHAMapNodeID const &) const
Definition: SHAMapTreeNode.cpp:184
ripple::SHAMapTreeNode::hash_
SHAMapHash hash_
Definition: SHAMapTreeNode.h:56
ripple::SHAMapHash
Definition: SHAMapHash.h:32
ripple::SHAMapNodeType::tnTRANSACTION_NM
@ tnTRANSACTION_NM
ripple::SHAMapLeafNode::invariants
void invariants(bool is_root=false) const final override
Definition: SHAMapLeafNode.cpp:88
ripple::SHAMapLeafNode::item_
std::shared_ptr< SHAMapItem const > item_
Definition: SHAMapLeafNode.h:35
ripple::SHAMapNodeType::tnTRANSACTION_MD
@ tnTRANSACTION_MD
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:53
std::to_string
T to_string(T... args)
std::uint32_t
ripple::SHAMapTreeNode::updateHash
virtual void updateHash()=0
Recalculate the hash of this node.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SHAMapTreeNode::getType
virtual SHAMapNodeType getType() const =0
Determines the type of node.
std
STL namespace.
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:38
ripple::SHAMapLeafNode::peekItem
std::shared_ptr< SHAMapItem const > const & peekItem() const
Definition: SHAMapLeafNode.cpp:44
ripple::SHAMapLeafNode::setItem
bool setItem(std::shared_ptr< SHAMapItem const > i)
Set the item that this node points to and update the node's hash.
Definition: SHAMapLeafNode.cpp:50