diff --git a/templates/default/deploy-scripts/Cargo.toml b/templates/default/deploy-scripts/Cargo.toml index c8df1a78..5c593d80 100644 --- a/templates/default/deploy-scripts/Cargo.toml +++ b/templates/default/deploy-scripts/Cargo.toml @@ -8,7 +8,8 @@ version = "1.0.0" [dependencies] anyhow = "1.0" chrono = "0.4.26" -tokio = {version = "1.18", features = ["rt", "macros", "rt-multi-thread"] } clap = { version = "4", features = ["derive", "env"]} -concordium-rust-sdk="3" +concordium-rust-sdk="4.2" +tokio = {version = "1.18", features = ["rt", "macros", "rt-multi-thread"] } +tonic = {version = "0.10", features = ["tls", "tls-roots"]} # Use system trust roots. {{crate_name}} = {path = "../"} diff --git a/templates/default/deploy-scripts/README.md b/templates/default/deploy-scripts/README.md index cc044dfe..63041357 100644 --- a/templates/default/deploy-scripts/README.md +++ b/templates/default/deploy-scripts/README.md @@ -1,10 +1,10 @@ # Deploy, Initialize, and Update Script Template -This project has boilerplate code to write deployment, initialization, and update scripts for Concordium smart contract protocols. +This project has boilerplate code to write deployment, initialization, and update scripts for Concordium smart contract protocols. # Purpose -Automatic scripts are useful to speed up the development and testing of your protocol on the chain. +Automatic scripts are useful to speed up the development and testing of your protocol on the chain. In addition, scripts help to set up identical protocols on different chains easily. E.g. you can deploy your protocol to testnet or mainnet by just specifying a corresponding node connection and account keys for the respective network when running the script. # Running The Script @@ -18,7 +18,7 @@ The following options are necessary when running the script ``` --node - V2 API of the concordium node. [default: http://node.testnet.concordium.com:20000] + V2 API of the concordium node. [default: https://grpc.testnet.concordium.com:20000] --account Path to the file containing the Concordium account keys exported from the wallet (e.g. ./myPath/4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export). --module @@ -32,7 +32,7 @@ genesis tool. Example: ``` -cargo run -- --node http://node.testnet.concordium.com:20000 --account ./myPath/4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export --module ./myPath/default.wasm.v1 --module ./default2.wasm.v1 +cargo run -- --node https://grpc.testnet.concordium.com:20000 --account ./myPath/4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export --module ./myPath/default.wasm.v1 --module ./default2.wasm.v1 ``` # Functionalities @@ -68,7 +68,7 @@ cargo concordium build --out ./deploy-scripts/default.wasm.v1 Navigate into the deploy-scripts folder and run the example with the `default` smart contract (replace your wallet account in the below command): ``` -cargo run -- --node http://node.testnet.concordium.com:20000 --account ./4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export --module ./default.wasm.v1 +cargo run -- --node https://grpc.testnet.concordium.com:20000 --account ./4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export --module ./default.wasm.v1 ``` The output should be: diff --git a/templates/default/deploy-scripts/src/main.rs b/templates/default/deploy-scripts/src/main.rs index 7b06af19..094b3006 100644 --- a/templates/default/deploy-scripts/src/main.rs +++ b/templates/default/deploy-scripts/src/main.rs @@ -19,6 +19,7 @@ use std::{ io::Cursor, path::{Path, PathBuf}, }; +use tonic::transport::ClientTlsConfig; /// Reads the wasm module from a given file path. fn get_wasm_module(file: &Path) -> Result { @@ -34,10 +35,10 @@ fn get_wasm_module(file: &Path) -> Result { struct App { #[clap( long = "node", - default_value = "http://node.testnet.concordium.com:20000", + default_value = "https://grpc.testnet.concordium.com:20000", help = "V2 API of the Concordium node." )] - url: v2::Endpoint, + endpoint: tonic::transport::Endpoint, #[clap( long = "account", help = "Path to the file containing the Concordium account keys exported from the wallet \ @@ -61,7 +62,22 @@ struct App { async fn main() -> Result<(), Error> { let app: App = App::parse(); - let concordium_client = v2::Client::new(app.url).await?; + let endpoint = if app + .endpoint + .uri() + .scheme() + .map_or(false, |x| *x == concordium_rust_sdk::v2::Scheme::HTTPS) + { + app.endpoint + .tls_config(ClientTlsConfig::new()) + .context("Unable to construct a TLS connection for the Concordium API.")? + } else { + app.endpoint + }; + + let concordium_client = v2::Client::new(endpoint) + .await + .context("Unable to establish connection to the node.")?; let mut deployer = Deployer::new(concordium_client, &app.key_file)?;