Ethereum  PoC-8
The C++ Implementation of Ethereum
BlockChainImporter.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "BlockChainImporter.h"
19 #include "BlockChain.h"
20 
21 #include <libdevcore/RLP.h>
22 #include <libethcore/BlockHeader.h>
23 
24 namespace dev
25 {
26 namespace eth
27 {
28 
29 namespace
30 {
31 
32 class BlockChainImporter: public BlockChainImporterFace
33 {
34 public:
35  explicit BlockChainImporter(BlockChain& _blockChain): m_blockChain(_blockChain) {}
36 
37  void importBlock(BlockHeader const& _header, RLP _transactions, RLP _uncles, RLP _receipts, u256 const& _totalDifficulty) override
38  {
39  RLPStream headerRlp;
40  _header.streamRLP(headerRlp);
41 
42  RLPStream block(3);
43  block.appendRaw(headerRlp.out());
44  block << _transactions << _uncles;
45 
46  m_blockChain.insertWithoutParent(block.out(), _receipts.data(), _totalDifficulty);
47  }
48 
49  void setChainStartBlockNumber(u256 const& _number) override
50  {
51  m_blockChain.setChainStartBlockNumber(static_cast<unsigned>(_number));
52  }
53 
54 private:
55  BlockChain& m_blockChain;
56 };
57 
58 }
59 
60 std::unique_ptr<BlockChainImporterFace> createBlockChainImporter(BlockChain& _blockChain)
61 {
62  return std::unique_ptr<BlockChainImporterFace>(new BlockChainImporter(_blockChain));
63 }
64 
65 }
66 }
BlockHeader.h
dev::eth::BlockChain
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
Definition: BlockChain.h:105
BlockChain.h
dev::u256
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:121
BlockChainImporter.h
dev
Definition: Address.cpp:21
RLP.h
dev::eth::createBlockChainImporter
std::unique_ptr< BlockChainImporterFace > createBlockChainImporter(BlockChain &_blockChain)
Definition: BlockChainImporter.cpp:60