rippled
Loading...
Searching...
No Matches
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 <xrpld/shamap/SHAMapLeafNode.h>
21
22namespace ripple {
23
25 boost::intrusive_ptr<SHAMapItem const> item,
26 std::uint32_t cowid)
27 : SHAMapTreeNode(cowid), item_(std::move(item))
28{
29 XRPL_ASSERT(
30 item_->size() >= 12,
31 "ripple::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
32 "SHAMapItem const>, std::uint32_t) : minimum input size");
33}
34
36 boost::intrusive_ptr<SHAMapItem const> item,
37 std::uint32_t cowid,
38 SHAMapHash const& hash)
39 : SHAMapTreeNode(cowid, hash), item_(std::move(item))
40{
41 XRPL_ASSERT(
42 item_->size() >= 12,
43 "ripple::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
44 "SHAMapItem const>, std::uint32_t, SHAMapHash const&) : minimum input "
45 "size");
46}
47
48boost::intrusive_ptr<SHAMapItem const> const&
50{
51 return item_;
52}
53
54bool
55SHAMapLeafNode::setItem(boost::intrusive_ptr<SHAMapItem const> item)
56{
57 XRPL_ASSERT(cowid_, "ripple::SHAMapLeafNode::setItem : nonzero cowid");
58 item_ = std::move(item);
59
60 auto const oldHash = hash_;
61
62 updateHash();
63
64 return (oldHash != hash_);
65}
66
69{
71
72 auto const type = getType();
73
75 ret += ",txn\n";
76 else if (type == SHAMapNodeType::tnTRANSACTION_MD)
77 ret += ",txn+md\n";
78 else if (type == SHAMapNodeType::tnACCOUNT_STATE)
79 ret += ",as\n";
80 else
81 ret += ",leaf\n";
82
83 ret += " Tag=";
84 ret += to_string(item_->key());
85 ret += "\n Hash=";
86 ret += to_string(hash_);
87 ret += "/";
88 ret += std::to_string(item_->size());
89 return ret;
90}
91
92void
94{
95 XRPL_ASSERT(
96 hash_.isNonZero(), "ripple::SHAMapLeafNode::invariants : nonzero hash");
97 XRPL_ASSERT(item_, "ripple::SHAMapLeafNode::invariants : non-null item");
98}
99
100} // namespace ripple
bool isNonZero() const
Definition: SHAMapHash.h:59
std::string getString(SHAMapNodeID const &) const final override
boost::intrusive_ptr< SHAMapItem const > item_
SHAMapLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
bool setItem(boost::intrusive_ptr< SHAMapItem const > i)
Set the item that this node points to and update the node's hash.
void invariants(bool is_root=false) const final override
boost::intrusive_ptr< SHAMapItem const > const & peekItem() const
Identifies a node inside a SHAMap.
Definition: SHAMapNodeID.h:34
virtual std::string getString(SHAMapNodeID const &) const
virtual void updateHash()=0
Recalculate the hash of this node.
std::uint32_t cowid_
Determines the owning SHAMap, if any.
virtual SHAMapNodeType getType() const =0
Determines the type of node.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
STL namespace.
T to_string(T... args)