casper_types/system/auction/
bridge.rsuse alloc::vec::Vec;
use crate::{
bytesrepr::{self, FromBytes, ToBytes},
CLType, CLTyped, EraId, PublicKey,
};
#[cfg(feature = "datasize")]
use datasize::DataSize;
#[cfg(feature = "json-schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "datasize", derive(DataSize))]
#[cfg_attr(feature = "json-schema", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct Bridge {
old_validator_public_key: PublicKey,
new_validator_public_key: PublicKey,
era_id: EraId,
}
impl Bridge {
pub fn new(
old_validator_public_key: PublicKey,
new_validator_public_key: PublicKey,
era_id: EraId,
) -> Self {
Self {
old_validator_public_key,
new_validator_public_key,
era_id,
}
}
pub fn old_validator_public_key(&self) -> &PublicKey {
&self.old_validator_public_key
}
pub fn new_validator_public_key(&self) -> &PublicKey {
&self.new_validator_public_key
}
pub fn era_id(&self) -> &EraId {
&self.era_id
}
}
impl CLTyped for Bridge {
fn cl_type() -> CLType {
CLType::Any
}
}
impl ToBytes for Bridge {
fn to_bytes(&self) -> Result<Vec<u8>, bytesrepr::Error> {
let mut result = bytesrepr::allocate_buffer(self)?;
self.write_bytes(&mut result)?;
Ok(result)
}
fn serialized_length(&self) -> usize {
self.old_validator_public_key.serialized_length()
+ self.new_validator_public_key.serialized_length()
+ self.era_id.serialized_length()
}
fn write_bytes(&self, writer: &mut Vec<u8>) -> Result<(), bytesrepr::Error> {
self.old_validator_public_key.write_bytes(writer)?;
self.new_validator_public_key.write_bytes(writer)?;
self.era_id.write_bytes(writer)?;
Ok(())
}
}
impl FromBytes for Bridge {
fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> {
let (old_validator_public_key, bytes) = FromBytes::from_bytes(bytes)?;
let (new_validator_public_key, bytes) = FromBytes::from_bytes(bytes)?;
let (era_id, bytes) = FromBytes::from_bytes(bytes)?;
Ok((
Bridge {
old_validator_public_key,
new_validator_public_key,
era_id,
},
bytes,
))
}
}