Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
misc: update config variable name to avoid confusion (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
rllola authored Feb 20, 2024
1 parent 6bfc74c commit 0e24ea0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion config/Settings.example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
log_level = "info"
log_format = "pretty"
network = "public-testnet-15"
# The chain name is the Chain ID value without what is after the '.' (e.g 'shielded-expedition.88f17d1d14' -> 'shielded-expedition')
chain_name = "public-testnet-15"

[database]
host = "localhost"
Expand Down
2 changes: 1 addition & 1 deletion docs/03-indexer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Settings.toml
# Level and format of logging in the indexer
log_level = "info"
log_format = "pretty" # optional; either "pretty" or "json"
network = "public-testnet-15" # IMPORANT! Do not use `.` just put the name of the network and don't have the hash (e.g 'shielded-expedition.b40d8e9055' becomes 'shielded-expedition')
chain_name = "public-testnet-15" # IMPORANT! Do not use `.` just put the name of the network and don't have the hash (e.g 'shielded-expedition.b40d8e9055' becomes 'shielded-expedition')

# Connection information for the PostgreSQL database
[database]
Expand Down
2 changes: 1 addition & 1 deletion docs/04-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Settings.toml
```toml
log_level = "info"
log_format = "pretty" # optional; either "pretty" or "json"
network = "public-testnet-15" # IMPORANT! Do not use `.` just put the name of the network and don't have the hash (e.g 'shielded-expedition.b40d8e9055' becomes 'shielded-expedition')
chain_name = "public-testnet-15" # IMPORANT! Do not use `.` the chain name is juste the Chain ID without what is after the '.' (e.g 'shielded-expedition.b40d8e9055' becomes 'shielded-expedition')

# Connection information for the PostgreSQL database
[database]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn main() -> Result<(), Error> {

info!("Starting database connection");

let db = Database::new(cfg.database_config(), cfg.network.as_str()).await?;
let db = Database::new(cfg.database_config(), cfg.chain_name.as_str()).await?;
info!("Creating tables");
db.create_tables().await?;

Expand Down
2 changes: 1 addition & 1 deletion src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() -> Result<(), Error> {

setup_logging(&cfg);

let db = Database::new(cfg.database_config(), cfg.network.as_str()).await?;
let db = Database::new(cfg.database_config(), cfg.chain_name.as_str()).await?;

// Start JSON server
start_server(db, cfg.server_config()).await?;
Expand Down
18 changes: 9 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const JAEGER_PORT: u16 = 6831;
pub const PROMETHEUS_HOST: &str = "localhost";
pub const PROMETHEUS_PORT: u16 = 9000;

pub const DEFAULT_NETWORK: &str = "public-testnet-15";
pub const DEFAULT_CHAIN_NAME: &str = "public-testnet-15";

pub const DEFAULT_LOG_FORMAT: &str = "pretty";

Expand Down Expand Up @@ -141,8 +141,8 @@ pub struct CliSettings {
pub log_level: String,
#[clap(long, env, default_value = DEFAULT_LOG_FORMAT)]
pub log_format: LogFormat,
#[clap(long, env, default_value = DEFAULT_NETWORK)]
pub network: String,
#[clap(long, env, default_value = DEFAULT_CHAIN_NAME)]
pub chain_name: String,
#[clap(long, env, default_value = SERVER_ADDR)]
pub server_serve_at: String,
#[clap(long, env, default_value_t = SERVER_PORT)]
Expand Down Expand Up @@ -180,7 +180,7 @@ pub struct Settings {
pub log_level: String,
#[serde(default)]
pub log_format: LogFormat,
pub network: String,
pub chain_name: String,
pub database: DatabaseConfig,
pub server: ServerConfig,
pub indexer: IndexerConfig,
Expand All @@ -193,7 +193,7 @@ impl Default for Settings {
Self {
log_level: Default::default(),
log_format: Default::default(),
network: DEFAULT_NETWORK.to_string(),
chain_name: DEFAULT_CHAIN_NAME.to_string(),
database: Default::default(),
server: Default::default(),
indexer: Default::default(),
Expand All @@ -208,7 +208,7 @@ impl From<CliSettings> for Settings {
Self {
log_level: value.log_level,
log_format: value.log_format,
network: value.network,
chain_name: value.chain_name,
database: DatabaseConfig {
host: value.database_host,
user: value.database_user,
Expand Down Expand Up @@ -252,9 +252,9 @@ impl Settings {

let settings: Self = config.try_deserialize().map_err(Error::from)?;

// verify if network is correct
if settings.network.contains('.') {
panic!("network cannot contains '.' (example of valid network 'public-testnet-14')")
// verify if chain_name is correct
if settings.chain_name.contains('.') {
panic!("chain_name cannot contains '.' (example of valid chain_name 'public-testnet-14')")
}

return Ok(settings);
Expand Down

0 comments on commit 0e24ea0

Please sign in to comment.