• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 17834551818

18 Sep 2025 04:04PM UTC coverage: 60.651% (-0.3%) from 60.975%
17834551818

push

github

SWvheerden
chore: new release v5.1.0-pre.1

74207 of 122350 relevant lines covered (60.65%)

293003.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_layer/node_components/src/blocks/new_blockheader_template.rs
1
// Copyright 2019. The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22

23
use std::fmt::{Display, Error, Formatter};
24

25
use borsh::{BorshDeserialize, BorshSerialize};
26
use serde::{Deserialize, Serialize};
27
use tari_common_types::types::{BlockHash, PrivateKey};
28
use tari_transaction_components::tari_proof_of_work::ProofOfWork;
29
use tari_utilities::hex::Hex;
30

31
use crate::blocks::block_header::BlockHeader;
32
/// The NewBlockHeaderTemplate is used for the construction of a new mineable block. It contains all the metadata for
33
/// the block that the Base Node is able to complete on behalf of a Miner.
34
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, BorshSerialize, BorshDeserialize)]
×
35
pub struct NewBlockHeaderTemplate {
36
    /// Version of the block
37
    pub version: u16,
38
    /// Height of this block since the genesis block (height 0)
39
    pub height: u64,
40
    /// Hash of the block previous to this in the chain.
41
    pub prev_hash: BlockHash,
42
    /// Total accumulated sum of kernel offsets since genesis block. We can derive the kernel offset sum for *this*
43
    /// block from the total kernel offset of the previous block header.
44
    pub total_kernel_offset: PrivateKey,
45
    /// Sum of script offsets for all kernels in this block.
46
    pub total_script_offset: PrivateKey,
47
    /// Proof of work summary
48
    pub pow: ProofOfWork,
49
}
50

51
impl NewBlockHeaderTemplate {
52
    pub(crate) fn from_header(header: BlockHeader) -> Self {
×
53
        Self {
×
54
            version: header.version,
×
55
            height: header.height,
×
56
            prev_hash: header.prev_hash,
×
57
            total_kernel_offset: header.total_kernel_offset,
×
58
            total_script_offset: header.total_script_offset,
×
59
            pow: header.pow,
×
60
        }
×
61
    }
×
62

63
    pub fn empty() -> Self {
×
64
        Self {
×
65
            version: 0,
×
66
            height: 0,
×
67
            prev_hash: Default::default(),
×
68
            total_kernel_offset: Default::default(),
×
69
            total_script_offset: Default::default(),
×
70
            pow: Default::default(),
×
71
        }
×
72
    }
×
73
}
74

75
impl Display for NewBlockHeaderTemplate {
76
    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
×
77
        let msg = format!(
×
78
            "Version: {}\nBlock height: {}\nPrevious block hash: {}\n",
×
79
            self.version, self.height, self.prev_hash,
×
80
        );
×
81
        fmt.write_str(&msg)?;
×
82
        fmt.write_str(&format!(
×
83
            "Total offset: {}\nTotal script offset: {}\nProof of work: {}",
×
84
            self.total_kernel_offset.to_hex(),
×
85
            self.total_script_offset.to_hex(),
×
86
            self.pow
×
87
        ))
×
88
    }
×
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc