Bzz.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Bzz.cpp
  15. * @authors:
  16. * Gav Wood <i@gavwood.com>
  17. * Marek Kotewicz <marek@ethdev.com>
  18. * @date 2015
  19. */
  20. #include <libdevcore/SHA3.h>
  21. #include <libdevcore/CommonData.h>
  22. #include <libwebthree/Swarm.h>
  23. #include <libdevcore/CommonIO.h>
  24. #include <libethcore/CommonJS.h>
  25. #include <libdevcore/TrieCommon.h> // TODO: bytes ostream operator doesn't work without this import
  26. #include "Bzz.h"
  27. using namespace std;
  28. using namespace dev;
  29. using namespace dev::rpc;
  30. Bzz::Bzz(dev::bzz::Interface& _bzz): m_bzz(_bzz){}
  31. std::string Bzz::bzz_put(std::string const& _data)
  32. {
  33. bytes b = jsToBytes(_data);
  34. m_bzz.put(b);
  35. return toJS(sha3(b));
  36. }
  37. std::string Bzz::bzz_get(std::string const& _hash)
  38. {
  39. return toJS(static_cast<bytesConstRef>(m_bzz.get(jsToFixed<32>(_hash))));
  40. }