Struct ChainId
pub struct ChainId {
pub id: String,
pub version: u64,
}
Expand description
This type is subject to future changes.
TODO: ChainId validation is not standardized yet.
is_epoch_format
will most likely be replaced by validate_chain_id()-style function.
See: https://github.com/informalsystems/ibc-rs/pull/304#discussion_r503917283.
Also, contrast with tendermint-rs ChainId
type.
Fields§
§id: String
§version: u64
Implementations§
§impl ChainId
impl ChainId
pub fn new(name: String, version: u64) -> ChainId
pub fn new(name: String, version: u64) -> ChainId
Creates a new ChainId
given a chain name and an epoch number.
The returned ChainId
will have the format: {chain name}-{epoch number}
.
let epoch_number = 10;
let id = ChainId::new("chainA".to_string(), epoch_number);
assert_eq!(id.version(), epoch_number);
pub fn from_string(id: &str) -> ChainId
pub fn chain_version(chain_id: &str) -> u64
pub fn chain_version(chain_id: &str) -> u64
Extract the version from the given chain identifier.
assert_eq!(ChainId::chain_version("chain--a-0"), 0);
assert_eq!(ChainId::chain_version("ibc-10"), 10);
assert_eq!(ChainId::chain_version("cosmos-hub-97"), 97);
assert_eq!(ChainId::chain_version("testnet-helloworld-2"), 2);
pub fn is_epoch_format(chain_id: &str) -> bool
pub fn is_epoch_format(chain_id: &str) -> bool
is_epoch_format() checks if a chain_id is in the format required for parsing epochs
The chainID must be in the form: {chainID}-{version}
assert_eq!(ChainId::is_epoch_format("chainA-0"), false);
assert_eq!(ChainId::is_epoch_format("chainA"), false);
assert_eq!(ChainId::is_epoch_format("chainA-1"), true);
assert_eq!(ChainId::is_epoch_format("c-1"), true);
pub fn with_version(self, version: u64) -> ChainId
pub fn with_version(self, version: u64) -> ChainId
with_version() checks if a chain_id is in the format required for parsing epochs, and if so replaces it’s version with the specified version
assert_eq!(ChainId::new("chainA".to_string(), 1).with_version(2), ChainId::new("chainA".to_string(), 2));
assert_eq!("chain1".parse::<ChainId>().unwrap().with_version(2), "chain1".parse::<ChainId>().unwrap());
Trait Implementations§
§impl<'de> Deserialize<'de> for ChainId
impl<'de> Deserialize<'de> for ChainId
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChainId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChainId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Ord for ChainId
impl Ord for ChainId
§impl PartialOrd for ChainId
impl PartialOrd for ChainId
§impl Serialize for ChainId
impl Serialize for ChainId
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for ChainId
impl StructuralPartialEq for ChainId
Auto Trait Implementations§
impl Freeze for ChainId
impl RefUnwindSafe for ChainId
impl Send for ChainId
impl Sync for ChainId
impl Unpin for ChainId
impl UnwindSafe for ChainId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request