unc_jsonrpc_client/methods/experimental/
changes.rs

1//! Returns account changes from transactions in a given account.
2//!
3//! The `RpcStateChangesInBlockByTypeRequest` struct takes in a `BlockReference` and a `StateChangesRequestView`, and returns an `RpcStateChangesInBlockResponse`.
4//!
5//! ## Examples
6//!
7//! The `StateChangesRequestView` enum has a couple of variants that can be used to specify what kind of changes to return.
8//!
9//! - `AccountChanges`
10//!
11//!     ```
12//!     # use unc_jsonrpc_client::{methods, JsonRpcClient};
13//!     use unc_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}};
14//!
15//!     # #[tokio::main]
16//!     # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
17//!     let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
18//!
19//!     let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
20//!         block_reference: BlockReference::BlockId(BlockId::Hash("94yBWhN848vHMnKcw5DxgBQWJW6JHRXnXD6FCLJGjxMU".parse()?)),
21//!         state_changes_request: StateChangesRequestView::AccountChanges {
22//!            account_ids: vec!["fido.testnet".parse()?, "rpc_docs.testnet".parse()?],
23//!         }
24//!     };
25//!
26//!     let response = client.call(request).await?;
27//!
28//!     assert!(matches!(
29//!         response,
30//!         methods::EXPERIMENTAL_changes::RpcStateChangesInBlockResponse { .. }
31//!     ));
32//!     # Ok(())
33//!     # }
34//!     ```
35//!
36//! - `SingleAccessKeyChanges`
37//!
38//!     ```
39//!     use unc_jsonrpc_client::{methods, JsonRpcClient};
40//!     use unc_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId, AccountWithPublicKey}};
41//!
42//!     # #[tokio::main]
43//!     # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
44//!     let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
45//!
46//!     let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
47//!         block_reference: BlockReference::BlockId(BlockId::Hash("94yBWhN848vHMnKcw5DxgBQWJW6JHRXnXD6FCLJGjxMU".parse()?)),
48//!         state_changes_request: StateChangesRequestView::SingleAccessKeyChanges {
49//!            keys: vec![
50//!                     AccountWithPublicKey {
51//!                         account_id: "fido.testnet".parse()?,
52//!                         public_key: "ed25519:GwRkfEckaADh5tVxe3oMfHBJZfHAJ55TRWqJv9hSpR38".parse()?,
53//!                     },
54//!                     AccountWithPublicKey {
55//!                         account_id: "rpc_docs.testnet".parse()?,
56//!                         public_key: "ed25519:FxGiXr6Dgn92kqBqbQzuoYdKngiizCnywpaN7ALar3Vv".parse()?,
57//!                     }
58//!
59//!                ],
60//!         }
61//!     };
62//!
63//!     let response = client.call(request).await?;
64//!
65//!     assert!(matches!(
66//!         response,
67//!         methods::EXPERIMENTAL_changes::RpcStateChangesInBlockResponse { .. }
68//!     ));
69//!     # Ok(())
70//!     # }
71//!     ```
72//!
73//! - `AllAccessKeyChanges`
74//!
75//!     ```
76//!     # use unc_jsonrpc_client::{methods, JsonRpcClient};
77//!     use unc_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}};
78//!
79//!     # #[tokio::main]
80//!     # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
81//!     let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
82//!
83//!     let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
84//!         block_reference: BlockReference::BlockId(BlockId::Hash("94yBWhN848vHMnKcw5DxgBQWJW6JHRXnXD6FCLJGjxMU".parse()?)),
85//!         state_changes_request: StateChangesRequestView::AllAccessKeyChanges {
86//!            account_ids: vec!["fido.testnet".parse()?, "rpc_docs.testnet".parse()?],
87//!         }
88//!     };
89//!
90//!     let response = client.call(request).await?;
91//!
92//!     assert!(matches!(
93//!         response,
94//!         methods::EXPERIMENTAL_changes::RpcStateChangesInBlockResponse { .. }
95//!     ));
96//!     # Ok(())
97//!     # }
98//!     ```
99//!
100//! - `ContractCodeChanges`
101//!
102//!     ```
103//!     # use unc_jsonrpc_client::{methods, JsonRpcClient};
104//!     use unc_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId}};
105//!
106//!     # #[tokio::main]
107//!     # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
108//!     let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
109//!
110//!     let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
111//!         block_reference: BlockReference::BlockId(BlockId::Hash("94yBWhN848vHMnKcw5DxgBQWJW6JHRXnXD6FCLJGjxMU".parse()?)),
112//!         state_changes_request: StateChangesRequestView::ContractCodeChanges {
113//!            account_ids: vec!["fido.testnet".parse()?, "rpc_docs.testnet".parse()?],
114//!         }
115//!     };
116//!
117//!     let response = client.call(request).await?;
118//!
119//!     assert!(matches!(
120//!         response,
121//!         methods::EXPERIMENTAL_changes::RpcStateChangesInBlockResponse { .. }
122//!     ));
123//!     # Ok(())
124//!     # }
125//!     ```
126//!
127//! - `DataChanges`
128//!
129//!     ```
130//!     # use unc_jsonrpc_client::{methods, JsonRpcClient};
131//!     use unc_primitives::{views::StateChangesRequestView, types::{BlockReference, BlockId, StoreKey}, hash::CryptoHash};
132//!
133//!     # #[tokio::main]
134//!     # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
135//!     let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
136//!
137//!     let request = methods::EXPERIMENTAL_changes::RpcStateChangesInBlockByTypeRequest {
138//!         block_reference: BlockReference::BlockId(BlockId::Hash("94yBWhN848vHMnKcw5DxgBQWJW6JHRXnXD6FCLJGjxMU".parse::<CryptoHash>()?)),
139//!         state_changes_request: StateChangesRequestView::DataChanges {
140//!            account_ids: vec!["fido.testnet".parse()?, "rpc_docs.testnet".parse()?],
141//!            key_prefix: StoreKey::from(vec![]),
142//!         }
143//!     };
144//!
145//!     let response = client.call(request).await?;
146//!
147//!     assert!(matches!(
148//!         response,
149//!         methods::EXPERIMENTAL_changes::RpcStateChangesInBlockResponse { .. }
150//!     ));
151//!     # Ok(())
152//!     # }
153//!     ```
154use super::*;
155
156pub use unc_jsonrpc_primitives::types::changes::{
157    RpcStateChangesError, RpcStateChangesInBlockByTypeRequest, RpcStateChangesInBlockResponse,
158};
159
160impl RpcHandlerResponse for RpcStateChangesInBlockResponse {}
161
162impl RpcMethod for RpcStateChangesInBlockByTypeRequest {
163    type Response = RpcStateChangesInBlockResponse;
164    type Error = RpcStateChangesError;
165
166    fn method_name(&self) -> &str {
167        "EXPERIMENTAL_changes"
168    }
169
170    fn params(&self) -> Result<serde_json::Value, io::Error> {
171        Ok(json!(self))
172    }
173}
174
175impl private::Sealed for RpcStateChangesInBlockByTypeRequest {}