-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement : Refactor Settings #106
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d14b790
feat : added settings
ocdbytes 620fe49
changelog
ocdbytes 247dfb3
feat : added env settings fucntion
ocdbytes 3d19e90
feat : updated settings module implementation
ocdbytes 471d6e8
Merge branch 'main' into refactor/settings
ocdbytes c9e81d1
feat : updated provider config
ocdbytes f194492
feat : added arc for aws config
ocdbytes 5185ccc
chore : refactoring
ocdbytes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,20 @@ | ||
use std::str::FromStr; | ||
|
||
use alloy::{network::Ethereum, providers::ProviderBuilder, rpc::client::RpcClient}; | ||
use async_trait::async_trait; | ||
use da_client_interface::DaConfig; | ||
use url::Url; | ||
use serde::{Deserialize, Serialize}; | ||
use utils::env_utils::get_env_var_or_panic; | ||
|
||
use crate::EthereumDaClient; | ||
|
||
#[derive(Clone, Debug)] | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct EthereumDaConfig { | ||
pub rpc_url: String, | ||
pub memory_pages_contract: String, | ||
pub private_key: String, | ||
} | ||
|
||
#[async_trait] | ||
impl DaConfig<EthereumDaClient> for EthereumDaConfig { | ||
fn new_from_env() -> Self { | ||
impl Default for EthereumDaConfig { | ||
/// Default config for Sepolia testnet | ||
fn default() -> Self { | ||
Self { | ||
rpc_url: get_env_var_or_panic("SETTLEMENT_RPC_URL"), | ||
memory_pages_contract: get_env_var_or_panic("MEMORY_PAGES_CONTRACT_ADDRESS"), | ||
private_key: get_env_var_or_panic("PRIVATE_KEY"), | ||
} | ||
} | ||
async fn build_client(&self) -> EthereumDaClient { | ||
let client = | ||
RpcClient::new_http(Url::from_str(self.rpc_url.as_str()).expect("Failed to parse SETTLEMENT_RPC_URL")); | ||
let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); | ||
|
||
EthereumDaClient { provider } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use utils::env_utils::get_env_var_or_panic; | ||
|
||
#[derive(Clone, Serialize, Deserialize)] | ||
pub struct AWSSNSConfig { | ||
/// AWS SNS ARN | ||
pub sns_arn: String, | ||
/// AWS SNS region | ||
pub sns_arn_region: String, | ||
} | ||
|
||
impl Default for AWSSNSConfig { | ||
fn default() -> Self { | ||
Self { sns_arn: get_env_var_or_panic("AWS_SNS_ARN"), sns_arn_region: get_env_var_or_panic("AWS_SNS_REGION") } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
mod config; | ||
|
||
use crate::alerts::aws_sns::config::AWSSNSConfig; | ||
use crate::alerts::Alerts; | ||
use async_trait::async_trait; | ||
use aws_sdk_sns::config::Region; | ||
use aws_sdk_sns::Client; | ||
use utils::env_utils::get_env_var_or_panic; | ||
use utils::settings::SettingsProvider; | ||
|
||
pub const AWS_SNS_SETTINGS_NAME: &str = "sns"; | ||
|
||
pub struct AWSSNS { | ||
client: Client, | ||
topic_arn: String, | ||
apoorvsadana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
impl AWSSNS { | ||
/// To create a new SNS client | ||
pub async fn new() -> Self { | ||
let sns_region = get_env_var_or_panic("AWS_SNS_REGION"); | ||
let config = aws_config::from_env().region(Region::new(sns_region)).load().await; | ||
AWSSNS { client: Client::new(&config) } | ||
pub async fn with_settings(settings: &impl SettingsProvider) -> Self { | ||
let sns_config: AWSSNSConfig = settings.get_settings(AWS_SNS_SETTINGS_NAME).unwrap(); | ||
let config = aws_config::from_env().region(Region::new(sns_config.sns_arn_region)).load().await; | ||
Self { client: Client::new(&config), topic_arn: sns_config.sns_arn } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Alerts for AWSSNS { | ||
async fn send_alert_message(&self, message_body: String) -> color_eyre::Result<()> { | ||
let topic_arn = get_env_var_or_panic("AWS_SNS_ARN"); | ||
self.client.publish().topic_arn(topic_arn).message(message_body).send().await?; | ||
self.client.publish().topic_arn(self.topic_arn.clone()).message(message_body).send().await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we actually did this before but then later in the celestia PR we realised that we wanted it to be async and this was the better way to do it, over here #46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for this to be async ? this is config which should not be an async operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in celestia it wasn't possible to do it sync, can you check with @heemankv once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me check