unc_jsonrpc_client/methods/sandbox/
patch_state.rs

1//! Patch account, access keys, contract code, or contract state.
2//!
3//! Only additions and mutations are supported. No deletions.
4//!
5//! Account, access keys, contract code, and contract states have different formats. See the example and docs for details about their format.
6//!
7//! ## Examples
8//!
9//! ```
10//! use unc_jsonrpc_client::{methods, JsonRpcClient};
11//! use unc_primitives::{state_record::StateRecord, account, types::AccountId, hash::CryptoHash};
12//!
13//! # #[tokio::main]
14//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
15//! let client = JsonRpcClient::connect("http://localhost:3030");
16//!
17//! let request = methods::sandbox_patch_state::RpcSandboxPatchStateRequest {
18//!     records: vec![
19//!         StateRecord::Account {
20//!             account_id: "fido.testnet".parse::<AccountId>()?,
21//!             account: account::Account::new(179, 0, CryptoHash::default(), 264)
22//!          }
23//!     ],
24//! };
25//!
26//! let response = client.call(request).await?;
27//!
28//! assert!(matches!(
29//!     response,
30//!     methods::sandbox_patch_state::RpcSandboxPatchStateResponse { .. }
31//! ));
32//! # Ok(())
33//! # }
34//! ```
35use super::*;
36
37pub use unc_jsonrpc_primitives::types::sandbox::{
38    RpcSandboxPatchStateError, RpcSandboxPatchStateRequest, RpcSandboxPatchStateResponse,
39};
40
41impl RpcHandlerResponse for RpcSandboxPatchStateResponse {}
42
43impl RpcHandlerError for RpcSandboxPatchStateError {}
44
45impl RpcMethod for RpcSandboxPatchStateRequest {
46    type Response = RpcSandboxPatchStateResponse;
47    type Error = RpcSandboxPatchStateError;
48
49    fn method_name(&self) -> &str {
50        "sandbox_patch_state"
51    }
52
53    fn params(&self) -> Result<serde_json::Value, io::Error> {
54        Ok(json!(self))
55    }
56}
57
58impl private::Sealed for RpcSandboxPatchStateRequest {}