Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #include <ciso646>
7 :
8 : #include "common/instanceof.hpp"
9 : #include "model/block.hpp"
10 : #include "model/commands/add_asset_quantity.hpp"
11 : #include "model/commands/add_peer.hpp"
12 : #include "model/commands/add_signatory.hpp"
13 : #include "model/commands/append_role.hpp"
14 : #include "model/commands/create_account.hpp"
15 : #include "model/commands/create_asset.hpp"
16 : #include "model/commands/create_domain.hpp"
17 : #include "model/commands/create_role.hpp"
18 : #include "model/commands/detach_role.hpp"
19 : #include "model/commands/grant_permission.hpp"
20 : #include "model/commands/remove_signatory.hpp"
21 : #include "model/commands/revoke_permission.hpp"
22 : #include "model/commands/set_account_detail.hpp"
23 : #include "model/commands/set_quorum.hpp"
24 : #include "model/commands/subtract_asset_quantity.hpp"
25 : #include "model/commands/transfer_asset.hpp"
26 :
27 : namespace iroha {
28 : namespace model {
29 :
30 : bool Command::operator!=(const Command &rhs) const {
31 19 : return not operator==(rhs);
32 : }
33 :
34 : bool Block::operator!=(const Block &rhs) const {
35 1 : return not operator==(rhs);
36 : }
37 :
38 : bool Proposal::operator!=(const Proposal &rhs) const {
39 0 : return not operator==(rhs);
40 : }
41 :
42 : bool Transaction::operator!=(const Transaction &rhs) const {
43 0 : return not operator==(rhs);
44 : }
45 :
46 : bool Signature::operator!=(const Signature &rhs) const {
47 1 : return not operator==(rhs);
48 : }
49 :
50 : bool AppendRole::operator==(const Command &command) const {
51 6 : if (! instanceof <AppendRole>(command))
52 0 : return false;
53 6 : auto cmd = static_cast<const AppendRole &>(command);
54 6 : return cmd.account_id == account_id and cmd.role_name == role_name;
55 6 : }
56 :
57 : bool DetachRole::operator==(const Command &command) const {
58 7 : if (! instanceof <DetachRole>(command))
59 0 : return false;
60 7 : auto cmd = static_cast<const DetachRole &>(command);
61 7 : return cmd.account_id == account_id and cmd.role_name == role_name;
62 7 : }
63 :
64 : bool CreateRole::operator==(const Command &command) const {
65 48 : if (! instanceof <CreateRole>(command))
66 0 : return false;
67 48 : auto cmd = static_cast<const CreateRole &>(command);
68 48 : return cmd.role_name == role_name and cmd.permissions == permissions;
69 48 : }
70 :
71 : bool GrantPermission::operator==(const Command &command) const {
72 6 : if (! instanceof <GrantPermission>(command))
73 0 : return false;
74 6 : auto cmd = static_cast<const GrantPermission &>(command);
75 6 : return cmd.account_id == account_id
76 6 : and cmd.permission_name == permission_name;
77 6 : }
78 :
79 : bool RevokePermission::operator==(const Command &command) const {
80 6 : if (! instanceof <RevokePermission>(command))
81 0 : return false;
82 6 : auto cmd = static_cast<const RevokePermission &>(command);
83 6 : return cmd.account_id == account_id
84 6 : and cmd.permission_name == permission_name;
85 6 : }
86 :
87 : /* AddAssetQuantity */
88 : bool AddAssetQuantity::operator==(const Command &command) const {
89 11 : if (! instanceof <AddAssetQuantity>(command))
90 0 : return false;
91 11 : auto add_asset_quantity = static_cast<const AddAssetQuantity &>(command);
92 11 : return add_asset_quantity.asset_id == asset_id
93 11 : && add_asset_quantity.amount == amount;
94 11 : }
95 :
96 : /* SubtractAssetQuantity */
97 : bool SubtractAssetQuantity::operator==(const Command &command) const {
98 10 : if (! instanceof <SubtractAssetQuantity>(command))
99 0 : return false;
100 : auto subtract_asset_quantity =
101 10 : static_cast<const SubtractAssetQuantity &>(command);
102 10 : return subtract_asset_quantity.asset_id == asset_id
103 10 : && subtract_asset_quantity.amount == amount;
104 10 : }
105 :
106 : /* AddPeer */
107 : bool AddPeer::operator==(const Command &command) const {
108 12 : if (! instanceof <AddPeer>(command))
109 0 : return false;
110 12 : auto add_peer = static_cast<const AddPeer &>(command);
111 12 : return add_peer.peer == peer;
112 12 : }
113 :
114 : /* AddSignatory */
115 : bool AddSignatory::operator==(const Command &command) const {
116 14 : if (! instanceof <AddSignatory>(command))
117 0 : return false;
118 14 : auto add_signatory = static_cast<const AddSignatory &>(command);
119 14 : return add_signatory.account_id == account_id
120 14 : && add_signatory.pubkey == pubkey;
121 14 : }
122 :
123 : /* CreateAccount */
124 : bool CreateAccount::operator==(const Command &command) const {
125 10 : if (! instanceof <CreateAccount>(command))
126 0 : return false;
127 10 : auto create_account = static_cast<const CreateAccount &>(command);
128 10 : return create_account.pubkey == pubkey
129 10 : && create_account.domain_id == domain_id
130 10 : && create_account.account_name == account_name;
131 10 : }
132 :
133 : /* SetAccountDetail */
134 : bool SetAccountDetail::operator==(const Command &rhs) const {
135 4 : if (! instanceof <SetAccountDetail>(rhs)) {
136 0 : return false;
137 : }
138 4 : auto setAccountDetail = static_cast<const SetAccountDetail &>(rhs);
139 4 : return setAccountDetail.account_id == account_id
140 4 : and setAccountDetail.key == key and setAccountDetail.value == value;
141 4 : }
142 :
143 : /* CreateAsset */
144 : bool CreateAsset::operator==(const Command &command) const {
145 13 : if (! instanceof <CreateAsset>(command))
146 0 : return false;
147 13 : auto create_asset = static_cast<const CreateAsset &>(command);
148 13 : return create_asset.domain_id == domain_id
149 13 : && create_asset.precision == precision
150 13 : && create_asset.asset_name == asset_name;
151 13 : }
152 :
153 : /* Create domain */
154 : bool CreateDomain::operator==(const Command &command) const {
155 13 : if (! instanceof <CreateDomain>(command))
156 0 : return false;
157 13 : auto create_domain = static_cast<const CreateDomain &>(command);
158 13 : return create_domain.domain_id == domain_id
159 13 : && create_domain.user_default_role == user_default_role;
160 13 : }
161 :
162 : /* Remove signatory */
163 : bool RemoveSignatory::operator==(const Command &command) const {
164 10 : if (! instanceof <RemoveSignatory>(command))
165 0 : return false;
166 10 : auto remove_signatory = static_cast<const RemoveSignatory &>(command);
167 10 : return remove_signatory.pubkey == pubkey
168 10 : && remove_signatory.account_id == account_id;
169 10 : }
170 :
171 : /* Set Quorum*/
172 : bool SetQuorum::operator==(const Command &command) const {
173 7 : if (! instanceof <SetQuorum>(command))
174 0 : return false;
175 7 : auto set_quorum = static_cast<const SetQuorum &>(command);
176 7 : return set_quorum.account_id == account_id
177 7 : && set_quorum.new_quorum == new_quorum;
178 7 : }
179 :
180 : /* Transfer Asset */
181 : bool TransferAsset::operator==(const Command &command) const {
182 10 : if (! instanceof <TransferAsset>(command))
183 0 : return false;
184 10 : auto transfer_asset = static_cast<const TransferAsset &>(command);
185 10 : return transfer_asset.asset_id == asset_id
186 10 : && transfer_asset.amount == amount
187 9 : && transfer_asset.src_account_id == src_account_id
188 9 : && transfer_asset.dest_account_id == dest_account_id
189 9 : && transfer_asset.description == description;
190 10 : }
191 :
192 : /* Signature */
193 : bool Signature::operator==(const Signature &rhs) const {
194 6 : return rhs.pubkey == pubkey;
195 : }
196 :
197 : /* Transaction */
198 : bool Transaction::operator==(const Transaction &rhs) const {
199 7 : return std::equal(commands.begin(),
200 7 : commands.end(),
201 7 : rhs.commands.begin(),
202 7 : rhs.commands.end(),
203 : [](const auto &i, const auto &j) { return *i == *j; })
204 7 : && rhs.quorum == quorum && rhs.created_ts == created_ts;
205 : }
206 :
207 : /* Proposal */
208 : bool Proposal::operator==(const Proposal &rhs) const {
209 0 : return rhs.height == height and rhs.created_time == created_time
210 0 : and rhs.transactions == transactions;
211 : }
212 :
213 : /* Block */
214 : bool Block::operator==(const Block &rhs) const {
215 4 : return rhs.hash == hash && rhs.height == height
216 4 : && rhs.prev_hash == prev_hash && rhs.txs_number == txs_number
217 3 : && rhs.sigs == sigs && rhs.transactions == transactions
218 3 : && rhs.created_ts == created_ts && rhs.hash == hash
219 3 : && rhs.rejected_transactions_hashes == rejected_transactions_hashes;
220 : }
221 :
222 : } // namespace model
223 : } // namespace iroha
|