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 
12 #include "datetime/time.hpp"
18 
19 namespace shared_model {
20 
21  namespace interface {
22  class Account;
23  class AccountAsset;
24  class AccountDetailPaginationMeta;
25  class AccountDetailRecordId;
26  class Amount;
27  class Asset;
28  class AssetPaginationMeta;
29  class BatchMeta;
30  class Domain;
31  class Peer;
32  class TxPaginationMeta;
33  } // namespace interface
34 
35  namespace validation {
36 
42  private:
43  using TimeFunction = std::function<iroha::ts64_t()>;
44 
45  public:
46  FieldValidator(std::shared_ptr<ValidatorsConfig> config,
47  time_t future_gap = kDefaultFutureGap,
48  TimeFunction time_provider = [] {
49  return iroha::time::now();
50  });
51 
52  std::optional<ValidationError> validateAccountId(
53  const interface::types::AccountIdType &account_id) const;
54 
55  std::optional<ValidationError> validateAssetId(
56  const interface::types::AssetIdType &asset_id) const;
57 
58  std::optional<ValidationError> validateEvmHexAddress(
59  std::string_view address) const;
60 
61  std::optional<ValidationError> validateBytecode(
62  interface::types::EvmCodeHexStringView input) const;
63 
64  std::optional<ValidationError> validatePeer(
65  const interface::Peer &peer) const;
66 
67  std::optional<ValidationError> validateAmount(
68  const interface::Amount &amount) const;
69 
70  std::optional<ValidationError> validatePubkey(
71  std::string_view pubkey) const;
72 
73  std::optional<ValidationError> validatePeerAddress(
74  const interface::types::AddressType &address) const;
75 
76  std::optional<ValidationError> validateRoleId(
77  const interface::types::RoleIdType &role_id) const;
78 
79  std::optional<ValidationError> validateAccountName(
80  const interface::types::AccountNameType &account_name) const;
81 
82  // clang-format off
103  // clang-format on
104  std::optional<ValidationError> validateDomainId(
105  const interface::types::DomainIdType &domain_id) const;
106 
107  std::optional<ValidationError> validateDomain(
108  const interface::Domain &domain) const;
109 
110  std::optional<ValidationError> validateAssetName(
111  const interface::types::AssetNameType &asset_name) const;
112 
113  std::optional<ValidationError> validateAccountDetailKey(
114  const interface::types::AccountDetailKeyType &key) const;
115 
116  std::optional<ValidationError> validateAccountDetailValue(
117  const interface::types::AccountDetailValueType &value) const;
118 
119  std::optional<ValidationError> validateOldAccountDetailValue(
120  const std::optional<interface::types::AccountDetailValueType>
121  &old_value) const;
122 
123  std::optional<ValidationError> validatePrecision(
124  const interface::types::PrecisionType &precision) const;
125 
126  std::optional<ValidationError> validateRolePermission(
127  const interface::permissions::Role &permission) const;
128 
129  std::optional<ValidationError> validateGrantablePermission(
130  const interface::permissions::Grantable &permission) const;
131 
132  std::optional<ValidationError> validateQuorum(
133  const interface::types::QuorumType &quorum) const;
134 
135  std::optional<ValidationError> validateCreatorAccountId(
136  const interface::types::AccountIdType &account_id) const;
137 
138  std::optional<ValidationError> validateAccount(
139  const interface::Account &account) const;
140 
144  std::optional<ValidationError> validateCreatedTime(
147 
151  std::optional<ValidationError> validateCreatedTime(
152  interface::types::TimestampType timestamp) const;
153 
154  std::optional<ValidationError> validateCounter(
155  const interface::types::CounterType &counter) const;
156 
157  std::optional<ValidationError> validateSignatureForm(
158  const interface::Signature &signature) const;
159 
160  std::optional<ValidationError> validateSignatures(
161  const interface::types::SignatureRangeType &signatures,
162  const crypto::Blob &source) const;
163 
164  std::optional<ValidationError> validateQueryPayloadMeta(
165  const interface::QueryPayloadMeta &meta) const;
166 
167  std::optional<ValidationError> validateDescription(
168  const interface::types::DescriptionType &description) const;
169 
170  std::optional<ValidationError> validateBatchMeta(
171  const interface::BatchMeta &description) const;
172 
173  std::optional<ValidationError> validateHeight(
174  const interface::types::HeightType &height) const;
175 
176  std::optional<ValidationError> validateHash(
177  const crypto::Hash &hash) const;
178 
179  std::optional<ValidationError> validateTxPaginationMeta(
180  const interface::TxPaginationMeta &tx_pagination_meta) const;
181 
182  std::optional<ValidationError> validateAccountAsset(
183  const interface::AccountAsset &account_asset) const;
184 
185  std::optional<ValidationError> validateAsset(
186  const interface::Asset &asset) const;
187 
188  std::optional<ValidationError> validateAssetPaginationMeta(
189  const interface::AssetPaginationMeta &asset_pagination_meta) const;
190 
191  std::optional<ValidationError> validateAccountDetailRecordId(
192  const interface::AccountDetailRecordId &record_id) const;
193 
194  std::optional<ValidationError> validateAccountDetailPaginationMeta(
195  const interface::AccountDetailPaginationMeta &pagination_meta) const;
196 
197  private:
198  // gap for future transactions
199  time_t future_gap_;
200  // time provider callback
201  TimeFunction time_provider_;
202 
203  public:
204  // max-delay between tx creation and validation
205  static constexpr auto kMaxDelay =
206  std::chrono::hours(24) / std::chrono::milliseconds(1);
207  // default value for future_gap field of FieldValidator
208  static constexpr auto kDefaultFutureGap =
209  std::chrono::minutes(5) / std::chrono::milliseconds(1);
210 
211  static constexpr size_t hash_size =
214  static constexpr size_t value_size = 4 * 1024 * 1024;
216  };
217 
218  std::optional<ValidationError> validatePubkey(
219  shared_model::interface::types::PublicKeyHexStringView pubkey);
220 
221  std::optional<ValidationError> validatePubkey(std::string_view pubkey);
222 
223  } // namespace validation
224 } // namespace shared_model
225 
226 #endif // IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
Definition: account.hpp:20
std::string AddressType
Type of peer address.
Definition: types.hpp:50
uint64_t HeightType
Type of height (for Block, Proposal etc)
Definition: types.hpp:48
Definition: hash.hpp:18
Definition: blob.hpp:27
Definition: signature.hpp:18
Grantable
Definition: permissions.hpp:76
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:56
Definition: amount.hpp:19
Definition: domain.hpp:19
auto now()
Definition: time.hpp:23
size_t max_description_size
Definition: field_validator.hpp:215
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:86
Definition: query_payload_meta.hpp:19
std::string AccountDetailKeyType
Type of account detail key.
Definition: types.hpp:79
std::optional< ValidationError > validatePubkey(shared_model::interface::types::PublicKeyHexStringView pubkey)
Role
Definition: permissions.hpp:17
std::string AccountIdType
Type of account id.
Definition: types.hpp:38
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:19
Definition: field_validator.hpp:41
uint8_t PrecisionType
Type of precision.
Definition: types.hpp:46
std::string AccountNameType
Type of account name.
Definition: types.hpp:71
uint64_t CounterType
Type of counter.
Definition: types.hpp:69
Definition: batch_meta.hpp:18
Provides query metadata for asset list pagination.
Definition: asset_pagination_meta.hpp:17
std::string AccountDetailValueType
Type of account detail value.
Definition: types.hpp:81
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:65
std::string AssetNameType
Type of asset name.
Definition: types.hpp:73
std::string RoleIdType
Type of role (i.e admin, user)
Definition: types.hpp:54
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:67
std::string AssetIdType
Type of asset id.
Definition: types.hpp:58