Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions apps/pyth-lazer-agent/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::Duration;

use config::{Environment, File};
use derivative::Derivative;
use serde::Deserialize;
use std::cmp::min;
use std::fmt::{Debug, Formatter};
use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::Duration;
use url::Url;

#[derive(Deserialize, Derivative, Clone, PartialEq)]
#[derivative(Debug)]
pub struct Config {
pub listen_address: SocketAddr,
pub relayer_urls: Vec<Url>,
pub authorization_token: Option<String>,
pub authorization_token: Option<AuthorizationToken>,
#[derivative(Debug = "ignore")]
pub publish_keypair_path: PathBuf,
#[serde(with = "humantime_serde", default = "default_publish_interval")]
pub publish_interval_duration: Duration,
pub history_service_url: Option<Url>,
}

#[derive(Deserialize, Derivative, Clone, PartialEq)]
pub struct AuthorizationToken(pub String);

impl Debug for AuthorizationToken {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let token_string = self.0.to_ascii_lowercase();
#[allow(clippy::string_slice, reason = "false positive")]
let last_chars = &token_string[token_string.len() - min(4, token_string.len())..];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't it panic if the string is empty?

write!(f, "\"...{last_chars}\"")
}
}

fn default_publish_interval() -> Duration {
Duration::from_micros(500)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/pyth-lazer-agent/src/lazer_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl LazerPublisher {
let authorization_token =
if let Some(authorization_token) = config.authorization_token.clone() {
// If authorization_token is configured, use it.
authorization_token
authorization_token.0
} else {
// Otherwise, use the base64 pubkey.
BASE64_STANDARD.encode(signing_key.verifying_key().to_bytes())
Expand Down