Skip to content

Commit

Permalink
Remove logging flag
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Oct 17, 2023
1 parent ae2dd29 commit 1635ef4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 66 deletions.
2 changes: 0 additions & 2 deletions templates/default/deploy-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ The following options are necessary when running the script
--module <MODULE_PATH>
Path of the Concordium smart contract module. Use this flag several times \
if you have several smart contract modules to be deployed (e.g. --module ./myPath/default.wasm.v1 --module ./default2.wasm.v1).
--no-logging <BOOL>
To specify if verbose logging should be disabled when running the script.
```

The `account` parameter should be a Concordium wallet account either exported from the
Expand Down
72 changes: 25 additions & 47 deletions templates/default/deploy-scripts/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ use concordium_rust_sdk::{
v2::{self, BlockIdentifier},
};
use std::path::Path;
use std::sync::Arc;

/// A struct containing connection and wallet information.
#[derive(Debug)]
pub struct Deployer {
/// The client to establish a connection to a Concordium node (V2 API).
pub client: v2::Client,
/// The account keys to be used for sending transactions.
pub key: WalletAccount,
pub key: Arc<WalletAccount>,
}

impl Deployer {
Expand All @@ -38,7 +39,7 @@ impl Deployer {

Ok(Deployer {
client,
key: key_data,
key: key_data.into(),
})
}

Expand Down Expand Up @@ -74,7 +75,6 @@ impl Deployer {
&mut self,
wasm_module: WasmModule,
expiry: Option<TransactionTime>,
logging: bool,
) -> Result<
(
Option<TransactionHash>,
Expand All @@ -83,21 +83,17 @@ impl Deployer {
),
DeployError,
> {
if logging {
println!("\nDeploying module....");
}
println!("\nDeploying module....");

let module_reference = wasm_module.get_module_ref();

let exists = self.module_exists(&module_reference).await?;

if exists {
if logging {
println!(
"Module with reference {} already exists on the chain.",
module_reference
);
}
println!(
"Module with reference {} already exists on the chain.",
module_reference
);
return Ok((None, None, module_reference));
}

Expand All @@ -112,7 +108,7 @@ impl Deployer {
));

let tx = deploy_module(
&self.key,
&*self.key,
self.key.address,
nonce.nonce,
expiry,
Expand All @@ -127,20 +123,16 @@ impl Deployer {
.await
.map_err(DeployError::TransactionRejected)?;

if logging {
println!("Sent tx: {tx_hash}");
}
println!("Sent tx: {tx_hash}");

let (_, block_item) = self.client.wait_until_finalized(&tx_hash).await?;

self.check_outcome_of_deploy_transaction(&block_item)?;

if logging {
println!(
"Transaction finalized: tx_hash={} module_ref={}",
tx_hash, module_reference,
);
}
println!(
"Transaction finalized: tx_hash={} module_ref={}",
tx_hash, module_reference,
);

Ok((Some(tx_hash), Some(block_item), module_reference))
}
Expand All @@ -159,11 +151,8 @@ impl Deployer {
payload: InitContractPayload,
energy: Option<Energy>,
expiry: Option<TransactionTime>,
logging: bool,
) -> Result<(TransactionHash, BlockItemSummary, ContractAddress), DeployError> {
if logging {
println!("\nInitializing contract....");
}
println!("\nInitializing contract....");

let nonce = self.get_nonce(self.key.address).await?;

Expand All @@ -178,7 +167,7 @@ impl Deployer {
));

let tx = init_contract(
&self.key,
&*self.key,
self.key.address,
nonce.nonce,
expiry,
Expand All @@ -195,20 +184,16 @@ impl Deployer {
.await
.map_err(DeployError::TransactionRejected)?;

if logging {
println!("Sent tx: {tx_hash}");
}
println!("Sent tx: {tx_hash}");

let (_, block_item) = self.client.wait_until_finalized(&tx_hash).await?;

let contract_address = self.check_outcome_of_initialization_transaction(&block_item)?;

if logging {
println!(
"Transaction finalized: tx_hash={} contract=({}, {})",
tx_hash, contract_address.index, contract_address.subindex,
);
}
println!(
"Transaction finalized: tx_hash={} contract=({}, {})",
tx_hash, contract_address.index, contract_address.subindex,
);

Ok((tx_hash, block_item, contract_address))
}
Expand All @@ -228,11 +213,8 @@ impl Deployer {
update_payload: UpdateContractPayload,
energy: Option<GivenEnergy>,
expiry: Option<TransactionTime>,
logging: bool,
) -> Result<(TransactionHash, BlockItemSummary), DeployError> {
if logging {
println!("\nUpdating contract....");
}
println!("\nUpdating contract....");

let nonce = self.get_nonce(self.key.address).await?;

Expand All @@ -251,7 +233,7 @@ impl Deployer {
let energy = energy.unwrap_or(GivenEnergy::Absolute(Energy { energy: 50000 }));

let tx = transactions::send::make_and_sign_transaction(
&self.key,
&*self.key,
self.key.address,
nonce.nonce,
expiry,
Expand All @@ -267,17 +249,13 @@ impl Deployer {
.await
.map_err(DeployError::TransactionRejected)?;

if logging {
println!("Sent tx: {tx_hash}");
}
println!("Sent tx: {tx_hash}");

let (_, block_item) = self.client.wait_until_finalized(&tx_hash).await?;

self.check_outcome_of_update_transaction(&block_item)?;

if logging {
println!("Transaction finalized: tx_hash={}", tx_hash,);
}
println!("Transaction finalized: tx_hash={}", tx_hash,);

Ok((tx_hash, block_item))
}
Expand Down
20 changes: 3 additions & 17 deletions templates/default/deploy-scripts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ struct App {
./myPath/default.wasm.v1 --module ./default2.wasm.v1)."
)]
module: Vec<PathBuf>,
#[clap(
long = "no_logging",
help = "To specify if verbose logging should be disabled when running the script."
)]
no_logging: bool,
}

/// Main function: It deploys to chain all wasm modules from the command line
Expand All @@ -125,9 +120,7 @@ async fn main() -> Result<(), DeployError> {
for contract in app.module.iter().unique() {
let wasm_module = get_wasm_module(contract.as_path())?;

let (_, _, module) = deployer
.deploy_wasm_module(wasm_module, None, !app.no_logging)
.await?;
let (_, _, module) = deployer.deploy_wasm_module(wasm_module, None).await?;

modules_deployed.push(module);
}
Expand All @@ -146,9 +139,7 @@ async fn main() -> Result<(), DeployError> {
param,
}; // Example

let (_, _, contract) = deployer
.init_contract(payload, None, None, !app.no_logging)
.await?; // Example
let (_, _, contract) = deployer.init_contract(payload, None, None).await?; // Example

// This is how you can use a type from your smart contract.
use {{crate_name}}::MyInputType; // Example
Expand All @@ -172,12 +163,7 @@ async fn main() -> Result<(), DeployError> {
energy.energy += 100; // Example

let _update_contract = deployer
.update_contract(
update_payload,
Some(GivenEnergy::Add(energy)),
None,
!app.no_logging,
)
.update_contract(update_payload, Some(GivenEnergy::Add(energy)), None)
.await?; // Example

// Write your own deployment/initialization script above. An example is given
Expand Down

0 comments on commit 1635ef4

Please sign in to comment.