Ethereum  PoC-8
The C++ Implementation of Ethereum
GasPricer.h
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 */
22 #pragma once
23 
24 #include <libethcore/Common.h>
25 
26 namespace dev
27 {
28 namespace eth
29 {
30 
31 class Block;
32 class BlockChain;
33 
35 {
36  Lowest = 0,
37  Low = 2,
38  Medium = 4,
39  High = 6,
40  Highest = 8
41 };
42 
43 static const u256 DefaultGasPrice = 20 * shannon;
44 
45 class GasPricer
46 {
47 public:
48  GasPricer() = default;
49  virtual ~GasPricer() = default;
50 
51  virtual u256 ask(Block const&) const = 0;
53 
54  virtual void update(BlockChain const&) {}
55 };
56 
58 {
59 public:
60  TrivialGasPricer() = default;
61  TrivialGasPricer(u256 const& _ask, u256 const& _bid): m_ask(_ask), m_bid(_bid) {}
62 
63  void setAsk(u256 const& _ask) { m_ask = _ask; }
64  void setBid(u256 const& _bid) { m_bid = _bid; }
65 
66  u256 ask() const { return m_ask; }
67  u256 ask(Block const&) const override { return m_ask; }
68  u256 bid(TransactionPriority = TransactionPriority::Medium) const override { return m_bid; }
69 
70 private:
71  u256 m_ask = DefaultGasPrice;
72  u256 m_bid = DefaultGasPrice;
73 };
74 
75 }
76 }
dev::eth::GasPricer::ask
virtual u256 ask(Block const &) const =0
dev::eth::TransactionPriority::Medium
@ Medium
dev::eth::GasPricer::GasPricer
GasPricer()=default
dev::eth::TransactionPriority::Low
@ Low
dev::eth::TrivialGasPricer::setAsk
void setAsk(u256 const &_ask)
Definition: GasPricer.h:63
dev::eth::TrivialGasPricer::ask
u256 ask() const
Definition: GasPricer.h:66
dev::eth::TrivialGasPricer::TrivialGasPricer
TrivialGasPricer()=default
dev::eth::TrivialGasPricer::TrivialGasPricer
TrivialGasPricer(u256 const &_ask, u256 const &_bid)
Definition: GasPricer.h:61
dev::eth::TrivialGasPricer::ask
u256 ask(Block const &) const override
Definition: GasPricer.h:67
dev::eth::GasPricer::~GasPricer
virtual ~GasPricer()=default
Common.h
dev::eth::GasPricer::update
virtual void update(BlockChain const &)
Definition: GasPricer.h:54
dev::eth::BlockChain
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
Definition: BlockChain.h:105
dev::eth::TransactionPriority::Lowest
@ Lowest
dev::eth::TrivialGasPricer::setBid
void setBid(u256 const &_bid)
Definition: GasPricer.h:64
dev::eth::GasPricer::bid
virtual u256 bid(TransactionPriority _p=TransactionPriority::Medium) const =0
dev::eth::TransactionPriority::High
@ High
dev::eth::TrivialGasPricer
Definition: GasPricer.h:58
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
dev::eth::TransactionPriority
TransactionPriority
Definition: GasPricer.h:35
dev
Definition: Address.cpp:21
dev::eth::GasPricer
Definition: GasPricer.h:46
dev::eth::TransactionPriority::Highest
@ Highest
dev::eth::Block
Active model of a block within the block chain. Keeps track of all transactions, receipts and state f...
Definition: Block.h:69
dev::eth::TrivialGasPricer::bid
u256 bid(TransactionPriority=TransactionPriority::Medium) const override
Definition: GasPricer.h:68