Skip to content

Commit

Permalink
Add counter to each command in CommandsValidator
Browse files Browse the repository at this point in the history
If command is invalid, it will have a counter before its name, which
allows user to understand exactly which command has failed.

Signed-off-by: Nikita Alekseev <[email protected]>
  • Loading branch information
nickaleks committed Jan 11, 2018
1 parent 29e465e commit 05a6894
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions shared_model/validators/transaction_validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::AddAssetQuantity> &aaq)
const {
ReasonsGroupType reason;
reason.first = "AddAssetQuantity";
addInvalidCommand(reason, "AddAssetQuantity");

validator_.validateAccountId(reason, aaq->accountId());
validator_.validateAssetId(reason, aaq->assetId());
Expand All @@ -54,7 +54,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::AddPeer> &ap) const {
ReasonsGroupType reason;
reason.first = "AddPeer";
addInvalidCommand(reason, "AddPeer");

validator_.validatePubkey(reason, ap->peerKey());
validator_.validatePeerAddress(reason, ap->peerAddress());
Expand All @@ -65,7 +65,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::AddSignatory> &as) const {
ReasonsGroupType reason;
reason.first = "AddSignatory";
addInvalidCommand(reason, "AddSignatory");

validator_.validateAccountId(reason, as->accountId());
validator_.validatePubkey(reason, as->pubkey());
Expand All @@ -76,7 +76,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::AppendRole> &ar) const {
ReasonsGroupType reason;
reason.first = "AppendRole";
addInvalidCommand(reason, "AppendRole");

validator_.validateAccountId(reason, ar->accountId());
validator_.validateRoleId(reason, ar->roleName());
Expand All @@ -88,7 +88,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::CreateAccount> &ca)
const {
ReasonsGroupType reason;
reason.first = "CreateAccount";
addInvalidCommand(reason, "CreateAccount");

validator_.validatePubkey(reason, ca->pubkey());
validator_.validateAccountName(reason, ca->accountName());
Expand All @@ -99,7 +99,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::CreateAsset> &ca) const {
ReasonsGroupType reason;
reason.first = "CreateAsset";
addInvalidCommand(reason, "CreateAsset");

validator_.validateAssetName(reason, ca->assetName());
validator_.validateDomainId(reason, ca->domainId());
Expand All @@ -111,7 +111,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::CreateDomain> &cd) const {
ReasonsGroupType reason;
reason.first = "CreateDomain";
addInvalidCommand(reason, "CreateDomain");

validator_.validateDomainId(reason, cd->domainId());

Expand All @@ -121,7 +121,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::CreateRole> &cr) const {
ReasonsGroupType reason;
reason.first = "CreateRole";
addInvalidCommand(reason, "CreateRole");

validator_.validateRoleId(reason, cr->roleName());
validator_.validatePermissions(reason, cr->rolePermissions());
Expand All @@ -132,7 +132,7 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::DetachRole> &dr) const {
ReasonsGroupType reason;
reason.first = "DetachRole";
addInvalidCommand(reason, "DetachRole");

validator_.validateAccountId(reason, dr->accountId());
validator_.validateRoleId(reason, dr->roleName());
Expand All @@ -144,7 +144,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::GrantPermission> &gp)
const {
ReasonsGroupType reason;
reason.first = "GrantPermission";
addInvalidCommand(reason, "GrantPermission");

validator_.validateAccountId(reason, gp->accountId());

Expand All @@ -155,7 +155,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::RemoveSignatory> &rs)
const {
ReasonsGroupType reason;
reason.first = "RemoveSignatory";
addInvalidCommand(reason, "RemoveSignatory");

validator_.validateAccountId(reason, rs->accountId());
validator_.validatePubkey(reason, rs->pubkey());
Expand All @@ -166,7 +166,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::RevokePermission> &rp)
const {
ReasonsGroupType reason;
reason.first = "RevokePermission";
addInvalidCommand(reason, "RevokePermission");

validator_.validateAccountId(reason, rp->accountId());
validator_.validatePermission(reason, rp->permissionName());
Expand All @@ -178,7 +178,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::SetAccountDetail> &sad)
const {
ReasonsGroupType reason;
reason.first = "SetAccountDetail";
addInvalidCommand(reason, "SetAccountDetail");

validator_.validateAccountId(reason, sad->accountId());
validator_.validateAccountDetailKey(reason, sad->key());
Expand All @@ -189,7 +189,8 @@ namespace shared_model {
ReasonsGroupType operator()(
const detail::PolymorphicWrapper<interface::SetQuorum> &sq) const {
ReasonsGroupType reason;
reason.first = "SetAccountQuorum";
addInvalidCommand(reason, "SetAccountQuorum");


validator_.validateAccountId(reason, sq->accountId());
validator_.validateQuorum(reason, sq->newQuorum());
Expand All @@ -201,7 +202,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::SubtractAssetQuantity>
&saq) const {
ReasonsGroupType reason;
reason.first = "SubtractAssetQuantity";
addInvalidCommand(reason,"SubtractAssetQuantity");

validator_.validateAccountId(reason, saq->accountId());
validator_.validateAssetId(reason, saq->assetId());
Expand All @@ -214,7 +215,7 @@ namespace shared_model {
const detail::PolymorphicWrapper<interface::TransferAsset> &ta)
const {
ReasonsGroupType reason;
reason.first = "TransferAsset";
addInvalidCommand(reason, "TransferAsset");

validator_.validateAccountId(reason, ta->srcAccountId());
validator_.validateAccountId(reason, ta->destAccountId());
Expand All @@ -226,6 +227,15 @@ namespace shared_model {

private:
FieldValidator validator_;
mutable int command_counter{0};

// adds command to a reason, appends and increments counter
void addInvalidCommand(ReasonsGroupType &reason,
const std::string &command_name) const {
reason.first =
(boost::format("%d %s") % command_counter % command_name).str();
command_counter++;
}
};

/**
Expand Down

0 comments on commit 05a6894

Please sign in to comment.