Skip to content

Commit

Permalink
Add TLS connection
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Jul 4, 2024
1 parent a4c56f9 commit e01fd55
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
5 changes: 3 additions & 2 deletions templates/default/deploy-scripts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../"}
10 changes: 5 additions & 5 deletions templates/default/deploy-scripts/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +18,7 @@ The following options are necessary when running the script

```
--node <CONCORDIUM_NODE_URL>
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 <CONCORDIUM_ACCOUNT_PATH>
Path to the file containing the Concordium account keys exported from the wallet (e.g. ./myPath/4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export).
--module <MODULE_PATH>
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 19 additions & 3 deletions templates/default/deploy-scripts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WasmModule, Error> {
Expand All @@ -34,10 +35,10 @@ fn get_wasm_module(file: &Path) -> Result<WasmModule, Error> {
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 \
Expand All @@ -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)?;

Expand Down

0 comments on commit e01fd55

Please sign in to comment.