Skip to content

Commit

Permalink
tested successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Sep 10, 2024
1 parent a173c85 commit 48f0bc1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
43 changes: 42 additions & 1 deletion client/src/commands/encointer_democracy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::cli_args::EncointerArgsExtractor;

use crate::utils::{ensure_payment, get_chain_api, keys::get_pair_from_str};
use crate::utils::{
ensure_payment, get_chain_api,
keys::{get_accountid_from_str, get_pair_from_str},
};
use chrono::{prelude::*, Utc};
use clap::ArgMatches;
use encointer_api_client_extension::{
Expand Down Expand Up @@ -81,6 +84,44 @@ pub fn submit_update_nominal_income_proposal(
.into()
}

pub fn submit_spend_native_proposal(
_args: &str,
matches: &ArgMatches<'_>,
) -> Result<(), clap::Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let who = matches.account_arg().map(get_pair_from_str).unwrap();
let mut api = get_chain_api(matches).await;
api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(who.clone())));
let maybecid = if let Some(cid) = matches.cid_arg() {
Some(api.verify_cid(cid, None).await)
} else {
None
};
let arg_to = matches.value_of("to").unwrap();
let to = get_accountid_from_str(arg_to);
let amount = matches
.value_of("amount")
.unwrap()
.parse::<u128>()
.expect("amount can be converted to u128");
let tx_payment_cid_arg = matches.tx_payment_cid_arg();
set_api_extrisic_params_builder(&mut api, tx_payment_cid_arg).await;

let xt: EncointerXt<_> = compose_extrinsic!(
api,
"EncointerDemocracy",
"submit_proposal",
ProposalAction::<AccountId, Balance>::SpendNative(maybecid, to.clone(), amount)
)
.unwrap();
ensure_payment(&api, &xt.encode().into(), tx_payment_cid_arg).await;
let _result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock).await;
println!("Proposal Submitted: Spend Native for cid {maybecid:?} to {to}, amount {amount}");
Ok(())
})
.into()
}
pub fn list_proposals(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap::Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
Expand Down
23 changes: 23 additions & 0 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,29 @@ fn main() {
})
.runner(commands::encointer_democracy::submit_update_nominal_income_proposal),
)
.add_cmd(
Command::new("submit-spend-native-proposal")
.description("Submit 'spend native' proposal for specified community, amount and beneficiary")
.options(|app| {
app.setting(AppSettings::ColoredHelp)
.account_arg()
.arg(
Arg::with_name("to")
.takes_value(true)
.required(true)
.value_name("SS58")
.help("beneficiary's AccountId in ss58check format"),
)
.arg(
Arg::with_name("amount")
.takes_value(true)
.required(true)
.value_name("U128")
.help("amount to be transferred"),
)
})
.runner(commands::encointer_democracy::submit_spend_native_proposal),
)
.add_cmd(
Command::new("list-proposals")
.description("list all proposals.")
Expand Down

0 comments on commit 48f0bc1

Please sign in to comment.