GasPricer.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 GasPricer.h
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2014
  17. */
  18. #pragma once
  19. #include <libethcore/Common.h>
  20. namespace dev
  21. {
  22. namespace eth
  23. {
  24. class Block;
  25. class BlockChain;
  26. enum class TransactionPriority
  27. {
  28. Lowest = 0,
  29. Low = 2,
  30. Medium = 4,
  31. High = 6,
  32. Highest = 8
  33. };
  34. static const u256 DefaultGasPrice = 20 * shannon;
  35. class GasPricer
  36. {
  37. public:
  38. GasPricer() = default;
  39. virtual ~GasPricer() = default;
  40. virtual u256 ask(Block const&) const = 0;
  41. virtual u256 bid(TransactionPriority _p = TransactionPriority::Medium) const = 0;
  42. virtual void update(BlockChain const&) {}
  43. };
  44. class TrivialGasPricer: public GasPricer
  45. {
  46. public:
  47. TrivialGasPricer() = default;
  48. TrivialGasPricer(u256 const& _ask, u256 const& _bid): m_ask(_ask), m_bid(_bid) {}
  49. void setAsk(u256 const& _ask) { m_ask = _ask; }
  50. void setBid(u256 const& _bid) { m_bid = _bid; }
  51. u256 ask() const { return m_ask; }
  52. u256 ask(Block const&) const override { return m_ask; }
  53. u256 bid(TransactionPriority = TransactionPriority::Medium) const override { return m_bid; }
  54. private:
  55. u256 m_ask = DefaultGasPrice;
  56. u256 m_bid = DefaultGasPrice;
  57. };
  58. }
  59. }