// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

mod header;
pub use header::{Header, Seed};

mod block;
pub use block::*;

mod transaction;
pub use transaction::{
    CanonicalTransaction, LedgerTransaction, SpendingId, SpentTransaction,
};

mod faults;
pub use faults::{Fault, InvalidFault, Slash, SlashType};

mod attestation;
use std::io::{self, Read, Write};

pub use attestation::{
    Attestation, IterationInfo, IterationsInfo, Signature, StepVotes,
};
#[cfg(any(feature = "faker", test))]
use fake::{Dummy, Fake, Faker};
use sha3::Digest;

use crate::Serializable;
use crate::bls::PublicKeyBytes;

/// Encode a byte array into a shortened HEX representation.
pub fn to_str(bytes: &[u8]) -> String {
    const OFFSET: usize = 16;
    let hex = hex::encode(bytes);
    if bytes.len() <= OFFSET {
        return hex;
    }

    let len = hex.len();

    let first = &hex[0..OFFSET];
    let last = &hex[len - OFFSET..];

    format!("{first}...{last}")
}

#[cfg(any(feature = "faker", test))]
pub mod faker {
    pub use super::transaction::faker::gen_dummy_tx;
}
