Skip to content

Commit

Permalink
add validate
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Jan 10, 2025
1 parent 3eb0cf0 commit e136dd2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
23 changes: 21 additions & 2 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -565,6 +568,22 @@ pub async fn set_session_keys(
Ok(())
}

pub async fn declare_validate(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
signer: sr25519::Pair,
prefs: ValidatorPrefs,
joining_server_info: JoiningServerInfo<SubxtAccountId32>,
quote: Vec<u8>,
) -> Result<ValidatorCandidateAccepted, ClientError> {
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::<ValidatorCandidateAccepted>()?.ok_or(SubstrateError::NoEvent)?;
Ok(result_event)
}

pub fn deconstruct_session_keys(session_keys: Vec<u8>) -> Result<SessionKeys, String> {
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;
Expand Down
24 changes: 22 additions & 2 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -206,13 +206,19 @@ enum CliCommand {
#[arg(short, long)]
mnemonic_option: Option<String>,
},
/// 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<String>,
},
/// Declares intention to validate
DeclareValidate {
/// The mnemonic for the signer which will trigger the call.
#[arg(short, long)]
mnemonic_option: Option<String>,
},
}

impl Cli {
Expand Down Expand Up @@ -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())
}
},
}
}

Expand Down

0 comments on commit e136dd2

Please sign in to comment.