rippled
LedgerHeader.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2023 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_PROTOCOL_LEDGERHEADER_H_INCLUDED
21 #define RIPPLE_PROTOCOL_LEDGERHEADER_H_INCLUDED
22 
23 #include <ripple/basics/Slice.h>
24 #include <ripple/basics/XRPAmount.h>
25 #include <ripple/basics/base_uint.h>
26 #include <ripple/basics/chrono.h>
27 #include <ripple/protocol/Protocol.h>
28 #include <ripple/protocol/Serializer.h>
29 
30 namespace ripple {
31 
34 {
35  explicit LedgerHeader() = default;
36 
37  //
38  // For all ledgers
39  //
40 
43 
44  //
45  // For closed ledgers
46  //
47 
48  // Closed means "tx set already determined"
49  uint256 hash = beast::zero;
50  uint256 txHash = beast::zero;
51  uint256 accountHash = beast::zero;
52  uint256 parentHash = beast::zero;
53 
54  XRPAmount drops = beast::zero;
55 
56  // If validated is false, it means "not yet validated."
57  // Once validated is true, it will never be set false at a later time.
58  // VFALCO TODO Make this not mutable
59  bool mutable validated = false;
60  bool accepted = false;
61 
62  // flags indicating how this ledger close took place
63  int closeFlags = 0;
64 
65  // the resolution for this ledger close time (2-120 seconds)
67 
68  // For closed ledgers, the time the ledger
69  // closed. For open ledgers, the time the ledger
70  // will close if there's no transactions.
71  //
73 };
74 
75 // We call them "headers" in conversation
76 // but "info" in code. Unintuitive.
77 // This alias lets us give the "correct" name to the class
78 // without yet disturbing existing uses.
80 
81 // ledger close flags
82 static std::uint32_t const sLCF_NoConsensusTime = 0x01;
83 
84 inline bool
86 {
87  return (info.closeFlags & sLCF_NoConsensusTime) == 0;
88 }
89 
90 void
91 addRaw(LedgerHeader const&, Serializer&, bool includeHash = false);
92 
94 LedgerHeader
95 deserializeHeader(Slice data, bool hasHash = false);
96 
98 LedgerHeader
99 deserializePrefixedHeader(Slice data, bool hasHash = false);
100 
101 } // namespace ripple
102 
103 #endif
ripple::LedgerHeader::closeFlags
int closeFlags
Definition: LedgerHeader.h:63
ripple::LedgerHeader::parentHash
uint256 parentHash
Definition: LedgerHeader.h:52
std::chrono::duration
ripple::LedgerHeader::seq
LedgerIndex seq
Definition: LedgerHeader.h:41
ripple::LedgerHeader::accountHash
uint256 accountHash
Definition: LedgerHeader.h:51
ripple::LedgerHeader::txHash
uint256 txHash
Definition: LedgerHeader.h:50
ripple::LedgerHeader::hash
uint256 hash
Definition: LedgerHeader.h:49
ripple::base_uint< 256 >
ripple::LedgerHeader::parentCloseTime
NetClock::time_point parentCloseTime
Definition: LedgerHeader.h:42
std::chrono::time_point
std::uint32_t
ripple::LedgerHeader::closeTime
NetClock::time_point closeTime
Definition: LedgerHeader.h:72
ripple::LedgerHeader
Information about the notional ledger backing the view.
Definition: LedgerHeader.h:33
ripple::LedgerHeader::LedgerHeader
LedgerHeader()=default
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::addRaw
void addRaw(LedgerHeader const &info, Serializer &s, bool includeHash)
Definition: protocol/impl/LedgerHeader.cpp:25
ripple::LedgerHeader::validated
bool validated
Definition: LedgerHeader.h:59
ripple::LedgerHeader::drops
XRPAmount drops
Definition: LedgerHeader.h:54
ripple::LedgerHeader::closeTimeResolution
NetClock::duration closeTimeResolution
Definition: LedgerHeader.h:66
ripple::deserializePrefixedHeader
LedgerHeader deserializePrefixedHeader(Slice data, bool hasHash)
Deserialize a ledger header (prefixed with 4 bytes) from a byte array.
Definition: protocol/impl/LedgerHeader.cpp:66
ripple::deserializeHeader
LedgerHeader deserializeHeader(Slice data, bool hasHash)
Deserialize a ledger header from a byte array.
Definition: protocol/impl/LedgerHeader.cpp:42
ripple::getCloseAgree
bool getCloseAgree(LedgerHeader const &info)
Definition: LedgerHeader.h:85
ripple::LedgerHeader::accepted
bool accepted
Definition: LedgerHeader.h:60
ripple::sLCF_NoConsensusTime
static const std::uint32_t sLCF_NoConsensusTime
Definition: LedgerHeader.h:82
ripple::XRPAmount
Definition: XRPAmount.h:46