Skip to content

Commit

Permalink
Add remove signatory validation
Browse files Browse the repository at this point in the history
  • Loading branch information
grimadas authored and lebdron committed Jul 18, 2017
1 parent 8fe1141 commit e8dc1aa
Showing 1 changed file with 109 additions and 87 deletions.
196 changes: 109 additions & 87 deletions irohad/model/impl/stateful_command_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,104 +15,126 @@
* limitations under the License.
*/

#include <model/commands/add_asset_quantity.hpp>
#include <model/commands/add_signatory.hpp>
#include <model/commands/assign_master_key.hpp>
#include <model/commands/create_account.hpp>
#include <model/commands/create_asset.hpp>
#include <model/commands/create_domain.hpp>
#include "model/commands/add_asset_quantity.hpp"
#include "model/commands/add_signatory.hpp"
#include "model/commands/assign_master_key.hpp"
#include "model/commands/create_account.hpp"
#include "model/commands/create_asset.hpp"
#include "model/commands/create_domain.hpp"
#include "model/commands/remove_signatory.hpp"
#include "model/commands/set_permissions.hpp"

#include <algorithm>

using namespace iroha::model;
namespace iroha {
namespace model {

/**
*
* @param queries
* @param creator
* @return
*/
bool AddAssetQuantity::validate(ametsuchi::WsvQuery &queries,
/**
*
* @param queries
* @param creator
* @return
*/
bool AddAssetQuantity::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Check if creator has MoneyCreator permission
return creator.permissions.issue_assets &&
// Asset must exist in the system
!queries.getAsset(asset_id).name.empty();
// Check if the amount if meaningful
// TODO: check if amount is in some scope
}

/**
*
* @param queries
* @param creator
* @return
*/
bool AddSignatory::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Check if creator has MoneyCreator permission
return creator.permissions.issue_assets &&
// Asset must exist in the system
!queries.getAsset(asset_id).name.empty();
// Check if the amount if meaningful
// TODO: check if amount is in some scope
}
return
// Case 1. When command creator wants to add their signatory to some
// account
creator.master_key == pubkey;
// TODO: What about other cases ?
}
/**
*
* @param queries
* @param creator
* @return
*/
bool AssignMasterKey::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Case 1: When creator wants to change key in their own account
auto signs = queries.getSignatories(account_id);

/**
*
* @param queries
* @param creator
* @return
*/
bool AddSignatory::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
return
// Case 1. When command creator wants to add their signatory to some
// account
creator.master_key == pubkey;
// TODO: What about other cases ?
}
/**
*
* @param queries
* @param creator
* @return
*/
bool AssignMasterKey::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Case 1: When creator wants to change key in their own account
auto signs = queries.getSignatories(account_id);
return
// Check if accout has at lest one signatory
!signs.empty() &&
// Check if new master key is not the same
creator.master_key != pubkey &&
// Check if new master key is in AccountSignatory relationship
std::find(signs.begin(), signs.end(), pubkey) != signs.end();

return
// Check if accout has at lest one signatory
!signs.empty() &&
// Check if new master key is not the same
creator.master_key != pubkey &&
// Check if new master key is in AccountSignatory relationship
std::find(signs.begin(), signs.end(), pubkey) != signs.end();
// TODO:Can there be case when creator can assign master key of other
// account?
}

// TODO:Can there be case when creator can assign master key of other account?
}
/**
*
* @param queries
* @param creator
* @return
*/
bool CreateAccount::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Creator must have permission to create account
return creator.permissions.create_assets;
}

/**
*
* @param queries
* @param creator
* @return
*/
bool CreateAccount::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Creator must have permission to create account
return creator.permissions.create_assets;
}
/**
*
* @param queries
* @param creator
* @return
*/
bool CreateAsset::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Creator must have permission to create assets
return creator.permissions.create_assets;
}

/**
*
* @param queries
* @param creator
* @return
*/
bool CreateAsset::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Creator must have permission to create assets
return creator.permissions.create_assets;
}
/**
*
* @param queries
* @param creator
* @return
*/
bool CreateDomain::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Creator must have permission to create domains
return creator.permissions.create_domains;
}

/**
*
* @param queries
* @param creator
* @return
*/
bool CreateDomain::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Creator must have permission to create domains
return creator.permissions.create_domains;
}
/**
*
* @param queries
* @param creator
* @return
*/
bool RemoveSignatory::validate(ametsuchi::WsvQuery &queries,
const Account &creator) {
// Case 1. Creator removes signatory from their account
return creator.account_id == account_id &&
// Can't remove master key (first reassign it)
pubkey != creator.master_key;

// TODO: can be there other cases?
}


} // namespace model

} // namespace iroha

0 comments on commit e8dc1aa

Please sign in to comment.