rippled
SHAMapAccountStateLeafNode.h
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 #ifndef RIPPLE_SHAMAP_SHAMAPACCOUNTSTATELEAFNODE_H_INCLUDED
21 #define RIPPLE_SHAMAP_SHAMAPACCOUNTSTATELEAFNODE_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/HashPrefix.h>
25 #include <ripple/protocol/digest.h>
26 #include <ripple/shamap/SHAMapItem.h>
27 #include <ripple/shamap/SHAMapLeafNode.h>
28 #include <ripple/shamap/SHAMapNodeID.h>
29 
30 namespace ripple {
31 
34  : public SHAMapLeafNode,
35  public CountedObject<SHAMapAccountStateLeafNode>
36 {
37 public:
39  boost::intrusive_ptr<SHAMapItem const> item,
41  : SHAMapLeafNode(std::move(item), cowid)
42  {
43  updateHash();
44  }
45 
47  boost::intrusive_ptr<SHAMapItem const> item,
49  SHAMapHash const& hash)
50  : SHAMapLeafNode(std::move(item), cowid, hash)
51  {
52  }
53 
55  clone(std::uint32_t cowid) const final override
56  {
57  return std::make_shared<SHAMapAccountStateLeafNode>(
58  item_, cowid, hash_);
59  }
60 
62  getType() const final override
63  {
65  }
66 
67  void
68  updateHash() final override
69  {
70  hash_ = SHAMapHash{
71  sha512Half(HashPrefix::leafNode, item_->slice(), item_->key())};
72  }
73 
74  void
75  serializeForWire(Serializer& s) const final override
76  {
77  s.addRaw(item_->slice());
78  s.addBitString(item_->key());
79  s.add8(wireTypeAccountState);
80  }
81 
82  void
83  serializeWithPrefix(Serializer& s) const final override
84  {
85  s.add32(HashPrefix::leafNode);
86  s.addRaw(item_->slice());
87  s.addBitString(item_->key());
88  }
89 };
90 
91 } // namespace ripple
92 
93 #endif
ripple::SHAMapTreeNode::cowid
std::uint32_t cowid() const
Returns the SHAMap that owns this node.
Definition: SHAMapTreeNode.h:116
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::shared_ptr
STL class.
ripple::SHAMapNodeType::tnACCOUNT_STATE
@ tnACCOUNT_STATE
ripple::SHAMapNodeType
SHAMapNodeType
Definition: SHAMapTreeNode.h:46
ripple::SHAMapAccountStateLeafNode::serializeWithPrefix
void serializeWithPrefix(Serializer &s) const final override
Serialize the node in a format appropriate for hashing.
Definition: SHAMapAccountStateLeafNode.h:83
ripple::SHAMapTreeNode::hash_
SHAMapHash hash_
Definition: SHAMapTreeNode.h:56
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::SHAMapHash
Definition: SHAMapHash.h:32
ripple::wireTypeAccountState
static constexpr unsigned const char wireTypeAccountState
Definition: SHAMapTreeNode.h:41
ripple::SHAMapAccountStateLeafNode::clone
std::shared_ptr< SHAMapTreeNode > clone(std::uint32_t cowid) const final override
Make a copy of this node, setting the owner.
Definition: SHAMapAccountStateLeafNode.h:55
ripple::SHAMapAccountStateLeafNode::SHAMapAccountStateLeafNode
SHAMapAccountStateLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid, SHAMapHash const &hash)
Definition: SHAMapAccountStateLeafNode.h:46
std::uint32_t
ripple::HashPrefix::leafNode
@ leafNode
account state
ripple::SHAMapLeafNode::item_
boost::intrusive_ptr< SHAMapItem const > item_
Definition: SHAMapLeafNode.h:35
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SHAMapAccountStateLeafNode::SHAMapAccountStateLeafNode
SHAMapAccountStateLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
Definition: SHAMapAccountStateLeafNode.h:38
ripple::SHAMapAccountStateLeafNode
A leaf node for a state object.
Definition: SHAMapAccountStateLeafNode.h:33
std
STL namespace.
ripple::sha512Half
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition: digest.h:216
ripple::SHAMapAccountStateLeafNode::updateHash
void updateHash() final override
Recalculate the hash of this node.
Definition: SHAMapAccountStateLeafNode.h:68
ripple::SHAMapAccountStateLeafNode::serializeForWire
void serializeForWire(Serializer &s) const final override
Serialize the node in a format appropriate for sending over the wire.
Definition: SHAMapAccountStateLeafNode.h:75
ripple::SHAMapAccountStateLeafNode::getType
SHAMapNodeType getType() const final override
Determines the type of node.
Definition: SHAMapAccountStateLeafNode.h:62