38 using namespace eth::validation;
39 namespace js = json_spirit;
41 ChainParams::ChainParams()
43 for (
unsigned i = 1; i <= 4; ++i)
52 ChainParams::ChainParams(
string const& _json,
h256 const& _stateRoot)
54 *
this = loadConfig(_json, _stateRoot);
58 string const& _json,
h256 const& _stateRoot,
const boost::filesystem::path& _configPath)
const
65 js::read_string_or_throw(_json, val);
67 catch (js::Error_position
const& error)
69 std::string
const comment =
"json parsing error detected on line " +
70 std::to_string(error.line_) +
" in column " +
71 std::to_string(error.column_) +
": " + error.reason_;
72 std::cerr << comment <<
"\n";
76 js::mObject obj = val.get_obj();
82 js::mObject params = obj[
c_params].get_obj();
95 auto setOptionalU256Parameter = [¶ms](
u256 &_destination,
string const& _name)
97 if (params.count(_name))
98 _destination = fromBigEndian<u256>(
fromHex(params.at(_name).get_str()));
123 string genesisStr = js::write_string(obj[
c_genesis],
false);
124 cp = cp.loadGenesis(genesisStr, _stateRoot);
126 string genesisStateStr = js::write_string(obj[
c_accounts],
false);
135 ChainParams ChainParams::loadGenesis(
string const& _json,
h256 const& _stateRoot)
const
140 js::read_string(_json, val);
141 js::mObject genesis = val.get_obj();
143 cp.parentHash =
h256(0);
147 cp.minimumDifficulty;
159 cp.sealRLP =
rlp(mixHash) +
rlp(nonce);
161 cp.stateRoot = _stateRoot ? _stateRoot : cp.calculateStateRoot();
167 SealEngineFace* ret = SealEngineRegistrar::create(sealEngineName);
168 assert(ret &&
"Seal engine not found");
180 void ChainParams::populateFromGenesis(
bytes const& _genesisRLP,
AccountMap const& _state)
183 parentHash = bi.parentHash();
184 author = bi.author();
185 difficulty = bi.difficulty();
186 gasLimit = bi.gasLimit();
187 gasUsed = bi.gasUsed();
188 timestamp = bi.timestamp();
189 extraData = bi.extraData();
192 sealFields = r[0].itemCount() - BlockHeader::BasicFields;
194 for (
unsigned i = BlockHeader::BasicFields; i < r[0].itemCount(); ++i)
195 sealRLP += r[0][i].data();
197 calculateStateRoot(
true);
199 auto b = genesisBlock();
200 if (b != _genesisRLP)
203 cdebug <<
"Genesis now:" << BlockHeader::headerHashFromBlock(b);
210 h256 ChainParams::calculateStateRoot(
bool _force)
const
215 if (!stateRoot || _force)
220 stateRoot = state.root();
225 bytes ChainParams::genesisBlock()
const
229 calculateStateRoot();
231 block.
appendList(BlockHeader::BasicFields + sealFields)