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

tari-project / tari / 17033178607

18 Aug 2025 06:45AM UTC coverage: 54.49% (-0.007%) from 54.497%
17033178607

push

github

stringhandler
Merge branch 'development' of github.com:tari-project/tari into odev

971 of 2923 new or added lines in 369 files covered. (33.22%)

5804 existing lines in 173 files now uncovered.

76688 of 140739 relevant lines covered (54.49%)

193850.18 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::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},
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};
44
        let response = match self {
×
45
            BlockResponse(block) => NodeCommsResponse::Block(Box::new(block.try_into()?)),
×
46
            FetchMempoolTransactionsByExcessSigsResponse(response) => {
×
47
                let transactions = response
×
48
                    .transactions
×
49
                    .into_iter()
×
50
                    .map(|tx| tx.try_into().map(Arc::new))
×
51
                    .collect::<Result<_, _>>()?;
×
52
                let not_found = response
×
53
                    .not_found
×
54
                    .into_iter()
×
55
                    .map(|bytes| {
×
56
                        PrivateKey::from_canonical_bytes(&bytes).map_err(|_| "Malformed excess signature".to_string())
×
57
                    })
×
58
                    .collect::<Result<_, _>>()?;
×
59
                NodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(
×
60
                    self::FetchMempoolTransactionsResponse {
×
61
                        transactions,
×
62
                        not_found,
×
63
                    },
×
64
                )
×
65
            },
66
        };
67

68
        Ok(response)
×
69
    }
×
70
}
71

72
impl TryFrom<NodeCommsResponse> for ProtoNodeCommsResponse {
73
    type Error = String;
74

75
    fn try_from(response: NodeCommsResponse) -> Result<Self, Self::Error> {
×
76
        use NodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse;
77
        match response {
×
78
            NodeCommsResponse::Block(block) => Ok(ProtoNodeCommsResponse::BlockResponse((*block).try_into()?)),
×
79
            FetchMempoolTransactionsByExcessSigsResponse(resp) => {
×
80
                let transactions = resp
×
81
                    .transactions
×
82
                    .into_iter()
×
83
                    .map(|tx| tx.try_into())
×
84
                    .collect::<Result<_, _>>()?;
×
85
                Ok(ProtoNodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(
×
86
                    proto::base_node::FetchMempoolTransactionsResponse {
×
87
                        transactions,
×
88
                        not_found: resp.not_found.into_iter().map(|s| s.to_vec()).collect(),
×
89
                    },
×
90
                ))
×
91
            },
92
            // This would only occur if a programming error sent out the unsupported response
NEW
93
            resp => Err(format!("Response not supported {resp:?}")),
×
94
        }
95
    }
×
96
}
97

98
impl From<Option<BlockHeader>> for proto::base_node::BlockHeaderResponse {
99
    fn from(v: Option<BlockHeader>) -> Self {
×
100
        Self {
×
101
            header: v.map(Into::into),
×
102
        }
×
103
    }
×
104
}
105

106
impl TryInto<Option<BlockHeader>> for proto::base_node::BlockHeaderResponse {
107
    type Error = String;
108

109
    fn try_into(self) -> Result<Option<BlockHeader>, Self::Error> {
×
110
        match self.header {
×
111
            Some(header) => {
×
112
                let header = header.try_into()?;
×
113
                Ok(Some(header))
×
114
            },
115
            None => Ok(None),
×
116
        }
117
    }
×
118
}
119
impl TryFrom<Option<Block>> for proto::base_node::BlockResponse {
120
    type Error = String;
121

122
    fn try_from(v: Option<Block>) -> Result<Self, Self::Error> {
×
123
        Ok(Self {
×
124
            block: v.map(TryInto::try_into).transpose()?,
×
125
        })
126
    }
×
127
}
128

129
impl TryInto<Option<Block>> for proto::base_node::BlockResponse {
130
    type Error = String;
131

132
    fn try_into(self) -> Result<Option<Block>, Self::Error> {
×
133
        match self.block {
×
134
            Some(block) => {
×
135
                let block = block.try_into()?;
×
136
                Ok(Some(block))
×
137
            },
138
            None => Ok(None),
×
139
        }
140
    }
×
141
}
142

143
//---------------------------------- Collection impls --------------------------------------------//
144

145
// The following allow `Iterator::collect` to collect into these repeated types
146

147
impl FromIterator<proto::types::TransactionKernel> for proto::base_node::TransactionKernels {
148
    fn from_iter<T: IntoIterator<Item = proto::types::TransactionKernel>>(iter: T) -> Self {
×
149
        Self {
×
150
            kernels: iter.into_iter().collect(),
×
151
        }
×
152
    }
×
153
}
154

155
impl FromIterator<proto::core::BlockHeader> for proto::base_node::BlockHeaders {
156
    fn from_iter<T: IntoIterator<Item = proto::core::BlockHeader>>(iter: T) -> Self {
×
157
        Self {
×
158
            headers: iter.into_iter().collect(),
×
159
        }
×
160
    }
×
161
}
162

163
impl FromIterator<proto::types::TransactionOutput> for proto::base_node::TransactionOutputs {
164
    fn from_iter<T: IntoIterator<Item = proto::types::TransactionOutput>>(iter: T) -> Self {
×
165
        Self {
×
166
            outputs: iter.into_iter().collect(),
×
167
        }
×
168
    }
×
169
}
170

171
impl FromIterator<proto::core::HistoricalBlock> for proto::base_node::HistoricalBlocks {
172
    fn from_iter<T: IntoIterator<Item = proto::core::HistoricalBlock>>(iter: T) -> Self {
×
173
        Self {
×
174
            blocks: iter.into_iter().collect(),
×
175
        }
×
176
    }
×
177
}
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