Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional git repo configuration #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/// for a long-running process as construction involves sending an individual GET request for every path in the registry which
/// takes a while.
use crate::{
get::*,
paths::{IBCPath, Tag},
registry::*,
};
use eyre::Result;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -48,9 +48,11 @@ impl RegistryCache {
///
/// ```ignore
/// use chain_registry::cache::{RegistryCache, Tag};
/// use chain_registry::registry::Registry;
///
/// // store paths from the registry repository in a cache
/// let cache = RegistryCache::try_new().await?;
/// let registry = Registry::new(None);
/// let cache = RegistryCache::try_new(&registry).await?;
/// let dex = "osmosis".to_string();
///
/// // paths will contain a vec of all IBC paths containing the tag dex:osmosis
Expand All @@ -70,9 +72,9 @@ impl RegistryCache {
.collect())
}

/// Creates a new cache by retrieving and deserializing each [`IBCPath`] from the Cosmos Chain Registry for easy filtering
pub async fn try_new() -> Result<RegistryCache> {
let path_names = list_paths().await?;
/// Creates a new cache by retrieving and deserializing each [`IBCPath`] from the provided [`Registry`] for easy filtering
pub async fn try_new(registry: &Registry) -> Result<RegistryCache> {
let path_names = registry.list_paths().await?;
let mut paths = HashMap::<String, IBCPath>::default();

for pn in path_names {
Expand All @@ -82,7 +84,10 @@ impl RegistryCache {
// retrieved earlier, therefore the Option returned should never be None.
paths.insert(
pn.clone(),
get_path(cn[0], cn[1]).await?.expect("path returned None"),
registry
.get_path(cn[0], cn[1])
.await?
.expect("path returned None"),
);
}

Expand Down
33 changes: 15 additions & 18 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
// by denying unknown fields we can be more confident that our structs match the
// current configured GIT_REF's schema. errors will occur if the chain.json is
// formatted incorrectly, however.
#[serde(default,)]
#[serde(default)]
pub struct ChainInfo {
#[serde(rename = "$schema")]
pub schema: String,
Expand All @@ -32,13 +29,13 @@ pub struct ChainInfo {
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Genesis {
pub genesis_url: String,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Codebase {
pub git_repo: String,
pub recommended_version: String,
Expand All @@ -52,7 +49,7 @@ pub struct Codebase {
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Binaries {
#[serde(rename = "linux/amd64")]
pub linux_amd_64: String,
Expand All @@ -67,15 +64,15 @@ pub struct Binaries {
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Peers {
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub seeds: Vec<Seed>,
pub persistent_peers: Vec<PersistentPeer>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Seed {
pub id: String,
pub address: String,
Expand All @@ -89,7 +86,7 @@ pub struct PersistentPeer {
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Apis {
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub rpc: Vec<Rpc>,
Expand All @@ -99,35 +96,35 @@ pub struct Apis {
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Rpc {
pub address: String,
pub provider: Option<String>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Rest {
pub address: String,
pub provider: Option<String>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Grpc {
pub address: String,
pub provider: Option<String>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Fees {
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub fee_tokens: Vec<FeeToken>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct FeeToken {
pub denom: String,
pub fixed_min_gas_price: f32,
Expand All @@ -137,20 +134,20 @@ pub struct FeeToken {
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Staking {
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub staking_tokens: Vec<StakingToken>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct StakingToken {
pub denom: String,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(default,)]
#[serde(default)]
pub struct Explorer {
pub kind: String,
pub url: String,
Expand Down
189 changes: 0 additions & 189 deletions src/get.rs

This file was deleted.

11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
//!
//! #[tokio::main]
//! fn main() {
//! let chain = get_chain("osmosis").await.unwrap();
//! let assets = get_assets("osmosis").await.unwrap();
//! let osmosis_hub_path = get_path("osmosis", "cosmoshub").await.unwrap();
//! let registry = Registry::new(None);
//! let chain = registry.get_chain("osmosis").await.unwrap();
//! let assets = registry.get_assets("osmosis").await.unwrap();
//! let osmosis_hub_path = registry.get_path("osmosis", "cosmoshub").await.unwrap();
//! let mut config: BotConfig = chain.into();
//!
//! config.set_default_asset(assets[0]);
Expand Down Expand Up @@ -77,9 +78,9 @@ pub mod chain;
/// A cache type for reading IBC path data into memory for faster and filterable queries
pub mod cache;

/// API for getting and listing data from the registry Github repo
pub mod get;
pub mod github;
/// API for getting and listing data from the registry Github repo
pub mod registry;

/// Modles for IBC path JSON ser/de
pub mod paths;
Loading