From e28cb96e28bfddfd859b4f9a40633a9cd9041df2 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo.trentesaux@lilo.org> Date: Fri, 15 Mar 2024 18:06:05 +0100 Subject: [PATCH] get cert count from cert meta (clients/rust/gcli-v2s!28) * also for smith cert * get cert count from cert meta --- src/commands/identity.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/commands/identity.rs b/src/commands/identity.rs index 3f75a82..be986cf 100644 --- a/src/commands/identity.rs +++ b/src/commands/identity.rs @@ -193,7 +193,9 @@ struct IdtyView { old_owner_key: Vec<AccountId>, expire_on: BlockNumber, cert_issued: Vec<String>, + cert_issued_count: u32, cert_received: Vec<String>, + cert_received_count: u32, smith: Option<SmithView>, linked_account: Vec<AccountId>, } @@ -210,16 +212,14 @@ impl std::fmt::Display for IdtyView { writeln!( f, "Certifications: issued {}, received {}", - self.cert_issued.len(), - self.cert_received.len() + self.cert_issued_count, self.cert_received_count )?; if let Some(smith) = &self.smith { writeln!(f, "Smith status: {:?}", smith.status)?; writeln!( f, "Smith certs: issued {}, received {}", - smith.cert_issued.len(), - smith.cert_received.len() + smith.cert_issued_count, smith.cert_received_count )?; } let a = self.linked_account.len(); @@ -234,7 +234,9 @@ impl std::fmt::Display for IdtyView { struct SmithView { status: SmithStatus, cert_issued: Vec<String>, + cert_issued_count: usize, cert_received: Vec<String>, + cert_received_count: usize, } /// get identity @@ -281,6 +283,19 @@ pub async fn get_identity( "<no indexer>".to_string() }); + // get cert meta + let cert_meta = client + .storage() + .at_latest() + .await? + .fetch( + &runtime::storage() + .certification() + .storage_idty_cert_meta(index), + ) + .await? + .expect("expected cert meta"); + // get certs if possible let (cert_issued, cert_received, linked_account, smith_cert_issued, smith_cert_received) = if let Some(indexer) = &indexer { @@ -315,7 +330,9 @@ pub async fn get_identity( let smith = get_smith(client, index).await?; let smith = smith.map(|s| SmithView { status: s.status, + cert_issued_count: s.issued_certs.len(), cert_issued: smith_cert_issued, + cert_received_count: s.received_certs.len(), cert_received: smith_cert_received, }); @@ -328,7 +345,9 @@ pub async fn get_identity( old_owner_key: vec![], // TODO fetch history of owner key change expire_on: value.next_scheduled, // TODO if zero use membership instead cert_issued, + cert_issued_count: cert_meta.issued_count, cert_received, + cert_received_count: cert_meta.received_count, smith, linked_account, }; -- GitLab