hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
field_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
7 #define IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
8 
9 #include <regex>
10 
11 #include "datetime/time.hpp"
17 
18 namespace shared_model {
19 
20  namespace interface {
21  class Account;
22  class AccountAsset;
23  class AccountDetailPaginationMeta;
24  class AccountDetailRecordId;
25  class Amount;
26  class Asset;
27  class AssetPaginationMeta;
28  class BatchMeta;
29  class Domain;
30  class Peer;
31  class TxPaginationMeta;
32  } // namespace interface
33 
34  namespace validation {
35 
41  private:
42  using TimeFunction = std::function<iroha::ts64_t()>;
43 
44  public:
45  FieldValidator(std::shared_ptr<ValidatorsConfig> config,
46  time_t future_gap = kDefaultFutureGap,
47  TimeFunction time_provider = [] {
48  return iroha::time::now();
49  });
50 
51  boost::optional<ValidationError> validateAccountId(
52  const interface::types::AccountIdType &account_id) const;
53 
54  boost::optional<ValidationError> validateAssetId(
55  const interface::types::AssetIdType &asset_id) const;
56 
57  boost::optional<ValidationError> validatePeer(
58  const interface::Peer &peer) const;
59 
60  boost::optional<ValidationError> validateAmount(
61  const interface::Amount &amount) const;
62 
63  boost::optional<ValidationError> validatePubkey(
64  const interface::types::PubkeyType &pubkey) const;
65 
66  boost::optional<ValidationError> validatePeerAddress(
67  const interface::types::AddressType &address) const;
68 
69  boost::optional<ValidationError> validateRoleId(
70  const interface::types::RoleIdType &role_id) const;
71 
72  boost::optional<ValidationError> validateAccountName(
73  const interface::types::AccountNameType &account_name) const;
74 
75  // clang-format off
96  // clang-format on
97  boost::optional<ValidationError> validateDomainId(
98  const interface::types::DomainIdType &domain_id) const;
99 
100  boost::optional<ValidationError> validateDomain(
101  const interface::Domain &domain) const;
102 
103  boost::optional<ValidationError> validateAssetName(
104  const interface::types::AssetNameType &asset_name) const;
105 
106  boost::optional<ValidationError> validateAccountDetailKey(
107  const interface::types::AccountDetailKeyType &key) const;
108 
109  boost::optional<ValidationError> validateAccountDetailValue(
110  const interface::types::AccountDetailValueType &value) const;
111 
112  boost::optional<ValidationError> validateOldAccountDetailValue(
113  const boost::optional<interface::types::AccountDetailValueType>
114  &old_value) const;
115 
116  boost::optional<ValidationError> validatePrecision(
117  const interface::types::PrecisionType &precision) const;
118 
119  boost::optional<ValidationError> validateRolePermission(
120  const interface::permissions::Role &permission) const;
121 
122  boost::optional<ValidationError> validateGrantablePermission(
123  const interface::permissions::Grantable &permission) const;
124 
125  boost::optional<ValidationError> validateQuorum(
126  const interface::types::QuorumType &quorum) const;
127 
128  boost::optional<ValidationError> validateCreatorAccountId(
129  const interface::types::AccountIdType &account_id) const;
130 
131  boost::optional<ValidationError> validateAccount(
132  const interface::Account &account) const;
133 
137  boost::optional<ValidationError> validateCreatedTime(
140 
144  boost::optional<ValidationError> validateCreatedTime(
145  interface::types::TimestampType timestamp) const;
146 
147  boost::optional<ValidationError> validateCounter(
148  const interface::types::CounterType &counter) const;
149 
150  boost::optional<ValidationError> validateSignatureForm(
151  const interface::Signature &signature) const;
152 
153  boost::optional<ValidationError> validateSignatures(
154  const interface::types::SignatureRangeType &signatures,
155  const crypto::Blob &source) const;
156 
157  boost::optional<ValidationError> validateQueryPayloadMeta(
158  const interface::QueryPayloadMeta &meta) const;
159 
160  boost::optional<ValidationError> validateDescription(
161  const interface::types::DescriptionType &description) const;
162 
163  boost::optional<ValidationError> validateBatchMeta(
164  const interface::BatchMeta &description) const;
165 
166  boost::optional<ValidationError> validateHeight(
167  const interface::types::HeightType &height) const;
168 
169  boost::optional<ValidationError> validateHash(
170  const crypto::Hash &hash) const;
171 
172  boost::optional<ValidationError> validateTxPaginationMeta(
173  const interface::TxPaginationMeta &tx_pagination_meta) const;
174 
175  boost::optional<ValidationError> validateAccountAsset(
176  const interface::AccountAsset &account_asset) const;
177 
178  boost::optional<ValidationError> validateAsset(
179  const interface::Asset &asset) const;
180 
181  boost::optional<ValidationError> validateAssetPaginationMeta(
182  const interface::AssetPaginationMeta &asset_pagination_meta) const;
183 
184  boost::optional<ValidationError> validateAccountDetailRecordId(
185  const interface::AccountDetailRecordId &record_id) const;
186 
187  boost::optional<ValidationError> validateAccountDetailPaginationMeta(
188  const interface::AccountDetailPaginationMeta &pagination_meta) const;
189 
190  private:
191  // gap for future transactions
192  time_t future_gap_;
193  // time provider callback
194  TimeFunction time_provider_;
195 
196  public:
197  // max-delay between tx creation and validation
198  static constexpr auto kMaxDelay =
199  std::chrono::hours(24) / std::chrono::milliseconds(1);
200  // default value for future_gap field of FieldValidator
201  static constexpr auto kDefaultFutureGap =
202  std::chrono::minutes(5) / std::chrono::milliseconds(1);
203 
204  // size of key
205  static const size_t public_key_size;
206  static const size_t signature_size;
207  static const size_t hash_size;
208  static const size_t value_size;
210  };
211 
212  boost::optional<ValidationError> validatePubkey(
213  const interface::types::PubkeyType &pubkey);
214 
215  } // namespace validation
216 } // namespace shared_model
217 
218 #endif // IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
Definition: account.hpp:20
static const size_t signature_size
Definition: field_validator.hpp:206
std::string AddressType
Type of peer address.
Definition: types.hpp:45
uint64_t HeightType
Type of height (for Block, Proposal etc)
Definition: types.hpp:43
Definition: hash.hpp:18
Definition: blob.hpp:25
Definition: signature.hpp:25
Grantable
Definition: permissions.hpp:70
Definition: peer.hpp:20
Provides query metadata for account detail list pagination.
Definition: account_detail_pagination_meta.hpp:18
decltype(iroha::time::now()) time_t
Definition: time.hpp:38
std::string DomainIdType
Iroha domain id type.
Definition: types.hpp:53
Definition: amount.hpp:19
Definition: domain.hpp:19
static const size_t public_key_size
Definition: field_validator.hpp:205
auto now()
Definition: time.hpp:23
size_t max_description_size
Definition: field_validator.hpp:209
boost::any_range< interface::Signature, boost::forward_traversal_tag, const Signature & > SignatureRangeType
Type of signature range, which returns when signatures are invoked.
Definition: range_types.hpp:24
Provides query metadata for account detail list pagination.
Definition: account_detail_record_id.hpp:17
std::string DescriptionType
Type of the transfer message.
Definition: types.hpp:83
Definition: query_payload_meta.hpp:19
std::string AccountDetailKeyType
Type of account detail key.
Definition: types.hpp:76
Role
Definition: permissions.hpp:17
std::string AccountIdType
Type of account id.
Definition: types.hpp:39
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Definition: asset.hpp:19
Provides query metadata for any transaction list pagination.
Definition: tx_pagination_meta.hpp:17
Definition: field_validator.hpp:40
uint8_t PrecisionType
Type of precision.
Definition: types.hpp:41
boost::optional< ValidationError > validatePubkey(const interface::types::PubkeyType &pubkey)
Definition: field_validator.cpp:382
std::string AccountNameType
Type of account name.
Definition: types.hpp:68
static const size_t value_size
limit for the set account detail size in bytes
Definition: field_validator.hpp:208
uint64_t CounterType
Type of counter.
Definition: types.hpp:66
Definition: public_key.hpp:16
Definition: batch_meta.hpp:18
static const size_t hash_size
Definition: field_validator.hpp:207
Provides query metadata for asset list pagination.
Definition: asset_pagination_meta.hpp:17
std::string AccountDetailValueType
Type of account detail value.
Definition: types.hpp:78
Definition: command_executor.hpp:12
Definition: account_asset.hpp:20
uint16_t QuorumType
Type of Quorum used in transaction and set quorum.
Definition: types.hpp:62
std::string AssetNameType
Type of asset name.
Definition: types.hpp:70
std::string RoleIdType
Type of role (i.e admin, user)
Definition: types.hpp:51
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:64
std::string AssetIdType
Type of asset id.
Definition: types.hpp:55