use crate::{app::App, utils::HexBytes};
use anyhow::Result;
use clap::Parser;
use colored::Colorize;
use gear_core::ids::ActorId;
#[derive(Clone, Debug, Parser)]
pub struct Send {
destination: ActorId,
#[arg(short, long, default_value = "0x")]
payload: HexBytes,
#[arg(short, long)]
gas_limit: Option<u64>,
#[arg(short, long, default_value = "0")]
value: u128,
}
impl Send {
pub async fn exec(self, app: &mut App) -> Result<()> {
let api = app.signed_api().await?;
let gas_limit = if let Some(gas_limit) = self.gas_limit {
gas_limit
} else {
api.calculate_handle_gas(self.destination, &self.payload, self.value, false)
.await?
.min_limit
};
let message_id = api
.send_message_bytes(
self.destination,
self.payload.clone(),
gas_limit,
self.value,
)
.await?
.value;
println!("Successfully sent the message");
println!();
println!("{} {}", "Message ID:".bold(), message_id);
Ok(())
}
}