From a71521b645bf9b174e698ce7b0ff4984b3b5aceb Mon Sep 17 00:00:00 2001 From: peg Date: Tue, 17 Dec 2024 16:36:31 +0100 Subject: [PATCH] Fixes, add helper --- crates/threshold-signature-server/src/lib.rs | 17 +++++++++++++++-- .../src/node_info/api.rs | 5 +++-- .../src/node_info/tests.rs | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/threshold-signature-server/src/lib.rs b/crates/threshold-signature-server/src/lib.rs index 841aeb1b6..d6055cca3 100644 --- a/crates/threshold-signature-server/src/lib.rs +++ b/crates/threshold-signature-server/src/lib.rs @@ -179,7 +179,10 @@ use entropy_kvdb::kv_manager::KvManager; use rand_core::OsRng; use sp_core::{crypto::AccountId32, sr25519, Pair}; use std::sync::{Arc, RwLock}; -use subxt::{tx::PairSigner, utils::AccountId32 as SubxtAccountId32}; +use subxt::{ + backend::legacy::LegacyRpcMethods, tx::PairSigner, utils::AccountId32 as SubxtAccountId32, + OnlineClient, +}; use tower_http::{ cors::{Any, CorsLayer}, trace::{self, TraceLayer}, @@ -190,7 +193,7 @@ use x25519_dalek::StaticSecret; pub use crate::helpers::{launch, validator::get_signer_and_x25519_secret}; use crate::{ attestation::api::{attest, get_attest}, - chain_api::EntropyConfig, + chain_api::{get_api, get_rpc, EntropyConfig}, health::api::healthz, launch::{development_mnemonic, Configuration, ValidatorName}, node_info::api::{hashes, info, version as get_version}, @@ -277,6 +280,16 @@ impl AppState { pub fn x25519_public_key(&self) -> [u8; 32] { x25519_dalek::PublicKey::from(&self.x25519_secret).to_bytes() } + + /// Convenience function to get chain api and rpc + pub async fn get_api_rpc( + &self, + ) -> Result<(OnlineClient, LegacyRpcMethods), subxt::Error> { + Ok(( + get_api(&self.configuration.endpoint).await?, + get_rpc(&self.configuration.endpoint).await?, + )) + } } pub fn app(app_state: AppState) -> Router { diff --git a/crates/threshold-signature-server/src/node_info/api.rs b/crates/threshold-signature-server/src/node_info/api.rs index 066199975..ba977c6f2 100644 --- a/crates/threshold-signature-server/src/node_info/api.rs +++ b/crates/threshold-signature-server/src/node_info/api.rs @@ -35,7 +35,8 @@ pub async fn hashes() -> Json> { /// Public signing and encryption keys associated with a TS server #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] pub struct TssPublicKeys { - pub connected_to_chain: bool, + /// Indicates that all prerequisite checks have passed + pub ready: bool, pub tss_account: AccountId32, pub x25519_public_key: X25519PublicKey, } @@ -44,7 +45,7 @@ pub struct TssPublicKeys { #[tracing::instrument(skip_all)] pub async fn info(State(app_state): State) -> Result, GetInfoError> { Ok(Json(TssPublicKeys { - connected_to_chain: app_state.is_ready(), + ready: app_state.is_ready(), x25519_public_key: app_state.x25519_public_key(), tss_account: app_state.subxt_account_id(), })) diff --git a/crates/threshold-signature-server/src/node_info/tests.rs b/crates/threshold-signature-server/src/node_info/tests.rs index 502dd7b2b..df74acb8c 100644 --- a/crates/threshold-signature-server/src/node_info/tests.rs +++ b/crates/threshold-signature-server/src/node_info/tests.rs @@ -74,7 +74,7 @@ async fn info_test() { TssPublicKeys { tss_account: TSS_ACCOUNTS[0].clone(), x25519_public_key: X25519_PUBLIC_KEYS[0], - connected_to_chain: true, + ready: true, } ); clean_tests();