ChainParams.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file ChainParams.h
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2015
  17. */
  18. #pragma once
  19. #include <libdevcore/Common.h>
  20. #include <libethcore/Common.h>
  21. #include <libethcore/ChainOperationParams.h>
  22. #include <libethcore/BlockHeader.h>
  23. #include "Account.h"
  24. namespace dev
  25. {
  26. namespace eth
  27. {
  28. class SealEngineFace;
  29. struct ChainParams: public ChainOperationParams
  30. {
  31. ChainParams();
  32. ChainParams(ChainParams const& /*_org*/) = default;
  33. ChainParams(std::string const& _s, h256 const& _stateRoot = h256());
  34. ChainParams(bytes const& _genesisRLP, AccountMap const& _state) { populateFromGenesis(_genesisRLP, _state); }
  35. ChainParams(std::string const& _json, bytes const& _genesisRLP, AccountMap const& _state): ChainParams(_json) { populateFromGenesis(_genesisRLP, _state); }
  36. SealEngineFace* createSealEngine();
  37. /// Genesis params.
  38. h256 parentHash = h256();
  39. Address author = Address();
  40. u256 difficulty = 1;
  41. u256 gasLimit = 1 << 31;
  42. u256 gasUsed = 0;
  43. u256 timestamp = 0;
  44. bytes extraData;
  45. mutable h256 stateRoot; ///< Only pre-populate if known equivalent to genesisState's root. If they're different Bad Things Will Happen.
  46. AccountMap genesisState;
  47. unsigned sealFields = 0;
  48. bytes sealRLP;
  49. h256 calculateStateRoot(bool _force = false) const;
  50. /// Genesis block info.
  51. bytes genesisBlock() const;
  52. /// load config/genesis
  53. ChainParams loadConfig(std::string const& _json, h256 const& _stateRoot = h256()) const;
  54. ChainParams loadGenesisState(std::string const& _json, h256 const& _stateRoot = h256()) const;
  55. ChainParams loadGenesis(std::string const& _json, h256 const& _stateRoot = h256()) const;
  56. private:
  57. void populateFromGenesis(bytes const& _genesisRLP, AccountMap const& _state);
  58. };
  59. }
  60. }