Skip to content

Commit

Permalink
add petition cli
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Sep 11, 2024
1 parent aa2f373 commit f28568e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions client/src/commands/encointer_democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use encointer_api_client_extension::{
use encointer_node_notee_runtime::{AccountId, Balance, Hash};
use encointer_primitives::{
ceremonies::{CeremonyIndexType, CommunityCeremony, ReputationCountType},
common::{FromStr, PalletString},
democracy::{
Proposal, ProposalAccessPolicy, ProposalAction, ProposalIdType, ProposalState,
ReputationVec, Vote,
Expand Down Expand Up @@ -84,6 +85,37 @@ pub fn submit_update_nominal_income_proposal(
.into()
}

pub fn submit_petition(_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 demand_str = matches.value_of("demand").unwrap();
let demand = PalletString::from_str(demand_str)
.expect("Petition demand too long. must be < 256 chars");
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>::Petition(maybecid, demand.clone())
)
.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: Petition for cid {maybecid:?} demanding: {demand_str}");
Ok(())
})
.into()
}
pub fn submit_spend_native_proposal(
_args: &str,
matches: &ArgMatches<'_>,
Expand Down
16 changes: 16 additions & 0 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,22 @@ fn main() {
})
.runner(commands::encointer_democracy::submit_update_nominal_income_proposal),
)
.add_cmd(
Command::new("submit-petition")
.description("Submit a petition for specified community (if --cid specified) or global")
.options(|app| {
app.setting(AppSettings::ColoredHelp)
.account_arg()
.arg(
Arg::with_name("demand")
.takes_value(true)
.required(true)
.value_name("DEMAND")
.help("what the petition demands"),
)
})
.runner(commands::encointer_democracy::submit_petition),
)
.add_cmd(
Command::new("submit-spend-native-proposal")
.description("Submit 'spend native' proposal for specified community, amount and beneficiary")
Expand Down

0 comments on commit f28568e

Please sign in to comment.