Fabcoin Core  0.16.2
P2P Digital Currency
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;
52  virtual u256 bid(TransactionPriority _p = TransactionPriority::Medium) 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 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Implements the blockchain database.
Definition: BlockChain.h:105
u256 bid(TransactionPriority=TransactionPriority::Medium) const override
Definition: GasPricer.h:68
Access a block of memory.
Definition: misc.h:2233
TransactionPriority
Definition: GasPricer.h:34
Active model of a block within the block chain.
Definition: Block.h:73
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
TrivialGasPricer(u256 const &_ask, u256 const &_bid)
Definition: GasPricer.h:61
void setBid(u256 const &_bid)
Definition: GasPricer.h:64
void setAsk(u256 const &_ask)
Definition: GasPricer.h:63
u256 ask(Block const &) const override
Definition: GasPricer.h:67
virtual void update(BlockChain const &)
Definition: GasPricer.h:54