From d54260b5d54f0bdc93886d87ce413db1d997fa8f Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Tue, 29 Oct 2024 15:14:46 +0700 Subject: [PATCH] improve cli --- Cargo.lock | 70 +++++++++++++++++++++++++++++++++++-------------- README.md | 68 ++++++++++++++++++++++++++++++++++++++--------- cli/Cargo.toml | 12 ++++++--- cli/src/main.rs | 13 ++++++++- 4 files changed, 128 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1adc64..b3b7904 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,25 +267,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "cli" -version = "0.1.0" -dependencies = [ - "base64 0.13.1", - "chrono", - "clap", - "env_logger 0.9.3", - "hex", - "log", - "pretty-hex", - "rand", - "regex", - "tokio", - "ton_liteapi", - "ton_networkconfig", - "ureq", -] - [[package]] name = "colorchoice" version = "1.0.0" @@ -1495,6 +1476,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "ton_lc" +version = "0.1.0" +dependencies = [ + "base64 0.13.1", + "chrono", + "clap", + "env_logger 0.9.3", + "hex", + "log", + "pretty-hex", + "rand", + "regex", + "tokio", + "ton_liteapi 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ton_networkconfig 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ureq", +] + [[package]] name = "ton_liteapi" version = "0.1.0" @@ -1518,6 +1518,27 @@ dependencies = [ "x25519-dalek", ] +[[package]] +name = "ton_liteapi" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2ccb9ece58a1ede8fc27ed076c8c1c8063f88e9ec7e825e488c436b49ab46ca" +dependencies = [ + "adnl", + "derivative", + "futures", + "hex", + "log", + "pin-project", + "rand", + "thiserror", + "tl-proto", + "tokio", + "tokio-tower", + "tokio-util", + "tower", +] + [[package]] name = "ton_networkconfig" version = "0.1.0" @@ -1527,6 +1548,17 @@ dependencies = [ "serde_with", ] +[[package]] +name = "ton_networkconfig" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ab402c6f30bbe26914481ad184d5d9e8e54deaf4a4f6e52946f3547c998342f" +dependencies = [ + "serde", + "serde_json", + "serde_with", +] + [[package]] name = "tower" version = "0.4.13" diff --git a/README.md b/README.md index 5ad4563..9370660 100644 --- a/README.md +++ b/README.md @@ -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 ` option. +To use your own config, pass `-c / --config ` 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
Liteserver address (IP:PORT) + -c, --config Local network config from file + -h, --help Print help information + --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 diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8ad7fa0..f963910 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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 "] [dependencies] base64 = "0.13.0" @@ -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"] } \ No newline at end of file diff --git a/cli/src/main.rs b/cli/src/main.rs index eebb41d..4d07233 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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, @@ -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, @@ -112,6 +116,7 @@ enum Commands { account_id: AccountId, lt: u64, }, + /// Iterate through transactions for an account GetTransactions { count: u32, #[clap(value_parser = parse_account_id)] @@ -119,6 +124,7 @@ enum Commands { 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, @@ -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, @@ -152,6 +159,7 @@ enum Commands { #[clap(requires = "after-account", long)] after_lt: Option, }, + /// Download masterchain proof GetBlockProof { #[clap(value_parser = parse_block_id_ext)] known_block: BlockIdExt, @@ -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, @@ -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, @@ -222,6 +232,7 @@ enum Commands { start_after: Option, modified_after: Option, }, + /// Download specified libraries GetLibraries { library_list: Vec, },