rippled
Loading...
Searching...
No Matches
STValidation.cpp
1#include <xrpl/basics/Blob.h>
2#include <xrpl/basics/Slice.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/protocol/HashPrefix.h>
7#include <xrpl/protocol/KeyType.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/SOTemplate.h>
11#include <xrpl/protocol/STBase.h>
12#include <xrpl/protocol/STObject.h>
13#include <xrpl/protocol/STValidation.h>
14#include <xrpl/protocol/Serializer.h>
15
16#include <cstddef>
17#include <utility>
18
19namespace ripple {
20
21STBase*
23{
24 return emplace(n, buf, *this);
25}
26
27STBase*
29{
30 return emplace(n, buf, std::move(*this));
31}
32
33SOTemplate const&
35{
36 // We can't have this be a magic static at namespace scope because
37 // it relies on the SField's below being initialized, and we can't
38 // guarantee the initialization order.
39 // clang-format off
40 static SOTemplate const format{
41 {sfFlags, soeREQUIRED},
42 {sfLedgerHash, soeREQUIRED},
43 {sfLedgerSequence, soeREQUIRED},
44 {sfCloseTime, soeOPTIONAL},
45 {sfLoadFee, soeOPTIONAL},
46 {sfAmendments, soeOPTIONAL},
47 {sfBaseFee, soeOPTIONAL},
48 {sfReserveBase, soeOPTIONAL},
49 {sfReserveIncrement, soeOPTIONAL},
50 {sfSigningTime, soeREQUIRED},
51 {sfSigningPubKey, soeREQUIRED},
52 {sfSignature, soeREQUIRED},
53 {sfConsensusHash, soeOPTIONAL},
54 {sfCookie, soeDEFAULT},
55 {sfValidatedHash, soeOPTIONAL},
56 {sfServerVersion, soeOPTIONAL},
57 // featureXRPFees
58 {sfBaseFeeDrops, soeOPTIONAL},
59 {sfReserveBaseDrops, soeOPTIONAL},
60 {sfReserveIncrementDrops, soeOPTIONAL},
61 };
62 // clang-format on
63
64 return format;
65};
66
72
75{
76 return getFieldH256(sfLedgerHash);
77}
78
81{
82 return getFieldH256(sfConsensusHash);
83}
84
90
93{
94 return seenTime_;
95}
96
97bool
98STValidation::isValid() const noexcept
99{
100 if (!valid_)
101 {
102 XRPL_ASSERT(
104 "ripple::STValidation::isValid : valid key type");
105
109 makeSlice(getFieldVL(sfSignature)),
111 }
112
113 return valid_.value();
114}
115
116bool
117STValidation::isFull() const noexcept
118{
119 return (getFlags() & vfFullValidation) != 0;
120}
121
122Blob
124{
125 return getFieldVL(sfSignature);
126}
127
128Blob
130{
131 Serializer s;
132 add(s);
133 return s.peekData();
134}
135
136} // namespace ripple
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:94
A type which can be exported to a well known binary format.
Definition STBase.h:116
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:214
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:644
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:596
void add(Serializer &s) const override
Definition STObject.cpp:122
uint256 getSigningHash(HashPrefix prefix) const
Definition STObject.cpp:385
std::uint32_t getFlags() const
Definition STObject.cpp:518
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:626
PublicKey const & getSignerPublic() const noexcept
uint256 getConsensusHash() const
std::optional< bool > valid_
Blob getSerialized() const
NetClock::time_point getSeenTime() const noexcept
static SOTemplate const & validationFormat()
bool isFull() const noexcept
NetClock::time_point seenTime_
STBase * copy(std::size_t n, void *buf) const override
uint256 getLedgerHash() const
bool isValid() const noexcept
uint256 getSigningHash() const
Blob getSignature() const
STBase * move(std::size_t n, void *buf) override
NetClock::time_point getSignTime() const
Blob const & peekData() const
Definition Serializer.h:183
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a secp256k1 signature on the digest of a message.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition Slice.h:225
constexpr std::uint32_t vfFullyCanonicalSig
constexpr std::uint32_t vfFullValidation
@ validation
validation for signing
@ soeOPTIONAL
Definition SOTemplate.h:17
@ soeREQUIRED
Definition SOTemplate.h:16
@ soeDEFAULT
Definition SOTemplate.h:18
T value(T... args)