Simplify code; mostly reduced nesting
This commit is contained in:
parent
1579ea7f5d
commit
655fa66609
3 changed files with 37 additions and 64 deletions
|
@ -257,28 +257,21 @@ void rai::uint256_union::encode_hex (std::string & text) const
|
|||
bool rai::uint256_union::decode_hex (std::string const & text)
|
||||
{
|
||||
auto result (false);
|
||||
if (!text.empty ())
|
||||
if (!text.empty () && text.size () <= 64)
|
||||
{
|
||||
if (text.size () <= 64)
|
||||
std::stringstream stream (text);
|
||||
stream << std::hex << std::noshowbase;
|
||||
rai::uint256_t number_l;
|
||||
try
|
||||
{
|
||||
std::stringstream stream (text);
|
||||
stream << std::hex << std::noshowbase;
|
||||
rai::uint256_t number_l;
|
||||
try
|
||||
{
|
||||
stream >> number_l;
|
||||
*this = number_l;
|
||||
if (!stream.eof ())
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &)
|
||||
stream >> number_l;
|
||||
*this = number_l;
|
||||
if (!stream.eof ())
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (std::runtime_error &)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
|
|
@ -89,12 +89,9 @@ void rai::network::send_keepalive (rai::endpoint const & endpoint_a)
|
|||
send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w, endpoint_a](boost::system::error_code const & ec, size_t) {
|
||||
if (auto node_l = node_w.lock ())
|
||||
{
|
||||
if (node_l->config.logging.network_keepalive_logging ())
|
||||
if (ec && node_l->config.logging.network_keepalive_logging ())
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error sending keepalive to %1% %2%") % endpoint_a % ec.message ());
|
||||
}
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error sending keepalive to %1% %2%") % endpoint_a % ec.message ());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -134,12 +131,9 @@ void rai::network::republish (rai::block_hash const & hash_a, std::shared_ptr<st
|
|||
send_buffer (buffer_a->data (), buffer_a->size (), endpoint_a, [buffer_a, node_w, endpoint_a](boost::system::error_code const & ec, size_t size) {
|
||||
if (auto node_l = node_w.lock ())
|
||||
{
|
||||
if (node_l->config.logging.network_logging ())
|
||||
if (ec && node_l->config.logging.network_logging ())
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error sending publish: %1% to %2%") % ec.message () % endpoint_a);
|
||||
}
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error sending publish: %1% to %2%") % ec.message () % endpoint_a);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -282,12 +276,9 @@ void rai::network::send_confirm_req (rai::endpoint const & endpoint_a, std::shar
|
|||
send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w](boost::system::error_code const & ec, size_t size) {
|
||||
if (auto node_l = node_w.lock ())
|
||||
{
|
||||
if (node_l->config.logging.network_logging ())
|
||||
if (ec && node_l->config.logging.network_logging ())
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error sending confirm request: %1%") % ec.message ());
|
||||
}
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error sending confirm request: %1%") % ec.message ());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1625,12 +1616,9 @@ void rai::network::confirm_send (rai::confirm_ack const & confirm_a, std::shared
|
|||
node.network.send_buffer (bytes_a->data (), bytes_a->size (), endpoint_a, [bytes_a, node_w, endpoint_a](boost::system::error_code const & ec, size_t size_a) {
|
||||
if (auto node_l = node_w.lock ())
|
||||
{
|
||||
if (node_l->config.logging.network_logging ())
|
||||
if (ec && node_l->config.logging.network_logging ())
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error broadcasting confirm_ack to %1%: %2%") % endpoint_a % ec.message ());
|
||||
}
|
||||
BOOST_LOG (node_l->log) << boost::str (boost::format ("Error broadcasting confirm_ack to %1%: %2%") % endpoint_a % ec.message ());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -896,18 +896,15 @@ std::shared_ptr<rai::block> rai::wallet::change_action (rai::account const & sou
|
|||
if (store.valid_password (transaction))
|
||||
{
|
||||
auto existing (store.find (transaction, source_a));
|
||||
if (existing != store.end ())
|
||||
if (existing != store.end () && !node.ledger.latest (transaction, source_a).is_zero ())
|
||||
{
|
||||
if (!node.ledger.latest (transaction, source_a).is_zero ())
|
||||
{
|
||||
rai::account_info info;
|
||||
auto error1 (node.ledger.store.account_get (transaction, source_a, info));
|
||||
assert (!error1);
|
||||
rai::raw_key prv;
|
||||
auto error2 (store.fetch (transaction, source_a, prv));
|
||||
assert (!error2);
|
||||
block.reset (new rai::change_block (info.head, representative_a, prv, source_a, generate_work_a ? work_fetch (transaction, source_a, info.head) : 0));
|
||||
}
|
||||
rai::account_info info;
|
||||
auto error1 (node.ledger.store.account_get (transaction, source_a, info));
|
||||
assert (!error1);
|
||||
rai::raw_key prv;
|
||||
auto error2 (store.fetch (transaction, source_a, prv));
|
||||
assert (!error2);
|
||||
block.reset (new rai::change_block (info.head, representative_a, prv, source_a, generate_work_a ? work_fetch (transaction, source_a, info.head) : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -939,18 +936,15 @@ std::shared_ptr<rai::block> rai::wallet::send_action (rai::account const & sourc
|
|||
if (existing != store.end ())
|
||||
{
|
||||
auto balance (node.ledger.account_balance (transaction, source_a));
|
||||
if (!balance.is_zero ())
|
||||
if (!balance.is_zero () && balance >= amount_a)
|
||||
{
|
||||
if (balance >= amount_a)
|
||||
{
|
||||
rai::account_info info;
|
||||
auto error1 (node.ledger.store.account_get (transaction, source_a, info));
|
||||
assert (!error1);
|
||||
rai::raw_key prv;
|
||||
auto error2 (store.fetch (transaction, source_a, prv));
|
||||
assert (!error2);
|
||||
block.reset (new rai::send_block (info.head, account_a, balance - amount_a, prv, source_a, generate_work_a ? work_fetch (transaction, source_a, info.head) : 0));
|
||||
}
|
||||
rai::account_info info;
|
||||
auto error1 (node.ledger.store.account_get (transaction, source_a, info));
|
||||
assert (!error1);
|
||||
rai::raw_key prv;
|
||||
auto error2 (store.fetch (transaction, source_a, prv));
|
||||
assert (!error2);
|
||||
block.reset (new rai::send_block (info.head, account_a, balance - amount_a, prv, source_a, generate_work_a ? work_fetch (transaction, source_a, info.head) : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1054,14 +1048,12 @@ uint64_t rai::wallet::work_fetch (MDB_txn * transaction_a, rai::account const &
|
|||
{
|
||||
result = node.generate_work (root_a);
|
||||
}
|
||||
else
|
||||
else if (rai::work_validate (root_a, result))
|
||||
{
|
||||
if (rai::work_validate (root_a, result))
|
||||
{
|
||||
BOOST_LOG (node.log) << "Cached work invalid, regenerating";
|
||||
result = node.generate_work (root_a);
|
||||
}
|
||||
BOOST_LOG (node.log) << "Cached work invalid, regenerating";
|
||||
result = node.generate_work (root_a);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue