rippled
Loading...
Searching...
No Matches
libxrpl/protocol/LedgerHeader.cpp
1#include <xrpl/basics/Slice.h>
2#include <xrpl/basics/chrono.h>
3#include <xrpl/protocol/HashPrefix.h>
4#include <xrpl/protocol/LedgerHeader.h>
5#include <xrpl/protocol/Serializer.h>
6#include <xrpl/protocol/digest.h>
7
8namespace xrpl {
9
10void
11addRaw(LedgerHeader const& info, Serializer& s, bool includeHash)
12{
13 s.add32(info.seq);
14 s.add64(info.drops.drops());
16 s.addBitString(info.txHash);
18 s.add32(info.parentCloseTime.time_since_epoch().count());
19 s.add32(info.closeTime.time_since_epoch().count());
21 s.add8(info.closeFlags);
22
23 if (includeHash)
24 s.addBitString(info.hash);
25}
26
27LedgerHeader
28deserializeHeader(Slice data, bool hasHash)
29{
30 SerialIter sit(data.data(), data.size());
31
32 LedgerHeader header;
33
34 header.seq = sit.get32();
35 header.drops = sit.get64();
36 header.parentHash = sit.get256();
37 header.txHash = sit.get256();
38 header.accountHash = sit.get256();
42 header.closeFlags = sit.get8();
43
44 if (hasHash)
45 header.hash = sit.get256();
46
47 return header;
48}
49
50LedgerHeader
52{
53 return deserializeHeader(data + 4, hasHash);
54}
55
58{
59 // VFALCO This has to match addRaw in View.h.
60 return sha512Half(
62 std::uint32_t(info.seq),
64 info.parentHash,
65 info.txHash,
66 info.accountHash,
71}
72
73} // namespace xrpl
std::uint64_t get64()
uint256 get256()
Definition Serializer.h:394
unsigned char get8()
std::uint32_t get32()
int addBitString(base_uint< Bits, Tag > const &v)
Definition Serializer.h:105
int add8(unsigned char i)
An immutable linear range of bytes.
Definition Slice.h:26
constexpr value_type drops() const
Returns the number of drops.
Definition XRPAmount.h:157
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:204
LedgerHeader deserializeHeader(Slice data, bool hasHash=false)
Deserialize a ledger header from a byte array.
uint256 calculateLedgerHash(LedgerHeader const &info)
Calculate the hash of a ledger header.
base_uint< 256 > uint256
Definition base_uint.h:531
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
@ ledgerMaster
ledger master data for signing
LedgerHeader deserializePrefixedHeader(Slice data, bool hasHash=false)
Deserialize a ledger header (prefixed with 4 bytes) from a byte array.
Information about the notional ledger backing the view.
NetClock::time_point parentCloseTime
NetClock::duration closeTimeResolution
NetClock::time_point closeTime
T time_since_epoch(T... args)