near_jsonrpc_client/methods/experimental/
receipt.rs

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