From 781fa5df061dccae77b1ef57ee206974a390aa1c Mon Sep 17 00:00:00 2001 From: telezhnaya Date: Wed, 10 Jan 2024 16:21:16 +0000 Subject: [PATCH] feat: add wait_until flag, drop check_tx method --- examples/contract_change_method.rs | 9 +- examples/create_account.rs | 46 +++---- examples/query_tx.rs | 8 +- examples/send_tx.rs | 112 ++++++++++++++++++ src/lib.rs | 8 +- src/methods/broadcast_tx_async.rs | 2 +- src/methods/broadcast_tx_commit.rs | 2 +- src/methods/experimental/mod.rs | 3 - src/methods/experimental/tx_status.rs | 30 +++-- src/methods/mod.rs | 11 +- .../{experimental/check_tx.rs => send_tx.rs} | 62 ++++------ src/methods/tx.rs | 38 ++++-- 12 files changed, 229 insertions(+), 102 deletions(-) create mode 100644 examples/send_tx.rs rename src/methods/{experimental/check_tx.rs => send_tx.rs} (51%) diff --git a/examples/contract_change_method.rs b/examples/contract_change_method.rs index 504a4e21..a77e3087 100644 --- a/examples/contract_change_method.rs +++ b/examples/contract_change_method.rs @@ -1,8 +1,9 @@ use near_jsonrpc_client::{methods, JsonRpcClient}; use near_jsonrpc_primitives::types::query::QueryResponseKind; -use near_jsonrpc_primitives::types::transactions::TransactionInfo; +use near_jsonrpc_primitives::types::transactions::{RpcTransactionError, TransactionInfo}; use near_primitives::transaction::{Action, FunctionCallAction, Transaction}; use near_primitives::types::BlockReference; +use near_primitives::views::TxExecutionStatus; use serde_json::json; use tokio::time; @@ -71,6 +72,7 @@ async fn main() -> Result<(), Box> { tx_hash, sender_account_id: signer.account_id.clone(), }, + wait_until: TxExecutionStatus::Executed, }) .await; let received_at = time::Instant::now(); @@ -82,7 +84,10 @@ async fn main() -> Result<(), Box> { match response { Err(err) => match err.handler_error() { - Some(methods::tx::RpcTransactionError::UnknownTransaction { .. }) => { + Some( + RpcTransactionError::TimeoutError + | RpcTransactionError::UnknownTransaction { .. }, + ) => { time::sleep(time::Duration::from_secs(2)).await; continue; } diff --git a/examples/create_account.rs b/examples/create_account.rs index 9995e182..dce9ae09 100644 --- a/examples/create_account.rs +++ b/examples/create_account.rs @@ -18,6 +18,7 @@ use near_primitives::transaction::{ Action, AddKeyAction, CreateAccountAction, FunctionCallAction, Transaction, TransferAction, }; use near_primitives::types::{AccountId, BlockReference}; +use near_primitives::views::{FinalExecutionStatus, TxExecutionStatus}; use serde_json::json; use tokio::time; @@ -205,6 +206,7 @@ async fn main() -> Result<(), Box> { tx_hash, sender_account_id: signer.account_id.clone(), }, + wait_until: TxExecutionStatus::Final, }) .await; let received_at = time::Instant::now(); @@ -215,40 +217,38 @@ async fn main() -> Result<(), Box> { } match response { - Ok( - ref outcome @ near_primitives::views::FinalExecutionOutcomeView { - status: near_primitives::views::FinalExecutionStatus::SuccessValue(ref s), - .. - }, - ) => { - // outcome.status != SuccessValue(`false`) - if s == b"false" { - println!("(i) Account successfully created after {}s", delta); - } else { - println!("{:#?}", outcome); - println!("(!) Creating the account failed, check above for full logs"); + Ok(tx) => { + // it's fine to unwrap because we asked for finalized tx + let outcome = tx.final_execution_outcome.unwrap().into_outcome(); + match outcome.status { + FinalExecutionStatus::Failure(err) => { + println!("{:#?}", err); + println!("(!) Creating the account failed, check above for full logs"); + break; + } + FinalExecutionStatus::SuccessValue(ref s) => { + // outcome.status != SuccessValue(`false`) + if s == b"false" { + println!("(i) Account successfully created after {}s", delta); + } else { + println!("{:#?}", outcome); + println!("(!) Creating the account failed, check above for full logs"); + } + break; + } + _ => {} } - break; - } - Ok(near_primitives::views::FinalExecutionOutcomeView { - status: near_primitives::views::FinalExecutionStatus::Failure(err), - .. - }) => { - println!("{:#?}", err); - println!("(!) Creating the account failed, check above for full logs"); - break; } Err(err) => match err.handler_error() { Some( RpcTransactionError::TimeoutError - | methods::tx::RpcTransactionError::UnknownTransaction { .. }, + | RpcTransactionError::UnknownTransaction { .. }, ) => { time::sleep(time::Duration::from_secs(2)).await; continue; } _ => Err(err)?, }, - _ => {} } } diff --git a/examples/query_tx.rs b/examples/query_tx.rs index 5236f7b0..8a40600b 100644 --- a/examples/query_tx.rs +++ b/examples/query_tx.rs @@ -93,22 +93,26 @@ async fn main() -> Result<(), Box> { break 'root; }; + let wait_until_str = utils::input("Enter the desired guaranteed execution status (can be one of: NONE, INCLUDED, INCLUDED_FINAL, EXECUTED, FINAL): ")?; + let wait_until = serde_json::from_str(&("\"".to_owned() + &wait_until_str + "\""))?; + match client .call(methods::tx::RpcTransactionStatusRequest { transaction_info: methods::tx::TransactionInfo::TransactionId { tx_hash, sender_account_id: account_id, }, + wait_until, }) .await { - Ok(block_details) => println!("{:#?}", block_details), + Ok(tx_details) => println!("{:#?}", tx_details), Err(err) => match err.handler_error() { Some(err) => { println!("(i) An error occurred `{:#?}`", err); continue; } - _ => println!("(i) A non-handler error ocurred `{:#?}`", err), + _ => println!("(i) A non-handler error occurred `{:#?}`", err), }, }; break; diff --git a/examples/send_tx.rs b/examples/send_tx.rs new file mode 100644 index 00000000..558c5e04 --- /dev/null +++ b/examples/send_tx.rs @@ -0,0 +1,112 @@ +use near_jsonrpc_client::{methods, JsonRpcClient}; +use near_jsonrpc_primitives::types::query::QueryResponseKind; +use near_jsonrpc_primitives::types::transactions::{RpcTransactionError, TransactionInfo}; +use near_primitives::transaction::{Action, FunctionCallAction, Transaction}; +use near_primitives::types::BlockReference; +use near_primitives::views::TxExecutionStatus; +use tokio::time; + +mod utils; + +#[tokio::main] +async fn main() -> Result<(), Box> { + env_logger::init(); + + let client = JsonRpcClient::connect("https://rpc.testnet.near.org"); + + let signer_account_id = utils::input("Enter the signer Account ID: ")?.parse()?; + let signer_secret_key = utils::input("Enter the signer's private key: ")?.parse()?; + let wait_until_str = utils::input("Enter the desired guaranteed execution status (can be one of: NONE, INCLUDED, INCLUDED_FINAL, EXECUTED, FINAL): ")?; + let wait_until: TxExecutionStatus = + serde_json::from_str(&("\"".to_owned() + &wait_until_str + "\""))?; + + let signer = near_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key); + + let access_key_query_response = client + .call(methods::query::RpcQueryRequest { + block_reference: BlockReference::latest(), + request: near_primitives::views::QueryRequest::ViewAccessKey { + account_id: signer.account_id.clone(), + public_key: signer.public_key.clone(), + }, + }) + .await?; + + let current_nonce = match access_key_query_response.kind { + QueryResponseKind::AccessKey(access_key) => access_key.nonce, + _ => Err("failed to extract current nonce")?, + }; + + let other_account = utils::input("Enter the account to be rated: ")?; + let rating = utils::input("Enter a rating: ")?.parse::()?; + + let transaction = Transaction { + signer_id: signer.account_id.clone(), + public_key: signer.public_key.clone(), + nonce: current_nonce + 1, + receiver_id: "nosedive.testnet".parse()?, + block_hash: access_key_query_response.block_hash, + actions: vec![Action::FunctionCall(Box::new(FunctionCallAction { + method_name: "rate".to_string(), + args: serde_json::json!({ + "account_id": other_account, + "rating": rating, + }) + .to_string() + .into_bytes(), + gas: 100_000_000_000_000, // 100 TeraGas + deposit: 0, + }))], + }; + let tx_hash = transaction.get_hash_and_size().0; + + let request = methods::send_tx::RpcSendTransactionRequest { + signed_transaction: transaction.sign(&signer), + wait_until: wait_until.clone(), + }; + + let sent_at = time::Instant::now(); + let response = match client.call(request).await { + Ok(response) => response, + Err(err) => { + match err.handler_error() { + Some(RpcTransactionError::TimeoutError) => {} + _ => Err(err)?, + } + loop { + let response = client + .call(methods::tx::RpcTransactionStatusRequest { + transaction_info: TransactionInfo::TransactionId { + tx_hash, + sender_account_id: signer.account_id.clone(), + }, + wait_until: wait_until.clone(), + }) + .await; + let received_at = time::Instant::now(); + let delta = (received_at - sent_at).as_secs(); + + if delta > 60 { + Err("time limit exceeded for the transaction to be recognized")?; + } + + match response { + Err(err) => match err.handler_error() { + Some(RpcTransactionError::TimeoutError) => {} + _ => Err(err)?, + }, + Ok(response) => { + break response; + } + } + } + } + }; + + let received_at = time::Instant::now(); + let delta = (received_at - sent_at).as_secs(); + println!("response gotten after: {}s", delta); + println!("response: {:#?}", response); + + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index cf55cc75..8d4ed244 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,7 @@ //! ```no_run //! use near_jsonrpc_client::{methods, JsonRpcClient}; //! use near_jsonrpc_primitives::types::transactions::TransactionInfo; +//! use near_primitives::views::TxExecutionStatus; //! //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { @@ -48,6 +49,7 @@ //! tx_hash: "9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U".parse()?, //! sender_account_id: "miraclx.near".parse()?, //! }, +//! wait_until: TxExecutionStatus::Executed, //! }; //! //! let tx_status = client.call(tx_status_request).await?; @@ -439,9 +441,9 @@ mod tests { assert!( matches!( tx_status, - Ok(methods::tx::RpcTransactionStatusResponse { ref transaction, .. }) - if transaction.signer_id == "miraclx.near" - && transaction.hash == "9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U".parse()? + Ok(methods::tx::RpcTransactionResponse { ref final_execution_outcome, .. }) + if final_execution_outcome.unwrap().into_outcome().transaction.signer_id == "miraclx.near" + && final_execution_outcome.unwrap().into_outcome().transaction.hash == "9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U".parse()? ), "expected an Ok(RpcTransactionStatusResponse) with matching signer_id + hash, found [{:?}]", tx_status diff --git a/src/methods/broadcast_tx_async.rs b/src/methods/broadcast_tx_async.rs index 92d47248..b6dc4bf2 100644 --- a/src/methods/broadcast_tx_async.rs +++ b/src/methods/broadcast_tx_async.rs @@ -70,7 +70,7 @@ impl From fn from(this: RpcBroadcastTxAsyncRequest) -> Self { Self { signed_transaction: this.signed_transaction, - wait_until: near_primitives::views::TxExecutionStatus::None, + wait_until: near_primitives::views::TxExecutionStatus::default(), } } } diff --git a/src/methods/broadcast_tx_commit.rs b/src/methods/broadcast_tx_commit.rs index ea9ae7df..c3bc79e0 100644 --- a/src/methods/broadcast_tx_commit.rs +++ b/src/methods/broadcast_tx_commit.rs @@ -72,7 +72,7 @@ impl From fn from(this: RpcBroadcastTxCommitRequest) -> Self { Self { signed_transaction: this.signed_transaction, - wait_until: near_primitives::views::TxExecutionStatus::None, + wait_until: near_primitives::views::TxExecutionStatus::default(), } } } diff --git a/src/methods/experimental/mod.rs b/src/methods/experimental/mod.rs index a19152d0..c76093f5 100644 --- a/src/methods/experimental/mod.rs +++ b/src/methods/experimental/mod.rs @@ -6,9 +6,6 @@ pub use changes as EXPERIMENTAL_changes; pub mod changes_in_block; pub use changes_in_block as EXPERIMENTAL_changes_in_block; -pub mod check_tx; -pub use check_tx as EXPERIMENTAL_check_tx; - pub mod genesis_config; pub use genesis_config as EXPERIMENTAL_genesis_config; diff --git a/src/methods/experimental/tx_status.rs b/src/methods/experimental/tx_status.rs index 08a6b0e1..83fbb04e 100644 --- a/src/methods/experimental/tx_status.rs +++ b/src/methods/experimental/tx_status.rs @@ -7,7 +7,7 @@ //! //! ``` //! use near_jsonrpc_client::{methods, JsonRpcClient}; -//! use near_primitives::views; +//! use near_primitives::views::TxExecutionStatus; //! //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { @@ -18,14 +18,15 @@ //! transaction_info: methods::EXPERIMENTAL_tx_status::TransactionInfo::TransactionId { //! tx_hash, //! sender_account_id: "itranscend.near".parse()?, -//! } +//! }, +//! wait_until: TxExecutionStatus::Executed, //! }; //! //! let response = client.call(request).await?; //! //! assert!(matches!( //! response, -//! views::FinalExecutionOutcomeWithReceiptView { .. } +//! near_jsonrpc_primitives::types::transactions::RpcTransactionResponse { .. } //! )); //! # Ok(()) //! # } @@ -33,14 +34,13 @@ use super::*; pub use near_jsonrpc_primitives::types::transactions::RpcTransactionError; +pub use near_jsonrpc_primitives::types::transactions::RpcTransactionResponse; pub use near_jsonrpc_primitives::types::transactions::TransactionInfo; -pub type RpcTransactionStatusResponse = - near_primitives::views::FinalExecutionOutcomeWithReceiptView; - #[derive(Debug)] pub struct RpcTransactionStatusRequest { pub transaction_info: TransactionInfo, + pub wait_until: near_primitives::views::TxExecutionStatus, } impl From @@ -49,15 +49,12 @@ impl From fn from(this: RpcTransactionStatusRequest) -> Self { Self { transaction_info: this.transaction_info, - wait_until: near_primitives::views::TxExecutionStatus::None, + wait_until: this.wait_until, } } } - -impl RpcHandlerResponse for RpcTransactionStatusResponse {} - impl RpcMethod for RpcTransactionStatusRequest { - type Response = RpcTransactionStatusResponse; + type Response = RpcTransactionResponse; type Error = RpcTransactionError; fn method_name(&self) -> &str { @@ -69,12 +66,19 @@ impl RpcMethod for RpcTransactionStatusRequest { TransactionInfo::Transaction(signed_transaction) => { match signed_transaction { near_jsonrpc_primitives::types::transactions::SignedTransaction::SignedTransaction(tx) => { - json!([common::serialize_signed_transaction(tx)?]) + json!({ + "signed_tx_base64": common::serialize_signed_transaction(tx)?, + "wait_until": self.wait_until + }) }, } } TransactionInfo::TransactionId { tx_hash,sender_account_id } => { - json!([tx_hash, sender_account_id]) + json!({ + "tx_hash": tx_hash, + "sender_account_id": sender_account_id, + "wait_until": self.wait_until + }) } }) } diff --git a/src/methods/mod.rs b/src/methods/mod.rs index f4e7a2ea..90369e02 100644 --- a/src/methods/mod.rs +++ b/src/methods/mod.rs @@ -86,6 +86,7 @@ pub mod light_client_proof; pub mod network_info; pub mod next_light_client_block; pub mod query; +pub mod send_tx; pub mod status; pub mod tx; pub mod validators; @@ -94,7 +95,6 @@ pub mod validators; mod experimental; pub use experimental::EXPERIMENTAL_changes; pub use experimental::EXPERIMENTAL_changes_in_block; -pub use experimental::EXPERIMENTAL_check_tx; pub use experimental::EXPERIMENTAL_genesis_config; pub use experimental::EXPERIMENTAL_protocol_config; pub use experimental::EXPERIMENTAL_receipt; @@ -214,7 +214,7 @@ mod common { // broadcast_tx_commit, tx impl RpcHandlerResponse for near_primitives::views::FinalExecutionOutcomeView {} - // broadcast_tx_commit, tx, EXPERIMENTAL_check_tx, EXPERIMENTAL_tx_status + // broadcast_tx_commit, tx, EXPERIMENTAL_tx_status impl RpcHandlerError for near_jsonrpc_primitives::types::transactions::RpcTransactionError { fn parse_legacy_error(value: serde_json::Value) -> Option> { match serde_json::from_value::(value) { @@ -237,11 +237,8 @@ mod common { } } - // EXPERIMENTAL_broadcast_tx_sync, EXPERIMENTAL_check_tx - impl RpcHandlerResponse - for near_jsonrpc_primitives::types::transactions::RpcBroadcastTxSyncResponse - { - } + // send_tx + impl RpcHandlerResponse for near_jsonrpc_primitives::types::transactions::RpcTransactionResponse {} // validators, EXPERIMENTAL_validators_ordered impl RpcHandlerError for near_jsonrpc_primitives::types::validator::RpcValidatorError {} diff --git a/src/methods/experimental/check_tx.rs b/src/methods/send_tx.rs similarity index 51% rename from src/methods/experimental/check_tx.rs rename to src/methods/send_tx.rs index 6ff407ad..0a7b0935 100644 --- a/src/methods/experimental/check_tx.rs +++ b/src/methods/send_tx.rs @@ -1,31 +1,34 @@ -//! Checks a transaction on the network. +//! Sends a transaction. //! -//! This code sample doesn't make any request to the RPC node. It's been truncated for brevity sake. +//! Sends a signed transaction to the RPC, returns the guaranteed execution status and the results the blockchain can provide at the moment. //! -//! An example detailing how to construct a complete request can be found at [`contract_change_method`](https://github.com/near/near-jsonrpc-client-rs/blob/master/examples/contract_change_method.rs). +//! Constructs a signed transaction to be sent to an RPC node. +//! +//! This code sample doesn't make any requests to the RPC node. It only shows how to construct the request. It's been truncated for brevity. +//! +//! A full example on how to use `send_tx` method can be found at [`send_tx`](https://github.com/near/near-jsonrpc-client-rs/blob/master/examples/send_tx.rs). //! //! ## Example //! //! ```no_run //! use near_jsonrpc_client::{methods, JsonRpcClient}; -//! use near_jsonrpc_primitives::types::{query::QueryResponseKind, transactions}; +//! use near_jsonrpc_primitives::types::{query::QueryResponseKind, transactions::TransactionInfo}; //! use near_primitives::types::{AccountId, BlockReference}; -//! use near_primitives::transaction::{Action, Transaction, FunctionCallAction}; -//! use near_crypto::SecretKey; -//! use core::str::FromStr; +//! use near_primitives::transaction::{Action, FunctionCallAction, Transaction}; //! use serde_json::json; //! //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { +//! use near_primitives::views::TxExecutionStatus; //! let client = JsonRpcClient::connect("https://archival-rpc.testnet.near.org"); //! //! let signer_account_id = "fido.testnet".parse::()?; -//! let signer_secret_key = SecretKey::from_str("ed25519:12dhevYshfiRqFSu8DSfxA27pTkmGRv6C5qQWTJYTcBEoB7MSTyidghi5NWXzWqrxCKgxVx97bpXPYQxYN5dieU")?; // Replace secret_key with valid signer_secret_key +//! let signer_secret_key = "ed25519:12dhevYshfiRqFSu8DSfxA27pTkmGRv6C5qQWTJYTcBEoB7MSTyidghi5NWXzWqrxCKgxVx97bpXPYQxYN5dieU".parse()?; //! //! let signer = near_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key); //! //! let other_account = "rpc_docs.testnet".parse::()?; -//! let rating = "4.7".parse::()?; +//! let rating = "4.5".parse::()?; //! //! let transaction = Transaction { //! signer_id: signer.account_id.clone(), @@ -46,48 +49,35 @@ //! }))], //! }; //! -//! let request = methods::EXPERIMENTAL_check_tx::RpcCheckTxRequest { -//! signed_transaction: transaction.sign(&signer) +//! let request = methods::send_tx::RpcSendTransactionRequest { +//! signed_transaction: transaction.sign(&signer), +//! wait_until: TxExecutionStatus::IncludedFinal, //! }; //! # Ok(()) //! # } //! ``` use super::*; - pub use near_jsonrpc_primitives::types::transactions::{ - RpcBroadcastTxSyncResponse, RpcTransactionError, + RpcSendTransactionRequest, RpcTransactionResponse, }; -pub use near_primitives::transaction::SignedTransaction; -#[derive(Debug)] -pub struct RpcCheckTxRequest { - pub signed_transaction: SignedTransaction, -} - -impl From - for near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest -{ - fn from(this: RpcCheckTxRequest) -> Self { - Self { - signed_transaction: this.signed_transaction, - wait_until: near_primitives::views::TxExecutionStatus::None, - } - } -} +pub use near_jsonrpc_primitives::types::transactions::RpcTransactionError; +pub use near_primitives::transaction::SignedTransaction; -impl RpcMethod for RpcCheckTxRequest { - type Response = RpcBroadcastTxSyncResponse; +impl RpcMethod for RpcSendTransactionRequest { + type Response = RpcTransactionResponse; type Error = RpcTransactionError; fn method_name(&self) -> &str { - "EXPERIMENTAL_check_tx" + "send_tx" } fn params(&self) -> Result { - Ok(json!([common::serialize_signed_transaction( - &self.signed_transaction - )?])) + Ok(json!([ + common::serialize_signed_transaction(&self.signed_transaction)?, + self.wait_until + ])) } } -impl private::Sealed for RpcCheckTxRequest {} +impl private::Sealed for RpcSendTransactionRequest {} diff --git a/src/methods/tx.rs b/src/methods/tx.rs index cf2fe9f4..73b74e54 100644 --- a/src/methods/tx.rs +++ b/src/methods/tx.rs @@ -9,6 +9,7 @@ //! //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { +//! use near_primitives::views::{FinalExecutionOutcomeViewEnum, TxExecutionStatus}; //! let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org"); //! let tx_hash = "B9aypWiMuiWR5kqzewL9eC96uZWA3qCMhLe67eBMWacq".parse()?; //! @@ -16,25 +17,33 @@ //! transaction_info: methods::tx::TransactionInfo::TransactionId { //! tx_hash, //! sender_account_id: "itranscend.near".parse()?, -//! } +//! }, +//! wait_until: TxExecutionStatus::Executed, //! }; //! //! let response = client.call(request).await?; -//! -//! assert_eq!(tx_hash, response.transaction.hash); +//! let outcome = response.final_execution_outcome.expect("Should be executed by this moment"); +//! match outcome { +//! FinalExecutionOutcomeViewEnum::FinalExecutionOutcome(outcome) => { +//! assert_eq!(tx_hash, outcome.transaction.hash); +//! } +//! FinalExecutionOutcomeViewEnum::FinalExecutionOutcomeWithReceipt(_) => { +//! panic!("We haven't asked for the receipts"); +//! } +//! }; //! # Ok(()) //! # } //! ``` use super::*; pub use near_jsonrpc_primitives::types::transactions::RpcTransactionError; +pub use near_jsonrpc_primitives::types::transactions::RpcTransactionResponse; pub use near_jsonrpc_primitives::types::transactions::TransactionInfo; -pub type RpcTransactionStatusResponse = near_primitives::views::FinalExecutionOutcomeView; - #[derive(Debug)] pub struct RpcTransactionStatusRequest { pub transaction_info: TransactionInfo, + pub wait_until: near_primitives::views::TxExecutionStatus, } impl From @@ -43,13 +52,13 @@ impl From fn from(this: RpcTransactionStatusRequest) -> Self { Self { transaction_info: this.transaction_info, - wait_until: near_primitives::views::TxExecutionStatus::None, + wait_until: this.wait_until, } } } impl RpcMethod for RpcTransactionStatusRequest { - type Response = RpcTransactionStatusResponse; + type Response = RpcTransactionResponse; type Error = RpcTransactionError; fn method_name(&self) -> &str { @@ -61,12 +70,19 @@ impl RpcMethod for RpcTransactionStatusRequest { TransactionInfo::Transaction(signed_transaction) => { match signed_transaction { near_jsonrpc_primitives::types::transactions::SignedTransaction::SignedTransaction(tx) => { - json!([common::serialize_signed_transaction(tx)?]) - } + json!({ + "signed_tx_base64": common::serialize_signed_transaction(tx)?, + "wait_until": self.wait_until + }) + }, } } - TransactionInfo::TransactionId { tx_hash,sender_account_id, ..} => { - json!([tx_hash, sender_account_id]) + TransactionInfo::TransactionId { tx_hash,sender_account_id } => { + json!({ + "tx_hash": tx_hash, + "sender_account_id": sender_account_id, + "wait_until": self.wait_until + }) } }) }