FixedClient.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 FixedClient.h
  15. * @author Marek Kotewicz <marek@ethdev.com>
  16. * @date 2015
  17. */
  18. #pragma once
  19. #include <libethereum/ClientBase.h>
  20. #include <libethereum/BlockChain.h>
  21. #include <libethereum/State.h>
  22. namespace dev
  23. {
  24. namespace test
  25. {
  26. /**
  27. * @brief mvp implementation of ClientBase
  28. * Doesn't support mining interface
  29. */
  30. class FixedClient: public dev::eth::ClientBase
  31. {
  32. public:
  33. FixedClient(eth::BlockChain const& _bc, eth::Block const& _block) : m_bc(_bc), m_block(_block) {}
  34. virtual ~FixedClient() {}
  35. // stub
  36. virtual void flushTransactions() override {}
  37. virtual eth::BlockChain& bc() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("FixedClient::bc()")); }
  38. virtual eth::BlockChain const& bc() const override { return m_bc; }
  39. using ClientBase::block;
  40. virtual eth::Block block(h256 const& _h) const override;
  41. virtual eth::Block preSeal() const override { ReadGuard l(x_stateDB); return m_block; }
  42. virtual eth::Block postSeal() const override { ReadGuard l(x_stateDB); return m_block; }
  43. virtual void setAuthor(Address const& _us) override { WriteGuard l(x_stateDB); m_block.setAuthor(_us); }
  44. virtual void prepareForTransaction() override {}
  45. private:
  46. eth::BlockChain const& m_bc;
  47. eth::Block m_block;
  48. mutable SharedMutex x_stateDB; ///< Lock on the state DB, effectively a lock on m_postSeal.
  49. };
  50. }
  51. }