diff --git a/ampd/src/commands/mod.rs b/ampd/src/commands/mod.rs index 5f4d091d2..15d6f80be 100644 --- a/ampd/src/commands/mod.rs +++ b/ampd/src/commands/mod.rs @@ -20,6 +20,7 @@ pub mod daemon; pub mod deregister_chain_support; pub mod register_chain_support; pub mod register_public_key; +pub mod send_tokens; pub mod verifier_address; #[derive(Debug, Subcommand, Valuable)] @@ -36,6 +37,8 @@ pub enum SubCommand { RegisterPublicKey(register_public_key::Args), /// Query the verifier address VerifierAddress, + /// Send tokens from the verifier account to a specified address + SendTokens(send_tokens::Args), } #[derive(Debug, Deserialize, Serialize, PartialEq)] diff --git a/ampd/src/commands/send_tokens.rs b/ampd/src/commands/send_tokens.rs new file mode 100644 index 000000000..c89fa6ddb --- /dev/null +++ b/ampd/src/commands/send_tokens.rs @@ -0,0 +1,41 @@ +use axelar_wasm_std::nonempty; +use cosmrs::bank::MsgSend; +use cosmrs::tx::Msg; +use cosmrs::{AccountId, Coin}; +use error_stack::Result; +use report::ResultCompatExt; +use valuable::Valuable; + +use crate::commands::{broadcast_tx, verifier_pub_key}; +use crate::config::Config; +use crate::{Error, PREFIX}; + +#[derive(clap::Args, Debug, Valuable)] +pub struct Args { + pub to_address: nonempty::String, + pub amount: u128, + pub denom: nonempty::String, +} + +pub async fn run(config: Config, args: Args) -> Result, Error> { + let coin = Coin::new(args.amount, args.denom.as_str()).change_context(Error::InvalidInput)?; + let pub_key = verifier_pub_key(config.tofnd_config.clone()).await?; + + let tx = MsgSend { + to_address: args + .to_address + .parse::() + .change_context(Error::InvalidInput)?, + from_address: pub_key.account_id(PREFIX).change_context(Error::Tofnd)?, + amount: vec![coin], + } + .into_any() + .expect("failed to serialize proto message"); + + let tx_hash = broadcast_tx(config, tx, pub_key).await?.txhash; + + Ok(Some(format!( + "successfully broadcast send transaction, tx hash: {}", + tx_hash + ))) +} diff --git a/ampd/src/main.rs b/ampd/src/main.rs index d5881bfb5..916beed6e 100644 --- a/ampd/src/main.rs +++ b/ampd/src/main.rs @@ -6,7 +6,7 @@ use std::process::ExitCode; use ::config::{Config as cfg, Environment, File, FileFormat, FileSourceFile}; use ampd::commands::{ bond_verifier, daemon, deregister_chain_support, register_chain_support, register_public_key, - verifier_address, SubCommand, + send_tokens, verifier_address, SubCommand, }; use ampd::config::Config; use ampd::Error; @@ -64,6 +64,7 @@ async fn main() -> ExitCode { } Some(SubCommand::RegisterPublicKey(args)) => register_public_key::run(cfg, args).await, Some(SubCommand::VerifierAddress) => verifier_address::run(cfg.tofnd_config).await, + Some(SubCommand::SendTokens(args)) => send_tokens::run(cfg, args).await, }; match result {