Skip to content
Snippets Groups Projects
Select Git revision
  • e7275f630dd03518bda890dd0d81a095a5f7f50e
  • master default protected
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • hugo/195-doc
  • hugo/195-graphql-schema
  • gtest-1000-0.8.0 protected
  • gtest-1000 protected
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
  • v0.4.1 protected
41 results

docker.sh

Blame
  • cache.rs 1.18 KiB
    use crate::indexer::*;
    use crate::*;
    
    use std::collections::{hash_map, HashMap};
    
    pub struct IdentityCache {
    	client: Client,
    	identities: HashMap<u32, String>,
    	indexer: Option<Indexer>,
    }
    
    impl IdentityCache {
    	pub fn new(client: Client, indexer: Option<Indexer>) -> Self {
    		Self {
    			client,
    			identities: HashMap::new(),
    			indexer,
    		}
    	}
    
    	pub async fn fetch_identity(
    		&mut self,
    		identity_id: u32,
    		parent_hash: sp_core::H256,
    	) -> anyhow::Result<String> {
    		Ok(match self.identities.entry(identity_id) {
    			hash_map::Entry::Occupied(entry) => entry.get().clone(),
    			hash_map::Entry::Vacant(entry) => entry
    				.insert({
    					let pubkey = self
    						.client
    						.storage()
    						.fetch(
    							&runtime::storage().identity().identities(identity_id),
    							Some(parent_hash),
    						)
    						.await?
    						.ok_or_else(|| anyhow!("Identity {} not found", identity_id))?
    						.owner_key
    						.to_string();
    					format!(
    						"“ {} ”",
    						if let Some(indexer) = &self.indexer {
    							if let Ok(Some(username)) = indexer.username_by_pubkey(&pubkey).await {
    								username
    							} else {
    								pubkey
    							}
    						} else {
    							pubkey
    						}
    					)
    				})
    				.clone(),
    		})
    	}
    }