Skip to content

Commit d54260b

Browse files
improve cli
1 parent 4fc23fb commit d54260b

File tree

4 files changed

+128
-35
lines changed

4 files changed

+128
-35
lines changed

Cargo.lock

+51-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+56-12
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,83 @@
11
# TON lite_api
22

3-
Implementation of [lite_api](https://github.com/ton-blockchain/ton/blob/master/tl/generate/scheme/lite_api.tl) and [lite-client](https://github.com/ton-blockchain/ton/tree/master/lite-client) in Rust using [adnl-rs](https://github.com/tonstack/adnl-rs).
3+
Implementation of low-level [lite_api](https://github.com/ton-blockchain/ton/blob/master/tl/generate/scheme/lite_api.tl) and [lite-client](https://github.com/ton-blockchain/ton/tree/master/lite-client) in Rust using [adnl-rs](https://github.com/tonstack/adnl-rs).
44

5-
| Feature | Status |
6-
| ----------------- | -------------------------------- |
7-
| lite_api client | ✅ Implemented |
8-
| lite_api server | ✅ Implemented |
9-
| lite-client cli | ✅ Implemented |
10-
| async | ✅ Implemented |
5+
| Feature | Status |
6+
| --------------- | -------------- |
7+
| lite_api client | ✅ Implemented |
8+
| lite_api server | ✅ Implemented |
9+
| lite-client cli | ✅ Implemented |
10+
| async | ✅ Implemented |
1111

1212
## Installation
13+
1314
```bash
14-
cargo install --git https://github.com/tonstack/lite-client
15+
cargo install ton_lc
1516
```
1617

1718
## Usage
19+
1820
Without any options, [mainnet config](https://ton.org/global.config.json) will be used.
1921
For testnet, use `-t / --testnet` flag.
20-
To use your own config, pass `-c / --config <FILE>` option.
22+
To use your own config, pass `-c / --config <FILE>` option.
23+
Also you can use `--address` and `--public-key` to connect to specific liteserver.
2124

2225
Send an external message to TON:
26+
2327
```bash
24-
echo 1234 | liteclient send - # accept message bytes from stdin
25-
liteclient send ./query.boc # read from file
28+
echo 1234 | ton_lc send-message - # accept message bytes from stdin
29+
ton_lc send-message ./query.boc # read from file
2630
```
31+
2732
It prints:
33+
2834
```
2935
[ERROR] Server error [code=0]: cannot apply external message to current state : failed to parse external message cannot deserialize bag-of-cells: invalid header, error 0
3036
```
3137

38+
```
39+
OPTIONS:
40+
--address <ADDRESS> Liteserver address (IP:PORT)
41+
-c, --config <FILE> Local network config from file
42+
-h, --help Print help information
43+
--public-key <PUBLIC_KEY> Liteserver public key (hex-encoded)
44+
-t, --testnet Use testnet config, if not provided use mainnet config
45+
-V, --version Print version information
46+
47+
SUBCOMMANDS:
48+
get-account-state Download account state at specified block
49+
get-all-shards-info
50+
get-block Downloads and dumps specified block
51+
get-block-header Download block header with specified merkle proofs
52+
get-block-proof Download masterchain proof
53+
get-config-all Download all config params
54+
get-config-params Download specified config params
55+
get-libraries Download specified libraries
56+
get-masterchain-info Get masterchain info
57+
get-masterchain-info-ext Get masterchain info with additional data
58+
get-one-transaction
59+
get-shard-info
60+
get-state Download state for masterchain block seqnos < 1000
61+
get-time Get server time
62+
get-transactions Iterate through transactions for an account
63+
get-validator-stats
64+
get-version Shows server time, version and capabilities
65+
help Print this message or the help of the given subcommand(s)
66+
list-block-transactions List transactions for a specified block
67+
lookup-block Find block by seqno, lt or utime, block header will be
68+
downloaded with specified merkle proofs
69+
run-smc-method Run get-method for smart contract
70+
send-message Send external message
71+
```
72+
3273
## Debug logging
74+
3375
```bash
34-
echo 1234 | RUST_LOG=debug liteclient send -
76+
echo 1234 | RUST_LOG=debug ton_lc send-message -
3577
```
78+
3679
prints:
80+
3781
```
3882
[2022-03-15T10:43:55Z DEBUG liteclient::private] Sending query:
3983
Length: 20 (0x14) bytes

cli/Cargo.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
[package]
2-
name = "cli"
2+
name = "ton_lc"
33
version = "0.1.0"
44
edition = "2021"
5+
description = "Low-level implementation of TON lite client"
6+
repository = "https://github.com/tonstack/lite-client"
7+
keywords = ["ton"]
8+
categories = ["network-programming"]
9+
license = "MIT"
10+
authors = ["Vladimir Lebedev <[email protected]>"]
511

612
[dependencies]
713
base64 = "0.13.0"
@@ -13,7 +19,7 @@ chrono = "0.4.19"
1319
hex = "0.4.3"
1420
ureq = "2.4.0"
1521
regex = "1"
16-
ton_liteapi = { path = "../liteapi" }
17-
ton_networkconfig = { path = "../network-config" }
22+
ton_liteapi = "0.1.0"
23+
ton_networkconfig = "0.1.0"
1824
rand = "0.8.5"
1925
tokio = { version = "1.36", features = ["full"] }

cli/src/main.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ enum Commands {
5656
#[clap(value_parser = parse_block_id_ext)]
5757
block_id_ext: BlockIdExt,
5858
},
59+
/// Download state for masterchain block seqnos < 1000
5960
GetState {
6061
#[clap(value_parser = parse_block_id_ext)]
6162
block_id_ext: BlockIdExt,
6263
},
64+
/// Download block header with specified merkle proofs
6365
GetBlockHeader {
6466
#[clap(value_parser = parse_block_id_ext)]
6567
block_id_ext: BlockIdExt,
@@ -77,15 +79,17 @@ enum Commands {
7779
/// Send external message
7880
#[clap(arg_required_else_help = true, parse(from_os_str))]
7981
SendMessage {
80-
/// File to send
82+
/// File to send or "-" for reading from stdin
8183
file: PathBuf,
8284
},
85+
/// Download account state at specified block
8386
GetAccountState {
8487
#[clap(value_parser = parse_block_id_ext)]
8588
block_id_ext: BlockIdExt,
8689
#[clap(value_parser = parse_account_id)]
8790
account_id: AccountId,
8891
},
92+
/// Run get-method for smart contract
8993
RunSmcMethod {
9094
#[clap(value_parser = parse_block_id_ext)]
9195
block_id_ext: BlockIdExt,
@@ -112,13 +116,15 @@ enum Commands {
112116
account_id: AccountId,
113117
lt: u64,
114118
},
119+
/// Iterate through transactions for an account
115120
GetTransactions {
116121
count: u32,
117122
#[clap(value_parser = parse_account_id)]
118123
account_id: AccountId,
119124
lt: u64,
120125
hash: Int256,
121126
},
127+
/// Find block by seqno, lt or utime, block header will be downloaded with specified merkle proofs
122128
LookupBlock {
123129
workchain: i32,
124130
shard: u64,
@@ -139,6 +145,7 @@ enum Commands {
139145
#[clap(long)]
140146
with_prev_blk_signatures: bool,
141147
},
148+
/// List transactions for a specified block
142149
ListBlockTransactions {
143150
#[clap(value_parser = parse_block_id_ext)]
144151
block_id_ext: BlockIdExt,
@@ -152,6 +159,7 @@ enum Commands {
152159
#[clap(requires = "after-account", long)]
153160
after_lt: Option<u64>,
154161
},
162+
/// Download masterchain proof
155163
GetBlockProof {
156164
#[clap(value_parser = parse_block_id_ext)]
157165
known_block: BlockIdExt,
@@ -162,6 +170,7 @@ enum Commands {
162170
#[clap(long)]
163171
base_block_from_request: bool,
164172
},
173+
/// Download all config params
165174
GetConfigAll {
166175
#[clap(value_parser = parse_block_id_ext)]
167176
block_id_ext: BlockIdExt,
@@ -188,6 +197,7 @@ enum Commands {
188197
#[clap(long)]
189198
extract_from_key_block: bool,
190199
},
200+
/// Download specified config params
191201
GetConfigParams {
192202
#[clap(value_parser = parse_block_id_ext)]
193203
block_id_ext: BlockIdExt,
@@ -222,6 +232,7 @@ enum Commands {
222232
start_after: Option<Int256>,
223233
modified_after: Option<u32>,
224234
},
235+
/// Download specified libraries
225236
GetLibraries {
226237
library_list: Vec<Int256>,
227238
},

0 commit comments

Comments
 (0)