Support.h 2.3 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 Support.h
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2015
  17. */
  18. #pragma once
  19. #include <libethcore/Common.h>
  20. #include <libethcore/ABI.h>
  21. #include <libethereum/Interface.h>
  22. namespace dev
  23. {
  24. class WebThreeDirect;
  25. /// Utilities supporting typical use of the Ethereum network.
  26. class Support
  27. {
  28. public:
  29. Support(WebThreeDirect* _web3);
  30. ~Support();
  31. // URI managment
  32. static strings decomposed(std::string const& _name);
  33. // Registrar
  34. Address registrar() const;
  35. h256 content(std::string const& _url) const { return lookup<h256>(decomposed(_url), "content"); }
  36. Address address(std::string const& _url) const { return lookup<Address>(decomposed(_url), "addr"); }
  37. Address subRegistrar(std::string const& _url) const { return lookup<Address>(decomposed(_url), "subRegistrar"); }
  38. Address owner(std::string const& _url) const { return lookup<Address>(decomposed(_url), "owner"); }
  39. // URL Hinter
  40. Address urlHint() const;
  41. std::string urlHint(h256 const& _content) const;
  42. void hintURL(h256 const& _content, std::string const& _url, Secret const& _s) const;
  43. // SHA256 Hinter
  44. Address sha256Hint() const;
  45. h256 sha256Hint(h256 const& _content) const;
  46. void hintSHA256(h256 const& _content, h256 const& _sha256, Secret const& _s) const;
  47. // ICAP
  48. Address icapRegistrar() const;
  49. std::pair<Address, bytes> decodeICAP(std::string const& _icap) const;
  50. private:
  51. bytes call(Address const& _to, bytes const& _data) const;
  52. template <class T> T lookup(strings const& _path, std::string const& _query) const
  53. {
  54. return eth::abiOut<T>(auxLookup(_path, _query));
  55. }
  56. bytes auxLookup(strings const& _path, std::string const& _query) const;
  57. WebThreeDirect* m_web3;
  58. };
  59. }