Skip to content

Commit

Permalink
refactoring, fix for linux
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Drobny <[email protected]>
  • Loading branch information
vdrobnyi committed Mar 1, 2018
1 parent 8073974 commit 8ac1188
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions irohad/ametsuchi/block_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace iroha {
* Public interface for queries on blocks and transactions
*/
class BlockQuery {
protected:
protected:
using wTransaction =
std::shared_ptr<shared_model::interface::Transaction>;
using wBlock = std::shared_ptr<shared_model::interface::Block>;
Expand Down Expand Up @@ -72,15 +72,15 @@ namespace iroha {
* @param count - number of blocks to retrieve
* @return observable of Model Block
*/
virtual rxcpp::observable<wBlock> getBlocks(uint32_t height,
virtual rxcpp::observable<wBlock> getBlocks(shared_model::interface::types::HeightType height,
uint32_t count) = 0;

/**
* Get all blocks starting from given height.
* @param from - starting height
* @return observable of Model Block
*/
virtual rxcpp::observable<wBlock> getBlocksFrom(uint32_t height) = 0;
virtual rxcpp::observable<wBlock> getBlocksFrom(shared_model::interface::types::HeightType height) = 0;

/**
* Get given number of blocks from top.
Expand Down
14 changes: 7 additions & 7 deletions irohad/ametsuchi/impl/postgres_block_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace iroha {
execute_{makeExecuteOptional(transaction_, log_)} {}

rxcpp::observable<BlockQuery::wBlock> PostgresBlockQuery::getBlocks(
uint32_t height, uint32_t count) {
auto last_id = block_store_.last_id();
shared_model::interface::types::HeightType height, uint32_t count) {
shared_model::interface::types::HeightType last_id = block_store_.last_id();
auto to = std::min(last_id, height + count - 1);
if (height > to or count == 0) {
return rxcpp::observable<>::empty<wBlock>();
Expand All @@ -48,7 +48,7 @@ namespace iroha {
return std::make_shared<shared_model::proto::Block>(
shared_model::proto::from_old(block_old));
};
return rxcpp::observable<>::create<wBlock>(
return rxcpp::observable<>::create<PostgresBlockQuery::wBlock>(
[this, block{std::move(block)}](auto s) {
if (block) {
s.on_next(block);
Expand All @@ -59,7 +59,7 @@ namespace iroha {
}

rxcpp::observable<BlockQuery::wBlock> PostgresBlockQuery::getBlocksFrom(
uint32_t height) {
shared_model::interface::types::HeightType height) {
return getBlocks(height, block_store_.last_id());
}

Expand Down Expand Up @@ -123,7 +123,7 @@ namespace iroha {
}),
[&](auto x) {
subscriber.on_next(
wTransaction(block->transactions().at(x)->copy()));
PostgresBlockQuery::wTransaction(block->transactions().at(x)->copy()));
});
};
}
Expand Down Expand Up @@ -209,13 +209,13 @@ namespace iroha {
shared_model::proto::from_old(block));
}
| [&](const auto &block) {
boost::optional<wTransaction> result;
boost::optional<PostgresBlockQuery::wTransaction> result;
auto it =
std::find_if(block.transactions().begin(),
block.transactions().end(),
[&hash](auto tx) { return tx->hash() == hash; });
if (it != block.transactions().end()) {
result = boost::optional<wTransaction>(wTransaction((*it)->copy()));
result = boost::optional<PostgresBlockQuery::wTransaction>(PostgresBlockQuery::wTransaction((*it)->copy()));
}
return result;
};
Expand Down
4 changes: 2 additions & 2 deletions irohad/ametsuchi/impl/postgres_block_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ namespace iroha {
boost::optional<wTransaction> getTxByHashSync(
const shared_model::crypto::Hash &hash) override;

rxcpp::observable<wBlock> getBlocks(uint32_t height,
rxcpp::observable<wBlock> getBlocks(shared_model::interface::types::HeightType height,
uint32_t count) override;

rxcpp::observable<wBlock> getBlocksFrom(uint32_t height) override;
rxcpp::observable<wBlock> getBlocksFrom(shared_model::interface::types::HeightType height) override;

rxcpp::observable<wBlock> getTopBlocks(uint32_t count) override;

Expand Down
4 changes: 2 additions & 2 deletions test/module/irohad/ametsuchi/ametsuchi_mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ namespace iroha {
getTransactions,
rxcpp::observable<boost::optional<wTransaction>>(
const std::vector<shared_model::crypto::Hash> &tx_hashes));
MOCK_METHOD2(getBlocks, rxcpp::observable<wBlock>(uint32_t, uint32_t));
MOCK_METHOD1(getBlocksFrom, rxcpp::observable<wBlock>(uint32_t));
MOCK_METHOD2(getBlocks, rxcpp::observable<wBlock>(shared_model::interface::types::HeightType, uint32_t));
MOCK_METHOD1(getBlocksFrom, rxcpp::observable<wBlock>(shared_model::interface::types::HeightType));
MOCK_METHOD1(getTopBlocks, rxcpp::observable<wBlock>(uint32_t));
};

Expand Down
13 changes: 11 additions & 2 deletions test/module/irohad/ametsuchi/block_query_transfer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ namespace iroha {
auto zero_string = std::string("0", 32);
auto fake_hash = shared_model::crypto::Hash(zero_string);

/*
/**
* Make block with one transaction(transfer 0 asset) with specified sender,
* receiver, asset and creator of transaction
* @param creator1 - source account for transfer
* @param creator2 - dest account for transfer
* @param asset - asset for transfer
* @param tx_creator - creator of the transaction
* @return block with one transaction
*/
shared_model::proto::Block makeBlockWithCreator(std::string creator1,
std::string creator2,
Expand All @@ -101,9 +106,13 @@ namespace iroha {
.build();
}

/*
/**
* Make block with one transaction(transfer 0 asset) with specified sender,
* receiver and asset
* @param creator1 - source account for transfer
* @param creator2 - dest account for transfer
* @param asset - asset for transfer
* @return block with one transaction
*/
shared_model::proto::Block makeBlock(
std::string creator1,
Expand Down

0 comments on commit 8ac1188

Please sign in to comment.