-
Notifications
You must be signed in to change notification settings - Fork 3
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
Refactor registry module, add IBC path cache, paths API #63
Conversation
Replaced the remaining uses of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of nits and one comment around testing.
ocular/src/registry.rs
Outdated
|
||
async fn get_file_content(r#ref: &str, path: &str) -> Result<String, ChainRegistryError> { | ||
let url = format!( | ||
"https://raw.githubusercontent.com/cosmos/chain-registry/{}/{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should probably be a constant
ocular/src/registry/paths.rs
Outdated
pub struct Channel { | ||
#[serde(rename = "chain-1")] | ||
pub chain_1: Chain12, | ||
#[serde(rename = "chain-2")] | ||
pub chain_2: Chain22, | ||
pub ordering: String, | ||
pub version: String, | ||
pub tags: Tags, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
#[serde(default, rename_all = "camelCase")] | ||
pub struct Chain12 { | ||
#[serde(rename = "channel-id")] | ||
pub channel_id: String, | ||
#[serde(rename = "port-id")] | ||
pub port_id: String, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
#[serde(default, rename_all = "camelCase")] | ||
pub struct Chain22 { | ||
#[serde(rename = "channel-id")] | ||
pub channel_id: String, | ||
#[serde(rename = "port-id")] | ||
pub port_id: String, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Potentially renaming these to chain a & b (or some other convention) might be more clear than 1 & 2 as Chain12 & Chain22 read more as chain twelve and chain twenty two imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunate schema design forced this; I generated the structs with a webtool and it derived those names haha. How about ChainA, ChainAA, ChainB, ChainBB?
EDIT: I'll go with Chain1, ChannelChain1, etc
#[assay] | ||
async fn registry_cache_happy_path() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it might be a good idea to get an unhappy path test here to verify things fail as expected.
for pn in path_names { | ||
let cn: Vec<&str> = pn.split('-').collect(); | ||
|
||
// this unwrap is safe becauase we query the path directly from the list of path .json file names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I missed it but I don't see what line this is referring to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.expect("path returned None")
I may should just make it return an error just in case
Going to merge this and can tweak as needed when we hear back from the Hermes relayer team |
Closes #13 and #15
This PR does a number of things:
registry
module such that it is no longer underchain
, and moves the asset objects into into their ownregistry::assets
submodule.raw.githubusercontent.com
file endpoints for single-file retrieval such as forget_chain()
andget_assets()
. The octocrab crate is still used for getting the list of IBC path and chain names.registry-cache
feature which houses theRegistryCache
type.get_path(chain_a, chain_b)
method. The former will make a network call to the chain registry github repo, the latter will use the already-cached data. This allows a path to be queried pairwise even without the cache feature enabled. To retrieve all paths with a given tag, the cache must be used.