Skip to content

Commit 1f93e78

Browse files
Merge pull request #5 from toncenter/develop
Changed name of parameter in getConfigParam to correspond to TL schema
2 parents 30891a1 + 4679c77 commit 1f93e78

3 files changed

Lines changed: 46 additions & 14 deletions

File tree

ton-http-api/schemas/v2.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ paths:
12341234
description: Get blockchain configuration parameter
12351235
operationId: getConfigParam_get
12361236
parameters:
1237-
- name: config_id
1237+
- name: param
12381238
in: query
12391239
description: Parameter number
12401240
required: true
@@ -2026,15 +2026,19 @@ components:
20262026
ConfigParamRequest:
20272027
type: object
20282028
additionalProperties: false
2029-
required:
2030-
- config_id
20312029
properties:
20322030
config_id:
20332031
oneOf:
20342032
- type: string
20352033
- type: integer
20362034
format: int32
20372035
x-usrv-cpp-type: 'std::int32_t'
2036+
param:
2037+
oneOf:
2038+
- type: string
2039+
- type: integer
2040+
format: int32
2041+
x-usrv-cpp-type: 'std::int32_t'
20382042
seqno:
20392043
oneOf:
20402044
- type: string

ton-http-api/src/handlers/config/GetConfigParamHandler.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ ton_http::schemas::v2::ConfigParamRequest ton_http::handlers::GetConfigParamHand
1313
const HttpRequest& request, RequestContext&
1414
) const {
1515
schemas::v2::ConfigParamRequest req;
16-
17-
try {
18-
req.config_id = boost::lexical_cast<std::int32_t>(request.GetArg("config_id"));
19-
} catch (std::exception& exc) {
20-
throw utils::TonlibException("failed to parse config_id", 422);
16+
if (request.HasArg("param")) {
17+
try {
18+
req.param = boost::lexical_cast<std::int32_t>(request.GetArg("param"));
19+
} catch (std::exception& exc) {
20+
throw utils::TonlibException("failed to parse param", 422);
21+
}
22+
}
23+
if (request.HasArg("config_id")) { // backward compatibility
24+
try {
25+
req.param = boost::lexical_cast<std::int32_t>(request.GetArg("config_id"));
26+
} catch (std::exception& exc) {
27+
throw utils::TonlibException("failed to parse config_id", 422);
28+
}
2129
}
2230
if (request.HasArg("seqno")) {
2331
try {
@@ -32,7 +40,17 @@ ton_http::schemas::v2::ConfigParamRequest ton_http::handlers::GetConfigParamHand
3240
td::Status ton_http::handlers::GetConfigParamHandler::ValidateRequest(
3341
const schemas::v2::ConfigParamRequest& request
3442
) const {
35-
if (request.config_id < 0) {
43+
std::int32_t param = -1;
44+
if (!(request.config_id.has_value() ^ request.param.has_value())) {
45+
return td::Status::Error(422, "only one of config_id or param should be specified");
46+
}
47+
if (request.config_id.has_value()) {
48+
param = request.config_id.value();
49+
}
50+
if (request.param.has_value()) {
51+
param = request.param.value();
52+
}
53+
if (param < 0) {
3654
return td::Status::Error(422, "param should be non-negative");
3755
}
3856
if (request.seqno.has_value() && request.seqno.value() <= 0) {
@@ -43,6 +61,7 @@ td::Status ton_http::handlers::GetConfigParamHandler::ValidateRequest(
4361
td::Result<ton_http::schemas::v2::ConfigInfo> ton_http::handlers::GetConfigParamHandler::HandleRequestTonlibThrow(
4462
schemas::v2::ConfigParamRequest& request, multiclient::SessionPtr& session
4563
) const {
46-
TRY_RESULT(result, tonlib_component_.DoRequest(&core::TonlibWorker::getConfigParam, request.config_id, request.seqno, session));
64+
auto param = (request.config_id.has_value() ? request.config_id.value() : request.param.has_value() ? request.param.value() : -1);
65+
TRY_RESULT(result, tonlib_component_.DoRequest(&core::TonlibWorker::getConfigParam, param, request.seqno, session));
4766
return converters::Convert(result);
4867
}

ton-http-api/static/openapi.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@
21832183
"operationId": "getConfigParam_get",
21842184
"parameters": [
21852185
{
2186-
"name": "config_id",
2186+
"name": "param",
21872187
"in": "query",
21882188
"description": "Parameter number",
21892189
"required": true,
@@ -3450,9 +3450,6 @@
34503450
"ConfigParamRequest": {
34513451
"type": "object",
34523452
"additionalProperties": false,
3453-
"required": [
3454-
"config_id"
3455-
],
34563453
"properties": {
34573454
"config_id": {
34583455
"oneOf": [
@@ -3466,6 +3463,18 @@
34663463
],
34673464
"x-usrv-cpp-type": "std::int32_t"
34683465
},
3466+
"param": {
3467+
"oneOf": [
3468+
{
3469+
"type": "string"
3470+
},
3471+
{
3472+
"type": "integer",
3473+
"format": "int32"
3474+
}
3475+
],
3476+
"x-usrv-cpp-type": "std::int32_t"
3477+
},
34693478
"seqno": {
34703479
"oneOf": [
34713480
{

0 commit comments

Comments
 (0)