@@ -13,6 +13,8 @@ use encointer_api_client_extension::{
13
13
use encointer_node_notee_runtime:: { AccountId , Balance , Hash } ;
14
14
use encointer_primitives:: {
15
15
ceremonies:: { CeremonyIndexType , CommunityCeremony , ReputationCountType } ,
16
+ common:: { FromStr , PalletString } ,
17
+ communities:: CommunityIdentifier ,
16
18
democracy:: {
17
19
Proposal , ProposalAccessPolicy , ProposalAction , ProposalIdType , ProposalState ,
18
20
ReputationVec , Vote ,
@@ -84,6 +86,37 @@ pub fn submit_update_nominal_income_proposal(
84
86
. into ( )
85
87
}
86
88
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
+ }
87
120
pub fn submit_spend_native_proposal (
88
121
_args : & str ,
89
122
matches : & ArgMatches < ' _ > ,
@@ -190,7 +223,18 @@ pub fn list_proposals(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap:
190
223
"Proposal id: {} (reputation commitment purpose id: {})" ,
191
224
* proposal_id, purpose_id
192
225
) ;
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) ;
194
238
println ! ( "▶️ started at: {}" , start. format( "%Y-%m-%d %H:%M:%S %Z" ) . to_string( ) ) ;
195
239
println ! (
196
240
"🏁 ends after: {}" ,
@@ -366,3 +410,10 @@ async fn get_relevant_electorate(
366
410
fn approval_threshold_percent ( electorate : u128 , turnout : u128 ) -> f64 {
367
411
100f64 / ( 1f64 + ( turnout as f64 / electorate as f64 ) . sqrt ( ) )
368
412
}
413
+
414
+ fn cid_or_global ( maybecid : & Option < CommunityIdentifier > ) -> String {
415
+ match maybecid {
416
+ Some ( cid) => format ! ( "{:?}" , cid) ,
417
+ None => "global" . into ( ) ,
418
+ }
419
+ }
0 commit comments