From d3b58eb19009c727a5f05e1532c5cdbbb6bd4280 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Wed, 7 Feb 2024 12:38:01 -0600 Subject: [PATCH] feat(common): add a route /info for operator public key --- common/src/address.rs | 21 +++++++++++++++++++ .../indexer_service/http/indexer_service.rs | 4 ++++ common/src/lib.rs | 1 + 3 files changed, 26 insertions(+) create mode 100644 common/src/address.rs diff --git a/common/src/address.rs b/common/src/address.rs new file mode 100644 index 00000000..330c90e2 --- /dev/null +++ b/common/src/address.rs @@ -0,0 +1,21 @@ +// Copyright 2023-, GraphOps and Semiotic Labs. +// SPDX-License-Identifier: Apache-2.0 + +use ethers::signers::{ + coins_bip39::English, LocalWallet, MnemonicBuilder, Signer, Wallet, WalletError, +}; +use ethers_core::k256::ecdsa::SigningKey; + +/// Build Wallet from Private key or Mnemonic +pub fn build_wallet(value: &str) -> Result, WalletError> { + value + .parse::() + .or(MnemonicBuilder::::default().phrase(value).build()) +} + +// Format public key to a String +pub fn public_key(value: &str) -> Result { + let wallet = build_wallet(value)?; + let addr = format!("{:?}", wallet.address()); + Ok(addr) +} diff --git a/common/src/indexer_service/http/indexer_service.rs b/common/src/indexer_service/http/indexer_service.rs index 7fe79e38..3f1571e3 100644 --- a/common/src/indexer_service/http/indexer_service.rs +++ b/common/src/indexer_service/http/indexer_service.rs @@ -31,6 +31,7 @@ use tower_governor::{errors::display_error, governor::GovernorConfigBuilder, Gov use tracing::info; use crate::{ + address::public_key, indexer_service::http::{ metrics::IndexerServiceMetrics, static_subgraph::static_subgraph_request_handler, }, @@ -312,9 +313,12 @@ impl IndexerService { )), }; + let operator_address = public_key(&options.config.indexer.operator_mnemonic)?; + let mut misc_routes = Router::new() .route("/", get("Service is up and running")) .route("/version", get(Json(options.release))) + .route("/info", get(Json(operator_address))) .layer( ServiceBuilder::new() .layer(HandleErrorLayer::new(|e: BoxError| async move { diff --git a/common/src/lib.rs b/common/src/lib.rs index 287a22ac..72d3c941 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,7 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +pub mod address; pub mod allocations; pub mod attestations; pub mod escrow_accounts;