Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsa committed Sep 25, 2017
1 parent 0233407 commit 68c7cf5
Show file tree
Hide file tree
Showing 22 changed files with 284 additions and 193 deletions.
8 changes: 6 additions & 2 deletions iroha-cli/impl/query_response_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "query_response_handler.hpp"
#include "model/converters/pb_common.hpp"

using namespace iroha::protocol;
namespace iroha_cli {
Expand Down Expand Up @@ -52,7 +53,8 @@ namespace iroha_cli {
if (it != handler_map_.end()) {
(this->*it->second)(response);
} else {
log_->error("Response Handle {} not Implemented", response.response_case());
log_->error("Response Handle {} not Implemented",
response.response_case());
}
}

Expand Down Expand Up @@ -83,7 +85,9 @@ namespace iroha_cli {
log_->info("[Account Assets]");
log_->info("-Account Id- {}", acc_assets.account_id());
log_->info("-Asset Id- {}", acc_assets.asset_id());
log_->info("-Balance- {}", acc_assets.balance());
auto balance =
iroha::model::converters::deserializeAmount(acc_assets.balance());
log_->info("-Balance- {}", balance.to_string());
}

void QueryResponseHandler::handleSignatoriesResponse(
Expand Down
21 changes: 9 additions & 12 deletions iroha-cli/interactive/impl/interactive_transaction_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ namespace iroha_cli {
std::vector<std::string> params) {
auto account_id = params[0];
auto asset_id = params[1];
iroha::Amount amount;
auto val_int = parser::parseValue<uint64_t >(params[2]);
auto val_frac = parser::parseValue<uint64_t>(params[3]);
if (not val_int.has_value() || not val_frac.has_value()) {
auto val_int =
parser::parseValue<boost::multiprecision::uint256_t>(params[2]);
auto precision = parser::parseValue<uint8_t>(params[3]);
if (not val_int.has_value() || not precision.has_value()) {
std::cout << "Wrong format for amount" << std::endl;
return nullptr;
}
amount.int_part = val_int.value();
amount.frac_part = val_frac.value();
iroha::Amount amount(val_int.value(), precision.value());
return generator_.generateAddAssetQuantity(account_id, asset_id, amount);
}

Expand Down Expand Up @@ -282,15 +281,13 @@ namespace iroha_cli {
auto src_account_id = params[0];
auto dest_account_id = params[1];
auto asset_id = params[2];
iroha::Amount amount;
auto val_int = parser::parseValue<uint64_t>(params[3]);
auto val_frac = parser::parseValue<uint64_t>(params[4]);
if (not val_int.has_value() || not val_frac.has_value()) {
auto val_int = parser::parseValue<boost::multiprecision::uint256_t>(params[3]);
auto precision = parser::parseValue<uint8_t >(params[4]);
if (not val_int.has_value() || not precision.has_value()) {
std::cout << "Wrong format for amount" << std::endl;
return nullptr;
}
amount.int_part = val_int.value();
amount.frac_part = val_frac.value();
iroha::Amount amount(val_int.value(), precision.value());
return generator_.generateTransferAsset(src_account_id, dest_account_id,
asset_id, amount);
}
Expand Down
2 changes: 1 addition & 1 deletion irohad/ametsuchi/impl/postgres_wsv_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace iroha {
" VALUES (" +
transaction_.quote(asset.account_id) + ", " +
transaction_.quote(asset.asset_id) + ", " +
transaction_.quote(asset.balance) + ", " +
transaction_.quote(asset.balance.to_string()) + ", " +
/*asset.permissions*/ transaction_.quote(0) +
")\n"
" ON CONFLICT (account_id, asset_id)\n"
Expand Down
4 changes: 3 additions & 1 deletion irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ namespace iroha {
auto row = result.at(0);
row.at("account_id") >> asset.account_id;
row.at("asset_id") >> asset.asset_id;
row.at("amount") >> asset.balance;
std::string amount_str;
row.at("amount") >> amount_str;
asset.balance = Amount::createFromString(amount_str).value();
// row.at("permissions") >> ?
return asset;
}
Expand Down
3 changes: 2 additions & 1 deletion irohad/model/account_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#define IROHA_ACCOUNT_ASSET_HPP

#include <string>
#include "amount/amount.hpp"

namespace iroha {
namespace model {
Expand All @@ -37,7 +38,7 @@ namespace iroha {
/**
* Current balance
*/
uint64_t balance;
Amount balance;
};
}
}
Expand Down
1 change: 1 addition & 0 deletions irohad/model/converters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_library(pb_model_converters
impl/pb_query_factory.cpp
impl/pb_query_response_factory.cpp
impl/pb_transaction_factory.cpp
impl/pb_common.cpp
)
target_link_libraries(pb_model_converters
model
Expand Down
21 changes: 1 addition & 20 deletions irohad/model/converters/impl/pb_command_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,14 @@
*/

#include "model/converters/pb_command_factory.hpp"
#include "model/converters/pb_common.hpp"

#include <string>

namespace iroha {
namespace model {
namespace converters {

protocol::Amount PbCommandFactory::serializeAmount(
iroha::Amount iroha_amount) {
protocol::Amount res;
res.set_precision(iroha_amount.getPrecision());
auto value = res.mutable_value();
auto vectorUint64s = iroha_amount.to_uint64s();
value->set_first(vectorUint64s.at(0));
value->set_second(vectorUint64s.at(1));
value->set_third(vectorUint64s.at(2));
value->set_fourth(vectorUint64s.at(3));
return res;
}

iroha::Amount PbCommandFactory::deserializeAmount(
protocol::Amount pb_amount) {
auto value = pb_amount.value();
return {value.first(), value.second(), value.third(), value.fourth(),
pb_amount.precision()};
}

// asset quantity
protocol::AddAssetQuantity PbCommandFactory::serializeAddAssetQuantity(
const model::AddAssetQuantity &add_asset_quantity) {
Expand Down
45 changes: 45 additions & 0 deletions irohad/model/converters/impl/pb_common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
* http://soramitsu.co.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "model/converters/pb_common.hpp"

namespace iroha {
namespace model {
namespace converters {

protocol::Amount serializeAmount(
iroha::Amount iroha_amount) {
protocol::Amount res;
res.set_precision(iroha_amount.getPrecision());
auto value = res.mutable_value();
auto vectorUint64s = iroha_amount.to_uint64s();
value->set_first(vectorUint64s.at(0));
value->set_second(vectorUint64s.at(1));
value->set_third(vectorUint64s.at(2));
value->set_fourth(vectorUint64s.at(3));
return res;
}

iroha::Amount deserializeAmount(
protocol::Amount pb_amount) {
auto value = pb_amount.value();
return {value.first(), value.second(), value.third(), value.fourth(),
pb_amount.precision()};
}
}
}
}
11 changes: 7 additions & 4 deletions irohad/model/converters/impl/pb_query_response_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "model/converters/pb_query_response_factory.hpp"
#include "model/converters/pb_transaction_factory.hpp"
#include "model/converters/pb_common.hpp"

namespace iroha {
namespace model {
Expand Down Expand Up @@ -131,15 +132,16 @@ namespace iroha {
protocol::AccountAsset pb_account_asset;
pb_account_asset.set_account_id(account_asset.account_id);
pb_account_asset.set_asset_id(account_asset.asset_id);
pb_account_asset.set_balance(account_asset.balance);
auto pb_balance = pb_account_asset.mutable_balance();
pb_balance->CopyFrom(serializeAmount(account_asset.balance));
return pb_account_asset;
}

model::AccountAsset PbQueryResponseFactory::deserializeAccountAsset(
const protocol::AccountAsset &account_asset) const {
model::AccountAsset res;
res.account_id = account_asset.account_id();
res.balance = account_asset.balance();
res.balance = deserializeAmount(account_asset.balance());
res.asset_id = account_asset.asset_id();
return res;
}
Expand All @@ -153,7 +155,8 @@ namespace iroha {
accountAssetResponse.acct_asset.asset_id);
pb_account_asset->set_account_id(
accountAssetResponse.acct_asset.account_id);
pb_account_asset->set_balance(accountAssetResponse.acct_asset.balance);
auto pb_amount = pb_account_asset->mutable_balance();
pb_amount->CopyFrom(serializeAmount(accountAssetResponse.acct_asset.balance));
return pb_response;
}

Expand All @@ -162,7 +165,7 @@ namespace iroha {
const protocol::AccountAssetResponse &account_asset_response) const {
model::AccountAssetResponse res;
res.acct_asset.balance =
account_asset_response.account_asset().balance();
deserializeAmount(account_asset_response.account_asset().balance());
res.acct_asset.account_id =
account_asset_response.account_asset().account_id();
res.acct_asset.asset_id =
Expand Down
4 changes: 0 additions & 4 deletions irohad/model/converters/pb_command_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ namespace iroha {
*/
class PbCommandFactory {
public:
// amount
protocol::Amount serializeAmount(iroha::Amount iroha_amount);
iroha::Amount deserializeAmount(protocol::Amount pb_amount);

// asset quantity
protocol::AddAssetQuantity serializeAddAssetQuantity(
const model::AddAssetQuantity &addAssetQuantity);
Expand Down
35 changes: 35 additions & 0 deletions irohad/model/converters/pb_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
* http://soramitsu.co.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef IROHA_PB_COMMON_HPP
#define IROHA_PB_COMMON_HPP

#include "commands.pb.h"
#include "amount/amount.hpp"

namespace iroha {
namespace model {
namespace converters {

// amount
protocol::Amount serializeAmount(iroha::Amount iroha_amount);
iroha::Amount deserializeAmount(protocol::Amount pb_amount);
}
}
}

#endif // IROHA_PB_COMMON_HPP
Loading

0 comments on commit 68c7cf5

Please sign in to comment.