xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
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
11
namespace
xrpl
{
12
13
void
14
addRaw
(
LedgerHeader
const
& info,
Serializer
& s,
bool
includeHash)
15
{
16
s.
add32
(info.
seq
);
17
s.
add64
(info.
drops
.
drops
());
18
s.
addBitString
(info.
parentHash
);
19
s.
addBitString
(info.
txHash
);
20
s.
addBitString
(info.
accountHash
);
21
s.
add32
(info.
parentCloseTime
.
time_since_epoch
().count());
22
s.
add32
(info.
closeTime
.
time_since_epoch
().count());
23
s.
add8
(info.
closeTimeResolution
.
count
());
24
s.
add8
(info.
closeFlags
);
25
26
if
(includeHash)
27
s.
addBitString
(info.
hash
);
28
}
29
30
LedgerHeader
31
deserializeHeader
(
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
();
42
header.
parentCloseTime
=
NetClock::time_point
{
NetClock::duration
{sit.
get32
()}};
43
header.
closeTime
=
NetClock::time_point
{
NetClock::duration
{sit.
get32
()}};
44
header.
closeTimeResolution
=
NetClock::duration
{sit.
get8
()};
45
header.
closeFlags
= sit.
get8
();
46
47
if
(hasHash)
48
header.
hash
= sit.
get256
();
49
50
return
header;
51
}
52
53
LedgerHeader
54
deserializePrefixedHeader
(
Slice
data,
bool
hasHash)
55
{
56
return
deserializeHeader
(data + 4, hasHash);
57
}
58
59
UInt256
60
calculateLedgerHash
(
LedgerHeader
const
& info)
61
{
62
// VFALCO This has to match addRaw in View.h.
63
return
sha512Half
(
64
HashPrefix::LedgerMaster
,
65
std::uint32_t
(info.
seq
),
66
std::uint64_t
(info.
drops
.
drops
()),
67
info.
parentHash
,
68
info.
txHash
,
69
info.
accountHash
,
70
std::uint32_t
(info.
parentCloseTime
.
time_since_epoch
().count()),
71
std::uint32_t
(info.
closeTime
.
time_since_epoch
().count()),
72
std::uint8_t
(info.
closeTimeResolution
.
count
()),
73
std::uint8_t
(info.
closeFlags
));
74
}
75
76
}
// namespace xrpl
xrpl::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition
chrono.h:48
xrpl::NetClock::duration
std::chrono::duration< rep, period > duration
Definition
chrono.h:47
xrpl::SerialIter
Definition
Serializer.h:478
xrpl::SerialIter::get256
UInt256 get256()
Definition
Serializer.h:553
xrpl::SerialIter::get64
std::uint64_t get64()
Definition
libxrpl/protocol/Serializer.cpp:410
xrpl::SerialIter::get8
unsigned char get8()
Definition
libxrpl/protocol/Serializer.cpp:373
xrpl::SerialIter::get32
std::uint32_t get32()
Definition
libxrpl/protocol/Serializer.cpp:397
xrpl::Serializer
Definition
Serializer.h:23
xrpl::Serializer::addBitString
int addBitString(BaseUInt< Bits, Tag > const &v)
Definition
Serializer.h:202
xrpl::Serializer::add64
int add64(T i)
Definition
Serializer.h:183
xrpl::Serializer::add8
int add8(unsigned char byteValue)
Definition
libxrpl/protocol/Serializer.cpp:146
xrpl::Serializer::add32
int add32(T i)
Definition
Serializer.h:167
xrpl::Slice
An immutable linear range of bytes.
Definition
Slice.h:28
xrpl::XRPAmount::drops
constexpr value_type drops() const
Returns the number of drops.
Definition
XRPAmount.h:170
std::chrono::duration::count
T count(T... args)
cstdint
std::uint32_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::deserializeHeader
LedgerHeader deserializeHeader(Slice data, bool hasHash=false)
Deserialize a ledger header from a byte array.
Definition
libxrpl/protocol/LedgerHeader.cpp:31
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::addRaw
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
Definition
libxrpl/protocol/LedgerHeader.cpp:14
xrpl::HashPrefix::LedgerMaster
@ LedgerMaster
ledger master data for signing
Definition
HashPrefix.h:59
xrpl::calculateLedgerHash
UInt256 calculateLedgerHash(LedgerHeader const &info)
Calculate the hash of a ledger header.
Definition
libxrpl/protocol/LedgerHeader.cpp:60
xrpl::deserializePrefixedHeader
LedgerHeader deserializePrefixedHeader(Slice data, bool hasHash=false)
Deserialize a ledger header (prefixed with 4 bytes) from a byte array.
Definition
libxrpl/protocol/LedgerHeader.cpp:54
xrpl::sha512Half
Sha512HalfHasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition
digest.h:215
xrpl::LedgerHeader
Information about the notional ledger backing the view.
Definition
LedgerHeader.h:19
xrpl::LedgerHeader::parentCloseTime
NetClock::time_point parentCloseTime
Definition
LedgerHeader.h:27
xrpl::LedgerHeader::seq
LedgerIndex seq
Definition
LedgerHeader.h:26
xrpl::LedgerHeader::accountHash
UInt256 accountHash
Definition
LedgerHeader.h:36
xrpl::LedgerHeader::closeFlags
int closeFlags
Definition
LedgerHeader.h:48
xrpl::LedgerHeader::txHash
UInt256 txHash
Definition
LedgerHeader.h:35
xrpl::LedgerHeader::hash
UInt256 hash
Definition
LedgerHeader.h:34
xrpl::LedgerHeader::closeTimeResolution
NetClock::duration closeTimeResolution
Definition
LedgerHeader.h:51
xrpl::LedgerHeader::parentHash
UInt256 parentHash
Definition
LedgerHeader.h:37
xrpl::LedgerHeader::drops
XRPAmount drops
Definition
LedgerHeader.h:39
xrpl::LedgerHeader::closeTime
NetClock::time_point closeTime
Definition
LedgerHeader.h:57
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
Generated by
1.17.0