kon-cli/src/cmd/tx/send.rs

41 lines
1.0 KiB
Rust

use clap::Args;
use pallas_addresses::Address;
use tokio::runtime::Runtime;
use crate::{
cardano::cardano::Cardano,
env::get_env,
tx::{
context::TxContext,
from_env,
send::{self, send},
},
};
#[derive(Debug, Args)]
pub struct Params {
/// `<who>:<amount>` It can be used multiple times
#[arg(long)]
to: Vec<String>,
}
pub fn handle(params: Params) {
let outputs = params
.to
.iter()
.map(|x| parse_to(x))
.collect::<Vec<(Address, u64)>>();
let env = get_env();
let tx_ctx = from_env(&env);
let rt = Runtime::new().expect("Failed to create Tokio runtime");
let tx = rt.block_on(async { send(tx_ctx, vec![]).await });
println!("{:?}", tx);
}
pub fn parse_to(to: &str) -> (Address, u64) {
let (a, b) = to.split_once(":").expect("Expect `<who>:<amount>`");
let addr = Address::from_bech32(a).expect("Cannot parse address");
let amount = b.parse::<u64>().expect("Cannot parse amount");
(addr, amount)
}