rippled
SHAMapTxPlusMetaLeafNode.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_SHAMAPLEAFTXPLUSMETANODE_H_INCLUDED
21 #define RIPPLE_SHAMAP_SHAMAPLEAFTXPLUSMETANODE_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<SHAMapTxPlusMetaLeafNode>
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 override
56  {
57  return std::make_shared<SHAMapTxPlusMetaLeafNode>(item_, cowid, hash_);
58  }
59 
61  getType() const override
62  {
64  }
65 
66  void
67  updateHash() final override
68  {
69  hash_ = SHAMapHash{
70  sha512Half(HashPrefix::txNode, item_->slice(), item_->key())};
71  }
72 
73  void
74  serializeForWire(Serializer& s) const final override
75  {
76  s.addRaw(item_->slice());
77  s.addBitString(item_->key());
79  }
80 
81  void
82  serializeWithPrefix(Serializer& s) const final override
83  {
84  s.add32(HashPrefix::txNode);
85  s.addRaw(item_->slice());
86  s.addBitString(item_->key());
87  }
88 };
89 
90 } // namespace ripple
91 
92 #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::HashPrefix::txNode
@ txNode
transaction plus metadata
ripple::SHAMapTxPlusMetaLeafNode::SHAMapTxPlusMetaLeafNode
SHAMapTxPlusMetaLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid, SHAMapHash const &hash)
Definition: SHAMapTxPlusMetaLeafNode.h:46
ripple::SHAMapNodeType
SHAMapNodeType
Definition: SHAMapTreeNode.h:46
ripple::SHAMapTxPlusMetaLeafNode::serializeWithPrefix
void serializeWithPrefix(Serializer &s) const final override
Serialize the node in a format appropriate for hashing.
Definition: SHAMapTxPlusMetaLeafNode.h:82
ripple::SHAMapTreeNode::hash_
SHAMapHash hash_
Definition: SHAMapTreeNode.h:56
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::SHAMapHash
Definition: SHAMapHash.h:32
ripple::SHAMapTxPlusMetaLeafNode::SHAMapTxPlusMetaLeafNode
SHAMapTxPlusMetaLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
Definition: SHAMapTxPlusMetaLeafNode.h:38
ripple::wireTypeTransactionWithMeta
static constexpr unsigned const char wireTypeTransactionWithMeta
Definition: SHAMapTreeNode.h:44
ripple::SHAMapTxPlusMetaLeafNode::getType
SHAMapNodeType getType() const override
Determines the type of node.
Definition: SHAMapTxPlusMetaLeafNode.h:61
ripple::SHAMapTxPlusMetaLeafNode::clone
std::shared_ptr< SHAMapTreeNode > clone(std::uint32_t cowid) const override
Make a copy of this node, setting the owner.
Definition: SHAMapTxPlusMetaLeafNode.h:55
ripple::SHAMapNodeType::tnTRANSACTION_MD
@ tnTRANSACTION_MD
ripple::SHAMapTxPlusMetaLeafNode::serializeForWire
void serializeForWire(Serializer &s) const final override
Serialize the node in a format appropriate for sending over the wire.
Definition: SHAMapTxPlusMetaLeafNode.h:74
ripple::SHAMapTxPlusMetaLeafNode::updateHash
void updateHash() final override
Recalculate the hash of this node.
Definition: SHAMapTxPlusMetaLeafNode.h:67
std::uint32_t
ripple::SHAMapTxPlusMetaLeafNode
A leaf node for a transaction and its associated metadata.
Definition: SHAMapTxPlusMetaLeafNode.h:33
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
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