diff --git a/mpc-recovery/src/client.rs b/mpc-recovery/src/client.rs index 647e61ad4..c18d77edc 100644 --- a/mpc-recovery/src/client.rs +++ b/mpc-recovery/src/client.rs @@ -1,8 +1,9 @@ -use near_jsonrpc_client::{methods, JsonRpcClient}; +use near_jsonrpc_client::{methods, JsonRpcClient, MethodCallResult}; use near_jsonrpc_primitives::types::query::QueryResponseKind; use near_primitives::hash::CryptoHash; +use near_primitives::transaction::SignedTransaction; use near_primitives::types::{AccountId, Finality}; -use near_primitives::views::{AccessKeyView, QueryRequest}; +use near_primitives::views::{AccessKeyView, FinalExecutionOutcomeView, QueryRequest}; #[derive(Clone)] pub struct NearRpcClient { @@ -41,6 +42,35 @@ impl NearRpcClient { } } + async fn query_broadcast_tx( + &self, + method: &methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest, + ) -> MethodCallResult< + FinalExecutionOutcomeView, + near_jsonrpc_primitives::types::transactions::RpcTransactionError, + > { + let result = self.rpc_client.call(method).await; + match &result { + Ok(response) => { + tracing::debug!( + target: "client", + "Submitting transaction with actions {:?} succeeded with status {:?}", + method.signed_transaction.transaction.actions, + response.status + ); + } + Err(error) => { + tracing::error!( + target: "client", + "Calling RPC method {:?} resulted in error {:?}", + method, + error + ); + } + }; + result + } + pub async fn access_key_nonce( &self, account_id: AccountId, @@ -59,6 +89,19 @@ impl NearRpcClient { .await?; Ok(block_view.header.hash) } + + pub async fn send_tx( + &self, + signed_transaction: SignedTransaction, + ) -> anyhow::Result { + let result = self + .query_broadcast_tx(&methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest { + signed_transaction, + }) + .await?; + + Ok(result) + } } #[cfg(test)] diff --git a/mpc-recovery/src/leader_node/mod.rs b/mpc-recovery/src/leader_node/mod.rs index 9e4838e55..aa0451305 100644 --- a/mpc-recovery/src/leader_node/mod.rs +++ b/mpc-recovery/src/leader_node/mod.rs @@ -124,10 +124,10 @@ async fn process_new_account( ); // Sign the transaction - let _signed_create_acc_tx = + let signed_create_acc_tx = sign_transaction(create_acc_tx, account_creator_id, account_creator_sk); - //TODO: Send transaction to the relayer + state.client.send_tx(signed_create_acc_tx).await?; Ok((StatusCode::OK, Json(NewAccountResponse::Ok))) } @@ -200,9 +200,9 @@ async fn process_add_key( // Sign the transaction // TODO: use key derivation or other techniques to generate a key let mpc_recovery_user_sk: SecretKey = "".parse().unwrap(); - let _signed_add_key_tx = sign_transaction(add_key_tx, user_account_id, mpc_recovery_user_sk); + let signed_add_key_tx = sign_transaction(add_key_tx, user_account_id, mpc_recovery_user_sk); - //TODO: Send transaction to the relayer + state.client.send_tx(signed_add_key_tx).await?; Ok((StatusCode::OK, Json(AddKeyResponse::Ok))) }