Skip to content

Commit 62e8f12

Browse files
Added getShardAccountCell method
1 parent 0b4b702 commit 62e8f12

10 files changed

Lines changed: 287 additions & 7 deletions

File tree

config/static_config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ components_manager:
142142
cache_size: 4096
143143
cache_ways: 16
144144
cache_ttl: 1s
145+
handler-GetShardAccountCellHandler:
146+
path: /api/v2/getShardAccountCell
147+
method: GET,POST
148+
cache_enabled: true
149+
cache_size: 4096
150+
cache_ways: 16
151+
cache_ttl: 1s
145152
handler-GetWalletInformation:
146153
path: /api/v2/getWalletInformation
147154
method: GET,POST

patches/ton_001.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/tonlib/tonlib/TonlibClient.cpp b/tonlib/tonlib/TonlibClient.cpp
2-
index 4ddcbbfa..5dd1c9cc 100644
2+
index 1591b872..455c1499 100644
33
--- a/tonlib/tonlib/TonlibClient.cpp
44
+++ b/tonlib/tonlib/TonlibClient.cpp
5-
@@ -3302,7 +3302,7 @@ td::Status TonlibClient::do_request(const tonlib_api::raw_sendMessage& request,
5+
@@ -3456,7 +3456,7 @@ td::Status TonlibClient::do_request(const tonlib_api::raw_sendMessage& request,
66
TRY_RESULT_PREFIX(body, vm::std_boc_deserialize(request.body_), TonlibError::InvalidBagOfCells("body"));
77
std::ostringstream os;
88
block::gen::t_Message_Any.print_ref(os, body);
@@ -11,11 +11,11 @@ index 4ddcbbfa..5dd1c9cc 100644
1111
make_request(int_api::SendMessage{std::move(body)}, to_any_promise(std::move(promise)));
1212
return td::Status::OK();
1313
}
14-
@@ -4837,6 +4837,7 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request,
14+
@@ -5003,6 +5003,7 @@ td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request,
1515
args.set_extra_currencies(it->second->get_extra_currencies());
1616
args.set_now(it->second->get_sync_time());
1717
args.set_address(it->second->get_address());
1818
+ args.set_limits(vm::GasLimits(4000000, 4000000));
1919

20-
client_.with_last_config([self = this, smc = std::move(smc), args = std::move(args), promise = std::move(promise)
21-
](td::Result<LastConfigState> r_state) mutable {
20+
client_.with_last_config([self = this, smc = std::move(smc), args = std::move(args),
21+
promise = std::move(promise)](td::Result<LastConfigState> r_state) mutable {

ton-http-api/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ set(TON_HTTP_API_CPP_SOURCE
119119
src/handlers/runmethod/RunGetMethodStdHandler.cpp
120120
src/handlers/send/EstimateFeeHandler.cpp
121121
src/handlers/runmethod/RunGetMethodHandler.cpp
122+
src/handlers/accounts/GetShardAccountCellHandler.cpp
123+
src/handlers/accounts/GetShardAccountCellHandler.h
122124
)
123125
add_executable(${PROJECT_NAME} ${TON_HTTP_API_CPP_SOURCE})
124126
target_include_directories(${PROJECT_NAME}

ton-http-api/schemas/v2.yaml

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ info:
99
The response contains a JSON object, which always has a boolean field `ok` and either `error` or `result`. If `ok` equals true, the request was successful and the result of the query can be found in the `result` field. In case of an unsuccessful request, `ok` equals false and the error is explained in the `error`.
1010
1111
API Key should be sent either as `api_key` query parameter or `X-API-Key` header
12-
version: '2.1.1'
12+
version: '2.1.11'
1313
paths:
1414
/api/v2/jsonRPC:
1515
post:
@@ -310,6 +310,52 @@ paths:
310310
security:
311311
- APIKeyHeader: [ ]
312312
- APIKeyQuery: [ ]
313+
/api/v2/getShardAccountCell:
314+
get:
315+
tags:
316+
- accounts
317+
summary: Get Shard Address Cell
318+
description: Get raw TVM cell with shard account
319+
operationId: getShardAccountCell_get
320+
parameters:
321+
- $ref: '#/components/parameters/address'
322+
- $ref: '#/components/parameters/seqnoOptional'
323+
responses:
324+
200:
325+
description: OK
326+
content:
327+
application/json:
328+
schema:
329+
$ref: '#/components/schemas/TonlibResponse'
330+
default:
331+
$ref: '#/components/responses/default'
332+
security:
333+
- APIKeyHeader: [ ]
334+
- APIKeyQuery: [ ]
335+
post:
336+
tags:
337+
- rpc
338+
summary: Get Shard Address Cell
339+
description: Get raw TVM cell with shard account
340+
operationId: getShardAccountCell_post
341+
requestBody:
342+
content:
343+
application/json:
344+
schema:
345+
$ref: '#/components/schemas/ShardAccountCellRequest'
346+
required: true
347+
responses:
348+
200:
349+
description: OK
350+
content:
351+
application/json:
352+
schema:
353+
$ref: '#/components/schemas/TonlibResponse'
354+
default:
355+
$ref: '#/components/responses/default'
356+
security:
357+
- APIKeyHeader: [ ]
358+
- APIKeyQuery: [ ]
313359
/api/v2/getWalletInformation:
314360
get:
315361
tags:
@@ -1790,6 +1836,8 @@ components:
17901836
$ref: '#/components/schemas/AddressRequest'
17911837
AddressInformationRequest:
17921838
$ref: '#/components/schemas/AddressWithSeqnoRequest'
1839+
ShardAccountCellRequest:
1840+
$ref: '#/components/schemas/AddressWithSeqnoRequest'
17931841
ExtendedAddressInformationRequest:
17941842
$ref: '#/components/schemas/AddressWithSeqnoRequest'
17951843
WalletInformationRequest:
@@ -3281,6 +3329,7 @@ components:
32813329
- $ref: '#/components/schemas/ResultOk'
32823330
- $ref: '#/components/schemas/RunGetMethodStdResult'
32833331
- $ref: '#/components/schemas/RunGetMethodResult'
3332+
- $ref: '#/components/schemas/TvmCell'
32843333
discriminator:
32853334
propertyName: '@type'
32863335
mapping:
@@ -3313,6 +3362,7 @@ components:
33133362
'ok': '#/components/schemas/ResultOk'
33143363
'smc.runResult': '#/components/schemas/RunGetMethodStdResult'
33153364
'ext.runResult': '#/components/schemas/RunGetMethodResult'
3365+
'tvm.cell': '#/components/schemas/TvmCell'
33163366
TonlibResponse:
33173367
type: object
33183368
title: TonlibResponse

ton-http-api/src/core/tonlib_worker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class TonlibWorker {
4646
std::optional<std::int32_t> seqno = std::nullopt,
4747
multiclient::SessionPtr session = nullptr
4848
) const;
49+
[[nodiscard]] td::Result<tonlib_api::getShardAccountCell::ReturnType> getShardAccountCell(
50+
const std::string& address,
51+
std::optional<std::int32_t> seqno = std::nullopt,
52+
multiclient::SessionPtr session = nullptr
53+
) const;
4954
[[nodiscard]] td::Result<tonlib_api::blocks_lookupBlock::ReturnType> lookupBlock(
5055
const std::int32_t& workchain,
5156
const std::int64_t& shard,

ton-http-api/src/core/tonlib_worker_accounts.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,47 @@ td::Result<tonlib_api::getAccountState::ReturnType> TonlibWorker::getExtendedAdd
8888
TRY_RESULT(result, send_request_function(std::move(request), true));
8989
return ton::move_tl_object_as<tonlib_api::fullAccountState>(result);
9090
}
91+
td::Result<tonlib_api::getShardAccountCell::ReturnType> TonlibWorker::getShardAccountCell(
92+
const std::string& address, std::optional<std::int32_t> seqno, multiclient::SessionPtr session
93+
) const {
94+
tonlib_api::object_ptr<tonlib_api::ton_blockIdExt> with_block;
95+
if (seqno.has_value()) {
96+
TRY_RESULT_ASSIGN(
97+
with_block, lookupBlock(ton::masterchainId, ton::shardIdAll, seqno.value(), std::nullopt, std::nullopt, session)
98+
);
99+
}
100+
if (!with_block) {
101+
auto request = multiclient::RequestFunction<tonlib_api::getShardAccountCell>{
102+
.parameters = {.mode = multiclient::RequestMode::Single},
103+
.request_creator =
104+
[address_ = address] {
105+
return tonlib_api::make_object<tonlib_api::getShardAccountCell>(
106+
tonlib_api::make_object<tonlib_api::accountAddress>(address_)
107+
);
108+
},
109+
.session = session
110+
};
111+
return send_request_function(std::move(request), true);
112+
}
113+
auto request = multiclient::RequestFunction<tonlib_api::withBlock>{
114+
.parameters = {.mode = multiclient::RequestMode::Single},
115+
.request_creator =
116+
[address_ = address,
117+
workchain_ = with_block->workchain_,
118+
shard_ = with_block->shard_,
119+
seqno_ = with_block->seqno_,
120+
root_hash_ = with_block->root_hash_,
121+
file_hash_ = with_block->file_hash_] {
122+
return tonlib_api::make_object<tonlib_api::withBlock>(
123+
tonlib_api::make_object<tonlib_api::ton_blockIdExt>(workchain_, shard_, seqno_, root_hash_, file_hash_),
124+
tonlib_api::make_object<tonlib_api::getShardAccountCell>(
125+
tonlib_api::make_object<tonlib_api::accountAddress>(address_)
126+
)
127+
);
128+
},
129+
.session = session
130+
};
131+
TRY_RESULT(result, send_request_function(std::move(request), true));
132+
return ton::move_tl_object_as<tonlib_api::tvm_cell>(result);
133+
}
91134
} // namespace ton_http::core
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "GetShardAccountCellHandler.h"
2+
3+
#include <boost/lexical_cast.hpp>
4+
#include "converters/convert.hpp"
5+
#include "utils/wallets.hpp"
6+
7+
ton_http::handlers::GetShardAccountCellHandler::GetShardAccountCellHandler(
8+
const userver::components::ComponentConfig& config, const userver::components::ComponentContext& context
9+
) :
10+
TonlibRequestHandler(config, context) {
11+
}
12+
13+
ton_http::schemas::v2::AddressInformationRequest ton_http::handlers::GetShardAccountCellHandler::
14+
ParseTonlibGetRequest(const HttpRequest& request, RequestContext&) const {
15+
schemas::v2::AddressInformationRequest req;
16+
17+
req.address = userver::chaotic::convert::Convert(
18+
request.GetArg("address"), userver::chaotic::convert::To<ton_http::types::ton_addr>{}
19+
);
20+
if (request.HasArg("seqno")) {
21+
try {
22+
req.seqno = boost::lexical_cast<std::int32_t>(request.GetArg("seqno"));
23+
} catch (std::exception& exc) {
24+
throw utils::TonlibException("failed to parse seqno", 422);
25+
}
26+
}
27+
return req;
28+
}
29+
td::Status ton_http::handlers::GetShardAccountCellHandler::ValidateRequest(
30+
const schemas::v2::ShardAccountCellRequest& request
31+
) const {
32+
if (request.address.empty()) {
33+
return td::Status::Error(422, "empty address");
34+
}
35+
if (request.seqno.has_value() && request.seqno.value() <= 0) {
36+
return td::Status::Error(422, "seqno should be positive");
37+
}
38+
return td::Status::OK();
39+
}
40+
td::Result<ton_http::schemas::v2::TvmCell>
41+
ton_http::handlers::GetShardAccountCellHandler::HandleRequestTonlibThrow(
42+
schemas::v2::ShardAccountCellRequest& request, multiclient::SessionPtr& session
43+
) const {
44+
auto result = tonlib_component_.DoRequest(
45+
&core::TonlibWorker::getShardAccountCell, request.address.GetUnderlying(), request.seqno, session
46+
);
47+
if (result.is_error()) {
48+
return result.move_as_error();
49+
}
50+
auto result_ok = result.move_as_ok();
51+
52+
// prepare response
53+
auto response = converters::Convert(result_ok);
54+
return response;
55+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include "handlers/TonlibRequestHandler.h"
3+
#include "schemas/v2.hpp"
4+
5+
6+
namespace ton_http::handlers {
7+
8+
class GetShardAccountCellHandler
9+
: public TonlibRequestHandler<schemas::v2::ShardAccountCellRequest, schemas::v2::TvmCell> {
10+
public:
11+
static constexpr std::string_view kName = "handler-GetShardAccountCellHandler";
12+
13+
GetShardAccountCellHandler(
14+
const userver::components::ComponentConfig& config, const userver::components::ComponentContext& context
15+
);
16+
17+
td::Status ValidateRequest(const schemas::v2::AddressInformationRequest& request) const override;
18+
schemas::v2::ShardAccountCellRequest ParseTonlibGetRequest(
19+
const HttpRequest& request, RequestContext& context
20+
) const override;
21+
22+
td::Result<schemas::v2::TvmCell> HandleRequestTonlibThrow(
23+
schemas::v2::ShardAccountCellRequest& request, multiclient::SessionPtr& session
24+
) const override;
25+
};
26+
27+
} // namespace ton_http::handlers

ton-http-api/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "handlers/accounts/GetAddressInformationHandler.h"
1717
#include "handlers/accounts/GetAddressStateHandler.h"
1818
#include "handlers/accounts/GetExtendedAddressInformationHandler.h"
19+
#include "handlers/accounts/GetShardAccountCellHandler.h"
1920
#include "handlers/accounts/GetTokenDataHandler.h"
2021
#include "handlers/accounts/GetWalletInformationHandler.h"
2122
#include "handlers/blocks/GetBlockHeaderHandler.h"
@@ -76,6 +77,7 @@ int main(int argc, char* argv[]) {
7677
// accounts
7778
component_list.Append<ton_http::handlers::GetAddressInformationHandler>();
7879
component_list.Append<ton_http::handlers::GetExtendedAddressInformationHandler>();
80+
component_list.Append<ton_http::handlers::GetShardAccountCellHandler>();
7981
component_list.Append<ton_http::handlers::GetWalletInformationHandler>();
8082
component_list.Append<ton_http::handlers::GetAddressBalanceHandler>();
8183
component_list.Append<ton_http::handlers::GetAddressStateHandler>();

0 commit comments

Comments
 (0)