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

tari-project / tari / 16123384529

07 Jul 2025 05:11PM UTC coverage: 64.327% (-7.6%) from 71.89%
16123384529

push

github

web-flow
chore: new release v4.9.0-pre.0 (#7289)

Description
---
new release esmeralda

77151 of 119935 relevant lines covered (64.33%)

227108.34 hits per line

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

0.0
/base_layer/core/src/base_node/proto/response.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::{
24
    convert::{TryFrom, TryInto},
25
    iter::FromIterator,
26
    sync::Arc,
27
};
28

29
use tari_common_types::types::PrivateKey;
30
use tari_utilities::{convert::try_convert_all, ByteArray};
31

32
pub use crate::proto::base_node::base_node_service_response::Response as ProtoNodeCommsResponse;
33
use crate::{
34
    base_node::comms_interface::{FetchMempoolTransactionsResponse, NodeCommsResponse},
35
    blocks::{Block, BlockHeader, HistoricalBlock},
36
    proto,
37
};
38

39
impl TryInto<NodeCommsResponse> for ProtoNodeCommsResponse {
40
    type Error = String;
41

42
    fn try_into(self) -> Result<NodeCommsResponse, Self::Error> {
×
43
        use ProtoNodeCommsResponse::{BlockResponse, FetchMempoolTransactionsByExcessSigsResponse, HistoricalBlocks};
44
        let response = match self {
×
45
            BlockResponse(block) => NodeCommsResponse::Block(Box::new(block.try_into()?)),
×
46
            HistoricalBlocks(blocks) => {
×
47
                let blocks = try_convert_all(blocks.blocks)?;
×
48
                NodeCommsResponse::HistoricalBlocks(blocks)
×
49
            },
50
            FetchMempoolTransactionsByExcessSigsResponse(response) => {
×
51
                let transactions = response
×
52
                    .transactions
×
53
                    .into_iter()
×
54
                    .map(|tx| tx.try_into().map(Arc::new))
×
55
                    .collect::<Result<_, _>>()?;
×
56
                let not_found = response
×
57
                    .not_found
×
58
                    .into_iter()
×
59
                    .map(|bytes| {
×
60
                        PrivateKey::from_canonical_bytes(&bytes).map_err(|_| "Malformed excess signature".to_string())
×
61
                    })
×
62
                    .collect::<Result<_, _>>()?;
×
63
                NodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(
×
64
                    self::FetchMempoolTransactionsResponse {
×
65
                        transactions,
×
66
                        not_found,
×
67
                    },
×
68
                )
×
69
            },
70
        };
71

72
        Ok(response)
×
73
    }
×
74
}
75

76
impl TryFrom<NodeCommsResponse> for ProtoNodeCommsResponse {
77
    type Error = String;
78

79
    fn try_from(response: NodeCommsResponse) -> Result<Self, Self::Error> {
×
80
        use NodeCommsResponse::{FetchMempoolTransactionsByExcessSigsResponse, HistoricalBlocks};
81
        match response {
×
82
            NodeCommsResponse::Block(block) => Ok(ProtoNodeCommsResponse::BlockResponse((*block).try_into()?)),
×
83
            HistoricalBlocks(historical_blocks) => {
×
84
                let historical_blocks = historical_blocks
×
85
                    .into_iter()
×
86
                    .map(TryInto::try_into)
×
87
                    .collect::<Result<Vec<proto::core::HistoricalBlock>, _>>()?
×
88
                    .into_iter()
×
89
                    .collect();
×
90
                Ok(ProtoNodeCommsResponse::HistoricalBlocks(historical_blocks))
×
91
            },
92
            FetchMempoolTransactionsByExcessSigsResponse(resp) => {
×
93
                let transactions = resp
×
94
                    .transactions
×
95
                    .into_iter()
×
96
                    .map(|tx| tx.try_into())
×
97
                    .collect::<Result<_, _>>()?;
×
98
                Ok(ProtoNodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(
×
99
                    proto::base_node::FetchMempoolTransactionsResponse {
×
100
                        transactions,
×
101
                        not_found: resp.not_found.into_iter().map(|s| s.to_vec()).collect(),
×
102
                    },
×
103
                ))
×
104
            },
105
            // This would only occur if a programming error sent out the unsupported response
106
            resp => Err(format!("Response not supported {:?}", resp)),
×
107
        }
108
    }
×
109
}
110

111
impl From<Option<BlockHeader>> for proto::base_node::BlockHeaderResponse {
112
    fn from(v: Option<BlockHeader>) -> Self {
×
113
        Self {
×
114
            header: v.map(Into::into),
×
115
        }
×
116
    }
×
117
}
118

119
impl TryInto<Option<BlockHeader>> for proto::base_node::BlockHeaderResponse {
120
    type Error = String;
121

122
    fn try_into(self) -> Result<Option<BlockHeader>, Self::Error> {
×
123
        match self.header {
×
124
            Some(header) => {
×
125
                let header = header.try_into()?;
×
126
                Ok(Some(header))
×
127
            },
128
            None => Ok(None),
×
129
        }
130
    }
×
131
}
132

133
impl TryFrom<Option<HistoricalBlock>> for proto::base_node::HistoricalBlockResponse {
134
    type Error = String;
135

136
    fn try_from(v: Option<HistoricalBlock>) -> Result<Self, Self::Error> {
×
137
        Ok(Self {
×
138
            block: v.map(TryInto::try_into).transpose()?,
×
139
        })
140
    }
×
141
}
142

143
impl TryInto<Option<HistoricalBlock>> for proto::base_node::HistoricalBlockResponse {
144
    type Error = String;
145

146
    fn try_into(self) -> Result<Option<HistoricalBlock>, Self::Error> {
×
147
        match self.block {
×
148
            Some(block) => {
×
149
                let block = block.try_into()?;
×
150
                Ok(Some(block))
×
151
            },
152
            None => Ok(None),
×
153
        }
154
    }
×
155
}
156

157
impl TryFrom<Option<Block>> for proto::base_node::BlockResponse {
158
    type Error = String;
159

160
    fn try_from(v: Option<Block>) -> Result<Self, Self::Error> {
×
161
        Ok(Self {
×
162
            block: v.map(TryInto::try_into).transpose()?,
×
163
        })
164
    }
×
165
}
166

167
impl TryInto<Option<Block>> for proto::base_node::BlockResponse {
168
    type Error = String;
169

170
    fn try_into(self) -> Result<Option<Block>, Self::Error> {
×
171
        match self.block {
×
172
            Some(block) => {
×
173
                let block = block.try_into()?;
×
174
                Ok(Some(block))
×
175
            },
176
            None => Ok(None),
×
177
        }
178
    }
×
179
}
180

181
//---------------------------------- Collection impls --------------------------------------------//
182

183
// The following allow `Iterator::collect` to collect into these repeated types
184

185
impl FromIterator<proto::types::TransactionKernel> for proto::base_node::TransactionKernels {
186
    fn from_iter<T: IntoIterator<Item = proto::types::TransactionKernel>>(iter: T) -> Self {
×
187
        Self {
×
188
            kernels: iter.into_iter().collect(),
×
189
        }
×
190
    }
×
191
}
192

193
impl FromIterator<proto::core::BlockHeader> for proto::base_node::BlockHeaders {
194
    fn from_iter<T: IntoIterator<Item = proto::core::BlockHeader>>(iter: T) -> Self {
×
195
        Self {
×
196
            headers: iter.into_iter().collect(),
×
197
        }
×
198
    }
×
199
}
200

201
impl FromIterator<proto::types::TransactionOutput> for proto::base_node::TransactionOutputs {
202
    fn from_iter<T: IntoIterator<Item = proto::types::TransactionOutput>>(iter: T) -> Self {
×
203
        Self {
×
204
            outputs: iter.into_iter().collect(),
×
205
        }
×
206
    }
×
207
}
208

209
impl FromIterator<proto::core::HistoricalBlock> for proto::base_node::HistoricalBlocks {
210
    fn from_iter<T: IntoIterator<Item = proto::core::HistoricalBlock>>(iter: T) -> Self {
×
211
        Self {
×
212
            blocks: iter.into_iter().collect(),
×
213
        }
×
214
    }
×
215
}
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