tendermint/public_key/
pub_key_request.rsuse crate::{chain::Id as ChainId, prelude::*};
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct PubKeyRequest {
pub chain_id: ChainId,
}
tendermint_pb_modules! {
use super::PubKeyRequest;
use crate::{chain::Id as ChainId, prelude::*};
use pb::privval::PubKeyRequest as RawPubKeyRequest;
impl Protobuf<RawPubKeyRequest> for PubKeyRequest {}
impl TryFrom<RawPubKeyRequest> for PubKeyRequest {
type Error = crate::Error;
fn try_from(value: RawPubKeyRequest) -> Result<Self, Self::Error> {
Ok(PubKeyRequest {
chain_id: ChainId::try_from(value.chain_id)?,
})
}
}
impl From<PubKeyRequest> for RawPubKeyRequest {
fn from(value: PubKeyRequest) -> Self {
RawPubKeyRequest {
chain_id: value.chain_id.as_str().to_string(),
}
}
}
}
#[cfg(test)]
mod tests {
tendermint_pb_modules! {
use super::super::PubKeyRequest;
use pb::privval::PubKeyRequest as RawPubKeyRequest;
use crate::{chain::Id as ChainId, prelude::*};
use core::str::FromStr;
#[test]
fn test_empty_pubkey_msg() {
let want: Vec<u8> = vec![10, 1, 65];
let msg = PubKeyRequest {
chain_id: ChainId::from_str("A").unwrap(),
};
let mut got = vec![];
Protobuf::<RawPubKeyRequest>::encode(msg.clone(), &mut got).unwrap();
assert_eq!(got, want);
match <PubKeyRequest as Protobuf<RawPubKeyRequest>>::decode(want.as_ref()) {
Ok(have) => assert_eq!(have, msg),
Err(err) => panic!("{}", err.to_string()),
}
}
}
}