diff --git a/Cargo.lock b/Cargo.lock index 2439bc57..570f4658 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1400,7 +1400,7 @@ dependencies = [ [[package]] name = "encointer-client-notee" -version = "0.8.3" +version = "0.8.4" dependencies = [ "clap 2.34.0", "clap-nested", @@ -1430,7 +1430,7 @@ dependencies = [ [[package]] name = "encointer-node-notee" -version = "0.8.3" +version = "0.8.4" dependencies = [ "clap 3.1.6", "encointer-node-notee-runtime", diff --git a/client/Cargo.toml b/client/Cargo.toml index d83bf36f..980901ca 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -3,7 +3,7 @@ name = "encointer-client-notee" authors = ["encointer.org "] edition = "2021" #keep with node version -version = "0.8.3" +version = "0.8.4" [dependencies] clap = "2.33" diff --git a/client/src/cli_args.rs b/client/src/cli_args.rs index aaeb4d68..62160ffc 100644 --- a/client/src/cli_args.rs +++ b/client/src/cli_args.rs @@ -5,9 +5,11 @@ const SIGNER_ARG: &'static str = "signer"; const CID_ARG: &'static str = "cid"; const CLAIMS_ARG: &'static str = "claims"; const CEREMONY_INDEX_ARG: &'static str = "ceremony-index"; -const IPFS_CID_ARG: &'static str = "ceremony-index"; +const IPFS_CID_ARG: &'static str = "ipfs-cid"; const BOOTSTRAPPER_ARG: &'static str = "bootstrapper"; const FUNDEES_ARG: &'static str = "fundees"; +const FROM_CINDEX_ARG: &'static str = "from-cindex"; +const TO_CINDEX_ARG: &'static str = "to-cindex"; const ENDORSEES_ARG: &'static str = "endorsees"; const ALL_FLAG: &'static str = "all"; @@ -20,6 +22,8 @@ pub trait EncointerArgs<'b> { fn ipfs_cid_arg(self) -> Self; fn bootstrapper_arg(self) -> Self; fn fundees_arg(self) -> Self; + fn from_cindex_arg(self) -> Self; + fn to_cindex_arg(self) -> Self; fn endorsees_arg(self) -> Self; fn all_flag(self) -> Self; } @@ -33,6 +37,8 @@ pub trait EncointerArgsExtractor { fn ipfs_cid_arg(&self) -> Option<&str>; fn bootstrapper_arg(&self) -> Option<&str>; fn fundees_arg(&self) -> Option>; + fn from_cindex_arg(&self) -> Option; + fn to_cindex_arg(&self) -> Option; fn endorsees_arg(&self) -> Option>; fn all_flag(&self) -> bool; } @@ -123,7 +129,24 @@ impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> { .help("Account(s) to be funded, ss58check encoded"), ) } - + fn from_cindex_arg(self) -> Self { + self.arg( + Arg::with_name(FROM_CINDEX_ARG) + .takes_value(true) + .required(true) + .value_name("FROM") + .help("first ceremony index to be purged"), + ) + } + fn to_cindex_arg(self) -> Self { + self.arg( + Arg::with_name(TO_CINDEX_ARG) + .takes_value(true) + .required(true) + .value_name("TO") + .help("last ceremony index to be purged"), + ) + } fn endorsees_arg(self) -> Self { self.arg( Arg::with_name(ENDORSEES_ARG) @@ -183,6 +206,13 @@ impl<'a> EncointerArgsExtractor for ArgMatches<'a> { self.values_of(FUNDEES_ARG).map(|v| v.collect()) } + fn from_cindex_arg(&self) -> Option { + self.value_of(FROM_CINDEX_ARG).map(|v| v.parse().unwrap()) + } + fn to_cindex_arg(&self) -> Option { + self.value_of(TO_CINDEX_ARG).map(|v| v.parse().unwrap()) + } + fn endorsees_arg(&self) -> Option> { self.values_of(ENDORSEES_ARG).map(|v| v.collect()) } diff --git a/client/src/main.rs b/client/src/main.rs index e5ebb51f..bec79fb4 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1059,6 +1059,71 @@ fn main() { Ok(()) }), ) + .add_cmd( + Command::new("purge-community-ceremony") + .description("purge all history within the provided ceremony index range for the specified community") + .options(|app| { + app.setting(AppSettings::ColoredHelp) + .from_cindex_arg() + .to_cindex_arg() + + }) + .runner(|_args: &str, matches: &ArgMatches<'_>| { + let sudoer = AccountKeyring::Alice.pair(); + let api = get_chain_api(matches).set_signer(sudoer); + + let current_ceremony_index = get_ceremony_index(&api); + + let from_cindex_arg = matches.from_cindex_arg().unwrap_or(0); + let to_cindex_arg = matches.to_cindex_arg().unwrap_or(0); + + let from_cindex = into_effective_cindex(from_cindex_arg, current_ceremony_index); + let to_cindex = into_effective_cindex(to_cindex_arg, current_ceremony_index); + + if from_cindex > to_cindex { + panic!("'from' <= 'to' ceremony index violated"); + } + let cid = verify_cid(&api, + matches + .cid_arg() + .expect("please supply argument --cid"), + ); + println!("purging ceremony index range [{} {}] for community {}", from_cindex, to_cindex, cid); + + let calls: Vec<_> = (from_cindex..=to_cindex) + .map(|idx| compose_call!( + api.metadata, + "EncointerCeremonies", + "purge_community_ceremony", + (cid, idx) + )) + .collect(); + let batch_call = compose_call!( + api.metadata, + "Utility", + "batch", + calls + ); + let unsigned_sudo_call = compose_call!( + api.metadata, + "Sudo", + "sudo", + batch_call.clone() + ); + info!("raw sudo batch call to sign with js/apps {}: 0x{}", cid, hex::encode(unsigned_sudo_call.encode())); + let xt: UncheckedExtrinsicV4<_> = compose_extrinsic!( + api, + "Sudo", + "sudo", + batch_call + ); + ensure_payment(&api, &xt.hex_encode()); + let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap(); + info!("[+] Transaction got included. Hash: {:?}\n", tx_hash); + Ok(()) + }), + ) + // To handle when no subcommands match .no_cmd(|_args, _matches| { println!("No subcommand matched"); diff --git a/node/Cargo.toml b/node/Cargo.toml index e2ae1cab..5fd064d8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -8,7 +8,7 @@ license = "GPL-3.0" name = "encointer-node-notee" repository = "https://github.com/encointer/encointer-node" #keep with client version -version = "0.8.3" +version = "0.8.4" [[bin]] name = "encointer-node-notee"