Select Git revision
-
* update schema for enums * update to hasura endpoint * more macro * Ignore non_camel_case_types in vscode stage Are we carring about conventions ? * 2 macros to rule them all * example on how to deserialize * adapt graphql request to Hasura engine
* update schema for enums * update to hasura endpoint * more macro * Ignore non_camel_case_types in vscode stage Are we carring about conventions ? * 2 macros to rule them all * example on how to deserialize * adapt graphql request to Hasura engine
indexer.rs 6.68 KiB
mod queries;
use crate::*;
use comfy_table::*;
use comfy_table::{ContentArrangement, Table};
use graphql_client::reqwest::post_graphql;
use graphql_client::GraphQLQuery;
use queries::*;
// use sp_core::Bytes;
#[derive(Clone, Debug)]
pub struct Indexer {
pub gql_client: reqwest::Client,
pub gql_url: String,
}
impl Indexer {
/// graphql query without error management
async fn query<T: GraphQLQuery>(
&self,
var: <T as GraphQLQuery>::Variables,
) -> <T as GraphQLQuery>::ResponseData {
post_graphql::<T, _>(&self.gql_client, &self.gql_url, var)
.await
.expect("indexer connexion error")
.data
.expect("indexer error")
}
/// index → name
pub async fn username_by_index(&self, index: u32) -> Option<String> {
self.query::<IdentityNameByIndex>(identity_name_by_index::Variables {
index: index.into(),
})
.await
.identity
.pop()
.map(|idty| idty.name)
}
/// index → name (multiple)
pub async fn names_by_indexes(&self, indexes: &[IdtyId]) -> Vec<(IdtyId, String)> {
self.query::<NamesByIndexes>(names_by_indexes::Variables {
indexes: indexes.iter().map(|i| *i as i64).collect(),
})
.await
.identity
.into_iter()
.map(|idty| (idty.index as IdtyId, idty.name))
.collect()
}
/// pubkey → name
pub async fn username_by_pubkey(&self, pubkey: &str) -> Option<String> {
self.query::<IdentityNameByPubkey>(identity_name_by_pubkey::Variables {
pubkey: pubkey.to_string(),
})
.await
.identity
.pop()
.map(|idty| idty.name)
}
/// pubkey → was name
pub async fn wasname_by_pubkey(&self, pubkey: &str) -> Option<String> {
self.query::<WasIdentityNameByPubkey>(was_identity_name_by_pubkey::Variables {
pubkey: pubkey.to_string(),
})
.await
.account_by_pk