Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/ametsuchi-api' into feat…
Browse files Browse the repository at this point in the history
…ure/ametsuchi-api
  • Loading branch information
lebdron committed Jun 22, 2017
2 parents 24d0129 + a051163 commit 2d871fc
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 77 deletions.
20 changes: 10 additions & 10 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
add_dependencies(rxcpp reactive_extensions_rxcpp)
87 changes: 71 additions & 16 deletions irohad/ametsuchi/query_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,83 @@ limitations under the License.
*/
#ifndef IROHA_QUERY_API_HPP
#define IROHA_QUERY_API_HPP
#include <dao.hpp>
#include <common.hpp>
#include <dao/dao.hpp>
#include <string>
#include <vector>
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<iroha::dao::Wallet> 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<iroha::dao::Wallet> 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<iroha::dao::Asset> get_domain_assets(
std::string domain_full_name) = 0;
/**
*
* @param pub_key
* @return
*/
virtual rxcpp::observable<iroha::dao::Transaction>
get_account_transactions(iroha::crypto::ed25519::pubkey_t pub_key) = 0;

}
/**
*
* @param asset_full_name
* @return
*/
virtual rxcpp::observable<iroha::dao::Transaction> get_asset_transactions(
std::string asset_full_name) = 0;
/**
*
* @param wallet_id
* @return
*/
virtual rxcpp::observable<iroha::dao::Transaction>
get_wallet_transactions(std::string wallet_id) = 0;
};
}
}

#endif //IROHA_QUERY_API_HPP
#endif // IROHA_QUERY_API_HPP
2 changes: 1 addition & 1 deletion libs/dao/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/module/vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
47 changes: 0 additions & 47 deletions test/module/vendor/observable_test.cpp

This file was deleted.

110 changes: 110 additions & 0 deletions test/module/vendor/rxcpp_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#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 <regex>
#include <random>
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<uint8_t> w){
return w |
reduce(
vector<uint8_t>(),
[](vector<uint8_t> v, uint8_t b){
v.push_back(b);
return v;
}) |
as_dynamic();
}) |
tap([](vector<uint8_t>& v){
// print input packet of bytes
copy(v.begin(), v.end(), ostream_iterator<long>(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<uint8_t> 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<string> 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<string> w) {
return w | start_with<string>("") | sum() | Rx::map(removespaces);
});

// print result
lines |
subscribe<string>(println(cout));
}

0 comments on commit 2d871fc

Please sign in to comment.