Ethereum  PoC-8
The C++ Implementation of Ethereum
BasicGasPricer.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 <array>
25 #include "GasPricer.h"
26 
27 namespace dev
28 {
29 namespace eth
30 {
31 
33 {
34 public:
35  explicit BasicGasPricer(u256 _weiPerRef, u256 _refsPerBlock): m_weiPerRef(_weiPerRef), m_refsPerBlock(_refsPerBlock) {}
36 
37  void setRefPrice(u256 _weiPerRef) { if ((bigint)m_refsPerBlock * _weiPerRef > std::numeric_limits<u256>::max() ) BOOST_THROW_EXCEPTION(Overflow() << errinfo_comment("ether price * block fees is larger than 2**256-1, choose a smaller number.") ); else m_weiPerRef = _weiPerRef; }
38  void setRefBlockFees(u256 _refsPerBlock) { if ((bigint)m_weiPerRef * _refsPerBlock > std::numeric_limits<u256>::max() ) BOOST_THROW_EXCEPTION(Overflow() << errinfo_comment("ether price * block fees is larger than 2**256-1, choose a smaller number.") ); else m_refsPerBlock = _refsPerBlock; }
39 
40  u256 ask(Block const&) const override { return m_weiPerRef * m_refsPerBlock / m_gasPerBlock; }
41  u256 bid(TransactionPriority _p = TransactionPriority::Medium) const override { return m_octiles[(int)_p] > 0 ? m_octiles[(int)_p] : (m_weiPerRef * m_refsPerBlock / m_gasPerBlock); }
42 
43  void update(BlockChain const& _bc) override;
44 
45 private:
46  u256 m_weiPerRef;
47  u256 m_refsPerBlock;
48  u256 m_gasPerBlock = DefaultBlockGasLimit;
49  std::array<u256, 9> m_octiles;
50 };
51 
52 }
53 }
dev::eth::TransactionPriority::Medium
@ Medium
dev::eth::BasicGasPricer::setRefPrice
void setRefPrice(u256 _weiPerRef)
Definition: BasicGasPricer.h:37
dev::eth::BasicGasPricer::setRefBlockFees
void setRefBlockFees(u256 _refsPerBlock)
Definition: BasicGasPricer.h:38
dev::eth::BasicGasPricer::bid
u256 bid(TransactionPriority _p=TransactionPriority::Medium) const override
Definition: BasicGasPricer.h:41
GasPricer.h
dev::eth::BlockChain
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
Definition: BlockChain.h:105
dev::eth::BasicGasPricer::update
void update(BlockChain const &_bc) override
Definition: BasicGasPricer.cpp:34
dev::bigint
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
Definition: Common.h:118
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::BasicGasPricer::ask
u256 ask(Block const &) const override
Definition: BasicGasPricer.h:40
dev::eth::GasPricer
Definition: GasPricer.h:46
dev::eth::BasicGasPricer
Definition: BasicGasPricer.h:33
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::errinfo_comment
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:69
dev::eth::BasicGasPricer::BasicGasPricer
BasicGasPricer(u256 _weiPerRef, u256 _refsPerBlock)
Definition: BasicGasPricer.h:35