[][src]Trait core_cbc_casper::blockchain::BlockData

pub trait BlockData: Hash + Clone + Eq + Send + Sync + Default + Serialize {
    type ValidatorName: ValidatorName;
    fn validator_name(&self) -> &Self::ValidatorName;
}

This trait must be implemented on a data type that is to be held by a Block<D>.

Example

use core_cbc_casper::blockchain::{Block, BlockData};
use core_cbc_casper::validator;

type ValidatorName = i32;

#[derive(Hash, Clone, PartialEq, Eq, Default, Debug, serde_derive::Serialize)]
struct StringBlockData {
    data: String,
    validator: ValidatorName,
}

impl BlockData for StringBlockData {
    type ValidatorName = ValidatorName;

    fn validator_name(&self) -> &Self::ValidatorName {
        &self.validator
    }
}

assert_eq!(
    Block::new(
        None,
        StringBlockData { data: "Hello, World!".to_string(), validator: 0 },
    ).data(),
    StringBlockData { data: "Hello, World!".to_string(), validator: 0 },
);

Associated Types

type ValidatorName: ValidatorName

The type of validators that can produce data of this type.

Loading content...

Required methods

fn validator_name(&self) -> &Self::ValidatorName

The name of the validator that produced the block containing this data.

Loading content...

Implementors

Loading content...