ChainOperationParams.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 ChainOperationsParams.h
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2015
  17. */
  18. #pragma once
  19. #include <libdevcore/Common.h>
  20. #include "Common.h"
  21. #include <libevmcore/EVMSchedule.h>
  22. namespace dev
  23. {
  24. namespace eth
  25. {
  26. class PrecompiledContract
  27. {
  28. public:
  29. PrecompiledContract() = default;
  30. PrecompiledContract(std::function<bigint(unsigned)> const& _cost, std::function<void(bytesConstRef, bytesRef)> const& _exec):
  31. m_cost(_cost),
  32. m_execute(_exec)
  33. {}
  34. PrecompiledContract(unsigned _base, unsigned _word, std::function<void(bytesConstRef, bytesRef)> const& _exec);
  35. bigint cost(bytesConstRef _in) const { return m_cost(_in.size()); }
  36. void execute(bytesConstRef _in, bytesRef _out) const { m_execute(_in, _out); }
  37. private:
  38. std::function<bigint(unsigned)> m_cost;
  39. std::function<void(bytesConstRef, bytesRef)> m_execute;
  40. };
  41. struct ChainOperationParams
  42. {
  43. ChainOperationParams();
  44. explicit operator bool() const { return accountStartNonce != Invalid256; }
  45. /// The chain sealer name: e.g. Ethash, NoProof, BasicAuthority
  46. std::string sealEngineName = "NoProof";
  47. /// General chain params.
  48. u256 blockReward = 0;
  49. u256 maximumExtraDataSize = 1024;
  50. u256 accountStartNonce = 0;
  51. bool tieBreakingGas = true;
  52. /// Precompiled contracts as specified in the chain params.
  53. std::unordered_map<Address, PrecompiledContract> precompiled;
  54. /**
  55. * @brief Additional parameters.
  56. *
  57. * e.g. Ethash specific:
  58. * - minGasLimit
  59. * - maxGasLimit
  60. * - gasLimitBoundDivisor
  61. * - minimumDifficulty
  62. * - difficultyBoundDivisor
  63. * - durationLimit
  64. */
  65. std::unordered_map<std::string, std::string> otherParams;
  66. /// Convenience method to get an otherParam as a u256 int.
  67. u256 u256Param(std::string const& _name) const;
  68. };
  69. }
  70. }