Skip to content

Commit

Permalink
Merge pull request #1 from tonlabs/nikitam/deploy-wc
Browse files Browse the repository at this point in the history
Add workchain id to deploy subcommand
  • Loading branch information
ar-tmp committed May 2, 2020
2 parents 813cadb + f8a226b commit 21bad68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::config::Config;
use crate::helpers::read_keys;
use ton_client_rs::TonClient;

pub fn deploy_contract(conf: Config, tvc: &str, abi: &str, params: &str, keys_file: &str) -> Result<(), String> {
pub fn deploy_contract(conf: Config, tvc: &str, abi: &str, params: &str, keys_file: &str, wc: i32) -> Result<(), String> {
let ton = TonClient::new_with_base_url(&conf.url)
.map_err(|e| format!("failed to create tonclient: {}", e.to_string()))?;

Expand All @@ -28,7 +28,7 @@ pub fn deploy_contract(conf: Config, tvc: &str, abi: &str, params: &str, keys_fi
.map_err(|e| format!("failed to read smart contract file: {}", e.to_string()))?;

println!("Deploying...");
let result = ton.contracts.deploy(&abi, &contract, None, params.into(), None, &keys, 0)
let result = ton.contracts.deploy(&abi, &contract, None, params.into(), None, &keys, wc)
.map_err(|e| format!("deploy failed: {}", e.to_string()))?;

println!("Transaction succeded.");
Expand Down
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ fn main_internal() -> Result <(), String> {
)
(@subcommand deploy =>
(@setting AllowNegativeNumbers)
(@setting AllowLeadingHyphen)
(about: "Deploy smart contract to blockchain.")
(version: "0.1")
(author: "TONLabs")
(@arg TVC: +required +takes_value "Compiled smart contract (tvc file)")
(@arg PARAMS: +required +takes_value "Constructor arguments.")
(@arg ABI: --abi +takes_value "Json file with contract ABI.")
(@arg SIGN: --sign +takes_value "Keypair used to sign 'constructor message'.")
(@arg WC: --wc +takes_value "Workchain id of the smart contract (default 0).")
(@arg VERBOSE: -v --verbose "Prints additional information about command execution.")
)
(@subcommand call =>
Expand Down Expand Up @@ -344,6 +346,7 @@ fn call_command(matches: &ArgMatches, config: Config, call: CallType) -> Result<
fn deploy_command(matches: &ArgMatches, config: Config) -> Result<(), String> {
let tvc = matches.value_of("TVC");
let params = matches.value_of("PARAMS");
let wc = matches.value_of("WC");
let abi = Some(
matches.value_of("ABI")
.map(|s| s.to_string())
Expand All @@ -356,8 +359,13 @@ fn deploy_command(matches: &ArgMatches, config: Config) -> Result<(), String> {
.or(config.keys_path.clone())
.ok_or("keypair file not defined. Supply it in config file or command line.".to_string())?
);
print_args!(matches, tvc, params, abi, keys);
deploy_contract(config, tvc.unwrap(), &abi.unwrap(), params.unwrap(), &keys.unwrap())
print_args!(matches, tvc, params, abi, keys, wc);

let wc = wc.map(|v| i32::from_str_radix(v, 10))
.transpose()
.map_err(|e| format!("failed to parse workchain id: {}", e))?
.unwrap_or(0);
deploy_contract(config, tvc.unwrap(), &abi.unwrap(), params.unwrap(), &keys.unwrap(), wc)
}

fn config_command(matches: &ArgMatches, config: Config) -> Result<(), String> {
Expand Down

0 comments on commit 21bad68

Please sign in to comment.