unc_jsonrpc_primitives/types/
receipts.rs

1#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
2pub struct ReceiptReference {
3    pub receipt_id: unc_primitives::hash::CryptoHash,
4}
5
6#[derive(serde::Serialize, serde::Deserialize, Debug)]
7pub struct RpcReceiptRequest {
8    #[serde(flatten)]
9    pub receipt_reference: ReceiptReference,
10}
11
12#[derive(serde::Serialize, serde::Deserialize, Debug)]
13pub struct RpcReceiptResponse {
14    #[serde(flatten)]
15    pub receipt_view: unc_primitives::views::ReceiptView,
16}
17
18#[derive(thiserror::Error, Debug, serde::Serialize, serde::Deserialize)]
19#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
20pub enum RpcReceiptError {
21    #[error("The node reached its limits. Try again later. More details: {error_message}")]
22    InternalError { error_message: String },
23    #[error("Receipt with id {receipt_id} has never been observed on this node")]
24    UnknownReceipt { receipt_id: unc_primitives::hash::CryptoHash },
25}
26
27impl From<RpcReceiptError> for crate::errors::RpcError {
28    fn from(error: RpcReceiptError) -> Self {
29        let error_data = match serde_json::to_value(error) {
30            Ok(value) => value,
31            Err(err) => {
32                return Self::new_internal_error(
33                    None,
34                    format!("Failed to serialize RpcReceiptError: {:?}", err),
35                )
36            }
37        };
38        Self::new_internal_or_handler_error(Some(error_data.clone()), error_data)
39    }
40}