Skip to content

Commit

Permalink
Fixes, add helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Dec 17, 2024
1 parent 12e940d commit a71521b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
17 changes: 15 additions & 2 deletions crates/threshold-signature-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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<EntropyConfig>, LegacyRpcMethods<EntropyConfig>), subxt::Error> {
Ok((
get_api(&self.configuration.endpoint).await?,
get_rpc(&self.configuration.endpoint).await?,
))
}
}

pub fn app(app_state: AppState) -> Router {
Expand Down
5 changes: 3 additions & 2 deletions crates/threshold-signature-server/src/node_info/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ pub async fn hashes() -> Json<Vec<HashingAlgorithm>> {
/// 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,
}
Expand All @@ -44,7 +45,7 @@ pub struct TssPublicKeys {
#[tracing::instrument(skip_all)]
pub async fn info(State(app_state): State<AppState>) -> Result<Json<TssPublicKeys>, 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(),
}))
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/node_info/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a71521b

Please sign in to comment.