diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 7afb1003d..a35e01ffd 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -34,13 +34,16 @@ use crate::{ entropy_runtime::SessionKeys, pallet_programs::pallet::ProgramInfo, pallet_registry::pallet::{ProgramInstance, RegisteredInfo}, - pallet_staking::RewardDestination, + pallet_staking::{RewardDestination, ValidatorPrefs}, + pallet_staking_extension::pallet::JoiningServerInfo, }, }, EntropyConfig, }, client::entropy::staking::events::Bonded, - client::entropy::staking_extension::events::{EndpointChanged, ThresholdAccountChanged}, + client::entropy::staking_extension::events::{ + EndpointChanged, ThresholdAccountChanged, ValidatorCandidateAccepted, + }, substrate::{get_registered_details, query_chain, submit_transaction_with_pair}, user::{ self, get_all_signers_from_chain, get_validators_not_signer_for_relay, UserSignatureRequest, @@ -565,6 +568,22 @@ pub async fn set_session_keys( Ok(()) } +pub async fn declare_validate( + api: &OnlineClient, + rpc: &LegacyRpcMethods, + signer: sr25519::Pair, + prefs: ValidatorPrefs, + joining_server_info: JoiningServerInfo, + quote: Vec, +) -> Result { + let validate_request = + entropy::tx().staking_extension().validate(prefs, joining_server_info, quote); + let in_block = submit_transaction_with_pair(api, rpc, &signer, &validate_request, None).await?; + let result_event = + in_block.find_first::()?.ok_or(SubstrateError::NoEvent)?; + Ok(result_event) +} + pub fn deconstruct_session_keys(session_keys: Vec) -> Result { use crate::chain_api::entropy::runtime_types::sp_core::ed25519::Public as EDPublic; use crate::chain_api::entropy::runtime_types::sp_core::sr25519::Public as SRPublic; diff --git a/crates/test-cli/src/lib.rs b/crates/test-cli/src/lib.rs index 199b72a94..a448f7856 100644 --- a/crates/test-cli/src/lib.rs +++ b/crates/test-cli/src/lib.rs @@ -30,7 +30,7 @@ use entropy_client::{ bond_account, get_accounts, get_api, get_oracle_headings, get_programs, get_quote_and_change_endpoint, get_quote_and_change_threshold_accounts, get_rpc, get_tdx_quote, jumpstart_network, register, remove_program, sign, store_program, - update_programs, VERIFYING_KEY_LENGTH, + update_programs, VERIFYING_KEY_LENGTH, declare_validate }, }; pub use entropy_shared::{QuoteContext, PROGRAM_VERSION_NUMBER}; @@ -206,13 +206,19 @@ enum CliCommand { #[arg(short, long)] mnemonic_option: Option, }, - /// Bonds an account. + /// Sets session keys for an account. SetSessionKeys { session_keys: String, /// The mnemonic for the signer which will trigger the call. #[arg(short, long)] mnemonic_option: Option, }, + /// Declares intention to validate + DeclareValidate { + /// The mnemonic for the signer which will trigger the call. + #[arg(short, long)] + mnemonic_option: Option, + }, } impl Cli { @@ -594,6 +600,20 @@ pub async fn run_command( Ok("Session Keys updates".to_string()) } }, + CliCommand::DeclareValidate { mnemonic_option } => { + let signer = handle_mnemonic(mnemonic_option)?; + cli.log(format!("Account being used for session keys: {}", signer.public())); + + // let result_event = + // declare_validate(&api, &rpc, signer).await?; + // cli.log(format!("Event result: {:?}", result_event)); + + if cli.json { + Ok("{}".to_string()) + } else { + Ok("Validation declared succefully".to_string()) + } + }, } }