1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Fetches a receipt by it's ID
//!
//! The `RpcReceiptRequest` takes in a [`ReceiptReference`](https://docs.rs/unc-jsonrpc-primitives/0.12.0/unc_jsonrpc_primitives/types/receipts/struct.ReceiptReference.html)
//!
//! ## Example
//!
//! Returns the receipt for this [transaction](https://explorer.unc.org/transactions/4nVcmhWkV8Y3uJp9VQWrJhfesncJERfrvt9WwDi77oEJ#3B5PPT9EKj5352Wks9GnCeSUBDsVvSF4ceMQv2nEULTf) on mainnet.
//!
//! ```
//! use unc_jsonrpc_client::{methods, JsonRpcClient};
//! use unc_jsonrpc_primitives::types::receipts::ReceiptReference;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.unc.org");
//!
//! let request = methods::EXPERIMENTAL_receipt::RpcReceiptRequest {
//!     receipt_reference: ReceiptReference {
//!         receipt_id: "3B5PPT9EKj5352Wks9GnCeSUBDsVvSF4ceMQv2nEULTf".parse()?,
//!     }
//! };
//!
//! let response = client.call(request).await?;
//!
//! assert!(matches!(
//!     response,
//!     methods::EXPERIMENTAL_receipt::RpcReceiptResponse { .. }
//! ));
//! # Ok(())
//! # }
//! ```
use super::*;

pub use unc_jsonrpc_primitives::types::receipts::{RpcReceiptError, RpcReceiptRequest};

pub type RpcReceiptResponse = unc_primitives::views::ReceiptView;

impl RpcHandlerResponse for RpcReceiptResponse {}

impl RpcHandlerError for RpcReceiptError {}

impl RpcMethod for RpcReceiptRequest {
    type Response = RpcReceiptResponse;
    type Error = RpcReceiptError;

    fn method_name(&self) -> &str {
        "EXPERIMENTAL_receipt"
    }

    fn params(&self) -> Result<serde_json::Value, io::Error> {
        Ok(json!(self))
    }
}

impl private::Sealed for RpcReceiptRequest {}