Skip to content

Commit d3b58eb

Browse files
committed
feat(common): add a route /info for operator public key
1 parent 6ba931c commit d3b58eb

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

common/src/address.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2023-, GraphOps and Semiotic Labs.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use ethers::signers::{
5+
coins_bip39::English, LocalWallet, MnemonicBuilder, Signer, Wallet, WalletError,
6+
};
7+
use ethers_core::k256::ecdsa::SigningKey;
8+
9+
/// Build Wallet from Private key or Mnemonic
10+
pub fn build_wallet(value: &str) -> Result<Wallet<SigningKey>, WalletError> {
11+
value
12+
.parse::<LocalWallet>()
13+
.or(MnemonicBuilder::<English>::default().phrase(value).build())
14+
}
15+
16+
// Format public key to a String
17+
pub fn public_key(value: &str) -> Result<String, WalletError> {
18+
let wallet = build_wallet(value)?;
19+
let addr = format!("{:?}", wallet.address());
20+
Ok(addr)
21+
}

common/src/indexer_service/http/indexer_service.rs

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use tower_governor::{errors::display_error, governor::GovernorConfigBuilder, Gov
3131
use tracing::info;
3232

3333
use crate::{
34+
address::public_key,
3435
indexer_service::http::{
3536
metrics::IndexerServiceMetrics, static_subgraph::static_subgraph_request_handler,
3637
},
@@ -312,9 +313,12 @@ impl IndexerService {
312313
)),
313314
};
314315

316+
let operator_address = public_key(&options.config.indexer.operator_mnemonic)?;
317+
315318
let mut misc_routes = Router::new()
316319
.route("/", get("Service is up and running"))
317320
.route("/version", get(Json(options.release)))
321+
.route("/info", get(Json(operator_address)))
318322
.layer(
319323
ServiceBuilder::new()
320324
.layer(HandleErrorLayer::new(|e: BoxError| async move {

common/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2023-, GraphOps and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
pub mod address;
45
pub mod allocations;
56
pub mod attestations;
67
pub mod escrow_accounts;

0 commit comments

Comments
 (0)