mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-24 15:40:08 +00:00
140 lines
4.4 KiB
C++
140 lines
4.4 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#ifndef RIPPLE_NODESTORE_NODEOBJECT_H_INCLUDED
|
|
#define RIPPLE_NODESTORE_NODEOBJECT_H_INCLUDED
|
|
|
|
#include <xrpl/basics/Blob.h>
|
|
#include <xrpl/basics/CountedObject.h>
|
|
#include <xrpl/protocol/Protocol.h>
|
|
|
|
// VFALCO NOTE Intentionally not in the NodeStore namespace
|
|
|
|
namespace ripple {
|
|
|
|
/** The types of node objects. */
|
|
enum NodeObjectType : std::uint32_t {
|
|
hotUNKNOWN = 0,
|
|
hotLEDGER = 1,
|
|
hotACCOUNT_NODE = 3,
|
|
hotTRANSACTION_NODE = 4,
|
|
hotDUMMY = 512, // an invalid or missing object
|
|
|
|
// Uncached variants - these bypass the cache when stored.
|
|
// These are routing-only values that MUST be reduced to their hot
|
|
// equivalents before serialization (on-disk format is a single byte).
|
|
pinnedACCOUNT_NODE = 1003,
|
|
pinnedTRANSACTION_NODE = 1004,
|
|
pinnedLEDGER = 1005
|
|
};
|
|
|
|
/** Returns true if the type is a pinned (routing-only) variant. */
|
|
inline bool
|
|
isPinnedType(NodeObjectType type)
|
|
{
|
|
return type == pinnedACCOUNT_NODE || type == pinnedTRANSACTION_NODE ||
|
|
type == pinnedLEDGER;
|
|
}
|
|
|
|
/** Map pinned types back to their serializable hot equivalents.
|
|
Returns the type unchanged if it is not a pinned variant.
|
|
*/
|
|
inline NodeObjectType
|
|
toHotType(NodeObjectType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case pinnedACCOUNT_NODE:
|
|
return hotACCOUNT_NODE;
|
|
case pinnedTRANSACTION_NODE:
|
|
return hotTRANSACTION_NODE;
|
|
case pinnedLEDGER:
|
|
return hotLEDGER;
|
|
default:
|
|
return type;
|
|
}
|
|
}
|
|
|
|
/** A simple object that the Ledger uses to store entries.
|
|
NodeObjects are comprised of a type, a hash, and a blob.
|
|
They can be uniquely identified by the hash, which is a half-SHA512 of
|
|
the blob. The blob is a variable length block of serialized data. The
|
|
type identifies what the blob contains.
|
|
|
|
@note No checking is performed to make sure the hash matches the data.
|
|
@see SHAMap
|
|
*/
|
|
class NodeObject : public CountedObject<NodeObject>
|
|
{
|
|
public:
|
|
static constexpr std::size_t keyBytes = 32;
|
|
|
|
private:
|
|
// This hack is used to make the constructor effectively private
|
|
// except for when we use it in the call to make_shared.
|
|
// There's no portable way to make make_shared<> a friend work.
|
|
struct PrivateAccess
|
|
{
|
|
explicit PrivateAccess() = default;
|
|
};
|
|
|
|
public:
|
|
// This constructor is private, use createObject instead.
|
|
NodeObject(
|
|
NodeObjectType type,
|
|
Blob&& data,
|
|
uint256 const& hash,
|
|
PrivateAccess);
|
|
|
|
/** Create an object from fields.
|
|
|
|
The caller's variable is modified during this call. The
|
|
underlying storage for the Blob is taken over by the NodeObject.
|
|
|
|
@param type The type of object.
|
|
@param ledgerIndex The ledger in which this object appears.
|
|
@param data A buffer containing the payload. The caller's variable
|
|
is overwritten.
|
|
@param hash The 256-bit hash of the payload data.
|
|
*/
|
|
static std::shared_ptr<NodeObject>
|
|
createObject(NodeObjectType type, Blob&& data, uint256 const& hash);
|
|
|
|
/** Returns the type of this object. */
|
|
NodeObjectType
|
|
getType() const;
|
|
|
|
/** Returns the hash of the data. */
|
|
uint256 const&
|
|
getHash() const;
|
|
|
|
/** Returns the underlying data. */
|
|
Blob const&
|
|
getData() const;
|
|
|
|
private:
|
|
NodeObjectType const mType;
|
|
uint256 const mHash;
|
|
Blob const mData;
|
|
};
|
|
|
|
} // namespace ripple
|
|
|
|
#endif
|