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