@@ -8,18 +8,21 @@ mod image_processor;
88mod ipfs;
99pub mod logger;
1010pub mod output_generator;
11+ mod wallet;
1112use alloy:: primitives:: Address ;
1213use blob:: BlobTransactionData ;
1314use contracts:: ContractsManager ;
1415use ddex_parser:: ParserError ;
1516pub use log;
16- use log_macros:: log_error;
17+ use log_macros:: { format_error , log_error} ;
1718use output_generator:: MessageDirProcessingContext ;
1819use sentry:: User ;
1920use serde_json:: json;
2021use std:: env;
2122use std:: str:: FromStr ;
2223
24+ use crate :: wallet:: OwenWallet ;
25+
2326#[ cfg( any( feature = "aws-integration" , feature = "local-s3" ) ) ]
2427pub mod s3_message_storage;
2528
@@ -41,7 +44,7 @@ pub enum IpfsInterface {
4144#[ derive( Debug , serde:: Serialize , Clone ) ]
4245pub struct Config {
4346 pub rpc_url : String ,
44- pub private_key : String ,
47+ pub private_key : Option < String > ,
4548 pub folder_path : String ,
4649 pub local_ipfs : bool ,
4750 pub output_files_dir : String ,
@@ -77,7 +80,6 @@ impl Config {
7780 . unwrap_or_else ( || Config :: get_env_var ( "INPUT_FILES_DIR" ) . to_string ( ) ) ;
7881
7982 let rpc_url = Config :: get_env_var ( "RPC_URL" ) ;
80- let private_key = Config :: get_env_var ( "PRIVATE_KEY" ) ;
8183 let local_ipfs = matches ! (
8284 std:: env:: var( "LOCAL_IPFS" )
8385 . unwrap_or_else( |_| "false" . to_string( ) )
@@ -110,26 +112,28 @@ impl Config {
110112 let ipfs_api_base_url = env:: var ( "IPFS_API_BASE_URL" )
111113 . unwrap_or_else ( |_| constants:: IPFS_API_BASE_URL . to_string ( ) ) ;
112114
115+ let mut signer_kms_id = None ;
116+ let mut private_key = None ;
113117 let use_kms = matches ! (
114118 std:: env:: var( "USE_KMS" )
115119 . unwrap_or_else( |_| "false" . to_string( ) )
116120 . as_str( ) ,
117121 "1" | "true"
118122 ) ;
119123
124+ if use_kms {
125+ signer_kms_id = Some ( Config :: get_env_var ( "SIGNER_KMS_ID" ) ) ;
126+ } else {
127+ private_key = Some ( Config :: get_env_var ( "PRIVATE_KEY" ) ) ;
128+ }
129+
120130 let use_batch_sender = matches ! (
121131 std:: env:: var( "USE_BATCH_SENDER" )
122132 . unwrap_or_else( |_| "false" . to_string( ) )
123133 . as_str( ) ,
124134 "1" | "true"
125135 ) ;
126136
127- let mut signer_kms_id: Option < String > = None ;
128-
129- if use_kms {
130- signer_kms_id = Some ( Config :: get_env_var ( "SIGNER_KMS_ID" ) ) ;
131- }
132-
133137 let config = Config {
134138 rpc_url,
135139 private_key,
@@ -149,13 +153,39 @@ impl Config {
149153
150154 config
151155 }
156+
157+ fn try_private_key ( & self ) -> anyhow:: Result < & String > {
158+ if self . use_kms == false {
159+ self . private_key
160+ . as_ref ( )
161+ . ok_or_else ( || format_error ! ( "Missing private_key" ) )
162+ } else {
163+ return Err ( format_error ! (
164+ "private_key not available with USE_KMS=true flag"
165+ ) ) ;
166+ }
167+ }
168+
169+ fn try_signer_kms_id ( & self ) -> anyhow:: Result < & String > {
170+ if self . use_kms == true {
171+ self . signer_kms_id
172+ . as_ref ( )
173+ . ok_or_else ( || format_error ! ( "Missing signer_kms_id" ) )
174+ } else {
175+ return Err ( format_error ! (
176+ "signer_kms_id not available without USE_KMS=true flag"
177+ ) ) ;
178+ }
179+ }
152180}
153181
154182pub async fn run ( config : & Config ) -> anyhow:: Result < Vec < MessageDirProcessingContext > > {
155- let contracts_manager = ContractsManager :: build ( & config) . await ?;
183+ let owen_wallet = OwenWallet :: build ( & config) . await ?;
184+ let contracts_manager = ContractsManager :: build ( & config, & owen_wallet) . await ?;
156185 contracts_manager. check_image_compatibility ( ) . await ?;
157186
158- let message_dir_processing_log = output_generator:: create_output_files ( & config) . await ?;
187+ let message_dir_processing_log =
188+ output_generator:: create_output_files ( & config, & owen_wallet) . await ?;
159189
160190 let blob_transaction_data = BlobTransactionData :: build ( & config. output_files_dir ) ?;
161191
@@ -185,10 +215,6 @@ pub async fn run_with_sentry(config: &Config) -> anyhow::Result<Vec<MessageDirPr
185215 username : Some ( config. username . to_owned ( ) ) ,
186216 ..Default :: default ( )
187217 } ) ) ;
188-
189- let mut cloned_config = config. clone ( ) ;
190- cloned_config. private_key = "***" . to_string ( ) ;
191- scope. set_extra ( "config" , json ! ( cloned_config) ) ;
192218 } ) ;
193219
194220 let message_dir_processing_context = run ( & config) . await . map_err ( |e| {
0 commit comments