This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 296
common objects factory for wsv query #1573
Merged
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
43d7902
Implement Abstract factory for peer
nickaleks f7eabe8
Factory returns Result instead of just pointer
nickaleks e904964
Add validation logic to factory
nickaleks 781cb39
Add account creation to factory
nickaleks 961fe11
Add account asset creation to factory
nickaleks a75f7fc
Add amount creation to factory
nickaleks 48b7605
Add asset and domain creation to factory
nickaleks 34a11ab
Add signature creation to factory
nickaleks 2f30e41
Add comments
nickaleks e40cb10
Fix review issues
nickaleks 8a73c24
change ametsuchi interfaces for new factory
nickaleks b6b9b3c
Fix compilation issues
nickaleks 79270cb
Fix merge conflicts
nickaleks 69cdd3f
Fix merge conflicts
nickaleks bb438e0
Merge develop
nickaleks 257ebe9
Remove postgres converter
nickaleks c436031
Fix issues
nickaleks 482e712
Merge remote-tracking branch 'origin/develop' into feature/common_obj…
nickaleks ad1ed98
Fix review issues
nickaleks be92c27
Fix review issues
nickaleks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
#include "ametsuchi/impl/postgres_wsv_query.hpp" | ||
#include "backend/protobuf/permissions.hpp" | ||
#include "common/result.hpp" | ||
|
||
namespace iroha { | ||
namespace ametsuchi { | ||
|
@@ -36,12 +37,17 @@ namespace iroha { | |
const std::string kAccountId = "account_id"; | ||
const std::string kDomainId = "domain_id"; | ||
|
||
PostgresWsvQuery::PostgresWsvQuery(soci::session &sql) | ||
: sql_(sql), log_(logger::log("PostgresWsvQuery")) {} | ||
PostgresWsvQuery::PostgresWsvQuery( | ||
soci::session &sql, | ||
std::shared_ptr<shared_model::interface::CommonObjectsFactory> factory) | ||
: sql_(sql), factory_(factory), log_(logger::log("PostgresWsvQuery")) {} | ||
|
||
PostgresWsvQuery::PostgresWsvQuery(std::unique_ptr<soci::session> sql_ptr) | ||
PostgresWsvQuery::PostgresWsvQuery( | ||
std::unique_ptr<soci::session> sql_ptr, | ||
std::shared_ptr<shared_model::interface::CommonObjectsFactory> factory) | ||
: sql_ptr_(std::move(sql_ptr)), | ||
sql_(*sql_ptr_), | ||
factory_(factory), | ||
log_(logger::log("PostgresWsvQuery")) {} | ||
|
||
bool PostgresWsvQuery::hasAccountGrantablePermission( | ||
|
@@ -133,8 +139,8 @@ namespace iroha { | |
return boost::none; | ||
} | ||
|
||
return fromResult( | ||
makeAccount(account_id, domain_id.get(), quorum.get(), data.get())); | ||
return fromResult(factory_->createAccount( | ||
account_id, domain_id.get(), quorum.get(), data.get())); | ||
} | ||
|
||
boost::optional<std::string> PostgresWsvQuery::getAccountDetail( | ||
|
@@ -221,7 +227,8 @@ namespace iroha { | |
return boost::none; | ||
} | ||
|
||
return fromResult(makeAsset(asset_id, domain_id.get(), precision.get())); | ||
return fromResult( | ||
factory_->createAsset(asset_id, domain_id.get(), precision.get())); | ||
} | ||
|
||
boost::optional< | ||
|
@@ -234,8 +241,11 @@ namespace iroha { | |
std::vector<std::shared_ptr<shared_model::interface::AccountAsset>> | ||
assets; | ||
for (auto &t : st) { | ||
fromResult(makeAccountAsset(account_id, t.get<1>(), t.get<2>())) | | ||
[&assets](const auto &asset) { assets.push_back(asset); }; | ||
fromResult(factory_->createAccountAsset( | ||
account_id, | ||
t.get<1>(), | ||
shared_model::interface::Amount(t.get<2>()))) | ||
| [&assets](const auto &asset) { assets.push_back(asset); }; | ||
} | ||
|
||
return boost::make_optional(assets); | ||
|
@@ -258,7 +268,8 @@ namespace iroha { | |
return boost::none; | ||
} | ||
|
||
return fromResult(makeAccountAsset(account_id, asset_id, amount.get())); | ||
return fromResult(factory_->createAccountAsset( | ||
account_id, asset_id, shared_model::interface::Amount(amount.get()))); | ||
} | ||
|
||
boost::optional<std::shared_ptr<shared_model::interface::Domain>> | ||
|
@@ -275,7 +286,7 @@ namespace iroha { | |
return boost::none; | ||
} | ||
|
||
return fromResult(makeDomain(domain_id, role.get())); | ||
return fromResult(factory_->createDomain(domain_id, role.get())); | ||
} | ||
|
||
boost::optional<std::vector<std::shared_ptr<shared_model::interface::Peer>>> | ||
|
@@ -284,16 +295,16 @@ namespace iroha { | |
(sql_.prepare << "SELECT public_key, address FROM peer"); | ||
std::vector<std::shared_ptr<shared_model::interface::Peer>> peers; | ||
|
||
auto results = transform< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is 'transform' from postgres_wsv_common.hpp called from somewhere? Can the method be removed? |
||
shared_model::builder::BuilderResult<shared_model::interface::Peer>>( | ||
rows, makePeer); | ||
for (auto &r : results) { | ||
r.match( | ||
[&](expected::Value<std::shared_ptr<shared_model::interface::Peer>> | ||
&v) { peers.push_back(v.value); }, | ||
[&](expected::Error<std::shared_ptr<std::string>> &e) { | ||
log_->info(*e.error); | ||
}); | ||
for (auto &row : rows) { | ||
auto address = row.get<std::string>(1); | ||
auto key = shared_model::crypto::PublicKey( | ||
shared_model::crypto::Blob::fromHexString(row.get<std::string>(0))); | ||
|
||
auto peer = factory_->createPeer(address, key); | ||
peer.match( | ||
[&](expected::Value<std::unique_ptr<shared_model::interface::Peer>> | ||
&v) { peers.push_back(std::move(v.value)); }, | ||
[&](expected::Error<std::string> &e) { log_->info(e.error); }); | ||
} | ||
return peers; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include is presented in postgres_wsv_common.hpp. It is not necessary to have it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better not to have transitive includes, so that if we change one header, we won't break stuff