use std::ops::{Deref, DerefMut};
use namada_core::address::Address;
use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use namada_core::chain::BlockHeight;
use namada_core::collections::HashSet;
use namada_core::key::common;
use namada_core::key::common::Signature;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
use namada_migrations::*;
use namada_tx::Signed;
#[derive(
Debug,
Clone,
PartialEq,
PartialOrd,
Ord,
Eq,
Hash,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
)]
pub struct BridgePoolRootVext {
pub validator_addr: Address,
pub block_height: BlockHeight,
pub sig: Signature,
}
pub type Vext = BridgePoolRootVext;
#[derive(
Clone,
Debug,
BorshSerialize,
BorshSchema,
BorshDeserialize,
BorshDeserializer,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
)]
pub struct SignedVext(pub Signed<BridgePoolRootVext>);
impl Deref for SignedVext {
type Target = Signed<BridgePoolRootVext>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<Signed<BridgePoolRootVext>> for SignedVext {
fn from(value: Signed<BridgePoolRootVext>) -> Self {
Self(value)
}
}
impl Vext {
#[inline]
pub fn sign(&self, sk: &common::SecretKey) -> SignedVext {
SignedVext(Signed::new(sk, self.clone()))
}
}
#[derive(
Debug,
Default,
Clone,
PartialEq,
Eq,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
)]
pub struct MultiSignedVext(pub HashSet<SignedVext>);
impl Deref for MultiSignedVext {
type Target = HashSet<SignedVext>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for MultiSignedVext {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl IntoIterator for MultiSignedVext {
type IntoIter = namada_core::collections::hash_set::IntoIter<SignedVext>;
type Item = SignedVext;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl From<SignedVext> for MultiSignedVext {
fn from(vext: SignedVext) -> Self {
Self(HashSet::from([vext]))
}
}