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

Fix object slicing warnings, duplicate code and some other code smells #2372

Merged
merged 14 commits into from
Mar 7, 2021
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
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.ubuntu-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ jobs:
mkdir -p "$CCACHE_DIR"
df -h
make -j 2 -C _build chain_test
make -j 2 -C _build cli_test
make -j 2 -C _build cli_wallet
make -j 2 -C _build witness_node
make -j 2 -C _build
df -h
du -hs _build/libraries/* _build/programs/* _build/tests/*
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ jobs:
- name: Prepare for scanning with SonarScanner
run: |
mkdir -p sonar_cache
find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir _build/programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print \
find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir \
_build/libraries/plugins/*/CMakeFiles/*.dir \
_build/programs/[cdgjsw]*/CMakeFiles/*.dir \
-type d -print \
| while read d; do srcd="${d:7}"; gcov -o "$d" "${srcd/CMakeFiles*.dir/.}"/*.cpp; done >/dev/null
programs/build_helpers/set_sonar_branch_for_github_actions sonar-project.properties
- name: Scan with SonarScanner
Expand Down
4 changes: 2 additions & 2 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg,
// during sync, it is unlikely that we'll see any old
contained_transaction_message_ids.reserve( contained_transaction_message_ids.size()
+ blk_msg.block.transactions.size() );
for (const processed_transaction& transaction : blk_msg.block.transactions)
for (const processed_transaction& ptrx : blk_msg.block.transactions)
{
graphene::net::trx_message transaction_message(transaction);
graphene::net::trx_message transaction_message(ptrx);
contained_transaction_message_ids.emplace_back(graphene::net::message(transaction_message).id());
}
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2409,15 +2409,15 @@ std::string database_api_impl::get_transaction_hex(const signed_transaction& trx
}

std::string database_api::get_transaction_hex_without_sig(
const signed_transaction &trx) const
const transaction &trx) const
{
return my->get_transaction_hex_without_sig(trx);
}

std::string database_api_impl::get_transaction_hex_without_sig(
const signed_transaction &trx) const
const transaction &trx) const
{
return fc::to_hex(fc::raw::pack(static_cast<transaction>(trx)));
return fc::to_hex(fc::raw::pack(trx));
}

set<public_key_type> database_api::get_required_signatures( const signed_transaction& trx,
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/database_api_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>

// Authority / validation
std::string get_transaction_hex(const signed_transaction& trx)const;
std::string get_transaction_hex_without_sig(const signed_transaction& trx)const;
std::string get_transaction_hex_without_sig(const transaction& trx)const;

set<public_key_type> get_required_signatures( const signed_transaction& trx,
const flat_set<public_key_type>& available_keys )const;
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ class database_api
* @param trx a transaction to get hexdump from
* @return the hexdump of the transaction without the signatures
*/
std::string get_transaction_hex_without_sig( const signed_transaction &trx ) const;
std::string get_transaction_hex_without_sig( const transaction &trx ) const;

/**
* This API will take a partially signed transaction and a set of public keys that the owner
Expand Down
6 changes: 3 additions & 3 deletions libraries/net/include/graphene/net/core_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ namespace graphene { namespace net {
static const core_message_type_enum type;

graphene::protocol::precomputable_transaction trx;
trx_message() {}
trx_message(graphene::protocol::signed_transaction transaction) :
trx(std::move(transaction))
trx_message() = default;
explicit trx_message(const graphene::protocol::signed_transaction& signed_trx) :
trx(signed_trx)
{}
};

Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/wallet_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace graphene { namespace wallet { namespace detail {
optional<asset_object> asset_to_fund = find_asset(symbol);
if (!asset_to_fund)
FC_THROW("No asset with that symbol exists!");
asset_object core_asset = get_asset(asset_id_type());
auto core_asset = get_asset(asset_id_type());

asset_fund_fee_pool_operation fund_op;
fund_op.from_account = from_account.id;
Expand All @@ -246,7 +246,7 @@ namespace graphene { namespace wallet { namespace detail {
optional<asset_object> asset_pool_to_claim = find_asset(symbol);
if (!asset_pool_to_claim)
FC_THROW("No asset with that symbol exists!");
asset_object core_asset = get_asset(asset_id_type());
auto core_asset = get_asset(asset_id_type());

asset_claim_pool_operation claim_op;
claim_op.issuer = asset_pool_to_claim->issuer;
Expand Down
81 changes: 24 additions & 57 deletions libraries/wallet/wallet_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ namespace graphene { namespace wallet { namespace detail {
std::map<string,std::function<string(fc::variant,const fc::variants&)>> wallet_api_impl::get_result_formatters() const
{
std::map<string,std::function<string(fc::variant,const fc::variants&)> > m;
m["help"] = [](variant result, const fc::variants& a)

m["help"] = [](variant result, const fc::variants&)
{
return result.get_string();
};

m["gethelp"] = [](variant result, const fc::variants& a)
m["gethelp"] = [](variant result, const fc::variants&)
{
return result.get_string();
};

m["get_account_history"] = [this](variant result, const fc::variants& a)
auto format_account_history = [this](variant result, const fc::variants&)
{
auto r = result.as<vector<operation_detail>>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;
Expand All @@ -58,26 +59,11 @@ std::map<string,std::function<string(fc::variant,const fc::variants&)>> wallet_a

return ss.str();
};
m["get_relative_account_history"] = [this](variant result, const fc::variants& a)
{
auto r = result.as<vector<operation_detail>>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;

for( operation_detail& d : r )
{
operation_history_object& i = d.op;
auto b = _remote_db->get_block_header(i.block_num);
FC_ASSERT(b);
ss << i.block_num << " ";
ss << b->timestamp.to_iso_string() << " ";
i.op.visit(operation_printer(ss, *this, i));
ss << " \n";
}

return ss.str();
};
m["get_account_history"] = format_account_history;
m["get_relative_account_history"] = format_account_history;

m["get_account_history_by_operations"] = [this](variant result, const fc::variants& a) {
m["get_account_history_by_operations"] = [this](variant result, const fc::variants&) {
auto r = result.as<account_history_operation_detail>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;
ss << "total_count : ";
Expand All @@ -101,7 +87,7 @@ std::map<string,std::function<string(fc::variant,const fc::variants&)>> wallet_a
return ss.str();
};

m["list_account_balances"] = [this](variant result, const fc::variants& a)
auto format_balances = [this](variant result, const fc::variants&)
{
auto r = result.as<vector<asset>>( GRAPHENE_MAX_NESTED_OBJECTS );
vector<asset_object> asset_recs;
Expand All @@ -116,58 +102,38 @@ std::map<string,std::function<string(fc::variant,const fc::variants&)>> wallet_a
return ss.str();
};

m["get_blind_balances"] = [this](variant result, const fc::variants& a)
{
auto r = result.as<vector<asset>>( GRAPHENE_MAX_NESTED_OBJECTS );
vector<asset_object> asset_recs;
std::transform(r.begin(), r.end(), std::back_inserter(asset_recs), [this](const asset& a) {
return get_asset(a.asset_id);
});
m["list_account_balances"] = format_balances;
m["get_blind_balances"] = format_balances;

std::stringstream ss;
for( unsigned i = 0; i < asset_recs.size(); ++i )
ss << asset_recs[i].amount_to_pretty_string(r[i]) << "\n";

return ss.str();
};
m["transfer_to_blind"] = [this](variant result, const fc::variants& a)
{
auto r = result.as<blind_confirmation>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;
r.trx.operations[0].visit( operation_printer( ss, *this, operation_history_object() ) );
ss << "\n";
for( const auto& out : r.outputs )
{
asset_object a = get_asset( out.decrypted_memo.amount.asset_id );
ss << a.amount_to_pretty_string( out.decrypted_memo.amount ) << " to " << out.label
<< "\n\t receipt: " << out.confirmation_receipt << "\n\n";
}
return ss.str();
};
m["blind_transfer"] = [this](variant result, const fc::variants& a)
auto format_blind_transfers = [this](variant result, const fc::variants&)
{
auto r = result.as<blind_confirmation>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;
r.trx.operations[0].visit( operation_printer( ss, *this, operation_history_object() ) );
ss << "\n";
for( const auto& out : r.outputs )
{
asset_object a = get_asset( out.decrypted_memo.amount.asset_id );
auto a = get_asset( out.decrypted_memo.amount.asset_id );
ss << a.amount_to_pretty_string( out.decrypted_memo.amount ) << " to " << out.label
<< "\n\t receipt: " << out.confirmation_receipt << "\n\n";
}
return ss.str();
};
m["receive_blind_transfer"] = [this](variant result, const fc::variants& a)

m["transfer_to_blind"] = format_blind_transfers;
m["blind_transfer"] = format_blind_transfers;

m["receive_blind_transfer"] = [this](variant result, const fc::variants&)
{
auto r = result.as<blind_receipt>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;
asset_object as = get_asset( r.amount.asset_id );
auto as = get_asset( r.amount.asset_id );
ss << as.amount_to_pretty_string( r.amount ) << " " << r.from_label << " => "
<< r.to_label << " " << r.memo <<"\n";
return ss.str();
};
m["blind_history"] = [this](variant result, const fc::variants& a)

m["blind_history"] = [this](variant result, const fc::variants&)
{
auto records = result.as<vector<blind_receipt>>( GRAPHENE_MAX_NESTED_OBJECTS );
std::stringstream ss;
Expand All @@ -176,14 +142,15 @@ std::map<string,std::function<string(fc::variant,const fc::variants&)>> wallet_a
ss << "====================================================================================\n";
for( auto& r : records )
{
asset_object as = get_asset( r.amount.asset_id );
auto as = get_asset( r.amount.asset_id );
ss << fc::get_approximate_relative_time_string( r.date )
<< " " << as.amount_to_pretty_string( r.amount ) << " " << r.from_label << " => " << r.to_label
<< " " << r.memo <<"\n";
}
return ss.str();
};
m["get_order_book"] = [](variant result, const fc::variants& a)

m["get_order_book"] = [](variant result, const fc::variants&)
{
auto orders = result.as<order_book>( GRAPHENE_MAX_NESTED_OBJECTS );
auto bids = orders.bids;
Expand Down Expand Up @@ -271,7 +238,7 @@ std::map<string,std::function<string(fc::variant,const fc::variants&)>> wallet_a
return ss.str();
};

m["sign_message"] = [](variant result, const fc::variants& a)
m["sign_message"] = [](variant result, const fc::variants&)
{
auto r = result.as<signed_message>( GRAPHENE_MAX_NESTED_OBJECTS );

Expand Down
24 changes: 5 additions & 19 deletions libraries/wallet/wallet_transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,32 +209,18 @@ namespace graphene { namespace wallet { namespace detail {
signed_transaction wallet_api_impl::borrow_asset(string seller_name, string amount_to_borrow,
string asset_symbol, string amount_of_collateral, bool broadcast )
{
account_object seller = get_account(seller_name);
asset_object mia = get_asset(asset_symbol);
FC_ASSERT(mia.is_market_issued());
asset_object collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset);

call_order_update_operation op;
op.funding_account = seller.id;
op.delta_debt = mia.amount_from_string(amount_to_borrow);
op.delta_collateral = collateral.amount_from_string(amount_of_collateral);

signed_transaction trx;
trx.operations = {op};
set_operation_fees( trx, _remote_db->get_global_properties().parameters.get_current_fees());
trx.validate();

return sign_transaction(trx, broadcast);
return borrow_asset_ext( seller_name, amount_to_borrow, asset_symbol, amount_of_collateral,
{}, broadcast );
}

signed_transaction wallet_api_impl::borrow_asset_ext( string seller_name, string amount_to_borrow,
string asset_symbol, string amount_of_collateral,
call_order_update_operation::extensions_type extensions, bool broadcast )
{
account_object seller = get_account(seller_name);
asset_object mia = get_asset(asset_symbol);
auto mia = get_asset(asset_symbol);
FC_ASSERT(mia.is_market_issued());
asset_object collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset);
auto collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset);

call_order_update_operation op;
op.funding_account = seller.id;
Expand Down Expand Up @@ -268,7 +254,7 @@ namespace graphene { namespace wallet { namespace detail {
signed_transaction wallet_api_impl::withdraw_vesting( string witness_name, string amount, string asset_symbol,
bool broadcast )
{ try {
asset_object asset_obj = get_asset( asset_symbol );
auto asset_obj = get_asset( asset_symbol );
fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(witness_name);
if( !vbid )
{
Expand Down
Loading