Skip to content

Commit

Permalink
improve cli
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker-volodya committed Oct 29, 2024
1 parent 4fc23fb commit d54260b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 35 deletions.
70 changes: 51 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 56 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,83 @@
# TON lite_api

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).
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).

| Feature | Status |
| ----------------- | -------------------------------- |
| lite_api client | ✅ Implemented |
| lite_api server | ✅ Implemented |
| lite-client cli | ✅ Implemented |
| async | ✅ Implemented |
| Feature | Status |
| --------------- | -------------- |
| lite_api client | ✅ Implemented |
| lite_api server | ✅ Implemented |
| lite-client cli | ✅ Implemented |
| async | ✅ Implemented |

## Installation

```bash
cargo install --git https://github.com/tonstack/lite-client
cargo install ton_lc
```

## Usage

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

Send an external message to TON:

```bash
echo 1234 | liteclient send - # accept message bytes from stdin
liteclient send ./query.boc # read from file
echo 1234 | ton_lc send-message - # accept message bytes from stdin
ton_lc send-message ./query.boc # read from file
```

It prints:

```
[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
```

```
OPTIONS:
--address <ADDRESS> Liteserver address (IP:PORT)
-c, --config <FILE> Local network config from file
-h, --help Print help information
--public-key <PUBLIC_KEY> Liteserver public key (hex-encoded)
-t, --testnet Use testnet config, if not provided use mainnet config
-V, --version Print version information
SUBCOMMANDS:
get-account-state Download account state at specified block
get-all-shards-info
get-block Downloads and dumps specified block
get-block-header Download block header with specified merkle proofs
get-block-proof Download masterchain proof
get-config-all Download all config params
get-config-params Download specified config params
get-libraries Download specified libraries
get-masterchain-info Get masterchain info
get-masterchain-info-ext Get masterchain info with additional data
get-one-transaction
get-shard-info
get-state Download state for masterchain block seqnos < 1000
get-time Get server time
get-transactions Iterate through transactions for an account
get-validator-stats
get-version Shows server time, version and capabilities
help Print this message or the help of the given subcommand(s)
list-block-transactions List transactions for a specified block
lookup-block Find block by seqno, lt or utime, block header will be
downloaded with specified merkle proofs
run-smc-method Run get-method for smart contract
send-message Send external message
```

## Debug logging

```bash
echo 1234 | RUST_LOG=debug liteclient send -
echo 1234 | RUST_LOG=debug ton_lc send-message -
```

prints:

```
[2022-03-15T10:43:55Z DEBUG liteclient::private] Sending query:
Length: 20 (0x14) bytes
Expand Down
12 changes: 9 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[package]
name = "cli"
name = "ton_lc"
version = "0.1.0"
edition = "2021"
description = "Low-level implementation of TON lite client"
repository = "https://github.com/tonstack/lite-client"
keywords = ["ton"]
categories = ["network-programming"]
license = "MIT"
authors = ["Vladimir Lebedev <d3fl4t3@gmail.com>"]

[dependencies]
base64 = "0.13.0"
Expand All @@ -13,7 +19,7 @@ chrono = "0.4.19"
hex = "0.4.3"
ureq = "2.4.0"
regex = "1"
ton_liteapi = { path = "../liteapi" }
ton_networkconfig = { path = "../network-config" }
ton_liteapi = "0.1.0"
ton_networkconfig = "0.1.0"
rand = "0.8.5"
tokio = { version = "1.36", features = ["full"] }
13 changes: 12 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ enum Commands {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
},
/// Download state for masterchain block seqnos < 1000
GetState {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
},
/// Download block header with specified merkle proofs
GetBlockHeader {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
Expand All @@ -77,15 +79,17 @@ enum Commands {
/// Send external message
#[clap(arg_required_else_help = true, parse(from_os_str))]
SendMessage {
/// File to send
/// File to send or "-" for reading from stdin
file: PathBuf,
},
/// Download account state at specified block
GetAccountState {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
#[clap(value_parser = parse_account_id)]
account_id: AccountId,
},
/// Run get-method for smart contract
RunSmcMethod {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
Expand All @@ -112,13 +116,15 @@ enum Commands {
account_id: AccountId,
lt: u64,
},
/// Iterate through transactions for an account
GetTransactions {
count: u32,
#[clap(value_parser = parse_account_id)]
account_id: AccountId,
lt: u64,
hash: Int256,
},
/// Find block by seqno, lt or utime, block header will be downloaded with specified merkle proofs
LookupBlock {
workchain: i32,
shard: u64,
Expand All @@ -139,6 +145,7 @@ enum Commands {
#[clap(long)]
with_prev_blk_signatures: bool,
},
/// List transactions for a specified block
ListBlockTransactions {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
Expand All @@ -152,6 +159,7 @@ enum Commands {
#[clap(requires = "after-account", long)]
after_lt: Option<u64>,
},
/// Download masterchain proof
GetBlockProof {
#[clap(value_parser = parse_block_id_ext)]
known_block: BlockIdExt,
Expand All @@ -162,6 +170,7 @@ enum Commands {
#[clap(long)]
base_block_from_request: bool,
},
/// Download all config params
GetConfigAll {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
Expand All @@ -188,6 +197,7 @@ enum Commands {
#[clap(long)]
extract_from_key_block: bool,
},
/// Download specified config params
GetConfigParams {
#[clap(value_parser = parse_block_id_ext)]
block_id_ext: BlockIdExt,
Expand Down Expand Up @@ -222,6 +232,7 @@ enum Commands {
start_after: Option<Int256>,
modified_after: Option<u32>,
},
/// Download specified libraries
GetLibraries {
library_list: Vec<Int256>,
},
Expand Down

0 comments on commit d54260b

Please sign in to comment.