rippled
Loading...
Searching...
No Matches
STValidation.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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/basics/Log.h>
21#include <xrpl/basics/contract.h>
22#include <xrpl/json/to_string.h>
23#include <xrpl/protocol/HashPrefix.h>
24#include <xrpl/protocol/STValidation.h>
25
26namespace ripple {
27
28STBase*
30{
31 return emplace(n, buf, *this);
32}
33
34STBase*
36{
37 return emplace(n, buf, std::move(*this));
38}
39
40SOTemplate const&
42{
43 // We can't have this be a magic static at namespace scope because
44 // it relies on the SField's below being initialized, and we can't
45 // guarantee the initialization order.
46 // clang-format off
47 static SOTemplate const format{
48 {sfFlags, soeREQUIRED},
49 {sfLedgerHash, soeREQUIRED},
50 {sfLedgerSequence, soeREQUIRED},
51 {sfCloseTime, soeOPTIONAL},
52 {sfLoadFee, soeOPTIONAL},
53 {sfAmendments, soeOPTIONAL},
54 {sfBaseFee, soeOPTIONAL},
55 {sfReserveBase, soeOPTIONAL},
56 {sfReserveIncrement, soeOPTIONAL},
57 {sfSigningTime, soeREQUIRED},
58 {sfSigningPubKey, soeREQUIRED},
59 {sfSignature, soeREQUIRED},
60 {sfConsensusHash, soeOPTIONAL},
61 // featureHardenedValidations
62 {sfCookie, soeDEFAULT},
63 {sfValidatedHash, soeOPTIONAL},
64 {sfServerVersion, soeOPTIONAL},
65 // featureXRPFees
66 {sfBaseFeeDrops, soeOPTIONAL},
67 {sfReserveBaseDrops, soeOPTIONAL},
68 {sfReserveIncrementDrops, soeOPTIONAL},
69 };
70 // clang-format on
71
72 return format;
73};
74
77{
79}
80
83{
84 return getFieldH256(sfLedgerHash);
85}
86
89{
90 return getFieldH256(sfConsensusHash);
91}
92
95{
97}
98
101{
102 return seenTime_;
103}
104
105bool
106STValidation::isValid() const noexcept
107{
108 if (!valid_)
109 {
110 XRPL_ASSERT(
112 "ripple::STValidation::isValid : valid key type");
113
117 makeSlice(getFieldVL(sfSignature)),
119 }
120
121 return valid_.value();
122}
123
124bool
125STValidation::isFull() const noexcept
126{
127 return (getFlags() & vfFullValidation) != 0;
128}
129
130Blob
132{
133 return getFieldVL(sfSignature);
134}
135
136Blob
138{
139 Serializer s;
140 add(s);
141 return s.peekData();
142}
143
144} // namespace ripple
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:113
A type which can be exported to a well known binary format.
Definition: STBase.h:124
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:222
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:627
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:585
void add(Serializer &s) const override
Definition: STObject.cpp:111
uint256 getSigningHash(HashPrefix prefix) const
Definition: STObject.cpp:374
std::uint32_t getFlags() const
Definition: STObject.cpp:507
uint256 getFieldH256(SField const &field) const
Definition: STObject.cpp:615
PublicKey const & getSignerPublic() const noexcept
Definition: STValidation.h:256
uint256 getConsensusHash() const
std::optional< bool > valid_
Definition: STValidation.h:51
Blob getSerialized() const
NetClock::time_point getSeenTime() const noexcept
static SOTemplate const & validationFormat()
bool isFull() const noexcept
NetClock::time_point seenTime_
Definition: STValidation.h:60
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:202
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
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.
Definition: PublicKey.cpp:222
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:207
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:243
constexpr std::uint32_t vfFullyCanonicalSig
Definition: STValidation.h:43
constexpr std::uint32_t vfFullValidation
Definition: STValidation.h:40
@ validation
validation for signing
@ soeOPTIONAL
Definition: SOTemplate.h:36
@ soeREQUIRED
Definition: SOTemplate.h:35
@ soeDEFAULT
Definition: SOTemplate.h:37
T value(T... args)