11use std:: path:: Path ;
22
3+ use axum:: http:: HeaderValue ;
34use rusx:: config:: OauthConfig ;
45use serde:: { Deserialize , Serialize } ;
56use tokio:: time;
@@ -19,6 +20,7 @@ pub struct Config {
1920 pub alert : AlertConfig ,
2021 pub x_association : XAssociationConfig ,
2122 pub remote_configs : RemoteConfigsConfig ,
23+ pub risk_checker : RiskCheckerConfig ,
2224}
2325
2426#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -31,6 +33,7 @@ pub struct ServerConfig {
3133 pub host : String ,
3234 pub port : u16 ,
3335 pub base_api_url : String ,
36+ pub cors_allowed_origins : Vec < String > ,
3437}
3538
3639#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -99,6 +102,16 @@ pub struct XAssociationConfig {
99102 pub keywords : String ,
100103}
101104
105+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
106+ pub struct RiskCheckerConfig {
107+ pub etherscan_api_key : String ,
108+ pub etherscan_base_url : String ,
109+ pub infura_api_key : String ,
110+ pub infura_base_url : String ,
111+ pub etherscan_calls_per_sec : u32 ,
112+ pub max_concurrent_requests : usize ,
113+ }
114+
102115impl Config {
103116 pub fn load ( config_path : & str ) -> Result < Self , config:: ConfigError > {
104117 let settings = config:: Config :: builder ( )
@@ -159,6 +172,20 @@ impl Config {
159172 & self . x_association . keywords
160173 }
161174
175+ pub fn get_cors_allowed_origins ( & self ) -> Vec < HeaderValue > {
176+ self . server
177+ . cors_allowed_origins
178+ . iter ( )
179+ . filter_map ( |o| match o. parse ( ) {
180+ Ok ( v) => Some ( v) ,
181+ Err ( e) => {
182+ tracing:: warn!( "Skipping invalid CORS origin {:?}: {}" , o, e) ;
183+ None
184+ }
185+ } )
186+ . collect ( )
187+ }
188+
162189 fn resolve_relative_paths ( & mut self , config_path : & str ) {
163190 let wallet_configs_path = Path :: new ( & self . remote_configs . wallet_configs_file ) ;
164191 if wallet_configs_path. is_absolute ( ) {
@@ -176,6 +203,7 @@ impl Default for Config {
176203 host : "127.0.0.1" . to_string ( ) ,
177204 port : 3000 ,
178205 base_api_url : "http://127.0.0.1:3000/api" . to_string ( ) ,
206+ cors_allowed_origins : vec ! [ "http://localhost:3000" . to_string( ) ] ,
179207 } ,
180208 blockchain : BlockchainConfig {
181209 website_url : "https://www.quantus.com" . to_string ( ) ,
@@ -231,6 +259,14 @@ impl Default for Config {
231259 remote_configs : RemoteConfigsConfig {
232260 wallet_configs_file : "wallet_configs/default_configs.json" . to_string ( ) ,
233261 } ,
262+ risk_checker : RiskCheckerConfig {
263+ etherscan_api_key : "change-me" . to_string ( ) ,
264+ etherscan_base_url : "https://api.etherscan.io/api" . to_string ( ) ,
265+ infura_api_key : "change-me" . to_string ( ) ,
266+ infura_base_url : "https://mainnet.infura.io/v3" . to_string ( ) ,
267+ etherscan_calls_per_sec : 3 ,
268+ max_concurrent_requests : 1 ,
269+ } ,
234270 }
235271 }
236272}
0 commit comments