rippled
Loading...
Searching...
No Matches
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 <xrpld/shamap/SHAMapItem.h>
24#include <xrpld/shamap/SHAMapLeafNode.h>
25
26#include <xrpl/basics/CountedObject.h>
27#include <xrpl/protocol/HashPrefix.h>
28#include <xrpl/protocol/digest.h>
29
30namespace ripple {
31
34 : public SHAMapLeafNode,
35 public CountedObject<SHAMapTxPlusMetaLeafNode>
36{
37public:
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 intr_ptr::make_shared<SHAMapTxPlusMetaLeafNode>(
58 item_, cowid, hash_);
59 }
60
62 getType() const override
63 {
65 }
66
67 void
68 updateHash() final override
69 {
71 sha512Half(HashPrefix::txNode, 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());
80 }
81
82 void
83 serializeWithPrefix(Serializer& s) const final override
84 {
85 s.add32(HashPrefix::txNode);
86 s.addRaw(item_->slice());
87 s.addBitString(item_->key());
88 }
89};
90
91} // namespace ripple
92
93#endif
Tracks the number of instances of an object.
boost::intrusive_ptr< SHAMapItem const > item_
A leaf node for a transaction and its associated metadata.
SHAMapNodeType getType() const override
Determines the type of node.
intr_ptr::SharedPtr< SHAMapTreeNode > clone(std::uint32_t cowid) const override
Make a copy of this node, setting the owner.
void serializeForWire(Serializer &s) const final override
Serialize the node in a format appropriate for sending over the wire.
void updateHash() final override
Recalculate the hash of this node.
SHAMapTxPlusMetaLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
SHAMapTxPlusMetaLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid, SHAMapHash const &hash)
void serializeWithPrefix(Serializer &s) const final override
Serialize the node in a format appropriate for hashing.
A shared intrusive pointer class that supports weak pointers.
std::uint32_t cowid() const
Returns the SHAMap that owns this node.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
static constexpr unsigned char const wireTypeTransactionWithMeta
@ txNode
transaction plus metadata
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:224
STL namespace.