@@ -157,16 +157,30 @@ state::Withdrawal from_json<state::Withdrawal>(const json::json& j)
157
157
template <>
158
158
state::BlockInfo from_json<state::BlockInfo>(const json::json& j)
159
159
{
160
- evmc::bytes32 difficulty;
160
+ evmc::bytes32 prev_randao;
161
+ int64_t current_difficulty = 0 ;
162
+ int64_t parent_difficulty = 0 ;
161
163
const auto prev_randao_it = j.find (" currentRandom" );
162
164
const auto current_difficulty_it = j.find (" currentDifficulty" );
163
165
const auto parent_difficulty_it = j.find (" parentDifficulty" );
166
+
167
+ if (current_difficulty_it != j.end ())
168
+ current_difficulty = from_json<int64_t >(*current_difficulty_it);
169
+ if (parent_difficulty_it != j.end ())
170
+ parent_difficulty = from_json<int64_t >(*parent_difficulty_it);
171
+
172
+ // When it's not defined init it with difficulty value.
164
173
if (prev_randao_it != j.end ())
165
- difficulty = from_json<bytes32>(*prev_randao_it);
174
+ prev_randao = from_json<bytes32>(*prev_randao_it);
166
175
else if (current_difficulty_it != j.end ())
167
- difficulty = from_json<bytes32>(*current_difficulty_it);
176
+ prev_randao = from_json<bytes32>(*current_difficulty_it);
168
177
else if (parent_difficulty_it != j.end ())
169
- difficulty = from_json<bytes32>(*parent_difficulty_it);
178
+ prev_randao = from_json<bytes32>(*parent_difficulty_it);
179
+
180
+ hash256 parent_uncle_hash;
181
+ const auto parent_uncle_hash_it = j.find (" parentUncleHash" );
182
+ if (parent_uncle_hash_it != j.end ())
183
+ parent_uncle_hash = from_json<hash256>(*parent_uncle_hash_it);
170
184
171
185
uint64_t base_fee = 0 ;
172
186
if (j.contains (" currentBaseFee" ))
@@ -192,10 +206,26 @@ state::BlockInfo from_json<state::BlockInfo>(const json::json& j)
192
206
block_hashes[from_json<int64_t >(j_num)] = from_json<hash256>(j_hash);
193
207
}
194
208
209
+ std::vector<state::Ommer> ommers;
210
+ if (const auto ommers_it = j.find (" ommers" ); ommers_it != j.end ())
211
+ {
212
+ for (const auto & ommer : *ommers_it)
213
+ {
214
+ ommers.push_back (
215
+ {from_json<evmc::address>(ommer.at (" address" )), ommer.at (" delta" ).get <uint32_t >()});
216
+ }
217
+ }
218
+
219
+ int64_t parent_timestamp = 0 ;
220
+ auto parent_timestamp_it = j.find (" parentTimestamp" );
221
+ if (parent_timestamp_it != j.end ())
222
+ parent_timestamp = from_json<int64_t >(*parent_timestamp_it);
223
+
195
224
return {from_json<int64_t >(j.at (" currentNumber" )), from_json<int64_t >(j.at (" currentTimestamp" )),
196
- from_json<int64_t >(j.at (" currentGasLimit" )),
197
- from_json<evmc::address>(j.at (" currentCoinbase" )), difficulty, base_fee,
198
- std::move (withdrawals), std::move (block_hashes)};
225
+ parent_timestamp, from_json<int64_t >(j.at (" currentGasLimit" )),
226
+ from_json<evmc::address>(j.at (" currentCoinbase" )), current_difficulty, parent_difficulty,
227
+ parent_uncle_hash, prev_randao, base_fee, std::move (ommers), std::move (withdrawals),
228
+ std::move (block_hashes)};
199
229
}
200
230
201
231
template <>
0 commit comments