xrpld
Loading...
Searching...
No Matches
libxrpl/protocol/LedgerHeader.cpp
1#include <xrpl/protocol/LedgerHeader.h>
2
3#include <xrpl/basics/Slice.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/protocol/HashPrefix.h>
6#include <xrpl/protocol/Serializer.h>
7#include <xrpl/protocol/digest.h>
8
9#include <cstdint>
10
11namespace xrpl {
12
13void
14addRaw(LedgerHeader const& info, Serializer& s, bool includeHash)
15{
16 s.add32(info.seq);
17 s.add64(info.drops.drops());
19 s.addBitString(info.txHash);
21 s.add32(info.parentCloseTime.time_since_epoch().count());
22 s.add32(info.closeTime.time_since_epoch().count());
24 s.add8(info.closeFlags);
25
26 if (includeHash)
27 s.addBitString(info.hash);
28}
29
30LedgerHeader
31deserializeHeader(Slice data, bool hasHash)
32{
33 SerialIter sit(data.data(), data.size());
34
35 LedgerHeader header;
36
37 header.seq = sit.get32();
38 header.drops = sit.get64();
39 header.parentHash = sit.get256();
40 header.txHash = sit.get256();
41 header.accountHash = sit.get256();
45 header.closeFlags = sit.get8();
46
47 if (hasHash)
48 header.hash = sit.get256();
49
50 return header;
51}
52
53LedgerHeader
55{
56 return deserializeHeader(data + 4, hasHash);
57}
58
61{
62 // VFALCO This has to match addRaw in View.h.
63 return sha512Half(
65 std::uint32_t(info.seq),
67 info.parentHash,
68 info.txHash,
69 info.accountHash,
74}
75
76} // namespace xrpl
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
std::chrono::duration< rep, period > duration
Definition chrono.h:45
std::uint64_t get64()
uint256 get256()
Definition Serializer.h:394
unsigned char get8()
std::uint32_t get32()
int addBitString(BaseUInt< 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:159
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.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
@ LedgerMaster
ledger master data for signing
Definition HashPrefix.h:48
BaseUInt< 256 > uint256
Definition base_uint.h:562
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)