diff --git a/CTID_8h_source.html b/CTID_8h_source.html index b467b78c9e..96107b9230 100644 --- a/CTID_8h_source.html +++ b/CTID_8h_source.html @@ -122,75 +122,101 @@ $(document).ready(function() { init_codefold(0); });
39// The Concise Transaction ID provides a way to identify a transaction
40// that includes which network the transaction was submitted to.
41
-
42inline std::optional<std::string>
-
-
43encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
-
44{
-
45 if (ledgerSeq > 0x0FFF'FFFF || txnIndex > 0xFFFF || networkID > 0xFFFF)
-
46 return {};
-
47
-
48 uint64_t ctidValue =
-
49 ((0xC000'0000ULL + static_cast<uint64_t>(ledgerSeq)) << 32) +
-
50 (static_cast<uint64_t>(txnIndex) << 16) + networkID;
-
51
-
52 std::stringstream buffer;
-
53 buffer << std::hex << std::uppercase << std::setfill('0') << std::setw(16)
-
54 << ctidValue;
-
55 return {buffer.str()};
-
56}
+
52inline std::optional<std::string>
+
+
53encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
+
54{
+
55 constexpr uint32_t maxLedgerSeq = 0x0FFF'FFFF;
+
56 constexpr uint32_t maxTxnIndex = 0xFFFF;
+
57 constexpr uint32_t maxNetworkID = 0xFFFF;
+
58
+
59 if (ledgerSeq > maxLedgerSeq || txnIndex > maxTxnIndex ||
+
60 networkID > maxNetworkID)
+
61 return std::nullopt;
+
62
+
63 uint64_t ctidValue =
+
64 ((0xC000'0000ULL + static_cast<uint64_t>(ledgerSeq)) << 32) |
+
65 ((static_cast<uint64_t>(txnIndex) << 16) | networkID);
+
66
+
67 std::stringstream buffer;
+
68 buffer << std::hex << std::uppercase << std::setfill('0') << std::setw(16)
+
69 << ctidValue;
+
70 return buffer.str();
+
71}
-
57
-
58template <typename T>
-
59inline std::optional<std::tuple<uint32_t, uint16_t, uint16_t>>
-
-
60decodeCTID(T const ctid) noexcept
-
61{
-
62 uint64_t ctidValue{0};
-
63 if constexpr (
- - -
66 {
-
67 std::string const ctidString(ctid);
-
68
-
69 if (ctidString.length() != 16)
-
70 return {};
-
71
-
72 if (!boost::regex_match(ctidString, boost::regex("^[0-9A-Fa-f]+$")))
-
73 return {};
-
74
-
75 ctidValue = std::stoull(ctidString, nullptr, 16);
-
76 }
-
77 else if constexpr (std::is_integral_v<T>)
-
78 ctidValue = ctid;
-
79 else
-
80 return {};
-
81
-
82 if ((ctidValue & 0xF000'0000'0000'0000ULL) != 0xC000'0000'0000'0000ULL)
-
83 return {};
-
84
-
85 uint32_t ledger_seq = (ctidValue >> 32) & 0xFFFF'FFFUL;
-
86 uint16_t txn_index = (ctidValue >> 16) & 0xFFFFU;
-
87 uint16_t network_id = ctidValue & 0xFFFFU;
-
88 return {{ledger_seq, txn_index, network_id}};
-
89}
+
72
+
81template <typename T>
+ +
+
83decodeCTID(T const ctid) noexcept
+
84{
+
85 uint64_t ctidValue = 0;
+
86
+
87 if constexpr (
+ + +
90 {
+
91 std::string const ctidString(ctid);
+
92
+
93 if (ctidString.size() != 16)
+
94 return std::nullopt;
+
95
+
96 static boost::regex const hexRegex("^[0-9A-Fa-f]{16}$");
+
97 if (!boost::regex_match(ctidString, hexRegex))
+
98 return std::nullopt;
+
99
+
100 try
+
101 {
+
102 ctidValue = std::stoull(ctidString, nullptr, 16);
+
103 }
+
104 // LCOV_EXCL_START
+
105 catch (...)
+
106 {
+
107 // should be impossible to hit given the length/regex check
+
108 return std::nullopt;
+
109 }
+
110 // LCOV_EXCL_STOP
+
111 }
+
112 else if constexpr (std::is_integral_v<T>)
+
113 {
+
114 ctidValue = static_cast<uint64_t>(ctid);
+
115 }
+
116 else
+
117 {
+
118 return std::nullopt;
+
119 }
+
120
+
121 // Validate CTID prefix.
+
122 constexpr uint64_t ctidPrefixMask = 0xF000'0000'0000'0000ULL;
+
123 constexpr uint64_t ctidPrefix = 0xC000'0000'0000'0000ULL;
+
124 if ((ctidValue & ctidPrefixMask) != ctidPrefix)
+
125 return std::nullopt;
+
126
+
127 uint32_t ledgerSeq = static_cast<uint32_t>((ctidValue >> 32) & 0x0FFF'FFFF);
+
128 uint16_t txnIndex = static_cast<uint16_t>((ctidValue >> 16) & 0xFFFF);
+
129 uint16_t networkID = static_cast<uint16_t>(ctidValue & 0xFFFF);
+
130
+
131 return std::make_tuple(ledgerSeq, txnIndex, networkID);
+
132}
-
90
-
91} // namespace RPC
-
92} // namespace ripple
-
93
-
94#endif
+
133
+
134} // namespace RPC
+
135} // namespace ripple
+
136
+
137#endif
T hex(T... args)
T is_same_v
-
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Definition CTID.h:43
-
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Definition CTID.h:60
+
T make_tuple(T... args)
+
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
Definition CTID.h:53
+
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Decodes a CTID string or integer into its component parts.
Definition CTID.h:83
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
T setfill(T... args)
T setw(T... args)
-
T length(T... args)
+
T size(T... args)
T stoull(T... args)
T str(T... args)
diff --git a/NetworkOPs_8cpp_source.html b/NetworkOPs_8cpp_source.html index b79e140e96..41e773b16a 100644 --- a/NetworkOPs_8cpp_source.html +++ b/NetworkOPs_8cpp_source.html @@ -5519,7 +5519,7 @@ $(document).ready(function() { init_codefold(0); });
void rngfill(void *const buffer, std::size_t const bytes, Generator &g)
Definition rngfill.h:34
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:68
-
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Definition CTID.h:43
+
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
Definition CTID.h:53
Json::Value computeBookChanges(std::shared_ptr< L const > const &lpAccepted)
Definition BookChanges.h:47
void insertNFTSyntheticInJson(Json::Value &, std::shared_ptr< STTx const > const &, TxMeta const &)
Adds common synthetic fields to transaction-related JSON responses.
void insertMPTokenIssuanceID(Json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
diff --git a/Transaction_8cpp_source.html b/Transaction_8cpp_source.html index 3567c8aafb..d53bff65ca 100644 --- a/Transaction_8cpp_source.html +++ b/Transaction_8cpp_source.html @@ -325,7 +325,7 @@ $(document).ready(function() { init_codefold(0); });
T is_same_v
-
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Definition CTID.h:43
+
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
Definition CTID.h:53
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
diff --git a/Transaction__test_8cpp_source.html b/Transaction__test_8cpp_source.html index fbb515ca0a..33337cfcc0 100644 --- a/Transaction__test_8cpp_source.html +++ b/Transaction__test_8cpp_source.html @@ -1094,9 +1094,9 @@ $(document).ready(function() { init_codefold(0); });
T is_same_v
T make_tuple(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
-
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Definition CTID.h:43
+
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
Definition CTID.h:53
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
-
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Definition CTID.h:60
+
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Decodes a CTID string or integer into its component parts.
Definition CTID.h:83
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcEXCESSIVE_LGR_RANGE
Definition ErrorCodes.h:135
diff --git a/Tx_8cpp_source.html b/Tx_8cpp_source.html index 12b1cf5ba6..48b196e0d7 100644 --- a/Tx_8cpp_source.html +++ b/Tx_8cpp_source.html @@ -470,12 +470,12 @@ $(document).ready(function() { init_codefold(0); });
T is_same_v
T make_pair(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
-
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Definition CTID.h:43
+
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
Definition CTID.h:53
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
void insertNFTSyntheticInJson(Json::Value &, std::shared_ptr< STTx const > const &, TxMeta const &)
Adds common synthetic fields to transaction-related JSON responses.
void insertMPTokenIssuanceID(Json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
-
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Definition CTID.h:60
+
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Decodes a CTID string or integer into its component parts.
Definition CTID.h:83
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcEXCESSIVE_LGR_RANGE
Definition ErrorCodes.h:135
@ rpcINVALID_LGR_RANGE
Definition ErrorCodes.h:136
diff --git a/namespaceripple_1_1RPC.html b/namespaceripple_1_1RPC.html index f087ff17ff..ae1e4df73d 100644 --- a/namespaceripple_1_1RPC.html +++ b/namespaceripple_1_1RPC.html @@ -187,9 +187,11 @@ Functions Json::Value computeBookChanges (std::shared_ptr< L const > const &lpAccepted)   std::optional< std::stringencodeCTID (uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept + Encodes ledger sequence, transaction index, and network ID into a CTID string.
  template<typename T > std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID (T const ctid) noexcept + Decodes a CTID string or integer into its component parts.
  template<class GetLedgerIndex , class GetCloseTime > std::optional< STAmountgetDeliveredAmount (GetLedgerIndex const &getLedgerIndex, GetCloseTime const &getCloseTime, std::shared_ptr< STTx const > const &serializedTx, TxMeta const &transactionMeta) @@ -1451,7 +1453,18 @@ template<class L >
-

Definition at line 43 of file CTID.h.

+

Encodes ledger sequence, transaction index, and network ID into a CTID string.

+
Parameters
+ + + + +
ledgerSeqLedger sequence number (max 0x0FFF'FFFF).
txnIndexTransaction index within the ledger (max 0xFFFF).
networkIDNetwork identifier (max 0xFFFF).
+
+
+
Returns
Optional CTID string in uppercase hexadecimal, or std::nullopt if inputs are out of range.
+ +

Definition at line 53 of file CTID.h.

@@ -1481,7 +1494,22 @@ template<typename T >
-

Definition at line 60 of file CTID.h.

+

Decodes a CTID string or integer into its component parts.

+
Template Parameters
+ + +
TType of the CTID input (string, string_view, char*, integral).
+
+
+
Parameters
+ + +
ctidCTID value to decode.
+
+
+
Returns
Optional tuple of (ledgerSeq, txnIndex, networkID), or std::nullopt if invalid.
+ +

Definition at line 83 of file CTID.h.