@@ -28,40 +28,21 @@ var (
2828)
2929
3030type  Config  struct  {
31- 	settlementChainAddr         string  `koanf:"settlement_chain_addr"` 
32- 	sequencingChainAddr         string  `koanf:"sequencing_chain_addr"` 
33- 	metaBasedChainAddr          string  `koanf:"meta_based_chain_addr"` 
34- 	sequencingContractAddress   string  `koanf:"sequencing_contract_address"` 
35- 	batcherAddress              string  `koanf:"batcher_address"` 
36- 	batchInboxAddress           string  `koanf:"batch_inbox_address"` 
37- 	batcherPrivateKey           string  `koanf:"batcher_private_key"` 
38- 	logLevel                    string  `koanf:"log_level"` 
39- 	settlementChainID           int64   `koanf:"settlement_chain_id"` 
40- 	settlementStartBlock        int     `koanf:"settlement_start_block"` 
41- 	sequencingStartBlock        int     `koanf:"sequencing_start_block"` 
42- 	sequencePerSettlementBlock  int     `koanf:"sequence_per_settlement_block"` 
43- 	port                        int     `koanf:"port"` 
44- 	frameSize                   int     `koanf:"frame_size"` 
45- 	pretty                      bool    `koanf:"pretty"` 
46- }
47- 
48- type  IConfig  interface  {
49- 	SettlementChainAddr () string 
50- 	SequencingChainAddr () string 
51- 	MetaBasedChainAddr () string 
52- 	LogLevel () string 
53- 	Port () int 
54- 	FrameSize () int 
55- 	Pretty () bool 
56- 
57- 	SequencingContractAddress () string 
58- 	BatcherAddress () string 
59- 	BatchInboxAddress () string 
60- 	BatcherPrivateKey () string 
61- 	SettlementChainID () int64 
62- 	SettlementStartBlock () int 
63- 	SequencingStartBlock () int 
64- 	SequencePerSettlementBlock () int 
31+ 	SettlementChainAddr         string  `koanf:"settlement_chain_addr"` 
32+ 	SequencingChainAddr         string  `koanf:"sequencing_chain_addr"` 
33+ 	MetaBasedChainAddr          string  `koanf:"meta_based_chain_addr"` 
34+ 	SequencingContractAddress   string  `koanf:"sequencing_contract_address"` 
35+ 	BatcherAddress              string  `koanf:"batcher_address"` 
36+ 	BatchInboxAddress           string  `koanf:"batch_inbox_address"` 
37+ 	BatcherPrivateKey           string  `koanf:"batcher_private_key"` 
38+ 	LogLevel                    string  `koanf:"log_level"` 
39+ 	SettlementChainID           int64   `koanf:"settlement_chain_id"` 
40+ 	SettlementStartBlock        int     `koanf:"settlement_start_block"` 
41+ 	SequencingStartBlock        int     `koanf:"sequencing_start_block"` 
42+ 	SequencePerSettlementBlock  int     `koanf:"sequence_per_settlement_block"` 
43+ 	Port                        int     `koanf:"port"` 
44+ 	FrameSize                   int     `koanf:"frame_size"` 
45+ 	Pretty                      bool    `koanf:"pretty"` 
6546}
6647
6748// setCLIFlags sets all valid CLI flags for the app 
@@ -85,22 +66,22 @@ func setCLIFlags(f *pflag.FlagSet) {
8566
8667// hydrateFromConfMap sets the Config values from the koanf conf map 
8768func  hydrateFromConfMap (config  * Config ) {
88- 	config .port  =  k .Int ("port" )
89- 	config .settlementChainAddr  =  k .String ("settlement_chain_addr" )
90- 	config .sequencingChainAddr  =  k .String ("sequencing_chain_addr" )
91- 	config .metaBasedChainAddr  =  k .String ("meta_based_chain_addr" )
92- 	config .frameSize  =  k .Int ("frame_size" )
93- 	config .logLevel  =  k .String ("log_level" )
94- 	config .pretty  =  k .Bool ("pretty" )
95- 
96- 	config .sequencingContractAddress  =  k .String ("sequencing_contract_address" )
97- 	config .batcherAddress  =  k .String ("batcher_address" )
98- 	config .batchInboxAddress  =  k .String ("batch_inbox_address" )
99- 	config .settlementStartBlock  =  k .Int ("settlement_start_block" )
100- 	config .sequencingStartBlock  =  k .Int ("sequencing_start_block" )
101- 	config .sequencePerSettlementBlock  =  k .Int ("sequence_per_settlement_block" )
102- 	config .batcherPrivateKey  =  k .String ("batcher_private_key" )
103- 	config .settlementChainID  =  k .Int64 ("settlement_chain_id" )
69+ 	config .Port  =  k .Int ("port" )
70+ 	config .SettlementChainAddr  =  k .String ("settlement_chain_addr" )
71+ 	config .SequencingChainAddr  =  k .String ("sequencing_chain_addr" )
72+ 	config .MetaBasedChainAddr  =  k .String ("meta_based_chain_addr" )
73+ 	config .FrameSize  =  k .Int ("frame_size" )
74+ 	config .LogLevel  =  k .String ("log_level" )
75+ 	config .Pretty  =  k .Bool ("pretty" )
76+ 
77+ 	config .SequencingContractAddress  =  k .String ("sequencing_contract_address" )
78+ 	config .BatcherAddress  =  k .String ("batcher_address" )
79+ 	config .BatchInboxAddress  =  k .String ("batch_inbox_address" )
80+ 	config .SettlementStartBlock  =  k .Int ("settlement_start_block" )
81+ 	config .SequencingStartBlock  =  k .Int ("sequencing_start_block" )
82+ 	config .SequencePerSettlementBlock  =  k .Int ("sequence_per_settlement_block" )
83+ 	config .BatcherPrivateKey  =  k .String ("batcher_private_key" )
84+ 	config .SettlementChainID  =  k .Int64 ("settlement_chain_id" )
10485}
10586
10687func  Init () * Config  {
@@ -136,135 +117,75 @@ func Init() *Config {
136117	hydrateFromConfMap (& config )
137118
138119	// Validate config 
139- 	if  err  =  validateConfigValues (& config ); err  !=  nil  {
120+ 	if  err  =  ValidateConfigValues (& config ); err  !=  nil  {
140121		log .Panic ().Err (err ).Msg ("error validating config" )
141122	}
142123	return  & config 
143124}
144125
145- func  validateConfigValues (config  * Config ) (result  error ) {
146- 	if  config .port  <=  0  {
126+ func  ValidateConfigValues (config  * Config ) (result  error ) {
127+ 	if  config .Port  <=  0  {
147128		result  =  multierror .Append (result , errors .New ("port must be a positive number" ))
148129	}
149130
150- 	if  config .frameSize  <=  0  {
131+ 	if  config .FrameSize  <=  0  {
151132		result  =  multierror .Append (result , errors .New ("frameSize must be a positive number" ))
152133	}
153134
154- 	if  config .frameSize  >  MaxFrameSize  {
135+ 	if  config .FrameSize  >  MaxFrameSize  {
155136		result  =  multierror .Append (result , errors .New ("frameSize must be less than maximum" ))
156137	}
157138
158- 	_ , err  :=  url .ParseRequestURI (config .sequencingChainAddr )
139+ 	_ , err  :=  url .ParseRequestURI (config .SequencingChainAddr )
159140	if  err  !=  nil  {
160141		result  =  multierror .Append (result , fmt .Errorf ("invalid URL for sequencing chain address: %w" , err ))
161142	}
162143
163- 	_ , err  =  url .ParseRequestURI (config .settlementChainAddr )
144+ 	_ , err  =  url .ParseRequestURI (config .SettlementChainAddr )
164145	if  err  !=  nil  {
165146		result  =  multierror .Append (result , fmt .Errorf ("invalid URL for settlement chain address: %w" , err ))
166147	}
167148
168- 	_ , err  =  url .ParseRequestURI (config .metaBasedChainAddr )
149+ 	_ , err  =  url .ParseRequestURI (config .MetaBasedChainAddr )
169150	if  err  !=  nil  {
170151		result  =  multierror .Append (result , fmt .Errorf ("invalid URL for meta based chain address: %w" , err ))
171152	}
172153
173- 	if  ! constants .IsValidLogLevel (config .logLevel ) {
154+ 	if  ! constants .IsValidLogLevel (config .LogLevel ) {
174155		result  =  multierror .Append (result , errors .New ("invalid log level" ))
175156	}
176157
177- 	if  ! common .IsHexAddress (config .sequencingContractAddress ) {
158+ 	if  ! common .IsHexAddress (config .SequencingContractAddress ) {
178159		result  =  multierror .Append (result , errors .New ("sequencingContractAddress must be a valid hex address" ))
179160	}
180161
181- 	if  ! common .IsHexAddress (config .batcherAddress ) {
162+ 	if  ! common .IsHexAddress (config .BatcherAddress ) {
182163		result  =  multierror .Append (result , errors .New ("batcherAddress must be a valid hex address" ))
183164	}
184165
185- 	if  ! common .IsHexAddress (config .batchInboxAddress ) {
166+ 	if  ! common .IsHexAddress (config .BatchInboxAddress ) {
186167		result  =  multierror .Append (result , errors .New ("batchInboxAddress must be a valid hex address" ))
187168	}
188169
189- 	if  config .sequencePerSettlementBlock  <=  0  {
190- 		result  =  multierror .Append (result , fmt .Errorf ("sequencePerSettlementBlock must be a positive number: %d" , config .sequencePerSettlementBlock ))
170+ 	if  config .SequencePerSettlementBlock  <=  0  {
171+ 		result  =  multierror .Append (result , fmt .Errorf ("sequencePerSettlementBlock must be a positive number: %d" , config .SequencePerSettlementBlock ))
191172	}
192173
193- 	if  config .settlementStartBlock  <=  0  {
194- 		result  =  multierror .Append (result , fmt .Errorf ("settlementStartBlock must be a positive number: %d" , config .settlementStartBlock ))
174+ 	if  config .SettlementStartBlock  <=  0  {
175+ 		result  =  multierror .Append (result , fmt .Errorf ("settlementStartBlock must be a positive number: %d" , config .SettlementStartBlock ))
195176	}
196177
197- 	if  config .sequencingStartBlock  <=  0  {
198- 		result  =  multierror .Append (result , fmt .Errorf ("sequencingStartBlock must be a positive number: %d" , config .sequencingStartBlock ))
178+ 	if  config .SequencingStartBlock  <=  0  {
179+ 		result  =  multierror .Append (result , fmt .Errorf ("sequencingStartBlock must be a positive number: %d" , config .SequencingStartBlock ))
199180	}
200181
201- 	if  config .batcherPrivateKey  ==  ""  {
182+ 	if  config .BatcherPrivateKey  ==  ""  {
202183		result  =  multierror .Append (result , fmt .Errorf ("batcherPrivateKey cannot be blank" ))
203184	}
204185
205- 	if  config .settlementChainID  <=  0  {
206- 		result  =  multierror .Append (result , fmt .Errorf ("settlementChainID must be a positive number: %d" , config .settlementChainID ))
186+ 	if  config .SettlementChainID  <=  0  {
187+ 		result  =  multierror .Append (result , fmt .Errorf ("settlementChainID must be a positive number: %d" , config .SettlementChainID ))
207188	}
208189
209190	return  result 
210191}
211- 
212- func  (c  * Config ) SettlementChainAddr () string  {
213- 	return  c .settlementChainAddr 
214- }
215- 
216- func  (c  * Config ) SequencingChainAddr () string  {
217- 	return  c .sequencingChainAddr 
218- }
219- 
220- func  (c  * Config ) MetaBasedChainAddr () string  {
221- 	return  c .metaBasedChainAddr 
222- }
223- 
224- func  (c  * Config ) Port () int  {
225- 	return  c .port 
226- }
227- 
228- func  (c  * Config ) FrameSize () int  {
229- 	return  c .frameSize 
230- }
231- 
232- func  (c  * Config ) LogLevel () string  {
233- 	return  c .logLevel 
234- }
235- 
236- func  (c  * Config ) Pretty () bool  {
237- 	return  c .pretty 
238- }
239- 
240- func  (c  * Config ) SequencingContractAddress () string  {
241- 	return  c .sequencingContractAddress 
242- }
243- 
244- func  (c  * Config ) BatcherAddress () string  {
245- 	return  c .batcherAddress 
246- }
247- 
248- func  (c  * Config ) BatchInboxAddress () string  {
249- 	return  c .batchInboxAddress 
250- }
251- 
252- func  (c  * Config ) SettlementStartBlock () int  {
253- 	return  c .settlementStartBlock 
254- }
255- 
256- func  (c  * Config ) SequencingStartBlock () int  {
257- 	return  c .sequencingStartBlock 
258- }
259- 
260- func  (c  * Config ) SequencePerSettlementBlock () int  {
261- 	return  c .sequencePerSettlementBlock 
262- }
263- 
264- func  (c  * Config ) BatcherPrivateKey () string  {
265- 	return  c .batcherPrivateKey 
266- }
267- 
268- func  (c  * Config ) SettlementChainID () int64  {
269- 	return  c .settlementChainID 
270- }
0 commit comments