diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 2444920cb9..fc1aa33675 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -466,24 +466,24 @@ set_target_properties(gflags PROPERTIES add_dependencies(gflags gflags_gflags) ########################## -# observable # +# rx c++ # ########################## -ExternalProject_Add(ddinu_observable - GIT_REPOSITORY "https://github.com/ddinu/observable" +ExternalProject_Add(reactive_extensions_rxcpp + GIT_REPOSITORY "https://github.com/Reactive-Extensions/RxCpp" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" # remove install step UPDATE_COMMAND "" # remove update step TEST_COMMAND "" # remove test step ) -ExternalProject_Get_Property(ddinu_observable source_dir) -set(OBSERVABLE_INCLUDE_DIRS ${source_dir}/include) -file(MAKE_DIRECTORY ${OBSERVABLE_INCLUDE_DIRS}) +ExternalProject_Get_Property(reactive_extensions_rxcpp source_dir binary_dir) +set(RXCPP_INCLUDE_DIRS ${source_dir}/Rx/v2/src) +file(MAKE_DIRECTORY ${RXCPP_INCLUDE_DIRS}) -add_library(observable INTERFACE IMPORTED) -set_target_properties(observable PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${OBSERVABLE_INCLUDE_DIRS} +add_library(rxcpp INTERFACE IMPORTED) +set_target_properties(rxcpp PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${RXCPP_INCLUDE_DIRS} ) -add_dependencies(observable ddinu_observable) \ No newline at end of file +add_dependencies(rxcpp reactive_extensions_rxcpp) \ No newline at end of file diff --git a/irohad/ametsuchi/query_api.hpp b/irohad/ametsuchi/query_api.hpp index f7c4c44ad6..73792ee76a 100644 --- a/irohad/ametsuchi/query_api.hpp +++ b/irohad/ametsuchi/query_api.hpp @@ -15,28 +15,83 @@ limitations under the License. */ #ifndef IROHA_QUERY_API_HPP #define IROHA_QUERY_API_HPP -#include +#include +#include +#include #include -namespace iroha { - -namespace ametsuchi { - -class QueryApi { - //TODO: - virtual iroha::dao::Account get_account() = 0; +#include "rxcpp/rx-observable.hpp" +#include "rxcpp/rx.hpp" - virtual iroha::dao::Domain get_domain() = 0; - - virtual iroha::dao::Asset get_asset() = 0; +namespace iroha { - virtual iroha::dao::Wallet get_wallet() = 0; + namespace ametsuchi { - virtual std::vector get_account_wallets() = 0; + class QueryApi { + /** + * Get account by it's first public key. + * @param pub_key + * @return DAO Account + */ + virtual iroha::dao::Account get_account( + iroha::crypto::ed25519::pubkey_t pub_key) = 0; + /** + * Get asset by full name. For example USD#soramitsu.co.jp + * @param full_name of an asset (name#domain) + * @return DAO Asset + */ + virtual iroha::dao::Asset get_asset(std::string asset_full_name) = 0; + /** + * Get domain by domain's full name. For example soramitsu.co.jp + * @param full_name of a domain + * @return DAO Domain + */ + virtual iroha::dao::Domain get_domain(std::string domain_full_name) = 0; + /** + * Get wallet by wallet_id + * @param wallet_id + * @return DAO Wallet + */ + virtual iroha::dao::Wallet get_wallet(std::string wallet_id) = 0; + /** + * Get all wallets of a account. + * @param pub_key of a account + * @return vector of DAO Wallet + */ + virtual std::vector get_account_wallets( + iroha::crypto::ed25519::pubkey_t pub_key) = 0; -}; + /** + * Get all asset of a domain. + * @param full_name of a domain + * @return vector of DAO Asset + */ + virtual std::vector get_domain_assets( + std::string domain_full_name) = 0; + /** + * + * @param pub_key + * @return + */ + virtual rxcpp::observable + get_account_transactions(iroha::crypto::ed25519::pubkey_t pub_key) = 0; -} + /** + * + * @param asset_full_name + * @return + */ + virtual rxcpp::observable get_asset_transactions( + std::string asset_full_name) = 0; + /** + * + * @param wallet_id + * @return + */ + virtual rxcpp::observable + get_wallet_transactions(std::string wallet_id) = 0; + }; + } } -#endif //IROHA_QUERY_API_HPP +#endif // IROHA_QUERY_API_HPP diff --git a/libs/dao/peer.h b/libs/dao/peer.h index 94f1057ff2..ef7a170718 100644 --- a/libs/dao/peer.h +++ b/libs/dao/peer.h @@ -34,7 +34,7 @@ namespace iroha { /** * Public key of peer */ - const iroha::ed25519::pubkey_t pubkey; + const iroha::crypto::ed25519::pubkey_t pubkey; /* * Peer account diff --git a/test/module/vendor/CMakeLists.txt b/test/module/vendor/CMakeLists.txt index 140836c217..9c44e48caa 100644 --- a/test/module/vendor/CMakeLists.txt +++ b/test/module/vendor/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(uvw_test uvw ) -AddTest(observable_test observable_test.cpp) -target_link_libraries(observable_test - observable +AddTest(rxcpp_test rxcpp_test.cpp) +target_link_libraries(rxcpp_test + rxcpp ) \ No newline at end of file diff --git a/test/module/vendor/observable_test.cpp b/test/module/vendor/observable_test.cpp deleted file mode 100644 index f921677220..0000000000 --- a/test/module/vendor/observable_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include - -#include -#include - -using namespace std; -using namespace observable; - -TEST(observable_test, usage_observable_test) { - auto sub = subject {}; - sub.subscribe([](auto const &msg) { cout << msg << endl; }); - - // "Hello world!" will be printed on stdout. - sub.notify("Hello world!"); - - auto a = value {5}; - auto b = value {5}; - auto avg = observe( - (a + b) / 2.0f - ); - auto eq_msg = observe( - select(a == b, "equal", "not equal") - ); - - avg.subscribe([](auto val) { cout << val << endl; }); - eq_msg.subscribe([](auto const &msg) { cout << msg << endl; }); - - // "10" and "not equal" will be printed on stdout in an - // unspecified order. - b = 15; -} \ No newline at end of file diff --git a/test/module/vendor/rxcpp_test.cpp b/test/module/vendor/rxcpp_test.cpp new file mode 100644 index 0000000000..debef8771e --- /dev/null +++ b/test/module/vendor/rxcpp_test.cpp @@ -0,0 +1,110 @@ +/* +Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include + +#include "rxcpp/rx.hpp" +namespace Rx { + using namespace rxcpp; + using namespace rxcpp::sources; + using namespace rxcpp::operators; + using namespace rxcpp::util; +} +using namespace Rx; + +#include +#include +using namespace std; +using namespace std::chrono; + +TEST(rxcppTest, usage_observable_test) { + random_device rd; // non-deterministic generator + mt19937 gen(rd()); + uniform_int_distribution<> dist(4, 18); + + // for testing purposes, produce byte stream that from lines of text + auto bytes = range(0, 10) | + flat_map([&](int i){ + auto body = from((uint8_t)('A' + i)) | + repeat(dist(gen)) | + as_dynamic(); + auto delim = from((uint8_t)'\r'); + return from(body, delim) | concat(); + }) | + window(17) | + flat_map([](observable w){ + return w | + reduce( + vector(), + [](vector v, uint8_t b){ + v.push_back(b); + return v; + }) | + as_dynamic(); + }) | + tap([](vector& v){ + // print input packet of bytes + copy(v.begin(), v.end(), ostream_iterator(cout, " ")); + cout << endl; + }); + + // + // recover lines of text from byte stream + // + + auto removespaces = [](string s){ + s.erase(remove_if(s.begin(), s.end(), ::isspace), s.end()); + return s; + }; + + // create strings split on \r + auto strings = bytes | + concat_map([](vector v){ + string s(v.begin(), v.end()); + regex delim(R"/(\r)/"); + cregex_token_iterator cursor(&s[0], &s[0] + s.size(), delim, {-1, 0}); + cregex_token_iterator end; + vector splits(cursor, end); + return iterate(move(splits)); + }) | + filter([](const string& s){ + return !s.empty(); + }) | + publish() | + ref_count(); + + // filter to last string in each line + auto closes = strings | + filter( + [](const string& s){ + return s.back() == '\r'; + }) | + Rx::map([](const string&){return 0;}); + + // group strings by line + auto linewindows = strings | + window_toggle(closes | start_with(0), [=](int){return closes;}); + + // reduce the strings for a line into one string + auto lines = linewindows | + flat_map([&](observable w) { + return w | start_with("") | sum() | Rx::map(removespaces); + }); + + // print result + lines | + subscribe(println(cout)); +} \ No newline at end of file