Use the sideband when available in ledger.is_send (#2620)

This commit is contained in:
Guilherme Lawless 2020-03-04 09:02:06 +00:00 committed by GitHub
commit 5600dc6bbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

@ -149,6 +149,11 @@ void nano::block::sideband_set (nano::block_sideband const & sideband_a)
sideband_m = sideband_a;
}
bool nano::block::has_sideband () const
{
return sideband_m.is_initialized ();
}
nano::account const & nano::block::representative () const
{
static nano::account rep{ 0 };

View file

@ -73,6 +73,7 @@ public:
nano::block_hash full_hash () const;
nano::block_sideband const & sideband () const;
void sideband_set (nano::block_sideband const &);
bool has_sideband () const;
std::string to_json () const;
virtual void hash (blake2b_state &) const = 0;
virtual uint64_t block_work () const = 0;

View file

@ -807,12 +807,19 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a)
bool nano::ledger::is_send (nano::transaction const & transaction_a, nano::state_block const & block_a) const
{
bool result (false);
nano::block_hash previous (block_a.hashables.previous);
if (!previous.is_zero ())
if (block_a.has_sideband ())
{
if (block_a.hashables.balance < balance (transaction_a, previous))
result = block_a.sideband ().details.is_send;
}
else
{
nano::block_hash previous (block_a.hashables.previous);
if (!previous.is_zero ())
{
result = true;
if (block_a.hashables.balance < balance (transaction_a, previous))
{
result = true;
}
}
}
return result;