rippled
Loading...
Searching...
No Matches
libxrpl/protocol/LedgerHeader.cpp
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#include <xrpl/protocol/LedgerHeader.h>
21
22namespace ripple {
23
24void
25addRaw(LedgerHeader const& info, Serializer& s, bool includeHash)
26{
27 s.add32(info.seq);
28 s.add64(info.drops.drops());
30 s.addBitString(info.txHash);
32 s.add32(info.parentCloseTime.time_since_epoch().count());
33 s.add32(info.closeTime.time_since_epoch().count());
35 s.add8(info.closeFlags);
36
37 if (includeHash)
38 s.addBitString(info.hash);
39}
40
41LedgerHeader
42deserializeHeader(Slice data, bool hasHash)
43{
44 SerialIter sit(data.data(), data.size());
45
46 LedgerHeader header;
47
48 header.seq = sit.get32();
49 header.drops = sit.get64();
50 header.parentHash = sit.get256();
51 header.txHash = sit.get256();
52 header.accountHash = sit.get256();
53 header.parentCloseTime =
57 header.closeFlags = sit.get8();
58
59 if (hasHash)
60 header.hash = sit.get256();
61
62 return header;
63}
64
65LedgerHeader
67{
68 return deserializeHeader(data + 4, hasHash);
69}
70
71} // namespace ripple
std::uint32_t get32()
Definition: Serializer.cpp:364
unsigned char get8()
Definition: Serializer.cpp:340
uint256 get256()
Definition: Serializer.h:421
std::uint64_t get64()
Definition: Serializer.cpp:377
int addBitString(base_uint< Bits, Tag > const &v)
Definition: Serializer.h:131
int add8(unsigned char i)
Definition: Serializer.cpp:143
An immutable linear range of bytes.
Definition: Slice.h:45
constexpr value_type drops() const
Returns the number of drops.
Definition: XRPAmount.h:177
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
LedgerHeader deserializePrefixedHeader(Slice data, bool hasHash=false)
Deserialize a ledger header (prefixed with 4 bytes) from a byte array.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
LedgerHeader deserializeHeader(Slice data, bool hasHash=false)
Deserialize a ledger header from a byte array.
Information about the notional ledger backing the view.
Definition: LedgerHeader.h:34
NetClock::time_point closeTime
Definition: LedgerHeader.h:72
NetClock::duration closeTimeResolution
Definition: LedgerHeader.h:66
NetClock::time_point parentCloseTime
Definition: LedgerHeader.h:42
T time_since_epoch(T... args)