Skip to content

Commit 9929efe

Browse files
committed
refactor: read key from file
1 parent 142ec9c commit 9929efe

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

config/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ exporter_endpoint = "http://127.0.0.1:4317"
235235
# authorization_token = "your-auth-token"
236236

237237
# Path to the publisher's secret key file
238-
# publisher_secret_key = "/path/to/publisher-key.json"
238+
# publish_keypair_path = "/path/to/publisher-key.json"
239239

240240
# Duration between price updates (defaults to 200ms if not specified)
241241
# publish_interval_duration = "200ms"

src/agent/services/lazer_exporter.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use {
1919
reqwest::Client,
2020
serde::Deserialize,
2121
std::{
22+
path::PathBuf,
2223
sync::Arc,
2324
time::Duration,
2425
},
@@ -48,7 +49,7 @@ pub struct Config {
4849
pub relayer_urls: Vec<Url>,
4950
pub publisher_id: u32,
5051
pub authorization_token: String,
51-
publisher_secret_key: PublisherSecretKey,
52+
pub publish_keypair_path: PathBuf,
5253
#[serde(with = "humantime_serde", default = "default_publish_interval")]
5354
pub publish_interval_duration: Duration,
5455
}
@@ -173,7 +174,10 @@ mod lazer_exporter {
173174
},
174175
state::local::LocalStore,
175176
},
176-
anyhow::bail,
177+
anyhow::{
178+
Context,
179+
bail,
180+
},
177181
ed25519_dalek::{
178182
Signer,
179183
SigningKey,
@@ -198,6 +202,7 @@ mod lazer_exporter {
198202
lazer_transaction::Payload,
199203
},
200204
},
205+
solana_sdk::signer::keypair,
201206
std::{
202207
collections::HashMap,
203208
sync::Arc,
@@ -260,7 +265,21 @@ mod lazer_exporter {
260265
stream_map.insert(config.relayer_urls[i].clone(), receiver);
261266
}
262267

263-
let signing_key = SigningKey::from_bytes(&config.publisher_secret_key.0);
268+
// Read the keypair from the file using Solana SDK because it's the same key used by the Pythnet publisher
269+
let publish_keypair = match keypair::read_keypair_file(&config.publish_keypair_path) {
270+
Ok(k) => k,
271+
Err(e) => {
272+
tracing::warn!(
273+
error = ?e,
274+
publish_keypair_path = config.publish_keypair_path.display().to_string(),
275+
"Reading publish keypair returned an error. ",
276+
);
277+
bail!("Reading publish keypair returned an error. ");
278+
}
279+
};
280+
281+
let signing_key = SigningKey::from_keypair_bytes(&publish_keypair.to_bytes())
282+
.context("Failed to create signing key from keypair")?;
264283
let mut publish_interval = tokio::time::interval(config.publish_interval_duration);
265284

266285
loop {

0 commit comments

Comments
 (0)