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

tari-project / tari / 17542535568

08 Sep 2025 07:01AM UTC coverage: 61.111% (-0.08%) from 61.19%
17542535568

push

github

web-flow
chore: improvements needed in new wallet  (#7471)

Description
---
Moved historical blocks out of tari core so that wallet can access them
without needing tari core
Created legacy transaction status for current wallet to use, with new
simplified transaction status for new wallet
Changed `try_output_key_recovery` top use private key and not key id
Add new wallet output constructor


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- New Features
- Dual support for legacy and new transaction statuses across gRPC,
wallet, and FFI.
  - Wallet seed birthday accessor added.
- Wallet can import existing outputs via a new imported-output
constructor.
- Exposed MAX_ENCRYPTED_DATA_SIZE and added Borsh serialization for
MemoField.

- Refactor
- Block-related types moved to a shared component and a builder-based
API introduced for accumulated header data.
  - Broad import-path and module surface cleanups.

- Breaking Changes
- Wallet and related APIs now use
LegacyTransactionStatus/LegacyImportStatus.
- Key-recovery APIs now accept an owned PrivateKey instead of a key ID.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

125 of 424 new or added lines in 22 files covered. (29.48%)

28 existing lines in 8 files now uncovered.

72887 of 119270 relevant lines covered (61.11%)

300900.42 hits per line

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

76.92
/base_layer/node_components/src/blocks/chain_block.rs
1
//  Copyright 2025, 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, fmt::Display, sync::Arc};
24

25
use tari_common_types::types::HashOutput;
26
use tari_transaction_components::aggregated_body::AggregateBody;
27

28
use crate::blocks::{Block, BlockHeader, BlockHeaderAccumulatedData};
29

30
/// A block linked to a chain.
31
/// A ChainBlock MUST have the same or stronger guarantees than `ChainHeader`
32
#[derive(Debug, Clone, PartialEq)]
33
pub struct ChainBlock {
34
    accumulated_data: BlockHeaderAccumulatedData,
35
    block: Arc<Block>,
36
}
37

38
impl Display for ChainBlock {
NEW
39
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
NEW
40
        writeln!(f, "{}", self.accumulated_data)?;
×
NEW
41
        writeln!(f, "{}", self.block)?;
×
NEW
42
        Ok(())
×
NEW
43
    }
×
44
}
45

46
impl ChainBlock {
47
    /// Attempts to construct a `ChainBlock` from a `Block` and associate `BlockHeaderAccumulatedData`. Returns None if
48
    /// the Block and the BlockHeaderAccumulatedData do not correspond (i.e have different hashes)
49
    pub fn try_construct(block: Arc<Block>, accumulated_data: BlockHeaderAccumulatedData) -> Option<Self> {
842✔
50
        if accumulated_data.hash != block.hash() {
842✔
NEW
51
            return None;
×
52
        }
842✔
53

842✔
54
        Some(Self {
842✔
55
            accumulated_data,
842✔
56
            block,
842✔
57
        })
842✔
58
    }
842✔
59

60
    pub fn height(&self) -> u64 {
283✔
61
        self.block.header.height
283✔
62
    }
283✔
63

64
    pub fn hash(&self) -> &HashOutput {
539✔
65
        &self.accumulated_data.hash
539✔
66
    }
539✔
67

68
    /// Returns a reference to the inner block
69
    pub fn block(&self) -> &Block {
911✔
70
        &self.block
911✔
71
    }
911✔
72

73
    /// Returns a reference to the inner block's header
74
    pub fn header(&self) -> &BlockHeader {
2,700✔
75
        &self.block.header
2,700✔
76
    }
2,700✔
77

78
    /// Returns the inner block wrapped in an atomically reference counted (ARC) pointer. This call is cheap and does
79
    /// not copy the block in memory.
80
    pub fn to_arc_block(&self) -> Arc<Block> {
271✔
81
        self.block.clone()
271✔
82
    }
271✔
83

84
    pub fn accumulated_data(&self) -> &BlockHeaderAccumulatedData {
1,075✔
85
        &self.accumulated_data
1,075✔
86
    }
1,075✔
87

88
    pub fn to_chain_header(&self) -> ChainHeader {
476✔
89
        // NOTE: Panic is impossible, a ChainBlock cannot be constructed if inconsistencies between the header and
476✔
90
        // accum data exist
476✔
91
        ChainHeader::try_construct(self.block.header.clone(), self.accumulated_data.clone()).unwrap()
476✔
92
    }
476✔
93
}
94

95
/// A block linked to a chain.
96
/// A ChainHeader guarantees (i.e cannot be constructed) that the block and accumulated data correspond by hash.
97
#[derive(Debug, Clone, PartialEq)]
98
pub struct ChainHeader {
99
    header: BlockHeader,
100
    accumulated_data: BlockHeaderAccumulatedData,
101
}
102

103
impl Display for ChainHeader {
NEW
104
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
NEW
105
        writeln!(f, "{}", self.header)?;
×
NEW
106
        writeln!(f, "{}", self.accumulated_data)?;
×
NEW
107
        Ok(())
×
NEW
108
    }
×
109
}
110

111
impl ChainHeader {
112
    /// Attempts to construct a `ChainHeader` from a `BlockHeader` and associate `BlockHeaderAccumulatedData`. Returns
113
    /// None if the Block and the BlockHeaderAccumulatedData do not correspond (i.e have different hashes)
114
    pub fn try_construct(header: BlockHeader, accumulated_data: BlockHeaderAccumulatedData) -> Option<Self> {
3,223✔
115
        if accumulated_data.hash != header.hash() {
3,223✔
116
            return None;
1✔
117
        }
3,222✔
118

3,222✔
119
        Some(Self {
3,222✔
120
            header,
3,222✔
121
            accumulated_data,
3,222✔
122
        })
3,222✔
123
    }
3,223✔
124

125
    pub fn height(&self) -> u64 {
1,306✔
126
        self.header.height
1,306✔
127
    }
1,306✔
128

129
    pub fn timestamp(&self) -> u64 {
571✔
130
        self.header.timestamp.as_u64()
571✔
131
    }
571✔
132

133
    pub fn hash(&self) -> &HashOutput {
995✔
134
        &self.accumulated_data.hash
995✔
135
    }
995✔
136

137
    pub fn header(&self) -> &BlockHeader {
3,105✔
138
        &self.header
3,105✔
139
    }
3,105✔
140

141
    pub fn accumulated_data(&self) -> &BlockHeaderAccumulatedData {
1,230✔
142
        &self.accumulated_data
1,230✔
143
    }
1,230✔
144

145
    pub fn into_parts(self) -> (BlockHeader, BlockHeaderAccumulatedData) {
158✔
146
        (self.header, self.accumulated_data)
158✔
147
    }
158✔
148

NEW
149
    pub fn into_header(self) -> BlockHeader {
×
NEW
150
        self.header
×
NEW
151
    }
×
152

NEW
153
    pub fn upgrade_to_chain_block(self, body: AggregateBody) -> ChainBlock {
×
NEW
154
        // NOTE: Panic cannot occur because a ChainBlock has the same guarantees as ChainHeader
×
NEW
155
        ChainBlock::try_construct(Arc::new(Block::new(self.header, body)), self.accumulated_data).unwrap()
×
NEW
156
    }
×
157
}
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