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

update to runtime 702

parent 53fc5b2e
Branches
Tags
1 merge request!15update to runtime 800
No preview for this file type
...@@ -4,7 +4,9 @@ use crate::*; ...@@ -4,7 +4,9 @@ use crate::*;
pub async fn certify(data: &Data, receiver: IdtyId) -> Result<(), anyhow::Error> { pub async fn certify(data: &Data, receiver: IdtyId) -> Result<(), anyhow::Error> {
let progress = submit_call( let progress = submit_call(
data, data,
&runtime::tx().cert().add_cert(data.idty_index(), receiver), &runtime::tx()
.certification()
.add_cert(data.idty_index(), receiver),
) )
.await?; .await?;
if data.args.no_wait { if data.args.no_wait {
...@@ -12,7 +14,7 @@ pub async fn certify(data: &Data, receiver: IdtyId) -> Result<(), anyhow::Error> ...@@ -12,7 +14,7 @@ pub async fn certify(data: &Data, receiver: IdtyId) -> Result<(), anyhow::Error>
} }
let events = track_progress(progress).await?; let events = track_progress(progress).await?;
// look for the expected event // look for the expected event
look_event::<runtime::cert::events::NewCert>(data, &events)?; look_event::<runtime::certification::events::CertAdded>(data, &events)?;
look_event::<runtime::cert::events::RenewedCert>(data, &events)?; look_event::<runtime::certification::events::CertRenewed>(data, &events)?;
Ok(()) Ok(())
} }
...@@ -13,25 +13,3 @@ pub async fn request_distance_evaluation(data: &Data) -> Result<(), subxt::Error ...@@ -13,25 +13,3 @@ pub async fn request_distance_evaluation(data: &Data) -> Result<(), subxt::Error
let _ = track_progress(progress).await?; let _ = track_progress(progress).await?;
Ok(()) Ok(())
} }
/// get identity distance status
pub async fn get_identity_distance_status(
data: &Data,
) -> Result<
Option<(
AccountId,
runtime::runtime_types::pallet_distance::types::DistanceStatus,
)>,
subxt::Error,
> {
data.client()
.storage()
.at_latest()
.await?
.fetch(
&runtime::storage()
.distance()
.identity_distance_status(data.idty_index()),
)
.await
}
...@@ -33,7 +33,7 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an ...@@ -33,7 +33,7 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an
let mut basic_certs_iter = client let mut basic_certs_iter = client
.storage() .storage()
.at(parent_hash) .at(parent_hash)
.iter(runtime::storage().cert().storage_certs_removable_on_iter()) .iter(runtime::storage().certification().certs_removable_on_iter())
.await?; .await?;
let mut basic_certs = BTreeMap::new(); let mut basic_certs = BTreeMap::new();
while let Some(Ok((k, v))) = basic_certs_iter.next().await { while let Some(Ok((k, v))) = basic_certs_iter.next().await {
...@@ -43,27 +43,7 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an ...@@ -43,27 +43,7 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an
} }
} }
let mut smith_certs_iter = client for (title, certs) in [("Certifications", basic_certs)] {
.storage()
.at(parent_hash)
.iter(
runtime::storage()
.smith_cert()
.storage_certs_removable_on_iter(),
)
.await?;
let mut smith_certs = BTreeMap::new();
while let Some(Ok((k, v))) = smith_certs_iter.next().await {
let block_number = BlockNumber::from_le_bytes(k[40..44].try_into().unwrap());
if block_number < end_block {
smith_certs.insert(block_number - current_block, v);
}
}
for (title, certs) in [
("Certifications", basic_certs),
("Smith certifications", smith_certs),
] {
println!("\n{title}:"); println!("\n{title}:");
for (blocks_left, certs) in certs { for (blocks_left, certs) in certs {
println!("{blocks_left} blocks before expiration:"); println!("{blocks_left} blocks before expiration:");
...@@ -102,27 +82,7 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an ...@@ -102,27 +82,7 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an
} }
} }
let mut smith_membership_iter = client for (title, memberships) in [("Memberships", basic_memberships)] {
.storage()
.at(parent_hash)
.iter(
runtime::storage()
.smith_membership()
.memberships_expire_on_iter(),
)
.await?;
let mut smith_memberships = BTreeMap::new();
while let Some(Ok((k, v))) = smith_membership_iter.next().await {
let block_number = BlockNumber::from_le_bytes(k[40..44].try_into().unwrap());
if block_number < end_block {
smith_memberships.insert(block_number - current_block, v);
}
}
for (title, memberships) in [
("Memberships", basic_memberships),
("Smith memberships", smith_memberships),
] {
println!("\n{title}:"); println!("\n{title}:");
for (blocks_left, membership) in memberships { for (blocks_left, membership) in memberships {
println!("{blocks_left} blocks before expiration:"); println!("{blocks_left} blocks before expiration:");
......
...@@ -31,14 +31,9 @@ pub enum Subcommand { ...@@ -31,14 +31,9 @@ pub enum Subcommand {
/// ///
/// To be called by the certified not-yet-member account, to become member. /// To be called by the certified not-yet-member account, to become member.
Confirm { name: String }, Confirm { name: String },
/// Validate an identity
/// Should be called when the distance has been evaluated positively
Validate { index: IdtyId },
/// Request distance evaluation /// Request distance evaluation
/// make sure that it's ok otherwise currency is slashed /// make sure that it's ok otherwise currency is slashed
RequestDistanceEvaluation, RequestDistanceEvaluation,
/// Get distance status
DistanceStatus,
/// Renew membership /// Renew membership
/// When membership comes to and end, it should be renewed for the identity to stay member /// When membership comes to and end, it should be renewed for the identity to stay member
RenewMembership, RenewMembership,
...@@ -96,16 +91,9 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -96,16 +91,9 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
Subcommand::Confirm { name } => { Subcommand::Confirm { name } => {
confirm_identity(&data, name).await?; confirm_identity(&data, name).await?;
} }
Subcommand::Validate { index } => {
validate_identity(&data, index).await?;
}
Subcommand::RequestDistanceEvaluation => { Subcommand::RequestDistanceEvaluation => {
commands::distance::request_distance_evaluation(&data).await?; commands::distance::request_distance_evaluation(&data).await?;
} }
Subcommand::DistanceStatus => {
data = data.fetch_idty_index().await?;
dbg!(commands::distance::get_identity_distance_status(&data).await?);
}
Subcommand::RenewMembership => { Subcommand::RenewMembership => {
renew_membership(&data).await?; renew_membership(&data).await?;
} }
...@@ -288,21 +276,15 @@ pub async fn confirm_identity(data: &Data, name: String) -> Result<(), subxt::Er ...@@ -288,21 +276,15 @@ pub async fn confirm_identity(data: &Data, name: String) -> Result<(), subxt::Er
.await .await
} }
/// confirm identity
pub async fn validate_identity(data: &Data, index: IdtyId) -> Result<(), subxt::Error> {
submit_call_and_look_event::<
runtime::identity::events::IdtyValidated,
Payload<runtime::identity::calls::types::ValidateIdentity>,
>(data, &runtime::tx().identity().validate_identity(index))
.await
}
/// renew membership /// renew membership
pub async fn renew_membership(data: &Data) -> Result<(), subxt::Error> { pub async fn renew_membership(data: &Data) -> Result<(), subxt::Error> {
submit_call_and_look_event::< submit_call_and_look_event::<
runtime::membership::events::MembershipRenewed, runtime::membership::events::MembershipRenewed,
Payload<runtime::membership::calls::types::RenewMembership>, Payload<runtime::distance::calls::types::RequestDistanceEvaluation>,
>(data, &runtime::tx().membership().renew_membership()) >(
data,
&runtime::tx().distance().request_distance_evaluation(),
)
.await .await
} }
......
...@@ -6,15 +6,15 @@ pub async fn runtime_info(data: Data) { ...@@ -6,15 +6,15 @@ pub async fn runtime_info(data: Data) {
// certifications // certifications
let cert_period = api let cert_period = api
.constants() .constants()
.at(&runtime::constants().cert().cert_period()) .at(&runtime::constants().certification().cert_period())
.unwrap(); .unwrap();
let max_by_issuer = api let max_by_issuer = api
.constants() .constants()
.at(&runtime::constants().cert().max_by_issuer()) .at(&runtime::constants().certification().max_by_issuer())
.unwrap(); .unwrap();
let validity_period = api let validity_period = api
.constants() .constants()
.at(&runtime::constants().cert().validity_period()) .at(&runtime::constants().certification().validity_period())
.unwrap(); .unwrap();
println!("certification period: {cert_period} blocks"); println!("certification period: {cert_period} blocks");
......
...@@ -36,16 +36,6 @@ fn session_keys_decode(session_keys: SessionKeys) -> RuntimeSessionKeys { ...@@ -36,16 +36,6 @@ fn session_keys_decode(session_keys: SessionKeys) -> RuntimeSessionKeys {
/// 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,
/// Emit a smith certification
Cert { to: IdtyId },
/// Claim smith membership
Claim,
/// Renew smith membership
Renew,
/// Revoke smith membership
Revoke,
/// go online /// go online
GoOnline, GoOnline,
/// go offline /// go offline
...@@ -66,36 +56,18 @@ pub enum Subcommand { ...@@ -66,36 +56,18 @@ pub enum Subcommand {
}, },
/// List online authorities /// List online authorities
ShowOnline, ShowOnline,
/// count of smith member
MemberCount,
} }
/// handle smith commands /// handle smith commands
pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> { pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> {
let mut data = data.build_client().await?; let mut data = data.build_client().await?;
match command { match command {
Subcommand::Request => {
request_smith_membership(&data).await?;
}
Subcommand::Claim => {
claim_smith_membership(&data).await?;
}
Subcommand::Renew => {
renew_smith_membership(&data).await?;
}
Subcommand::Revoke => {
revoke_smith_membership(&data).await?;
}
Subcommand::GoOnline => { Subcommand::GoOnline => {
go_online(&data).await?; go_online(&data).await?;
} }
Subcommand::GoOffline => { Subcommand::GoOffline => {
go_offline(&data).await?; go_offline(&data).await?;
} }
Subcommand::Cert { to } => {
data = data.fetch_idty_index().await?;
cert(&data, to).await?
}
Subcommand::UpdateKeys => { Subcommand::UpdateKeys => {
update_session_keys(&data).await?; update_session_keys(&data).await?;
} }
...@@ -116,21 +88,6 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -116,21 +88,6 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
data = data.build_client().await?; data = data.build_client().await?;
online(&data).await? online(&data).await?
} }
Subcommand::MemberCount => {
println!(
"smith member count: {:?}",
data.client()
.storage()
.at_latest()
.await?
.fetch(
&runtime::storage()
.smith_membership()
.counter_for_membership(),
)
.await?
)
}
}; };
Ok(()) Ok(())
...@@ -154,15 +111,6 @@ pub async fn rotate_keys(data: &Data) -> Result<SessionKeys, anyhow::Error> { ...@@ -154,15 +111,6 @@ pub async fn rotate_keys(data: &Data) -> Result<SessionKeys, anyhow::Error> {
.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) -> Result<(), subxt::Error> {
submit_call_and_look_event::<
runtime::smith_membership::events::MembershipRequested,
Payload<runtime::smith_membership::calls::types::RequestMembership>,
>(data, &runtime::tx().smith_membership().request_membership())
.await
}
/// set session keys /// set session keys
pub async fn set_session_keys( pub async fn set_session_keys(
data: &Data, data: &Data,
...@@ -217,33 +165,6 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> { ...@@ -217,33 +165,6 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> {
.map_err(|e| e.into()) .map_err(|e| e.into())
} }
/// claim smith membership
pub async fn claim_smith_membership(data: &Data) -> Result<(), subxt::Error> {
submit_call_and_look_event::<
runtime::smith_membership::events::MembershipAcquired,
Payload<runtime::smith_membership::calls::types::ClaimMembership>,
>(data, &runtime::tx().smith_membership().claim_membership())
.await
}
/// renew smith membership
pub async fn renew_smith_membership(data: &Data) -> Result<(), subxt::Error> {
submit_call_and_look_event::<
runtime::smith_membership::events::MembershipRenewed,
Payload<runtime::smith_membership::calls::types::RenewMembership>,
>(data, &runtime::tx().smith_membership().renew_membership())
.await
}
/// revoke smith membership
pub async fn revoke_smith_membership(data: &Data) -> Result<(), subxt::Error> {
submit_call_and_look_event::<
runtime::smith_membership::events::MembershipRevoked,
Payload<runtime::smith_membership::calls::types::RevokeMembership>,
>(data, &runtime::tx().smith_membership().revoke_membership())
.await
}
/// submit go_offline /// submit go_offline
pub async fn go_offline(data: &Data) -> Result<(), subxt::Error> { pub async fn go_offline(data: &Data) -> Result<(), subxt::Error> {
submit_call_and_look_event::< submit_call_and_look_event::<
...@@ -333,22 +254,3 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> { ...@@ -333,22 +254,3 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
Ok(()) Ok(())
} }
/// submit a smith certification and track progress
pub async fn cert(data: &Data, receiver: IdtyId) -> Result<(), anyhow::Error> {
let progress = submit_call(
data,
&runtime::tx()
.smith_cert()
.add_cert(data.idty_index(), receiver),
)
.await?;
if data.args.no_wait {
return Ok(());
}
let events = track_progress(progress).await?;
// look for the expected event
look_event::<runtime::smith_cert::events::NewCert>(data, &events)?;
look_event::<runtime::smith_cert::events::RenewedCert>(data, &events)?;
Ok(())
}
...@@ -9,7 +9,7 @@ pub enum Subcommand { ...@@ -9,7 +9,7 @@ pub enum Subcommand {
Nothing, Nothing,
/// set sudo keys /// set sudo keys
SetKey { new_key: AccountId }, SetKey { new_key: AccountId },
/// force set distance status to DistanceStatus::Valid /// force valid distance status
SetDistanceOk { identity: IdtyId }, SetDistanceOk { identity: IdtyId },
} }
...@@ -40,13 +40,7 @@ pub async fn set_key(data: &Data, new_key: AccountId) -> Result<(), subxt::Error ...@@ -40,13 +40,7 @@ pub async fn set_key(data: &Data, new_key: AccountId) -> Result<(), subxt::Error
/// set distance ok /// set distance ok
pub async fn set_distance_ok(data: &Data, identity: IdtyId) -> Result<(), subxt::Error> { pub async fn set_distance_ok(data: &Data, identity: IdtyId) -> Result<(), subxt::Error> {
let inner = runtime::distance::Call::force_set_distance_status { let inner = runtime::distance::Call::force_valid_distance_status { identity };
identity,
status: Some((
data.address(),
runtime::runtime_types::pallet_distance::types::DistanceStatus::Valid,
)),
};
let inner = runtime::Call::Distance(inner); let inner = runtime::Call::Distance(inner);
submit_call_and_look_event::< submit_call_and_look_event::<
runtime::sudo::events::Sudid, runtime::sudo::events::Sudid,
......
...@@ -14,26 +14,16 @@ impl DisplayEvent for runtime::universal_dividend::events::UdsClaimed { ...@@ -14,26 +14,16 @@ impl DisplayEvent for runtime::universal_dividend::events::UdsClaimed {
) )
} }
} }
impl DisplayEvent for runtime::cert::events::NewCert { impl DisplayEvent for runtime::certification::events::CertAdded {
fn display(&self, _data: &Data) -> String { fn display(&self, _data: &Data) -> String {
format!("new certification {} → {}", self.issuer, self.receiver) format!("new certification {} → {}", self.issuer, self.receiver)
} }
} }
impl DisplayEvent for runtime::cert::events::RenewedCert { impl DisplayEvent for runtime::certification::events::CertRenewed {
fn display(&self, _data: &Data) -> String { fn display(&self, _data: &Data) -> String {
format!("renewed cert {:?}", self) format!("renewed cert {:?}", self)
} }
} }
impl DisplayEvent for runtime::smith_cert::events::NewCert {
fn display(&self, _data: &Data) -> String {
format!("certified as smith {:?}", self)
}
}
impl DisplayEvent for runtime::smith_cert::events::RenewedCert {
fn display(&self, _data: &Data) -> String {
format!("renewed smith cert {:?}", self)
}
}
impl DisplayEvent for runtime::account::events::AccountUnlinked { impl DisplayEvent for runtime::account::events::AccountUnlinked {
fn display(&self, _data: &Data) -> String { fn display(&self, _data: &Data) -> String {
format!("account unlinked: {}", self.0) format!("account unlinked: {}", self.0)
...@@ -60,11 +50,6 @@ impl DisplayEvent for runtime::identity::events::IdtyConfirmed { ...@@ -60,11 +50,6 @@ impl DisplayEvent for runtime::identity::events::IdtyConfirmed {
) )
} }
} }
impl DisplayEvent for runtime::identity::events::IdtyValidated {
fn display(&self, _data: &Data) -> String {
format!("identity validated {:?}", self)
}
}
impl DisplayEvent for runtime::identity::events::IdtyChangedOwnerKey { impl DisplayEvent for runtime::identity::events::IdtyChangedOwnerKey {
fn display(&self, _data: &Data) -> String { fn display(&self, _data: &Data) -> String {
format!("identity changed owner key {:?}", self) format!("identity changed owner key {:?}", self)
...@@ -95,31 +80,11 @@ impl DisplayEvent for runtime::oneshot_account::events::OneshotAccountConsumed { ...@@ -95,31 +80,11 @@ impl DisplayEvent for runtime::oneshot_account::events::OneshotAccountConsumed {
format!("oneshot {:?}", self) format!("oneshot {:?}", self)
} }
} }
impl DisplayEvent for runtime::smith_membership::events::MembershipRequested {
fn display(&self, _data: &Data) -> String {
format!("smith membership requested {:?}", self)
}
}
impl DisplayEvent for runtime::authority_members::events::MemberGoOnline { impl DisplayEvent for runtime::authority_members::events::MemberGoOnline {
fn display(&self, _data: &Data) -> String { fn display(&self, _data: &Data) -> String {
format!("smith went online {:?}", self) format!("smith went online {:?}", self)
} }
} }
impl DisplayEvent for runtime::smith_membership::events::MembershipAcquired {
fn display(&self, _data: &Data) -> String {
format!("smith membership aquired {:?}", self)
}
}
impl DisplayEvent for runtime::smith_membership::events::MembershipRenewed {
fn display(&self, _data: &Data) -> String {
format!("smith membership renewed {:?}", self)
}
}
impl DisplayEvent for runtime::smith_membership::events::MembershipRevoked {
fn display(&self, _data: &Data) -> String {
format!("smith membership revoked {:?}", self)
}
}
impl DisplayEvent for runtime::authority_members::events::MemberGoOffline { impl DisplayEvent for runtime::authority_members::events::MemberGoOffline {
fn display(&self, _data: &Data) -> String { fn display(&self, _data: &Data) -> String {
format!("smith went offline {:?}", self) format!("smith went offline {:?}", self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment