/* This file is part of cpp-ethereum. cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Foobar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Foobar. If not, see . */ /** @file BlockInfo.cpp * @author Gav Wood * @date 2014 */ #include "Common.h" #include "Exceptions.h" #include "RLP.h" #include "BlockInfo.h" using namespace std; using namespace eth; BlockInfo* BlockInfo::s_genesis = nullptr; BlockInfo::BlockInfo() { number = Invalid256; } bytes BlockInfo::createGenesisBlock() { RLPStream block(3); auto sha256EmptyList = sha3(RLPEmptyList); block.appendList(7) << (uint)0 << sha256EmptyList << (uint)0 << sha256EmptyList << ((uint)1 << 36) << (uint)0 << (uint)0; block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList); return block.out(); } void BlockInfo::populateGenesis() { bytes genesisBlock = createGenesisBlock(); populate(&genesisBlock, 0); } void BlockInfo::populate(bytesConstRef _block, u256 _number) { number = _number; RLP root(_block); try { RLP header = root[0]; hash = eth::sha3(_block); parentHash = header[0].toInt(); sha256Uncles = header[1].toInt(); coinbaseAddress = header[2].toInt(); sha256Transactions = header[3].toInt(); difficulty = header[4].toInt(); timestamp = header[5].toInt(); nonce = header[6].toInt(); } catch (RLP::BadCast) { throw InvalidBlockFormat(); } } void BlockInfo::verifyInternals(bytesConstRef _block) { RLP root(_block); if (sha256Transactions != sha3(root[1].data())) throw InvalidTransactionsHash(); if (sha256Uncles != sha3(root[2].data())) throw InvalidUnclesHash(); // TODO: check difficulty against timestamp. // TODO: check proof of work. // TODO: check each transaction - allow coinbaseAddress for the miner fees, but everything else must be exactly how we would do it. }