diff --git a/workspaces/Cargo.toml b/workspaces/Cargo.toml index 29bbabd2..b9f6566d 100644 --- a/workspaces/Cargo.toml +++ b/workspaces/Cargo.toml @@ -26,11 +26,11 @@ tokio-retry = "0.3" tracing = "0.1" url = { version = "2.2.2", features = ["serde"] } -near-account-id = "0.5" -near-crypto = "0.5" -near-primitives = "0.5" -near-jsonrpc-primitives = "0.5" -near-jsonrpc-client = { version = "0.1", features = ["sandbox"] } +near-account-id = "0.12.0" +near-crypto = "0.12.0" +near-primitives = "0.12.0" +near-jsonrpc-primitives = "0.12.0" +near-jsonrpc-client = { version = "0.3.0", features = ["sandbox"] } near-sandbox-utils = "0.1.1" [build-dependencies] diff --git a/workspaces/src/rpc/client.rs b/workspaces/src/rpc/client.rs index 49290642..14594c61 100644 --- a/workspaces/src/rpc/client.rs +++ b/workspaces/src/rpc/client.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fmt::Debug; use tokio_retry::strategy::{jitter, ExponentialBackoff}; use tokio_retry::Retry; @@ -37,11 +38,67 @@ impl Client { Self { rpc_addr } } - pub(crate) async fn query( + pub(crate) async fn query_broadcast_tx( &self, - method: &M, - ) -> MethodCallResult { - retry(|| async { JsonRpcClient::connect(&self.rpc_addr).call(method).await }).await + method: &methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest, + ) -> MethodCallResult< + FinalExecutionOutcomeView, + near_jsonrpc_primitives::types::transactions::RpcTransactionError, + > { + retry(|| async { + let result = JsonRpcClient::connect(&self.rpc_addr).call(method).await; + match &result { + Ok(response) => { + // When user sets logging level to INFO we only print one-liners with submitted + // actions and the resulting status. If the level is DEBUG or lower, we print + // the entire request and response structures. + if tracing::level_enabled!(tracing::Level::DEBUG) { + tracing::debug!( + target: "workspaces", + "Calling RPC method {:?} succeeded with {:?}", + method, + response + ); + } else { + tracing::info!( + target: "workspaces", + "Submitting transaction with actions {:?} succeeded with status {:?}", + method.signed_transaction.transaction.actions, + response.status + ); + } + } + Err(error) => { + tracing::error!( + target: "workspaces", + "Calling RPC method {:?} resulted in error {:?}", + method, + error + ); + } + }; + result + }) + .await + } + + pub(crate) async fn query(&self, method: &M) -> MethodCallResult + where + M: methods::RpcMethod + Debug, + M::Response: Debug, + M::Error: Debug, + { + retry(|| async { + let result = JsonRpcClient::connect(&self.rpc_addr).call(method).await; + tracing::debug!( + target: "workspaces", + "Querying RPC with {:?} resulted in {:?}", + method, + result + ); + result + }) + .await } async fn send_tx_and_retry( @@ -323,7 +380,7 @@ pub(crate) async fn send_tx( tx: SignedTransaction, ) -> anyhow::Result { client - .query(&methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest { + .query_broadcast_tx(&methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest { signed_transaction: tx, }) .await diff --git a/workspaces/tests/create_account.rs b/workspaces/tests/create_account.rs index 5e64b53c..f9a31d04 100644 --- a/workspaces/tests/create_account.rs +++ b/workspaces/tests/create_account.rs @@ -1,3 +1,4 @@ +#![recursion_limit = "256"] use test_log::test; use workspaces::prelude::*; diff --git a/workspaces/tests/deploy.rs b/workspaces/tests/deploy.rs index 2de9d670..bc1f7b73 100644 --- a/workspaces/tests/deploy.rs +++ b/workspaces/tests/deploy.rs @@ -1,3 +1,4 @@ +#![recursion_limit = "256"] use serde::{Deserialize, Serialize}; use test_log::test; use workspaces::prelude::*;