Skip to content
Snippets Groups Projects
Commit ebcae718 authored by Hugo Trentesaux's avatar Hugo Trentesaux Committed by Hugo Trentesaux
Browse files

WIP add smith request

fix no need indexer for account
tweak claim ud command name
parent c7d143f3
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ pub enum Subcommand { ...@@ -28,7 +28,7 @@ pub enum Subcommand {
/// handle account commands /// handle account commands
pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
let mut data = data.build_client().await?.build_indexer().await?; let mut data = data.build_client().await?;
match command { match command {
Subcommand::Balance => { Subcommand::Balance => {
data = data data = data
......
...@@ -3,23 +3,25 @@ use crate::*; ...@@ -3,23 +3,25 @@ use crate::*;
use std::ops::Deref; use std::ops::Deref;
type SessionKeys = [u8; 128]; type SessionKeys = [u8; 128];
#[cfg(feature = "gdev")]
type SmithMembershipMetaData = runtime::runtime_types::common_runtime::entities::SmithMembershipMetaData::<SessionKeys>;
/// define smith subcommands /// define smith subcommands
#[derive(Clone, Default, Debug, clap::Parser)] #[derive(Clone, Default, Debug, clap::Parser)]
pub enum Subcommand { pub enum Subcommand {
/// Request smith membership
Request { endpoint: String },
/// Emit a smith certification /// Emit a smith certification
Cert { to: u32 }, Cert { to: u32 },
/// go online /// go online
GoOnline, GoOnline,
#[default]
/// go offline /// go offline
#[default]
GoOffline, GoOffline,
/// Rotate and set session keys /// Rotate and set session keys
UpdateKeys, UpdateKeys,
/// set sudo keys /// set sudo keys
SudoSetKey { SudoSetKey { new_key: AccountId },
new_key: AccountId,
},
/// List upcoming expirations that require an action /// List upcoming expirations that require an action
ShowExpire { ShowExpire {
/// Show certs that expire within less than this number of blocks /// Show certs that expire within less than this number of blocks
...@@ -35,32 +37,36 @@ pub enum Subcommand { ...@@ -35,32 +37,36 @@ pub enum Subcommand {
/// handle smith commands /// handle smith commands
pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
let mut data = data.build_client().await?.build_indexer().await?; let mut data = data.build_client().await?;
match command { match command {
Subcommand::Request { endpoint } => {
data = data.build_keypair();
dbg!(request_smith_membership(&data, endpoint).await)?;
}
Subcommand::GoOnline => { Subcommand::GoOnline => {
commands::smith::go_online(&data).await?; go_online(&data).await?;
} }
Subcommand::GoOffline => { Subcommand::GoOffline => {
commands::smith::go_offline(&data).await?; go_offline(&data).await?;
} }
Subcommand::Cert { to } => { Subcommand::Cert { to } => {
data = data.build_keypair().fetch_idty_index().await?; data = data.build_keypair().fetch_idty_index().await?;
commands::smith::cert(&data, to).await? cert(&data, to).await?
} }
Subcommand::UpdateKeys => { Subcommand::UpdateKeys => {
commands::smith::update_session_keys(&data).await?; update_session_keys(&data).await?;
} }
Subcommand::SudoSetKey { new_key } => { Subcommand::SudoSetKey { new_key } => {
data = data.build_keypair().build_client().await?; data = data.build_keypair().build_client().await?;
commands::sudo::set_key(data.keypair(), data.client(), new_key).await?; commands::sudo::set_key(data.keypair(), data.client(), new_key).await?;
} }
Subcommand::ShowExpire { blocks, sessions } => { Subcommand::ShowExpire { blocks, sessions } => {
data = data.build_client().await?; data = data.build_client().await?.build_indexer().await?;
commands::expire::monitor_expirations(&data, blocks, sessions).await? commands::expire::monitor_expirations(&data, blocks, sessions).await?
} }
Subcommand::ShowOnline => { Subcommand::ShowOnline => {
data = data.build_client().await?; data = data.build_client().await?;
commands::smith::online(&data).await? online(&data).await?
} }
}; };
...@@ -68,16 +74,45 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( ...@@ -68,16 +74,45 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
} }
/// rotate session keys /// rotate session keys
/// (needs to be connected to unsafe RPC)
pub async fn rotate_keys(client: &Client) -> Result<SessionKeys, anyhow::Error> { pub async fn rotate_keys(client: &Client) -> Result<SessionKeys, anyhow::Error> {
client client
.rpc() .rpc()
.rotate_keys() .rotate_keys()
.await? .await.map_err(|e| anyhow!("Please make sure you are connected to your validator node with the unsafe RPC API enabled {e}"))?
.deref() .deref()
.try_into() .try_into()
.map_err(|e| anyhow!("Session keys have wrong length: {:?}", e)) .map_err(|e| anyhow!("Session keys have wrong length: {:?}", e))
} }
/// request smith membership
pub async fn request_smith_membership(data: &Data, endpoint: String) -> Result<(), anyhow::Error> {
let session_keys = rotate_keys(data.client()).await?;
let metadata =
SmithMembershipMetaData {
session_keys,
owner_key: data.address(),
p2p_endpoint: endpoint,
};
let progress = data
.client()
.tx()
.sign_and_submit_then_watch(
&runtime::tx()
.smith_membership()
.request_membership(metadata),
&PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
let events = track_progress(progress).await?;
let request = events.find_first::<runtime::smith_membership::events::MembershipRequested>()?;
if let Some(event) = request {
println!("{event:?}");
}
Ok(())
}
/// set session keys /// set session keys
pub async fn set_session_keys( pub async fn set_session_keys(
data: &Data, data: &Data,
...@@ -121,7 +156,8 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> { ...@@ -121,7 +156,8 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> {
)); ));
} }
let progress = data.client() let progress = data
.client()
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx().authority_members().go_online(), &runtime::tx().authority_members().go_online(),
...@@ -243,7 +279,9 @@ pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> { ...@@ -243,7 +279,9 @@ pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> {
.client() .client()
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx().smith_cert().add_cert(data.idty_index(), receiver), &runtime::tx()
.smith_cert()
.add_cert(data.idty_index(), receiver),
&PairSigner::new(data.keypair()), &PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(), BaseExtrinsicParamsBuilder::new(),
) )
......
...@@ -5,7 +5,7 @@ use crate::*; ...@@ -5,7 +5,7 @@ use crate::*;
pub enum Subcommand { pub enum Subcommand {
#[default] #[default]
/// Claim uds /// Claim uds
ClaimUds, Claim,
} }
/// handle ud commands /// handle ud commands
...@@ -14,7 +14,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( ...@@ -14,7 +14,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
let mut data = data.build_client().await?; let mut data = data.build_client().await?;
// match subcommand // match subcommand
match command { match command {
Subcommand::ClaimUds => { Subcommand::Claim => {
data = data.build_keypair(); data = data.build_keypair();
claim_ud(data).await?; claim_ud(data).await?;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment