Skip to content

Commit

Permalink
Add param title
Browse files Browse the repository at this point in the history
  • Loading branch information
dominious1 committed Oct 17, 2023
1 parent b7910c2 commit 00af182
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 18 deletions.
3 changes: 2 additions & 1 deletion iroha-cli/interactive/impl/interactive_transaction_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ namespace iroha_cli {
std::vector<std::string> 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<iroha::model::Command>
Expand Down
9 changes: 7 additions & 2 deletions irohad/model/commands/add_asset_quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions irohad/model/commands/subtract_asset_quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions irohad/model/converters/impl/json_command_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -122,7 +123,8 @@ namespace iroha {
auto des = makeFieldDeserializer(document);
return make_optional_ptr<AddAssetQuantity>()
| 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
Expand Down Expand Up @@ -520,7 +522,8 @@ namespace iroha {
auto des = makeFieldDeserializer(document);
return make_optional_ptr<SubtractAssetQuantity>()
| 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
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/converters/impl/pb_command_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions irohad/model/generators/command_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ namespace iroha {
const std::string &account_id, uint32_t quorum);

std::shared_ptr<Command> 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<Command> 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
Expand Down
8 changes: 4 additions & 4 deletions irohad/model/generators/impl/command_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ namespace iroha {
}

std::shared_ptr<Command> CommandGenerator::generateAddAssetQuantity(
const std::string &asset_id, const std::string &amount) {
return generateCommand<AddAssetQuantity>(asset_id, amount);
const std::string &asset_id, const std::string &amount, const std::string &title) {
return generateCommand<AddAssetQuantity>(asset_id, amount, title);
}

std::shared_ptr<Command> CommandGenerator::generateSubtractAssetQuantity(
const std::string &asset_id, const std::string &amount) {
return generateCommand<SubtractAssetQuantity>(asset_id, amount);
const std::string &asset_id, const std::string &amount, const std::string &title) {
return generateCommand<SubtractAssetQuantity>(asset_id, amount, title);
}

std::shared_ptr<Command> CommandGenerator::generateSetQuorum(
Expand Down
3 changes: 2 additions & 1 deletion irohad/model/impl/model_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ namespace iroha {
auto subtract_asset_quantity =
static_cast<const SubtractAssetQuantity &>(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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ namespace shared_model {
return amount_;
}

const std::string &AddAssetQuantity::title() const {
return title_;
}


} // namespace proto
} // namespace shared_model
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ namespace shared_model {
return amount_;
}

const std::string &SubtractAssetQuantity::title() const {
return title_;
}

} // namespace proto
} // namespace shared_model
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shared_model/interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions shared_model/interfaces/commands/add_asset_quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion shared_model/interfaces/commands/impl/add_asset_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions shared_model/interfaces/commands/subtract_asset_quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions shared_model/schema/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "primitive.proto";
message AddAssetQuantity {
string asset_id = 1;
string amount = 2;
string title = 3;
}

message AddPeer {
Expand Down Expand Up @@ -97,6 +98,7 @@ message RevokePermission {
message SubtractAssetQuantity {
string asset_id = 1;
string amount = 2;
string title = 3;
}

message CompareAndSetAccountDetail {
Expand Down
3 changes: 3 additions & 0 deletions test/module/irohad/model/converters/json_commands_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/module/irohad/model/operators/model_operators_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ AddAssetQuantity createAddAssetQuantity() {
AddAssetQuantity aaq;
aaq.amount = "10.10";
aaq.asset_id = "123";
aaq.title = "testtitle";
return aaq;
}

Expand All @@ -66,6 +67,7 @@ SubtractAssetQuantity createSubtractAssetQuantity() {
SubtractAssetQuantity saq;
saq.amount = "10.10";
saq.asset_id = "ast";
saq.title = "testtitle";
return saq;
}

Expand Down

0 comments on commit 00af182

Please sign in to comment.