Skip to content

Commit 7f815fc

Browse files
authored
Add "getconfig" to tonlib-cli (ton-blockchain#780)
1 parent b2a09ed commit 7f815fc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tonlib/tonlib/tonlib-cli.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ class TonlibCli : public td::actor::Actor {
390390
"<addr> with specified parameters\n";
391391
td::TerminalIO::out() << "getstate <key_id>\tget state of wallet with requested key\n";
392392
td::TerminalIO::out() << "getstatebytransaction <key_id> <lt> <hash>\tget state of wallet with requested key after transaction with local time <lt> and hash <hash> (base64url)\n";
393+
td::TerminalIO::out() << "getconfig <param>\tshow specified configuration parameter from the latest masterchain state\n";
393394
td::TerminalIO::out() << "guessrevision <key_id>\tsearch of existing accounts corresponding to the given key\n";
394395
td::TerminalIO::out() << "guessaccount <key_id>\tsearch of existing accounts corresponding to the given key\n";
395396
td::TerminalIO::out() << "getaddress <key_id>\tget address of wallet with requested key\n";
@@ -492,6 +493,8 @@ class TonlibCli : public td::actor::Actor {
492493
get_state(parser.read_word(), std::move(cmd_promise));
493494
} else if (cmd == "getstatebytransaction") {
494495
get_state_by_transaction(parser, std::move(cmd_promise));
496+
} else if (cmd == "getconfig") {
497+
get_config_param(parser, std::move(cmd_promise));
495498
} else if (cmd == "getaddress") {
496499
get_address(parser.read_word(), std::move(cmd_promise));
497500
} else if (cmd == "importkeypem") {
@@ -2094,6 +2097,26 @@ class TonlibCli : public td::actor::Actor {
20942097
}));
20952098
}
20962099

2100+
void get_config_param(td::ConstParser& parser, td::Promise<td::Unit> promise) {
2101+
TRY_RESULT_PROMISE(promise, param, td::to_integer_safe<td::int32>(parser.read_word()));
2102+
send_query(make_object<tonlib_api::getConfigParam>(0, param),
2103+
promise.wrap([param](auto&& result) -> td::Result<td::Unit> {
2104+
TRY_RESULT(cell, vm::std_boc_deserialize(result->config_->bytes_, true));
2105+
if (cell.is_null()) {
2106+
td::TerminalIO::out() << "ConfigParam(" << param << ") = (null)\n";
2107+
return td::Unit();
2108+
}
2109+
std::ostringstream os;
2110+
if (param >= 0) {
2111+
block::gen::ConfigParam{param}.print_ref(4096, os, cell);
2112+
os << "\n";
2113+
}
2114+
vm::load_cell_slice(cell).print_rec(4096, os);
2115+
td::TerminalIO::out() << "ConfigParam(" << param << ") = " << os.str() << "\n";
2116+
return td::Unit();
2117+
}));
2118+
}
2119+
20972120
void get_address(td::Slice key, td::Promise<td::Unit> promise) {
20982121
TRY_RESULT_PROMISE(promise, address, to_account_address(key, false));
20992122
promise.set_value(td::Unit());

0 commit comments

Comments
 (0)