|
|
@ -28,57 +28,6 @@ using namespace dev; |
|
|
|
using namespace dev::test; |
|
|
|
using namespace dev::eth; |
|
|
|
|
|
|
|
namespace dev |
|
|
|
{ |
|
|
|
namespace test |
|
|
|
{ |
|
|
|
dev::eth::BlockInfo toBlockInfo(Json::Value const& _json); |
|
|
|
bytes toGenesisBlock(Json::Value const& _json); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
dev::eth::BlockInfo dev::test::toBlockInfo(Json::Value const& _json) |
|
|
|
{ |
|
|
|
RLPStream rlpStream; |
|
|
|
auto size = _json.getMemberNames().size(); |
|
|
|
rlpStream.appendList(_json["hash"].empty() ? size : (size - 1)); |
|
|
|
rlpStream << fromHex(_json["parentHash"].asString()); |
|
|
|
rlpStream << fromHex(_json["uncleHash"].asString()); |
|
|
|
rlpStream << fromHex(_json["coinbase"].asString()); |
|
|
|
rlpStream << fromHex(_json["stateRoot"].asString()); |
|
|
|
rlpStream << fromHex(_json["transactionsTrie"].asString()); |
|
|
|
rlpStream << fromHex(_json["receiptTrie"].asString()); |
|
|
|
rlpStream << fromHex(_json["bloom"].asString()); |
|
|
|
rlpStream << bigint(_json["difficulty"].asString()); |
|
|
|
rlpStream << bigint(_json["number"].asString()); |
|
|
|
rlpStream << bigint(_json["gasLimit"].asString()); |
|
|
|
rlpStream << bigint(_json["gasUsed"].asString()); |
|
|
|
rlpStream << bigint(_json["timestamp"].asString()); |
|
|
|
rlpStream << fromHex(_json["extraData"].asString()); |
|
|
|
rlpStream << fromHex(_json["mixHash"].asString()); |
|
|
|
rlpStream << fromHex(_json["nonce"].asString()); |
|
|
|
|
|
|
|
BlockInfo result; |
|
|
|
RLP rlp(rlpStream.out()); |
|
|
|
result.populateFromHeader(rlp, IgnoreNonce); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
bytes dev::test::toGenesisBlock(Json::Value const& _json) |
|
|
|
{ |
|
|
|
BlockInfo bi = toBlockInfo(_json); |
|
|
|
RLPStream rlpStream; |
|
|
|
bi.streamRLP(rlpStream, WithNonce); |
|
|
|
|
|
|
|
RLPStream fullStream(3); |
|
|
|
fullStream.appendRaw(rlpStream.out()); |
|
|
|
fullStream.appendRaw(RLPEmptyList); |
|
|
|
fullStream.appendRaw(RLPEmptyList); |
|
|
|
bi.verifyInternals(&fullStream.out()); |
|
|
|
|
|
|
|
return fullStream.out(); |
|
|
|
} |
|
|
|
|
|
|
|
BlockChainLoader::BlockChainLoader(Json::Value const& _json) |
|
|
|
{ |
|
|
|
// load pre state
|
|
|
@ -86,7 +35,7 @@ BlockChainLoader::BlockChainLoader(Json::Value const& _json) |
|
|
|
m_state = sl.state(); |
|
|
|
|
|
|
|
// load genesisBlock
|
|
|
|
m_bc.reset(new BlockChain(toGenesisBlock(_json["genesisBlockHeader"]), m_dir.path(), true)); |
|
|
|
m_bc.reset(new BlockChain(fromHex(_json["genesisRLP"].asString()), m_dir.path(), true)); |
|
|
|
|
|
|
|
// load blocks
|
|
|
|
for (auto const& block: _json["blocks"]) |
|
|
|