From 00af182d6600ec9c3a38be60529d9f7ccda7202a Mon Sep 17 00:00:00 2001 From: dominious1 Date: Wed, 18 Oct 2023 00:05:12 +0200 Subject: [PATCH] Add param title --- .../interactive/impl/interactive_transaction_cli.cpp | 3 ++- irohad/model/commands/add_asset_quantity.hpp | 9 +++++++-- irohad/model/commands/subtract_asset_quantity.hpp | 10 ++++++++-- irohad/model/converters/impl/json_command_factory.cpp | 7 +++++-- irohad/model/converters/impl/pb_command_factory.cpp | 2 +- irohad/model/generators/command_generator.hpp | 4 ++-- irohad/model/generators/impl/command_generator.cpp | 8 ++++---- irohad/model/impl/model_operators.cpp | 3 ++- .../commands/impl/proto_add_asset_quantity.cpp | 5 +++++ .../commands/impl/proto_subtract_asset_quantity.cpp | 4 ++++ .../protobuf/commands/proto_add_asset_quantity.hpp | 3 +++ .../commands/proto_subtract_asset_quantity.hpp | 3 +++ shared_model/interfaces/CMakeLists.txt | 2 +- .../interfaces/commands/add_asset_quantity.hpp | 2 ++ .../interfaces/commands/impl/add_asset_quantity.cpp | 3 ++- .../commands/impl/subtract_asset_quantity.cpp | 3 ++- .../interfaces/commands/subtract_asset_quantity.hpp | 5 +++++ shared_model/schema/commands.proto | 2 ++ .../irohad/model/converters/json_commands_test.cpp | 3 +++ .../irohad/model/operators/model_operators_test.cpp | 2 ++ 20 files changed, 65 insertions(+), 18 deletions(-) diff --git a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp index cebdfd89a0b..c8604f64b20 100644 --- a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp +++ b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp @@ -405,7 +405,8 @@ namespace iroha_cli { std::vector params) { auto asset_id = params[0]; auto amount = params[1]; - return generator_.generateSubtractAssetQuantity(asset_id, amount); + auto title = params[2]; + return generator_.generateSubtractAssetQuantity(asset_id, amount, title); } std::shared_ptr diff --git a/irohad/model/commands/add_asset_quantity.hpp b/irohad/model/commands/add_asset_quantity.hpp index 4e502370f55..6fda8db27ba 100644 --- a/irohad/model/commands/add_asset_quantity.hpp +++ b/irohad/model/commands/add_asset_quantity.hpp @@ -27,12 +27,17 @@ namespace iroha { */ std::string amount; + /** + * title + */ + std::string title; + bool operator==(const Command &command) const override; AddAssetQuantity() {} - AddAssetQuantity(const std::string &asset_id, const std::string &amount) - : asset_id(asset_id), amount(amount) {} + AddAssetQuantity(const std::string &asset_id, const std::string &amount, const std::string &title) + : asset_id(asset_id), amount(amount), title(title) {} }; } // namespace model } // namespace iroha diff --git a/irohad/model/commands/subtract_asset_quantity.hpp b/irohad/model/commands/subtract_asset_quantity.hpp index 86d44951267..71089356b70 100644 --- a/irohad/model/commands/subtract_asset_quantity.hpp +++ b/irohad/model/commands/subtract_asset_quantity.hpp @@ -26,13 +26,19 @@ namespace iroha { */ std::string amount; + /** + * Title + */ + std::string title; + bool operator==(const Command &command) const override; SubtractAssetQuantity() {} SubtractAssetQuantity(const std::string &asset_id, - const std::string &amount) - : asset_id(asset_id), amount(amount) {} + const std::string &amount, + const std::string &title) + : asset_id(asset_id), amount(amount), title(title) {} }; } // namespace model } // namespace iroha diff --git a/irohad/model/converters/impl/json_command_factory.cpp b/irohad/model/converters/impl/json_command_factory.cpp index c070df86bed..d46292b4485 100644 --- a/irohad/model/converters/impl/json_command_factory.cpp +++ b/irohad/model/converters/impl/json_command_factory.cpp @@ -113,6 +113,7 @@ namespace iroha { document.AddMember("command_type", "AddAssetQuantity", allocator); document.AddMember("asset_id", add_asset_quantity->asset_id, allocator); document.AddMember("amount", add_asset_quantity->amount, allocator); + document.AddMember("title", add_asset_quantity->title, allocator); return document; } @@ -122,7 +123,8 @@ namespace iroha { auto des = makeFieldDeserializer(document); return make_optional_ptr() | des.String(&AddAssetQuantity::asset_id, "asset_id") - | des.String(&AddAssetQuantity::amount, "amount") | toCommand; + | des.String(&AddAssetQuantity::amount, "amount") + | des.String(&AddAssetQuantity::title, "title") | toCommand; } // AddPeer @@ -520,7 +522,8 @@ namespace iroha { auto des = makeFieldDeserializer(document); return make_optional_ptr() | des.String(&SubtractAssetQuantity::asset_id, "asset_id") - | des.String(&SubtractAssetQuantity::amount, "amount") | toCommand; + | des.String(&SubtractAssetQuantity::amount, "amount") + | des.String(&SubtractAssetQuantity::title, "title") | toCommand; } // Abstract diff --git a/irohad/model/converters/impl/pb_command_factory.cpp b/irohad/model/converters/impl/pb_command_factory.cpp index 14d38a043da..00c97a0011c 100644 --- a/irohad/model/converters/impl/pb_command_factory.cpp +++ b/irohad/model/converters/impl/pb_command_factory.cpp @@ -200,7 +200,7 @@ namespace iroha { subtract_asset_quantity.asset_id = pb_subtract_asset_quantity.asset_id(); subtract_asset_quantity.amount = pb_subtract_asset_quantity.amount(); - + subtract_asset_quantity.title = pb_subtract_asset_quantity.title(); return subtract_asset_quantity; } diff --git a/irohad/model/generators/command_generator.hpp b/irohad/model/generators/command_generator.hpp index 0e9421a378d..9a4b87e615e 100644 --- a/irohad/model/generators/command_generator.hpp +++ b/irohad/model/generators/command_generator.hpp @@ -58,10 +58,10 @@ namespace iroha { const std::string &account_id, uint32_t quorum); std::shared_ptr generateAddAssetQuantity( - const std::string &asset_id, const std::string &amount); + const std::string &asset_id, const std::string &amount, const std::string &title); std::shared_ptr generateSubtractAssetQuantity( - const std::string &asset_id, const std::string &amount); + const std::string &asset_id, const std::string &amount, const std::string &title); /** * Generate transfer assets from source account_id to target account_id * @param src_account_id - source account identifier diff --git a/irohad/model/generators/impl/command_generator.cpp b/irohad/model/generators/impl/command_generator.cpp index 7218e6eacc9..78de2c7fe96 100644 --- a/irohad/model/generators/impl/command_generator.cpp +++ b/irohad/model/generators/impl/command_generator.cpp @@ -89,13 +89,13 @@ namespace iroha { } std::shared_ptr CommandGenerator::generateAddAssetQuantity( - const std::string &asset_id, const std::string &amount) { - return generateCommand(asset_id, amount); + const std::string &asset_id, const std::string &amount, const std::string &title) { + return generateCommand(asset_id, amount, title); } std::shared_ptr CommandGenerator::generateSubtractAssetQuantity( - const std::string &asset_id, const std::string &amount) { - return generateCommand(asset_id, amount); + const std::string &asset_id, const std::string &amount, const std::string &title) { + return generateCommand(asset_id, amount, title); } std::shared_ptr CommandGenerator::generateSetQuorum( diff --git a/irohad/model/impl/model_operators.cpp b/irohad/model/impl/model_operators.cpp index c756141f351..d21e4c007f6 100644 --- a/irohad/model/impl/model_operators.cpp +++ b/irohad/model/impl/model_operators.cpp @@ -100,7 +100,8 @@ namespace iroha { auto subtract_asset_quantity = static_cast(command); return subtract_asset_quantity.asset_id == asset_id - && subtract_asset_quantity.amount == amount; + && subtract_asset_quantity.amount == amount + && subtract_asset_quantity.title == title; } /* AddPeer */ diff --git a/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp b/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp index 24765852726..d1bffc708a4 100644 --- a/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp +++ b/shared_model/backend/protobuf/commands/impl/proto_add_asset_quantity.cpp @@ -20,5 +20,10 @@ namespace shared_model { return amount_; } + const std::string &AddAssetQuantity::title() const { + return title_; + } + + } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp b/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp index 5b681154ee1..482cd08ea7b 100644 --- a/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp +++ b/shared_model/backend/protobuf/commands/impl/proto_subtract_asset_quantity.cpp @@ -22,5 +22,9 @@ namespace shared_model { return amount_; } + const std::string &SubtractAssetQuantity::title() const { + return title_; + } + } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp index 55528756efe..5ab41ee4401 100644 --- a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp +++ b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp @@ -21,10 +21,13 @@ namespace shared_model { const interface::Amount &amount() const override; + const std::string &title() const override; + private: const iroha::protocol::AddAssetQuantity &add_asset_quantity_; const interface::Amount amount_; + const std::string title_; }; } // namespace proto } // namespace shared_model diff --git a/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp index d6f8c34ac78..f77d8e79062 100644 --- a/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp +++ b/shared_model/backend/protobuf/commands/proto_subtract_asset_quantity.hpp @@ -22,10 +22,13 @@ namespace shared_model { const interface::Amount &amount() const override; + const std::string &title() const override; + private: const iroha::protocol::SubtractAssetQuantity &subtract_asset_quantity_; const interface::Amount amount_; + const std::string title_; }; } // namespace proto diff --git a/shared_model/interfaces/CMakeLists.txt b/shared_model/interfaces/CMakeLists.txt index eb4616ced3b..62942f137f8 100644 --- a/shared_model/interfaces/CMakeLists.txt +++ b/shared_model/interfaces/CMakeLists.txt @@ -52,7 +52,7 @@ add_library(shared_model_interfaces common_objects/impl/amount.cpp common_objects/impl/signature.cpp common_objects/impl/peer.cpp - ) +) if (IROHA_ROOT_PROJECT) target_sources(shared_model_interfaces PRIVATE diff --git a/shared_model/interfaces/commands/add_asset_quantity.hpp b/shared_model/interfaces/commands/add_asset_quantity.hpp index a44c346812f..afb1682af58 100644 --- a/shared_model/interfaces/commands/add_asset_quantity.hpp +++ b/shared_model/interfaces/commands/add_asset_quantity.hpp @@ -28,6 +28,8 @@ namespace shared_model { */ virtual const Amount &amount() const = 0; + virtual const std::string &title() const = 0; + std::string toString() const override; bool operator==(const ModelType &rhs) const override; diff --git a/shared_model/interfaces/commands/impl/add_asset_quantity.cpp b/shared_model/interfaces/commands/impl/add_asset_quantity.cpp index 5fd562b8d7b..ea86ae3316e 100644 --- a/shared_model/interfaces/commands/impl/add_asset_quantity.cpp +++ b/shared_model/interfaces/commands/impl/add_asset_quantity.cpp @@ -13,11 +13,12 @@ namespace shared_model { .init("AddAssetQuantity") .appendNamed("asset_id", assetId()) .appendNamed("amount", amount()) + .appendNamed("title", title()) .finalize(); } bool AddAssetQuantity::operator==(const ModelType &rhs) const { - return assetId() == rhs.assetId() and amount() == rhs.amount(); + return assetId() == rhs.assetId() and amount() == rhs.amount() and title() == rhs.title(); } } // namespace interface diff --git a/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp b/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp index 1444bdf07cb..4c291950837 100644 --- a/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp +++ b/shared_model/interfaces/commands/impl/subtract_asset_quantity.cpp @@ -13,11 +13,12 @@ namespace shared_model { .init("SubtractAssetQuantity") .appendNamed("asset_id", assetId()) .appendNamed("amount", amount()) + .appendNamed("title", title()) .finalize(); } bool SubtractAssetQuantity::operator==(const ModelType &rhs) const { - return assetId() == rhs.assetId() and amount() == rhs.amount(); + return assetId() == rhs.assetId() and amount() == rhs.amount() and title() == rhs.title(); } } // namespace interface diff --git a/shared_model/interfaces/commands/subtract_asset_quantity.hpp b/shared_model/interfaces/commands/subtract_asset_quantity.hpp index e16b9fb4303..547fa0f6d81 100644 --- a/shared_model/interfaces/commands/subtract_asset_quantity.hpp +++ b/shared_model/interfaces/commands/subtract_asset_quantity.hpp @@ -28,6 +28,11 @@ namespace shared_model { */ virtual const Amount &amount() const = 0; + /** + * @return quantity of asset for subtracting + */ + virtual const std::string &title() const = 0; + std::string toString() const override; bool operator==(const ModelType &rhs) const override; diff --git a/shared_model/schema/commands.proto b/shared_model/schema/commands.proto index 320a523bbe1..30c519c0e88 100644 --- a/shared_model/schema/commands.proto +++ b/shared_model/schema/commands.proto @@ -13,6 +13,7 @@ import "primitive.proto"; message AddAssetQuantity { string asset_id = 1; string amount = 2; + string title = 3; } message AddPeer { @@ -97,6 +98,7 @@ message RevokePermission { message SubtractAssetQuantity { string asset_id = 1; string amount = 2; + string title = 3; } message CompareAndSetAccountDetail { diff --git a/test/module/irohad/model/converters/json_commands_test.cpp b/test/module/irohad/model/converters/json_commands_test.cpp index f1c87ad87fc..14d29ab266f 100644 --- a/test/module/irohad/model/converters/json_commands_test.cpp +++ b/test/module/irohad/model/converters/json_commands_test.cpp @@ -71,6 +71,7 @@ TEST_F(JsonCommandTest, InvalidWhenUnknownCommandType) { "command_type": "Unknown", "account_id": "admin@test", "asset_id": "usd#test", + "title": "testtitle", "amount": { "int_part": -20, "frac_part": 0 @@ -95,6 +96,7 @@ TEST_F(JsonCommandTest, add_asset_quantity) { orig_command->amount = "1.50"; orig_command->asset_id = "23"; + orig_command->title = "testtitle"; auto json_command = factory.serializeAddAssetQuantity(orig_command); auto serial_command = factory.deserializeAddAssetQuantity(json_command); @@ -114,6 +116,7 @@ TEST_F(JsonCommandTest, subtract_asset_quantity) { orig_command->amount = "1.50"; orig_command->asset_id = "23"; + orig_command->title = "testtitle"; auto json_command = factory.serializeSubtractAssetQuantity(orig_command); auto serial_command = factory.deserializeSubtractAssetQuantity(json_command); diff --git a/test/module/irohad/model/operators/model_operators_test.cpp b/test/module/irohad/model/operators/model_operators_test.cpp index 454936951cd..e88d052374d 100644 --- a/test/module/irohad/model/operators/model_operators_test.cpp +++ b/test/module/irohad/model/operators/model_operators_test.cpp @@ -48,6 +48,7 @@ AddAssetQuantity createAddAssetQuantity() { AddAssetQuantity aaq; aaq.amount = "10.10"; aaq.asset_id = "123"; + aaq.title = "testtitle"; return aaq; } @@ -66,6 +67,7 @@ SubtractAssetQuantity createSubtractAssetQuantity() { SubtractAssetQuantity saq; saq.amount = "10.10"; saq.asset_id = "ast"; + saq.title = "testtitle"; return saq; }