Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ksrichard committed Nov 28, 2024
1 parent 7d1d5ef commit 1f9f34b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
11 changes: 8 additions & 3 deletions crates/cli/src/cli/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn handle(args: &DeployArgs) -> anyhow::Result<()> {
// confirmation
if !args.yes {
let confirmation = Confirm::new()
.with_prompt("❓Deploying a template costs some μXTM, are you sure to continue?")
.with_prompt("❓Deploying a template costs some μT, are you sure to continue?")
.interact()?;
if !confirmation {
return Err(anyhow!("💥 Deployment aborted!"));
Expand Down Expand Up @@ -144,14 +144,19 @@ pub async fn handle(args: &DeployArgs) -> anyhow::Result<()> {
deployer.upload_template(&template_bin).await
)?;

// check balance
deployer
.check_balance_to_deploy(deploy_params.clone(), fee_per_gram)
.await?;

if !args.yes {
let fee = deployer
.registration_fee(deploy_params.clone(), fee_per_gram)
.await?;
let confirmation = Confirm::new()
.with_prompt(format!(
"❓Deploying this template costs {} μXTM, are you sure to continue?",
fee.as_u64()
"❓Deploying this template costs {} (estimated), are you sure to continue?",
fee
))
.interact()?;
if !confirmation {
Expand Down
10 changes: 8 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use clap::Parser;
use std::process::exit;

use crate::cli::arguments::Cli;

Expand All @@ -11,6 +12,11 @@ mod project;
mod templates;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Cli::parse().handle_command().await
async fn main() {
if let Err(error) = Cli::parse().handle_command().await {
println!("❌ {error:?}");
exit(1);
}

exit(0);
}
13 changes: 8 additions & 5 deletions crates/tari_deploy/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ where
fee_per_gram: MicroMinotari,
) -> Result<TemplateAddress> {
let register_request = self
.template_registration_request(params, fee_per_gram)
.await?;
self.check_balance_to_deploy(register_request.clone())
.template_registration_request(params.clone(), fee_per_gram)
.await?;
self.check_balance_to_deploy(params, fee_per_gram).await?;
self.register_template(register_request).await
}

Expand Down Expand Up @@ -107,10 +106,14 @@ where
}

/// Check if we have enough balance or not to deploy the template.
async fn check_balance_to_deploy(
pub async fn check_balance_to_deploy(
&self,
request: CreateTemplateRegistrationRequest,
params: DeployParams,
fee_per_gram: MicroMinotari,
) -> Result<()> {
let request = self
.template_registration_request(params, fee_per_gram)
.await?;
let wallet_balance = self.wallet_balance().await?;
let fee = self.get_registration_fee(request).await?;
if fee > wallet_balance {
Expand Down
2 changes: 1 addition & 1 deletion crates/tari_deploy/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ pub enum Error {
InvalidHash(#[from] HashParseError),
#[error("Config error: {0}")]
Config(#[from] config::Error),
#[error("Insufficient balance in Tari L1 wallet! Current balance: {0} μXTM, Fee: {1} μXTM")]
#[error("Insufficient balance in Tari L1 wallet! Current balance: {0}, Estimated Fee: {1}")]
InsufficientBalance(MicroMinotari, MicroMinotari),
}
1 change: 1 addition & 0 deletions crates/tari_deploy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ mod error;
pub mod uploader;

pub use config::*;
pub use error::Error as DeployerError;

0 comments on commit 1f9f34b

Please sign in to comment.