Skip to content

Commit 0936061

Browse files
refactor: Duplicate ledger_index pattern for RPC handlers (#2755)
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
1 parent 224e835 commit 0936061

30 files changed

+114
-198
lines changed

src/rpc/handlers/AMMInfo.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,8 @@ tag_invoke(boost::json::value_to_tag<AMMInfoHandler::Input>, boost::json::value
316316
if (jsonObject.contains(JS(ledger_hash)))
317317
input.ledgerHash = boost::json::value_to<std::string>(jv.at(JS(ledger_hash)));
318318

319-
if (jsonObject.contains(JS(ledger_index))) {
320-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
321-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
322-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
323-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
324-
}
325-
}
319+
if (jsonObject.contains(JS(ledger_index)))
320+
input.ledgerIndex = util::getLedgerIndex(jsonObject.at(JS(ledger_index)));
326321

327322
if (jsonObject.contains(JS(asset)))
328323
input.issue1 = parseIssue(jsonObject.at(JS(asset)).as_object());
@@ -332,6 +327,7 @@ tag_invoke(boost::json::value_to_tag<AMMInfoHandler::Input>, boost::json::value
332327

333328
if (jsonObject.contains(JS(account)))
334329
input.accountID = accountFromStringStrict(boost::json::value_to<std::string>(jsonObject.at(JS(account))));
330+
335331
if (jsonObject.contains(JS(amm_account)))
336332
input.ammAccount = accountFromStringStrict(boost::json::value_to<std::string>(jsonObject.at(JS(amm_account))));
337333

src/rpc/handlers/AccountChannels.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,8 @@ tag_invoke(boost::json::value_to_tag<AccountChannelsHandler::Input>, boost::json
154154
if (jsonObject.contains(JS(destination_account)))
155155
input.destinationAccount = boost::json::value_to<std::string>(jv.at(JS(destination_account)));
156156

157-
if (jsonObject.contains(JS(ledger_index))) {
158-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
159-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
160-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
161-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
162-
}
163-
}
157+
if (jsonObject.contains(JS(ledger_index)))
158+
input.ledgerIndex = util::getLedgerIndex(jv.at(JS(ledger_index)));
164159

165160
return input;
166161
}

src/rpc/handlers/AccountCurrencies.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,8 @@ tag_invoke(boost::json::value_to_tag<AccountCurrenciesHandler::Input>, boost::js
128128
if (jsonObject.contains(JS(ledger_hash)))
129129
input.ledgerHash = boost::json::value_to<std::string>(jv.at(JS(ledger_hash)));
130130

131-
if (jsonObject.contains(JS(ledger_index))) {
132-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
133-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
134-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
135-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
136-
}
137-
}
131+
if (jsonObject.contains(JS(ledger_index)))
132+
input.ledgerIndex = util::getLedgerIndex(jv.at(JS(ledger_index)));
138133

139134
return input;
140135
}

src/rpc/handlers/AccountInfo.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,8 @@ tag_invoke(boost::json::value_to_tag<AccountInfoHandler::Input>, boost::json::va
205205
if (jsonObject.contains(JS(ledger_hash)))
206206
input.ledgerHash = boost::json::value_to<std::string>(jsonObject.at(JS(ledger_hash)));
207207

208-
if (jsonObject.contains(JS(ledger_index))) {
209-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
210-
input.ledgerIndex = util::integralValueAs<uint32_t>(jsonObject.at(JS(ledger_index)));
211-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
212-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jsonObject.at(JS(ledger_index))));
213-
}
214-
}
208+
if (jsonObject.contains(JS(ledger_index)))
209+
input.ledgerIndex = util::getLedgerIndex(jsonObject.at(JS(ledger_index)));
215210

216211
if (jsonObject.contains(JS(signer_lists)))
217212
input.signerLists = boost::json::value_to<JsonBool>(jsonObject.at(JS(signer_lists)));

src/rpc/handlers/AccountLines.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,8 @@ tag_invoke(boost::json::value_to_tag<AccountLinesHandler::Input>, boost::json::v
215215
if (jsonObject.contains(JS(ignore_default)))
216216
input.ignoreDefault = jv.at(JS(ignore_default)).as_bool();
217217

218-
if (jsonObject.contains(JS(ledger_index))) {
219-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
220-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
221-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
222-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
223-
}
224-
}
218+
if (jsonObject.contains(JS(ledger_index)))
219+
input.ledgerIndex = util::getLedgerIndex(jv.at(JS(ledger_index)));
225220

226221
return input;
227222
}

src/rpc/handlers/AccountMPTokenIssuances.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,8 @@ tag_invoke(boost::json::value_to_tag<AccountMPTokenIssuancesHandler::Input>, boo
164164
if (jsonObject.contains(JS(ledger_hash)))
165165
input.ledgerHash = boost::json::value_to<std::string>(jv.at(JS(ledger_hash)));
166166

167-
if (jsonObject.contains(JS(ledger_index))) {
168-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
169-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
170-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
171-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
172-
}
173-
}
167+
if (jsonObject.contains(JS(ledger_index)))
168+
input.ledgerIndex = util::getLedgerIndex(jv.at(JS(ledger_index)));
174169

175170
return input;
176171
}

src/rpc/handlers/AccountMPTokens.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,15 @@ tag_invoke(boost::json::value_to_tag<AccountMPTokensHandler::Input>, boost::json
132132

133133
if (jsonObject.contains(JS(limit)))
134134
input.limit = util::integralValueAs<uint32_t>(jv.at(JS(limit)));
135+
135136
if (jsonObject.contains(JS(marker)))
136137
input.marker = boost::json::value_to<std::string>(jv.at(JS(marker)));
138+
137139
if (jsonObject.contains(JS(ledger_hash)))
138140
input.ledgerHash = boost::json::value_to<std::string>(jv.at(JS(ledger_hash)));
139-
if (jsonObject.contains(JS(ledger_index))) {
140-
if (!jv.at(JS(ledger_index)).is_string()) {
141-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
142-
} else if (boost::json::value_to<std::string>(jv.at(JS(ledger_index))) != "validated") {
143-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
144-
}
145-
}
141+
142+
if (jsonObject.contains(JS(ledger_index)))
143+
input.ledgerIndex = util::getLedgerIndex(jv.at(JS(ledger_index)));
146144

147145
return input;
148146
}

src/rpc/handlers/AccountNFTs.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,8 @@ tag_invoke(boost::json::value_to_tag<AccountNFTsHandler::Input>, boost::json::va
157157
if (jsonObject.contains(JS(ledger_hash)))
158158
input.ledgerHash = boost::json::value_to<std::string>(jsonObject.at(JS(ledger_hash)));
159159

160-
if (jsonObject.contains(JS(ledger_index))) {
161-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
162-
input.ledgerIndex = util::integralValueAs<uint32_t>(jsonObject.at(JS(ledger_index)));
163-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
164-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jsonObject.at(JS(ledger_index))));
165-
}
166-
}
160+
if (jsonObject.contains(JS(ledger_index)))
161+
input.ledgerIndex = util::getLedgerIndex(jsonObject.at(JS(ledger_index)));
167162

168163
if (jsonObject.contains(JS(limit)))
169164
input.limit = util::integralValueAs<uint32_t>(jsonObject.at(JS(limit)));

src/rpc/handlers/AccountObjects.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,8 @@ tag_invoke(boost::json::value_to_tag<AccountObjectsHandler::Input>, boost::json:
153153
if (jsonObject.contains(JS(ledger_hash)))
154154
input.ledgerHash = boost::json::value_to<std::string>(jv.at(JS(ledger_hash)));
155155

156-
if (jsonObject.contains(JS(ledger_index))) {
157-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
158-
input.ledgerIndex = util::integralValueAs<uint32_t>(jv.at(JS(ledger_index)));
159-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
160-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jv.at(JS(ledger_index))));
161-
}
162-
}
156+
if (jsonObject.contains(JS(ledger_index)))
157+
input.ledgerIndex = util::getLedgerIndex(jv.at(JS(ledger_index)));
163158

164159
if (jsonObject.contains(JS(type))) {
165160
input.type =

src/rpc/handlers/AccountOffers.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,11 @@ tag_invoke(boost::json::value_to_tag<AccountOffersHandler::Input>, boost::json::
166166

167167
input.account = boost::json::value_to<std::string>(jsonObject.at(JS(account)));
168168

169-
if (jsonObject.contains(JS(ledger_hash))) {
169+
if (jsonObject.contains(JS(ledger_hash)))
170170
input.ledgerHash = boost::json::value_to<std::string>(jsonObject.at(JS(ledger_hash)));
171-
}
172-
if (jsonObject.contains(JS(ledger_index))) {
173-
if (!jsonObject.at(JS(ledger_index)).is_string()) {
174-
input.ledgerIndex = util::integralValueAs<uint32_t>(jsonObject.at(JS(ledger_index)));
175-
} else if (jsonObject.at(JS(ledger_index)).as_string() != "validated") {
176-
input.ledgerIndex = std::stoi(boost::json::value_to<std::string>(jsonObject.at(JS(ledger_index))));
177-
}
178-
}
171+
172+
if (jsonObject.contains(JS(ledger_index)))
173+
input.ledgerIndex = util::getLedgerIndex(jsonObject.at(JS(ledger_index)));
179174

180175
if (jsonObject.contains(JS(limit)))
181176
input.limit = util::integralValueAs<uint32_t>(jsonObject.at(JS(limit)));

0 commit comments

Comments
 (0)