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
//! Checks a transaction on the network.
//!
//! This code sample doesn't make any request to the RPC node. It's been truncated for brevity sake.
//!
//! An example detailing how to construct a complete request can be found at [`contract_change_method`](https://github.com/unc/unc-jsonrpc-client-rs/blob/master/examples/contract_change_method.rs).
//!
//! ## Example
//!
//! ```no_run
//! use unc_jsonrpc_client::{methods, JsonRpcClient};
//! use unc_jsonrpc_primitives::types::{query::QueryResponseKind, transactions};
//! use unc_primitives::types::{AccountId, BlockReference};
//! use unc_primitives::transaction::{Action, Transaction, FunctionCallAction};
//! use unc_crypto::SecretKey;
//! use core::str::FromStr;
//! use serde_json::json;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
//!
//! let signer_account_id = "fido.testnet".parse::<AccountId>()?;
//! let signer_secret_key = SecretKey::from_str("ed25519:12dhevYshfiRqFSu8DSfxA27pTkmGRv6C5qQWTJYTcBEoB7MSTyidghi5NWXzWqrxCKgxVx97bpXPYQxYN5dieU")?; // Replace secret_key with valid signer_secret_key
//!
//! let signer = unc_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key);
//!
//! let other_account = "rpc_docs.testnet".parse::<AccountId>()?;
//! let rating = "4.7".parse::<f32>()?;
//!
//! let transaction = Transaction {
//! signer_id: signer.account_id.clone(),
//! public_key: signer.public_key.clone(),
//! nonce: 904565 + 1,
//! receiver_id: "nosedive.testnet".parse::<AccountId>()?,
//! block_hash: "AUDcb2iNUbsmCsmYGfGuKzyXKimiNcCZjBKTVsbZGnoH".parse()?,
//! actions: vec![Action::FunctionCall(Box::new(FunctionCallAction {
//! method_name: "rate".to_string(),
//! args: json!({
//! "account_id": other_account,
//! "rating": rating,
//! })
//! .to_string()
//! .into_bytes(),
//! gas: 100_000_000_000_000, // 100 TeraGas
//! deposit: 0,
//! }))],
//! };
//!
//! let request = methods::EXPERIMENTAL_check_tx::RpcCheckTxRequest {
//! signed_transaction: transaction.sign(&signer)
//! };
//! # Ok(())
//! # }
//! ```
use super::*;
pub use unc_jsonrpc_primitives::types::transactions::{
RpcBroadcastTxSyncResponse, RpcTransactionError,
};
pub use unc_primitives::transaction::SignedTransaction;
#[derive(Debug)]
pub struct RpcCheckTxRequest {
pub signed_transaction: SignedTransaction,
}
impl From<RpcCheckTxRequest>
for unc_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest
{
fn from(this: RpcCheckTxRequest) -> Self {
Self {
signed_transaction: this.signed_transaction,
wait_until: unc_primitives::views::TxExecutionStatus::None,
}
}
}
impl RpcMethod for RpcCheckTxRequest {
type Response = RpcBroadcastTxSyncResponse;
type Error = RpcTransactionError;
fn method_name(&self) -> &str {
"EXPERIMENTAL_check_tx"
}
fn params(&self) -> Result<serde_json::Value, io::Error> {
Ok(json!([common::serialize_signed_transaction(
&self.signed_transaction
)?]))
}
}
impl private::Sealed for RpcCheckTxRequest {}