Skip to content

Commit

Permalink
add petition cli (#377)
Browse files Browse the repository at this point in the history
* add petition cli

* nicer proposal action printout

* adapt python parser for proposals

* fixing python parser for proposals
  • Loading branch information
brenzi authored Sep 12, 2024
1 parent aa2f373 commit 717ccec
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "encointer-client-notee"
authors = ["encointer.org <[email protected]>"]
edition = "2021"
#keep with node version. major, minor and patch
version = "1.14.2"
version = "1.14.3"

[dependencies]
# todo migrate to clap >=3 https://github.com/encointer/encointer-node/issues/107
Expand Down
2 changes: 1 addition & 1 deletion client/py_client/democracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_proposals(text):
proposal = "Proposal id:" + proposal # Add back the identifier
lines = proposal.split("\n")
id = int(re.search(r'\d+', lines[0]).group())
action = re.search(r'ProposalAction::\w+\([\w, .]+\)', lines[1]).group()
action = re.search(r'action:\s*"?([^"]+)"?', lines[1]).group()
started = datetime.strptime(re.search(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}', lines[2]).group(),
'%Y-%m-%d %H:%M:%S')
ends = datetime.strptime(re.search(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}', lines[3]).group(),
Expand Down
53 changes: 52 additions & 1 deletion client/src/commands/encointer_democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use encointer_api_client_extension::{
use encointer_node_notee_runtime::{AccountId, Balance, Hash};
use encointer_primitives::{
ceremonies::{CeremonyIndexType, CommunityCeremony, ReputationCountType},
common::{FromStr, PalletString},
communities::CommunityIdentifier,
democracy::{
Proposal, ProposalAccessPolicy, ProposalAction, ProposalIdType, ProposalState,
ReputationVec, Vote,
Expand Down Expand Up @@ -84,6 +86,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 Expand Up @@ -190,7 +223,18 @@ pub fn list_proposals(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap:
"Proposal id: {} (reputation commitment purpose id: {})",
*proposal_id, purpose_id
);
println!("🛠 action: {:?}", proposal.action);
let proposal_str = match &proposal.action {
ProposalAction::SetInactivityTimeout(timeout) =>
format!("Set inactivity timeout to {timeout}"),
ProposalAction::UpdateNominalIncome(cid, income) =>
format!("Update nominal income for {cid} to {income}"),
ProposalAction::Petition(maybecid, demand) =>
format!("Petition for {} demanding: {}", cid_or_global(maybecid), String::from_utf8_lossy(demand)),
ProposalAction::SpendNative(maybecid, to, amount) =>
format!("Spend Native from {} treasury to {to}, amount {amount}", cid_or_global(maybecid)),
_ => format!("{:?}", proposal.action),
};
println!("🛠 action: {:?}", proposal_str);
println!("▶️ started at: {}", start.format("%Y-%m-%d %H:%M:%S %Z").to_string());
println!(
"🏁 ends after: {}",
Expand Down Expand Up @@ -366,3 +410,10 @@ async fn get_relevant_electorate(
fn approval_threshold_percent(electorate: u128, turnout: u128) -> f64 {
100f64 / (1f64 + (turnout as f64 / electorate as f64).sqrt())
}

fn cid_or_global(maybecid: &Option<CommunityIdentifier>) -> String {
match maybecid {
Some(cid) => format!("{:?}", cid),
None => "global".into(),
}
}
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
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/encointer/encointer-node"
# * Align major and minor version with polkadot-sdk major.minor.
# * Bump patch version for new releases, and make it the release tag.
# * The client should follow this version.
version = "1.14.2"
version = "1.14.3"

[[bin]]
name = "encointer-node-notee"
Expand Down

0 comments on commit 717ccec

Please sign in to comment.