Skip to content

Commit

Permalink
Merge pull request #874 from tonlabs/SilkovAlexander/abi_with_data_or…
Browse files Browse the repository at this point in the history
…_link

Pass abi with data or link
  • Loading branch information
SilkovAlexander authored Oct 3, 2022
2 parents 21839a3 + 0377e35 commit 447ea2a
Show file tree
Hide file tree
Showing 23 changed files with 606 additions and 284 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ tests/PipechainTest1.chain
*.txns
*.log
*.boc
!tests/samples/SafeMultisigWallet_msg.boc
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## Version: 0.28.12

### New
- Added ability to specify link to the abi file of json data instead of path.


## Version: 0.28.3

### Breaking changes:
Expand Down
42 changes: 21 additions & 21 deletions Cargo.lock

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

3 changes: 2 additions & 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.12'
version = '0.28.13'

[dependencies]
async-trait = '0.1.42'
Expand All @@ -43,6 +43,7 @@ tokio-retry = '0.3'
log = { features = [ 'std' ], version = '0.4.11' }
serde = { features = [ 'derive' ], version = '1.0' }
tokio = { default-features = false, features = [ 'full' ], version = '1' }
url = '2.3.1'
ton_abi = { git = 'https://github.com/tonlabs/ton-labs-abi.git', tag = '2.3.7' }
ton_block = { git = 'https://github.com/tonlabs/ton-labs-block.git', tag = '1.8.3' }
ton_client = { git = 'https://github.com/tonlabs/TON-SDK.git', tag = '1.37.2' }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ subcommand.
List of available options:

```bash
--abi <ABI> Path to the contract ABI file.
--abi <ABI> Path or link to the contract ABI file or pure json ABI data.
--access_key <ACCESS_KEY> Project secret or JWT in Evercloud (dashboard.evercloud.dev).
--addr <ADDR> Contract address.
--async_call <ASYNC_CALL> Disables wait for transaction to appear in the network after call command.
Expand Down Expand Up @@ -932,7 +932,7 @@ or
`--wc <int8>` ID of the workchain the wallet will be deployed to (`-1` for masterchain, `0` for basechain). By default, this value is set to 0.
`--abi <contract.abi.json>` - contract interface file.
`--abi <contract.abi.json>` - Path or link to the contract ABI file or pure json ABI data. Can be specified in the config file.
`--alias <alias>` - allows to save contract parameters (address, abi, keys) to use them easier with `callx` or `runx` commands.
Expand Down
54 changes: 23 additions & 31 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
*/
use crate::config::Config;
use crate::convert;
use crate::helpers::{
TonClient, now_ms, create_client_verbose, load_abi,
query_account_field, SDK_EXECUTION_ERROR_CODE, create_client
};
use ton_abi::{Contract, ParamType};

use ton_client::abi::{
encode_message,
decode_message,
ParamsOfDecodeMessage,
ParamsOfEncodeMessage,
Abi,
};
use crate::helpers::{TonClient, now_ms, create_client_verbose, load_abi, query_account_field, SDK_EXECUTION_ERROR_CODE, create_client, load_ton_abi};

use ton_client::abi::{encode_message, decode_message, ParamsOfDecodeMessage, ParamsOfEncodeMessage,
Abi};
use ton_client::processing::{
ParamsOfSendMessage,
ParamsOfWaitForTransaction,
Expand All @@ -42,6 +33,7 @@ use ton_block::{Account, Serializable, Deserializable, Message};
use std::str::FromStr;
use clap::ArgMatches;
use serde_json::{Value};
use ton_abi::ParamType;
use ton_client::error::ClientError;
use crate::debug::{execute_debug, DebugLogger};
use crate::message::{EncodedMessage, prepare_message_params, print_encoded_message, unpack_message};
Expand Down Expand Up @@ -76,8 +68,8 @@ fn parse_integer_param(value: &str) -> Result<String, String> {
}
}

fn build_json_from_params(params_vec: Vec<&str>, abi: &str, method: &str) -> Result<String, String> {
let abi_obj = Contract::load(abi.as_bytes()).map_err(|e| format!("failed to parse ABI: {}", e))?;
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?;
let functions = abi_obj.functions();

let func_obj = functions.get(method).ok_or("failed to load function from abi")?;
Expand Down Expand Up @@ -182,7 +174,7 @@ pub async fn send_message_and_wait(
abi: Option<Abi>,
msg: String,
config: &Config,
) -> Result<serde_json::Value, String> {
) -> Result<Value, String> {

if !config.is_json {
println!("Processing... ");
Expand Down Expand Up @@ -225,7 +217,7 @@ pub async fn process_message(
ton: TonClient,
msg: ParamsOfEncodeMessage,
config: &Config,
) -> Result<serde_json::Value, ClientError> {
) -> Result<Value, ClientError> {
let callback = |event| { async move {
if let ProcessingEvent::DidSend { shard_block_id: _, message_id, message: _ } = event {
println!("MessageId: {}", message_id)
Expand Down Expand Up @@ -259,13 +251,13 @@ pub async fn process_message(
pub async fn call_contract_with_result(
config: &Config,
addr: &str,
abi: String,
abi_path: &str,
method: &str,
params: &str,
keys: Option<String>,
is_fee: bool,
matches: Option<&ArgMatches<'_>>,
) -> Result<serde_json::Value, String> {
) -> Result<Value, String> {
let ton = if config.debug_fail != "None".to_string() {
let log_path = format!("call_{}_{}.log", addr, method);
log::set_max_level(log::LevelFilter::Trace);
Expand All @@ -276,21 +268,21 @@ pub async fn call_contract_with_result(
} else {
create_client_verbose(config)?
};
call_contract_with_client(ton, config, addr, abi, method, params, keys, is_fee, matches).await
call_contract_with_client(ton, config, addr, abi_path, method, params, keys, is_fee, matches).await
}

pub async fn call_contract_with_client(
ton: TonClient,
config: &Config,
addr: &str,
abi_string: String,
abi_path: &str,
method: &str,
params: &str,
keys: Option<String>,
is_fee: bool,
matches: Option<&ArgMatches<'_>>,
) -> Result<serde_json::Value, String> {
let abi = load_abi(&abi_string)?;
) -> Result<Value, String> {
let abi = load_abi(abi_path).await?;

let msg_params = prepare_message_params(
addr,
Expand Down Expand Up @@ -350,8 +342,8 @@ pub async fn call_contract_with_client(
&& res.clone().err().unwrap().code == SDK_EXECUTION_ERROR_CODE {
if config.is_json {
let e = format!("{:#}", res.clone().err().unwrap());
let err: serde_json::Value = serde_json::from_str(&e)
.unwrap_or(serde_json::Value::String(e));
let err: Value = serde_json::from_str(&e)
.unwrap_or(Value::String(e));
let res = json!({"Error": err});
println!("{}", serde_json::to_string_pretty(&res)
.unwrap_or("{{ \"JSON serialization error\" }}".to_string()));
Expand Down Expand Up @@ -390,14 +382,14 @@ pub fn print_json_result(result: Value, config: &Config) -> Result<(), String> {
pub async fn call_contract(
config: &Config,
addr: &str,
abi: String,
abi_path: &str,
method: &str,
params: &str,
keys: Option<String>,
is_fee: bool,
matches: Option<&ArgMatches<'_>>,
) -> Result<(), String> {
let result = call_contract_with_result(config, addr, abi, method, params, keys, is_fee, matches).await?;
let result = call_contract_with_result(config, addr, abi_path, method, params, keys, is_fee, matches).await?;
if !config.is_json {
println!("Succeeded.");
}
Expand All @@ -406,9 +398,9 @@ pub async fn call_contract(
}


pub async fn call_contract_with_msg(config: &Config, str_msg: String, abi: String) -> Result<(), String> {
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)?;
let abi = load_abi(abi_path).await?;

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

pub fn parse_params(params_vec: Vec<&str>, abi: &str, method: &str) -> Result<String, String> {
pub async fn parse_params(params_vec: Vec<&str>, abi_path: &str, method: &str) -> 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, method)
build_json_from_params(params_vec, abi_path, method).await
}
}
12 changes: 7 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,11 @@ impl FullConfig {

pub fn clear_config(
full_config: &mut FullConfig,
matches: &ArgMatches
matches: &ArgMatches,
is_json: bool,
) -> Result<(), String> {
let mut config = &mut full_config.config;
let is_json = config.is_json;
let is_json = config.is_json || is_json;
if matches.is_present("URL") {
let url = default_url();
config.endpoints = FullConfig::default_map()[&url].clone();
Expand Down Expand Up @@ -464,7 +465,8 @@ pub fn clear_config(

pub fn set_config(
full_config: &mut FullConfig,
matches: &ArgMatches
matches: &ArgMatches,
is_json: bool,
) -> Result<(), String> {
let mut config= &mut full_config.config;
if let Some(s) = matches.value_of("URL") {
Expand Down Expand Up @@ -569,13 +571,13 @@ pub fn set_config(
}
if let Some(s) = matches.value_of("ACCESS_KEY") {
config.access_key = Some(s.to_string());
if config.project_id.is_none() && !config.is_json {
if config.project_id.is_none() && !(config.is_json || is_json) {
println!("Warning: You have access_key set without project_id. It has no sense in case of authentication.");
}
}

full_config.to_file(&full_config.path)?;
if !full_config.config.is_json {
if !(full_config.config.is_json || is_json) {
println!("Succeeded.");
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/debot/term_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ 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())?)?;
let abi = load_abi(abi_ref.ok_or("DeBot ABI is not defined".to_string())?).await?;
if !autorun {
Self::print_info(&info);
}
Expand Down
Loading

0 comments on commit 447ea2a

Please sign in to comment.