Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce an optional title parameter to the AddAssetQuantity and SubtractAssetQuantity, enhancing functionality within Iroha Core for improved message communication. Ensure corresponding handling capabilities in Iroha CLI for seamless integration. #4003

Merged
merged 16 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions iroha-cli/interactive/impl/interactive_transaction_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ namespace iroha_cli {
std::vector<std::string> params) {
auto asset_id = params[0];
auto amount = params[1];
return generator_.generateAddAssetQuantity(asset_id, amount);
auto description = params[2];
return generator_.generateAddAssetQuantity(asset_id, amount, description);
}

std::shared_ptr<iroha::model::Command>
Expand Down Expand Up @@ -405,7 +406,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 description = params[2];
return generator_.generateSubtractAssetQuantity(asset_id, amount, description);
}

std::shared_ptr<iroha::model::Command>
Expand Down
2 changes: 1 addition & 1 deletion iroha-lib/examples/DomainAssetCreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ iroha::protocol::Transaction generateTransactionWhichAddsAssetQuantiti(
return iroha_lib::Tx(
account_name,
keypair)
.addAssetQuantity(assetIdWithDomain, assetAmount)
.addAssetQuantity(assetIdWithDomain, assetAmount, "")
.signAndAddSignature();
}

Expand Down
12 changes: 8 additions & 4 deletions iroha-lib/model/Tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ void Tx::addCommand(const iroha::protocol::Command& command)

Tx& Tx::addAssetQuantity(
const std::string& asset_id,
const std::string& amount)
const std::string& amount,
const std::string& description)
{
auto cmd = cmd_generator_.generateAddAssetQuantity(
asset_id,
amount);
amount,
description);
addCommand(*cmd);
return *this;
}
Expand Down Expand Up @@ -191,11 +193,13 @@ Tx& Tx::setAccountQuorum(

Tx& Tx::subtractAssetQuantity(
const std::string& asset_id,
const std::string& amount)
const std::string& amount,
const std::string& description)
{
auto cmd = cmd_generator_.generateSubtractAssetQuantity(
asset_id,
amount);
amount,
description);
addCommand(*cmd);
return *this;
}
Expand Down
8 changes: 5 additions & 3 deletions iroha-lib/model/Tx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class Tx {
void addCommand(const iroha::protocol::Command& command);

Tx& addAssetQuantity(
const std::string& account_id,
const std::string& role_name);
const std::string& asset_id,
const std::string& amount,
const std::string& title);
Tx& addPeer(
const std::string& address,
const std::string& pubkey,
Expand Down Expand Up @@ -83,7 +84,8 @@ class Tx {
uint32_t quorum);
Tx& subtractAssetQuantity(
const std::string& asset_id,
const std::string& amount);
const std::string& amount,
const std::string& title);
Tx& transferAsset(
const std::string& account_id,
const std::string& dest_account_id,
Expand Down
13 changes: 11 additions & 2 deletions iroha-lib/model/generators/CommandGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ namespace iroha_lib {

std::shared_ptr<Command> CommandGenerator::generateAddAssetQuantity(
const std::string& asset_id,
const std::string& amount)
const std::string& amount,
const std::string& description)
{
AddAssetQuantity addAssetQuantity;
addAssetQuantity.set_asset_id(asset_id);
addAssetQuantity.set_amount(amount);
if (!description.empty()) {
addAssetQuantity.set_description(description);
}

auto cmd = Command();
cmd.set_allocated_add_asset_quantity(new AddAssetQuantity(addAssetQuantity));
Expand Down Expand Up @@ -227,11 +231,16 @@ std::shared_ptr<Command> CommandGenerator::generateSetAccountQuorum(

std::shared_ptr<Command> CommandGenerator::generateSubtractAssetQuantity(
const std::string& asset_id,
const std::string& amount)
const std::string& amount,
const std::string& description)
{
SubtractAssetQuantity subtractAssetQuantity;
subtractAssetQuantity.set_asset_id(asset_id);
subtractAssetQuantity.set_amount(amount);
std::optional<std::string> description_optional = description;
if (description_optional) {
subtractAssetQuantity.set_description(*description_optional);
}

auto cmd = Command();
cmd.set_allocated_subtract_asset_quantity(new SubtractAssetQuantity(subtractAssetQuantity));
Expand Down
6 changes: 4 additions & 2 deletions iroha-lib/model/generators/CommandGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class CommandGenerator {

std::shared_ptr<Command> generateAddAssetQuantity(
const std::string& asset_id,
const std::string& amount);
const std::string& amount,
const std::string& title);
std::shared_ptr<Command> generateAddPeer(
const std::string& address,
const std::string& pubkey,
Expand Down Expand Up @@ -67,7 +68,8 @@ class CommandGenerator {
const std::string& account_id, uint32_t quorum);
std::shared_ptr<Command> generateSubtractAssetQuantity(
const std::string& asset_id,
const std::string& amount);
const std::string& amount,
const std::string& title);
std::shared_ptr<Command> generateTransferAsset(
const std::string& account_id,
const std::string& dest_account_id,
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;

/**
* Description
*/
std::string description;

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 &description)
: asset_id(asset_id), amount(amount), description(description) {}
};
} // 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;

/**
* Description
*/
std::string description;

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), description(description) {}
};
} // namespace model
} // namespace iroha
Expand Down
9 changes: 7 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("description", add_asset_quantity->description, 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::description, "description") | toCommand;
}

// AddPeer
Expand Down Expand Up @@ -510,6 +512,8 @@ namespace iroha {
"asset_id", subtract_asset_quantity->asset_id, allocator);
document.AddMember(
"amount", subtract_asset_quantity->amount, allocator);
document.AddMember(
"description", subtract_asset_quantity->description, allocator);

return document;
}
Expand All @@ -520,7 +524,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::description, "description") | 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.description = pb_subtract_asset_quantity.description();
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 &description) {
return generateCommand<AddAssetQuantity>(asset_id, amount, description);
}

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 &description) {
return generateCommand<SubtractAssetQuantity>(asset_id, amount, description);
}

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.description == description;
}

/* AddPeer */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ namespace shared_model {
return amount_;
}

const std::string &AddAssetQuantity::description() const {
return description_;
}

} // 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::description() const {
return description_;
}

} // 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 &description() const override;

private:
const iroha::protocol::AddAssetQuantity &add_asset_quantity_;

const interface::Amount amount_;
const std::string description_;
};
} // 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 &description() const override;

private:
const iroha::protocol::SubtractAssetQuantity &subtract_asset_quantity_;

const interface::Amount amount_;
const std::string description_;
};

} // namespace proto
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 &description() const = 0;

std::string toString() const override;

bool operator==(const ModelType &rhs) const override;
Expand Down
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("description", description())
.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 description() == rhs.description();
}

} // 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("description", description())
.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 description() == rhs.description();
}

} // namespace interface
Expand Down
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 description
*/
virtual const std::string &description() const = 0;

std::string toString() const override;

bool operator==(const ModelType &rhs) const override;
Expand Down
2 changes: 2 additions & 0 deletions shared_model/interfaces/common_objects/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace shared_model {
using DomainIdType = std::string;
/// Type of asset id
using AssetIdType = std::string;
/// Type of description
using DescriptionType = std::string;
/// Permission type used in permission commands
using PermissionNameType = std::string;
/// Permission set
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;
optional string description = 3;
}

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

message CompareAndSetAccountDetail {
Expand Down
Loading
Loading