Skip to content

Commit

Permalink
feat(minor-ampd): add command to send tokens from verifier address (#586
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cjcobb23 authored Aug 19, 2024
1 parent 45df3df commit e66af90
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ampd/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down
41 changes: 41 additions & 0 deletions ampd/src/commands/send_tokens.rs
Original file line number Diff line number Diff line change
@@ -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<Option<String>, 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::<AccountId>()
.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
)))
}
3 changes: 2 additions & 1 deletion ampd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e66af90

Please sign in to comment.