-
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
Collin/chain name enum #18
Conversation
758c7ae
to
e20c132
Compare
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.
Not necessarily requesting changes, just some points to discuss potentially.
A slightly different way to approach this would be to have a type which provides a impl ChainId {
const AGORIC: ChainId = ChainId::new("agoric");
const AKASH: ChainId = ChainId::new("akash");
const ARKH: ChainId = ChainId::new("arkh");
[...]
} Using inherent constants the syntax is nearly identical to an enum: https://github.com/iqlusioninc/crates/blob/main/bip32/src/prefix.rs I'd otherwise recommend using I can open a PR upstream for that if this sounds interesting. |
'+ 1' on the const fn's I think that sounds pretty good. |
In PeggyJV/ocular#18 we are trying to create a registry of "well-known" chain IDs. I proposed using `tendermint::chain::Id` for this, but to do so we'd need to have a const initializer support. This commit changes the internal representation of `chain::Id` to `Cow<'static, str>`. This permits a `const fn` initializer, but avoids adding a lifetime to `chain::Id` itself. It also adds `chain::Id::new` which is defined as a `const fn`, which can be used to define chain ID constants.
I opened a PR to add a |
In PeggyJV/ocular#18 we are trying to create a registry of "well-known" chain IDs. I proposed using `tendermint::chain::Id` for this, but to do so we'd need to have a const initializer support. This commit changes the internal representation of `chain::Id` to `Cow<'static, str>`. This permits a `const fn` initializer, but avoids adding a lifetime to `chain::Id` itself. It also adds `chain::Id::new` which is defined as a `const fn`, which can be used to define chain ID constants.
In PeggyJV/ocular#18 we are trying to create a registry of "well-known" chain IDs. I proposed using `tendermint::chain::Id` for this, but to do so we'd need to have a const initializer support. This commit changes the internal representation of `chain::Id` to `Cow<'static, str>`. This permits a `const fn` initializer, but avoids adding a lifetime to `chain::Id` itself. It also adds `chain::Id::new` which is defined as a `const fn`, which can be used to define chain ID constants.
+1, neat solution. I'd expect chains to change relatively fast, cadence of say ~1/month, so I can imagine binding new constants while 99% of time using the well-known definitions. If we can rely on tendermint::chain::Id that would be even better. |
In PeggyJV/ocular#18 we are trying to create a registry of "well-known" chain IDs. I proposed using `tendermint::chain::Id` for this, but to do so we'd need to have a const initializer support. This commit changes the internal representation of `chain::Id` to `Cow<'static, str>`. This permits a `const fn` initializer, but avoids adding a lifetime to `chain::Id` itself. It also adds `chain::Id::new` which is defined as a `const fn`, which can be used to define chain ID constants.
In PeggyJV/ocular#18 we are trying to create a registry of "well-known" chain IDs. I proposed using `tendermint::chain::Id` for this, but to do so we'd need to have a const initializer support. This commit changes the internal representation of `chain::Id` to `Cow<'static, str>`. This permits a `const fn` initializer, but avoids adding a lifetime to `chain::Id` itself. It also adds `chain::Id::new` which is defined as a `const fn`, which can be used to define chain ID constants.
@@ -2,3 +2,58 @@ pub mod client; | |||
pub mod config; | |||
pub mod info; | |||
pub mod registry; | |||
|
|||
pub type ChainName = tendermint::chain::Id; |
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.
Why not just call this ChainId
to match the tendermint
name?
Also note that prefixing a type with the module it's contained in is non-idiomatic:
https://rust-lang.github.io/rfcs/0356-no-module-prefixes.html
I would suggest just re-exporting tendermint::chain::Id
here:
pub type ChainName = tendermint::chain::Id; | |
pub use tendermint::chain::Id; |
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.
My concern is that referring to the reference name as an ID will be conflating the chain-id
in the registry with the chain name, thus the type alias and rename to make it match the field in the registry chains.json
, rather than to prefix it with the module name. That's just a coincidence. Does that change your opinion?
No description provided.