Skip to content

Commit

Permalink
Add query execution impl:
Browse files Browse the repository at this point in the history
- Add to new queries map
- Add new command to ametsuchi: hasGrantablePermission
- Add tests to query executor

Fix query execution test:
- Add mock methods

Fix query execution:
- Add moves
- Add corrected 'expect-calls'

Add clang-format rule for non-assignment binary operators, fix json

Fix review issues
  • Loading branch information
grimadas committed Sep 26, 2017
1 parent edbfb0d commit 3bdc2e1
Show file tree
Hide file tree
Showing 40 changed files with 393 additions and 224 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
BasedOnStyle: Google
NamespaceIndentation: All
BreakBeforeBinaryOperators: NonAssignment
AlignOperands: false
4 changes: 3 additions & 1 deletion iroha-cli/interactive/impl/interactive_transaction_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ namespace iroha_cli {
std::shared_ptr<iroha::model::Command>
InteractiveTransactionCli::parseCreateRole(
std::vector<std::string> params) {
// TODO: implement scheme on working with permissions
auto role = params[0];
return std::make_shared<CreateRole>(role);
std::vector<std::string> perms = {};
return std::make_shared<CreateRole>(role, perms);
}

std::shared_ptr<iroha::model::Command>
Expand Down
7 changes: 7 additions & 0 deletions irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ namespace iroha {
PostgresWsvQuery::PostgresWsvQuery(pqxx::nontransaction &transaction)
: transaction_(transaction) {}

bool PostgresWsvQuery::hasAccountGrantablePermission(
const std::string &permitee_account_id, const std::string &account_id,
const std::string &permission_id) {
// TODO: implement
return false;
};

nonstd::optional<std::vector<std::string>>
PostgresWsvQuery::getAccountRoles(const std::string &account_id) {
// TODO: implement
Expand Down
3 changes: 3 additions & 0 deletions irohad/ametsuchi/impl/postgres_wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace iroha {
const std::string &account_id, const std::string &asset_id) override;
nonstd::optional<std::vector<model::Peer>> getPeers() override;
nonstd::optional<std::vector<std::string>> getRoles() override;
bool hasAccountGrantablePermission(
const std::string &permitee_account_id, const std::string &account_id,
const std::string &permission_id) override;

private:
pqxx::nontransaction &transaction_;
Expand Down
12 changes: 12 additions & 0 deletions irohad/ametsuchi/wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ namespace iroha {
public:
virtual ~WsvQuery() = default;

/**
* Check if permitee has permission on account
* @param permitee_account_id
* @param account_id
* @param permission_id
* @return true if has permission, false otherwise
*/
virtual bool
hasAccountGrantablePermission(const std::string &permitee_account_id,
const std::string &account_id,
const std::string &permission_id) = 0;

/**
* Get account's roles
* @param account_id
Expand Down
4 changes: 1 addition & 3 deletions irohad/model/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ namespace iroha {
using TransactionsType = decltype(transactions);

bool operator==(const Block& rhs) const;
bool operator!=(const Block& rhs) const {
return !operator==(rhs);
};
bool operator!=(const Block& rhs) const;
};
}
}
Expand Down
4 changes: 1 addition & 3 deletions irohad/model/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ namespace iroha {

virtual bool operator==(const Command& rhs) const = 0;

virtual bool operator!=(const Command& rhs) const {
return !operator==(rhs);
}
virtual bool operator!=(const Command& rhs) const;
};
} // namespace model
} // namespace iroha
Expand Down
6 changes: 3 additions & 3 deletions irohad/model/commands/add_asset_quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ namespace iroha {
*/
Amount amount;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

AddAssetQuantity() {}

AddAssetQuantity(std::string account_id, std::string asset_id,
Amount amount)
AddAssetQuantity(const std::string &account_id,
const std::string &asset_id, Amount amount)
: account_id(account_id), asset_id(asset_id), amount(amount) {}
};
} // namespace model
Expand Down
4 changes: 2 additions & 2 deletions irohad/model/commands/add_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ namespace iroha {

std::string address;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

AddPeer() {}

AddPeer(ed25519::pubkey_t peer_key, std::string address)
AddPeer(const ed25519::pubkey_t &peer_key, const std::string &address)
: peer_key(peer_key), address(address) {}
};
} // namespace model
Expand Down
5 changes: 3 additions & 2 deletions irohad/model/commands/add_signatory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ namespace iroha {
*/
ed25519::pubkey_t pubkey;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

AddSignatory() {}

AddSignatory(std::string account_id, ed25519::pubkey_t pubkey)
AddSignatory(const std::string &account_id,
const ed25519::pubkey_t &pubkey)
: account_id(account_id), pubkey(pubkey) {}
};
} // namespace model
Expand Down
6 changes: 3 additions & 3 deletions irohad/model/commands/append_role.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace iroha {
*/
std::string role_name;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

AppendRole(){}
AppendRole() {}

AppendRole(std::string account_id_, std::string role_name_)
AppendRole(const std::string &account_id_, const std::string &role_name_)
: account_id(account_id_), role_name(role_name_) {}
};
} // namespace model
Expand Down
7 changes: 4 additions & 3 deletions irohad/model/commands/create_account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ namespace iroha {
*/
ed25519::pubkey_t pubkey;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

CreateAccount() {}

CreateAccount(std::string account_name, std::string domain_id,
ed25519::pubkey_t pubkey)
CreateAccount(const std::string &account_name,
const std::string &domain_id,
const ed25519::pubkey_t &pubkey)
: account_name(account_name), domain_id(domain_id), pubkey(pubkey) {}
};
} // namespace model
Expand Down
4 changes: 2 additions & 2 deletions irohad/model/commands/create_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ namespace iroha {
*/
uint8_t precision;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

CreateAsset() {}

CreateAsset(std::string asset_name, std::string domain_id,
CreateAsset(const std::string &asset_name, const std::string &domain_id,
uint8_t precision)
: asset_name(asset_name),
domain_id(domain_id),
Expand Down
4 changes: 2 additions & 2 deletions irohad/model/commands/create_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace iroha {

CreateDomain() {}

CreateDomain(std::string domain_name) : domain_name(domain_name) {}
CreateDomain(const std::string& domain_name) : domain_name(domain_name) {}
};
} // namespace model
}
} // namespace iroha
#endif // IROHA_CREATE_DOMAIN_HPP
15 changes: 10 additions & 5 deletions irohad/model/commands/create_role.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#ifndef IROHA_CREATE_ROLE_HPP
#define IROHA_CREATE_ROLE_HPP

#include "model/command.hpp"
#include <string>
#include "model/command.hpp"

namespace iroha {
namespace model {
Expand All @@ -32,13 +32,18 @@ namespace iroha {
*/
std::string role_name;

bool operator==(const Command& command) const override;
/**
* Role permissions
*/
std::vector<std::string> permissions;

CreateRole(){}
bool operator==(const Command &command) const override;

CreateRole(std::string role_name_)
: role_name(role_name_) {}
CreateRole() {}

CreateRole(const std::string &role_name_,
const std::vector<std::string> &perms)
: role_name(role_name_), permissions(perms) {}
};
} // namespace model
} // namespace iroha
Expand Down
13 changes: 6 additions & 7 deletions irohad/model/commands/grant_permission.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace iroha {
* Grant permission from creator to account_id
*/
struct GrantPermission : public Command {

/**
* Account to which grant the permission.
* Permission will be granted from creator to account_id on *permission_name*
* Permission will be granted from creator to account_id on
* *permission_name*
*/
std::string account_id;

Expand All @@ -40,14 +40,13 @@ namespace iroha {
*/
std::string permission_name;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

GrantPermission() {}

GrantPermission(std::string account_id_,
std::string permission_name_)
: account_id(account_id_),
permission_name(permission_name_) {}
GrantPermission(const std::string &account_id_,
const std::string &permission_name_)
: account_id(account_id_), permission_name(permission_name_) {}
};
} // namespace model
} // namespace iroha
Expand Down
5 changes: 3 additions & 2 deletions irohad/model/commands/remove_signatory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ namespace iroha {
*/
ed25519::pubkey_t pubkey;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

RemoveSignatory() {}

RemoveSignatory(std::string account_id, ed25519::pubkey_t pubkey)
RemoveSignatory(const std::string &account_id,
const ed25519::pubkey_t &pubkey)
: account_id(account_id), pubkey(pubkey) {}
};
} // namespace model
Expand Down
5 changes: 3 additions & 2 deletions irohad/model/commands/revoke_permission.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ namespace iroha {
*/
std::string permission_name;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

RevokePermission() {}

RevokePermission(std::string account_id_, std::string permission_name_)
RevokePermission(const std::string &account_id_,
const std::string &permission_name_)
: account_id(account_id_), permission_name(permission_name_) {}
};
} // namespace model
Expand Down
4 changes: 2 additions & 2 deletions irohad/model/commands/set_quorum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ namespace iroha {
*/
uint32_t new_quorum;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

SetQuorum() {}

SetQuorum(std::string account_id, uint32_t new_quorum)
SetQuorum(const std::string &account_id, uint32_t new_quorum)
: account_id(account_id), new_quorum(new_quorum) {}
};
} // namespace model
Expand Down
7 changes: 4 additions & 3 deletions irohad/model/commands/transfer_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ namespace iroha {
*/
Amount amount;

bool operator==(const Command& command) const override;
bool operator==(const Command &command) const override;

TransferAsset() {}

TransferAsset(std::string src_account_id, std::string dest_account_id,
std::string asset_id, Amount amount)
TransferAsset(const std::string &src_account_id,
const std::string &dest_account_id,
const std::string &asset_id, const Amount &amount)
: src_account_id(src_account_id),
dest_account_id(dest_account_id),
asset_id(asset_id),
Expand Down
16 changes: 8 additions & 8 deletions irohad/model/converters/impl/json_block_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace iroha {
Value signatures;
signatures.SetArray();
for (const auto &signature : block.sigs) {
signatures.PushBack(serializeSignature(signature, allocator), allocator);
signatures.PushBack(serializeSignature(signature, allocator),
allocator);
}
document.AddMember("signatures", signatures, allocator);

Expand Down Expand Up @@ -67,14 +68,13 @@ namespace iroha {
auto des = makeFieldDeserializer(document);
auto des_transactions = [this](auto array) {
auto acc_transactions = [this](auto init, auto &x) {
return init
| [this, &x](auto transactions) {
return factory_.deserialize(x)
| [&transactions](auto transaction) {
transactions.push_back(transaction);
return nonstd::make_optional(transactions);
};
return init | [this, &x](auto transactions) {
return factory_.deserialize(x) |
[&transactions](auto transaction) {
transactions.push_back(transaction);
return nonstd::make_optional(transactions);
};
};
};
return std::accumulate(
array.begin(), array.end(),
Expand Down
Loading

0 comments on commit 3bdc2e1

Please sign in to comment.