Skip to content

Commit

Permalink
feat(common): add a route /info for operator public key
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Feb 10, 2024
1 parent 6ba931c commit d3b58eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions common/src/address.rs
Original file line number Diff line number Diff line change
@@ -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<Wallet<SigningKey>, WalletError> {
value
.parse::<LocalWallet>()
.or(MnemonicBuilder::<English>::default().phrase(value).build())
}

// Format public key to a String
pub fn public_key(value: &str) -> Result<String, WalletError> {
let wallet = build_wallet(value)?;
let addr = format!("{:?}", wallet.address());
Ok(addr)
}
4 changes: 4 additions & 0 deletions common/src/indexer_service/http/indexer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit d3b58eb

Please sign in to comment.