Skip to content

Commit

Permalink
Merge pull request #881 from tonlabs/SilkovAlexander/fix_alternativ_p…
Browse files Browse the repository at this point in the history
…arams

Fixed alternative syntax and added test
  • Loading branch information
SilkovAlexander committed Oct 10, 2022
2 parents f5c373d + 8f01f1f commit 956ec27
Show file tree
Hide file tree
Showing 25 changed files with 1,478 additions and 166 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ license = 'Apache-2.0'
name = 'tonos-cli'
readme = 'README.md'
repository = 'https://github.com/tonlabs/tonos-cli'
version = '0.28.17'
version = '0.28.18'

[dependencies]
async-trait = '0.1.42'
Expand Down
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ complete -C __tonos-cli_completion tonos-cli
```

After adding completion script, user can use `<Tab>` key to complete `--addr` option with aliases saved in the config
file and `-m/--method` option with methods loaded from the abi file.
file and `-m/--method` option with methods loaded from the ABI file.

### Windows debug build troubleshooting

Expand Down Expand Up @@ -355,7 +355,7 @@ List of available options:
--project_id <PROJECT_ID> Project Id in Evercloud (dashboard.evercloud.dev).
--pubkey <PUBKEY> User public key. Used by DeBot Browser.
--retries <RETRIES> Number of attempts to call smart contract function if previous attempt was unsuccessful.
--timeout <TIMEOUT> Network `wait_for` timeout in ms.
--timeout <TIMEOUT> Network `wait_for` timeout in ms. This value is also used as timeout for remote files (specified with link, e.g. ABI file) loading.
--url <URL> Url to connect.
--wallet <WALLET> Multisig wallet address.
--wc <WC> Workchain id.
Expand Down Expand Up @@ -741,6 +741,80 @@ Config: /home/user/TONLabs/tonos-cli/tonos-cli.conf.json
{}
```
## 2.10. Enabling verbose mode for SDK execution
User can increase log level of the tool execution to see more messages. To do it one need to specify environment
variable `RUST_LOG=debug`:
```bash
$ tonos-cli callx --addr 0:75186644bf5157d1b638390889ec2ba297a12250f6e90d935618918cb82d12c3 --abi ../samples/1_Accumulator.abi.json --keys keys/key0 -m add --value 1
Input arguments:
address: 0:75186644bf5157d1b638390889ec2ba297a12250f6e90d935618918cb82d12c3
method: add
params: {"value":"1"}
abi: ../samples/1_Accumulator.abi.json
keys: keys/key0
Connecting to:
Url: net.evercloud.dev
Endpoints: ["https://devnet.evercloud.dev/b2ad82504ee54fccb5bc6db8cbb3df1e"]
MessageId: b3e24321924526dbfdc8ffdd9cc94aeb2da80edca7d87bd7f16f4a0a2afbfa20
Succeeded.
Result: {}
# Enable verbose mode
$ export RUST_LOG=debug
$ tonos-cli callx --addr 0:75186644bf5157d1b638390889ec2ba297a12250f6e90d935618918cb82d12c3 --abi ../samples/1_Accumulator.abi.json --keys keys/key0 -m add --value 1
Input arguments:
address: 0:75186644bf5157d1b638390889ec2ba297a12250f6e90d935618918cb82d12c3
method: add
params: {"value":"1"}
abi: ../samples/1_Accumulator.abi.json
keys: keys/key0
Connecting to:
Url: net.evercloud.dev
Endpoints: ["https://devnet.evercloud.dev/b2ad82504ee54fccb5bc6db8cbb3df1e"]
starting new connection: https://devnet.evercloud.dev/
Last block "76657141a65727996dadf9b929d40887cc3c78df09a97b9daecabd8b3e01327a"
MessageId: 64c98e8fbf5aa9ccf9d6526c6275bc617f6eb6f747b616f82e85cda7403c165b
message_expiration_time 1664983987
fetch_block_timeout 88688
1664983931: block received {
"id": "b3ab65d5b8503dedfa1250d72b7d8247e802551dfedabb80b82454abb6e755ce",
"gen_utime": 1664983924,
"after_split": false,
"workchain_id": 0,
"shard": "7800000000000000",
"in_msg_descr": []
}
fetch_block_timeout 85461
1664983933: block received {
"id": "8dc7cc2c4ab9be6b4ac0e9d3bcd6aac3179825683f4c8df02f76e9929a649ffc",
"gen_utime": 1664983926,
"after_split": false,
"workchain_id": 0,
"shard": "7800000000000000",
"in_msg_descr": []
}
fetch_block_timeout 83209
1664983936: block received {
"id": "b6977305cf28b86a0547a7fd34c03ad0534a94fb5453c3639e5f28e18a0c5d6b",
"gen_utime": 1664983929,
"after_split": false,
"workchain_id": 0,
"shard": "7800000000000000",
"in_msg_descr": [
{
"msg_id": "64c98e8fbf5aa9ccf9d6526c6275bc617f6eb6f747b616f82e85cda7403c165b",
"transaction_id": "796ebf67fab053ea88bdf9a971d088fc6dbcb47b106f420c740815246f28c8b7"
}
]
}
Succeeded.
Result: {}
```
# 3. Cryptographic commands
Expand Down
46 changes: 20 additions & 26 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* See the License for the specific TON DEV software governing permissions and
* limitations under the License.
*/
use std::sync::Arc;
use crate::helpers::{check_dir, create_client_verbose, json_account, print_account, query_account_field};
use crate::config::Config;
use serde_json::{json, Value};
Expand Down Expand Up @@ -302,17 +303,6 @@ pub async fn dump_accounts(config: &Config, addresses: Vec<String>, path: Option
Ok(())
}

lazy_static::lazy_static! {
static ref TX: tokio::sync::Mutex<Option<tokio::sync::mpsc::Sender<Result<(), String>>>> =
tokio::sync::Mutex::new(None);
}

async fn terminate(res: Result<(), String>) {
let lock = TX.lock().await;
let tx = lock.as_ref().unwrap().clone();
tx.send(res).await.unwrap();
}

fn extract_last_trans_lt(v: &serde_json::Value) -> Option<&str> {
v.as_object()?["last_trans_lt"].as_str()
}
Expand Down Expand Up @@ -340,22 +330,26 @@ pub async fn wait_for_change(config: &Config, account_address: &str, wait_secs:
.ok_or_else(|| format!("Failed to parse query result: {}", query.result[0]))?;

let (s, mut r) = tokio::sync::mpsc::channel(1);
*TX.lock().await = Some(s);
let s = Arc::new(s);

let callback = |result: Result<ResultOfSubscription, ClientError>| async {
let res = match result {
Ok(res) => {
if extract_last_trans_lt(&res.result).is_some() {
Ok(())
} else {
Err(format!("Can't parse the result: {}", res.result))
let ss = s.clone();
let callback = move |result: Result<ResultOfSubscription, ClientError>| {
let s = ss.clone();
async move {
let res = match result {
Ok(res) => {
if extract_last_trans_lt(&res.result).is_some() {
Ok(())
} else {
Err(format!("Can't parse the result: {}", res.result))
}
}
}
Err(e) => {
Err(format!("Client error: {}", e))
}
};
terminate(res).await
Err(e) => {
Err(format!("Client error: {}", e))
}
};
s.send(res).await.unwrap()
}
};

let subscription = ton_client::net::subscribe_collection(
Expand All @@ -378,7 +372,7 @@ pub async fn wait_for_change(config: &Config, account_address: &str, wait_secs:

tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(wait_secs)).await;
terminate(Err("Timeout".to_owned())).await
s.send(Err("Timeout".to_owned())).await.unwrap()
});

let res = r.recv().await.ok_or_else(|| "Sender has dropped".to_owned())?;
Expand Down
14 changes: 7 additions & 7 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ fn parse_integer_param(value: &str) -> Result<String, String> {
}
}

async fn build_json_from_params(params_vec: Vec<&str>, abi_path: &str, method: &str) -> Result<String, String> {
let abi_obj = load_ton_abi(abi_path).await?;
async fn build_json_from_params(params_vec: Vec<&str>, abi_path: &str, method: &str, config: &Config) -> Result<String, String> {
let abi_obj = load_ton_abi(abi_path, config).await?;
let functions = abi_obj.functions();

let func_obj = functions.get(method).ok_or("failed to load function from abi")?;
Expand All @@ -78,7 +78,7 @@ async fn build_json_from_params(params_vec: Vec<&str>, abi_path: &str, method: &
let mut params_json = json!({ });
for input in inputs {
let mut iter = params_vec.iter();
let _param = iter.find(|x| x.trim_start_matches('-') == input.name)
let _param = iter.find(|x| x.starts_with('-') && (x.trim_start_matches('-') == input.name))
.ok_or(format!(r#"argument "{}" of type "{}" not found"#, input.name, input.kind))?;

let value = iter.next()
Expand Down Expand Up @@ -282,7 +282,7 @@ pub async fn call_contract_with_client(
is_fee: bool,
matches: Option<&ArgMatches<'_>>,
) -> Result<Value, String> {
let abi = load_abi(abi_path).await?;
let abi = load_abi(abi_path, config).await?;

let msg_params = prepare_message_params(
addr,
Expand Down Expand Up @@ -400,7 +400,7 @@ pub async fn call_contract(

pub async fn call_contract_with_msg(config: &Config, str_msg: String, abi_path: &str) -> Result<(), String> {
let ton = create_client_verbose(&config)?;
let abi = load_abi(abi_path).await?;
let abi = load_abi(abi_path, config).await?;

let (msg, _) = unpack_message(&str_msg)?;
if config.is_json {
Expand Down Expand Up @@ -431,11 +431,11 @@ pub async fn call_contract_with_msg(config: &Config, str_msg: String, abi_path:
Ok(())
}

pub async fn parse_params(params_vec: Vec<&str>, abi_path: &str, method: &str) -> Result<String, String> {
pub async fn parse_params(params_vec: Vec<&str>, abi_path: &str, method: &str, config: &Config) -> Result<String, String> {
if params_vec.len() == 1 {
// if there is only 1 parameter it must be a json string with arguments
Ok(params_vec[0].to_owned())
} else {
build_json_from_params(params_vec, abi_path, method).await
build_json_from_params(params_vec, abi_path, method, config).await
}
}
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::helpers::default_config_name;

const TESTNET: &str = "net.evercloud.dev";
const MAINNET: &str = "main.evercloud.dev";
const LOCALNET: &str = "http://127.0.0.1/";
pub const LOCALNET: &str = "http://127.0.0.1/";

fn default_url() -> String {
TESTNET.to_string()
Expand Down
3 changes: 2 additions & 1 deletion src/debot/term_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl TerminalBrowser {
let info: DebotInfo = dengine.init().await?.into();
let abi_version = info.dabi_version.clone();
let abi_ref = info.dabi.as_ref();
let abi = load_abi(abi_ref.ok_or("DeBot ABI is not defined".to_string())?).await?;
let def_config = Config::default();
let abi = load_abi(abi_ref.ok_or("DeBot ABI is not defined".to_string())?, &def_config).await?;
if !autorun {
Self::print_info(&info);
}
Expand Down
Loading

0 comments on commit 956ec27

Please sign in to comment.