36
36
import com .exonum .binding .core .storage .indices .EntryIndexProxy ;
37
37
import com .exonum .binding .core .storage .indices .MapIndex ;
38
38
import com .exonum .binding .core .transaction .RawTransaction ;
39
- import com .exonum .binding .qaservice .Config .InitialConfiguration ;
39
+ import com .exonum .binding .qaservice .Config .QaConfiguration ;
40
40
import com .exonum .binding .qaservice .transactions .IncrementCounterTx ;
41
41
import com .exonum .binding .qaservice .transactions .UnknownTx ;
42
42
import com .exonum .binding .time .TimeSchema ;
@@ -101,7 +101,7 @@ public List<HashCode> getStateHashes(Snapshot snapshot) {
101
101
@ Override
102
102
public void initialize (Fork fork , Configuration configuration ) {
103
103
// Init the time oracle
104
- initTimeOracle (fork , configuration );
104
+ updateTimeOracle (fork , configuration );
105
105
106
106
// Add a default counter to the blockchain.
107
107
createCounter (DEFAULT_COUNTER_NAME , fork );
@@ -110,20 +110,6 @@ public void initialize(Fork fork, Configuration configuration) {
110
110
createCounter (AFTER_COMMIT_COUNTER_NAME , fork );
111
111
}
112
112
113
- private void initTimeOracle (Fork fork , Configuration configuration ) {
114
- QaSchema schema = createDataSchema (fork );
115
- InitialConfiguration config = configuration .getAsMessage (InitialConfiguration .class );
116
- String timeOracleName = config .getTimeOracleName ();
117
- // Check the time oracle name is non-empty.
118
- // We do *not* check if the time oracle is active to (a) allow running this service with
119
- // reduced read functionality without time oracle; (b) testing time schema when it is not
120
- // active.
121
- checkArgument (!Strings .isNullOrEmpty (timeOracleName ), "Empty time oracle name: %s" ,
122
- timeOracleName );
123
- // Save the configuration
124
- schema .timeOracleName ().set (timeOracleName );
125
- }
126
-
127
113
private void createCounter (String name , Fork fork ) {
128
114
QaSchema schema = createDataSchema (fork );
129
115
MapIndex <HashCode , Long > counters = schema .counters ();
@@ -231,4 +217,37 @@ private HashCode submitTransaction(RawTransaction rawTransaction) {
231
217
private void checkBlockchainInitialized () {
232
218
checkState (node != null , "Service has not been fully initialized yet" );
233
219
}
220
+
221
+ @ Override
222
+ public void verifyConfiguration (Fork fork , Configuration configuration ) {
223
+ QaConfiguration config = configuration .getAsMessage (QaConfiguration .class );
224
+ checkConfiguration (config );
225
+ }
226
+
227
+ @ Override
228
+ public void applyConfiguration (Fork fork , Configuration configuration ) {
229
+ updateTimeOracle (fork , configuration );
230
+ }
231
+
232
+ private void checkConfiguration (QaConfiguration config ) {
233
+ String timeOracleName = config .getTimeOracleName ();
234
+ // Check the time oracle name is non-empty.
235
+ // We do *not* check if the time oracle is active to (a) allow running this service with
236
+ // reduced read functionality without time oracle; (b) testing time schema when it is not
237
+ // active.
238
+ checkArgument (!Strings .isNullOrEmpty (timeOracleName ), "Empty time oracle name: %s" ,
239
+ timeOracleName );
240
+ }
241
+
242
+ private void updateTimeOracle (Fork fork , Configuration configuration ) {
243
+ QaSchema schema = createDataSchema (fork );
244
+ QaConfiguration config = configuration .getAsMessage (QaConfiguration .class );
245
+
246
+ // Verify the configuration
247
+ checkConfiguration (config );
248
+
249
+ // Save the configuration
250
+ String timeOracleName = config .getTimeOracleName ();
251
+ schema .timeOracleName ().set (timeOracleName );
252
+ }
234
253
}
0 commit comments