Skip to content

Commit 717ccec

Browse files
authored
add petition cli (#377)
* add petition cli * nicer proposal action printout * adapt python parser for proposals * fixing python parser for proposals
1 parent aa2f373 commit 717ccec

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "encointer-client-notee"
33
authors = ["encointer.org <alain@encointer.org>"]
44
edition = "2021"
55
#keep with node version. major, minor and patch
6-
version = "1.14.2"
6+
version = "1.14.3"
77

88
[dependencies]
99
# todo migrate to clap >=3 https://github.com/encointer/encointer-node/issues/107

client/py_client/democracy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def parse_proposals(text):
2323
proposal = "Proposal id:" + proposal # Add back the identifier
2424
lines = proposal.split("\n")
2525
id = int(re.search(r'\d+', lines[0]).group())
26-
action = re.search(r'ProposalAction::\w+\([\w, .]+\)', lines[1]).group()
26+
action = re.search(r'action:\s*"?([^"]+)"?', lines[1]).group()
2727
started = datetime.strptime(re.search(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}', lines[2]).group(),
2828
'%Y-%m-%d %H:%M:%S')
2929
ends = datetime.strptime(re.search(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}', lines[3]).group(),

client/src/commands/encointer_democracy.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use encointer_api_client_extension::{
1313
use encointer_node_notee_runtime::{AccountId, Balance, Hash};
1414
use encointer_primitives::{
1515
ceremonies::{CeremonyIndexType, CommunityCeremony, ReputationCountType},
16+
common::{FromStr, PalletString},
17+
communities::CommunityIdentifier,
1618
democracy::{
1719
Proposal, ProposalAccessPolicy, ProposalAction, ProposalIdType, ProposalState,
1820
ReputationVec, Vote,
@@ -84,6 +86,37 @@ pub fn submit_update_nominal_income_proposal(
8486
.into()
8587
}
8688

89+
pub fn submit_petition(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap::Error> {
90+
let rt = tokio::runtime::Runtime::new().unwrap();
91+
rt.block_on(async {
92+
let who = matches.account_arg().map(get_pair_from_str).unwrap();
93+
let mut api = get_chain_api(matches).await;
94+
api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(who.clone())));
95+
let maybecid = if let Some(cid) = matches.cid_arg() {
96+
Some(api.verify_cid(cid, None).await)
97+
} else {
98+
None
99+
};
100+
let demand_str = matches.value_of("demand").unwrap();
101+
let demand = PalletString::from_str(demand_str)
102+
.expect("Petition demand too long. must be < 256 chars");
103+
let tx_payment_cid_arg = matches.tx_payment_cid_arg();
104+
set_api_extrisic_params_builder(&mut api, tx_payment_cid_arg).await;
105+
106+
let xt: EncointerXt<_> = compose_extrinsic!(
107+
api,
108+
"EncointerDemocracy",
109+
"submit_proposal",
110+
ProposalAction::<AccountId, Balance>::Petition(maybecid, demand.clone())
111+
)
112+
.unwrap();
113+
ensure_payment(&api, &xt.encode().into(), tx_payment_cid_arg).await;
114+
let _result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock).await;
115+
println!("Proposal Submitted: Petition for cid {maybecid:?} demanding: {demand_str}");
116+
Ok(())
117+
})
118+
.into()
119+
}
87120
pub fn submit_spend_native_proposal(
88121
_args: &str,
89122
matches: &ArgMatches<'_>,
@@ -190,7 +223,18 @@ pub fn list_proposals(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap:
190223
"Proposal id: {} (reputation commitment purpose id: {})",
191224
*proposal_id, purpose_id
192225
);
193-
println!("🛠 action: {:?}", proposal.action);
226+
let proposal_str = match &proposal.action {
227+
ProposalAction::SetInactivityTimeout(timeout) =>
228+
format!("Set inactivity timeout to {timeout}"),
229+
ProposalAction::UpdateNominalIncome(cid, income) =>
230+
format!("Update nominal income for {cid} to {income}"),
231+
ProposalAction::Petition(maybecid, demand) =>
232+
format!("Petition for {} demanding: {}", cid_or_global(maybecid), String::from_utf8_lossy(demand)),
233+
ProposalAction::SpendNative(maybecid, to, amount) =>
234+
format!("Spend Native from {} treasury to {to}, amount {amount}", cid_or_global(maybecid)),
235+
_ => format!("{:?}", proposal.action),
236+
};
237+
println!("🛠 action: {:?}", proposal_str);
194238
println!("▶️ started at: {}", start.format("%Y-%m-%d %H:%M:%S %Z").to_string());
195239
println!(
196240
"🏁 ends after: {}",
@@ -366,3 +410,10 @@ async fn get_relevant_electorate(
366410
fn approval_threshold_percent(electorate: u128, turnout: u128) -> f64 {
367411
100f64 / (1f64 + (turnout as f64 / electorate as f64).sqrt())
368412
}
413+
414+
fn cid_or_global(maybecid: &Option<CommunityIdentifier>) -> String {
415+
match maybecid {
416+
Some(cid) => format!("{:?}", cid),
417+
None => "global".into(),
418+
}
419+
}

client/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,22 @@ fn main() {
611611
})
612612
.runner(commands::encointer_democracy::submit_update_nominal_income_proposal),
613613
)
614+
.add_cmd(
615+
Command::new("submit-petition")
616+
.description("Submit a petition for specified community (if --cid specified) or global")
617+
.options(|app| {
618+
app.setting(AppSettings::ColoredHelp)
619+
.account_arg()
620+
.arg(
621+
Arg::with_name("demand")
622+
.takes_value(true)
623+
.required(true)
624+
.value_name("DEMAND")
625+
.help("what the petition demands"),
626+
)
627+
})
628+
.runner(commands::encointer_democracy::submit_petition),
629+
)
614630
.add_cmd(
615631
Command::new("submit-spend-native-proposal")
616632
.description("Submit 'spend native' proposal for specified community, amount and beneficiary")

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/encointer/encointer-node"
1111
# * Align major and minor version with polkadot-sdk major.minor.
1212
# * Bump patch version for new releases, and make it the release tag.
1313
# * The client should follow this version.
14-
version = "1.14.2"
14+
version = "1.14.3"
1515

1616
[[bin]]
1717
name = "encointer-node-notee"

0 commit comments

Comments
 (0)