Skip to content

Commit

Permalink
Refactor to_steem(), to_sbd(), is_comment_payout_dust() out of database
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Jan 13, 2017
1 parent 0d258d2 commit 4f6dca7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file(GLOB HEADERS "include/steemit/chain/*.hpp")
file(GLOB HEADERS "include/steemit/chain/*.hpp" "include/steemit/chain/util/*.hpp")

if( MSVC )
set( hardfork_hpp_file "${CMAKE_CURRENT_SOURCE_DIR}/include/steemit/chain/hardfork.hpp" )
Expand Down
21 changes: 6 additions & 15 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <steemit/chain/shared_db_merkle.hpp>
#include <steemit/chain/operation_notification.hpp>

#include <steemit/chain/util/asset.hpp>
#include <steemit/chain/util/reward.hpp>

#include <fc/smart_ref_impl.hpp>
#include <fc/uint128.hpp>

Expand Down Expand Up @@ -2436,22 +2439,12 @@ void database::process_conversions()

asset database::to_sbd( const asset& steem )const
{
FC_ASSERT( steem.symbol == STEEM_SYMBOL );
const auto& feed_history = get_feed_history();
if( feed_history.current_median_history.is_null() )
return asset( 0, SBD_SYMBOL );

return steem * feed_history.current_median_history;
return util::to_sbd( get_feed_history().current_median_history, steem );
}

asset database::to_steem( const asset& sbd )const
{
FC_ASSERT( sbd.symbol == SBD_SYMBOL );
const auto& feed_history = get_feed_history();
if( feed_history.current_median_history.is_null() )
return asset( 0, STEEM_SYMBOL );

return sbd * feed_history.current_median_history;
return util::to_steem( get_feed_history().current_median_history, sbd );
}

/**
Expand All @@ -2477,9 +2470,7 @@ share_type database::claim_rshare_reward( share_type rshares, uint16_t reward_we
FC_ASSERT( payout_u256 <= u256( uint64_t( std::numeric_limits<int64_t>::max() ) ) );
uint64_t payout = static_cast< uint64_t >( payout_u256 );

asset sbd_payout_value = to_sbd( asset(payout, STEEM_SYMBOL) );

if( sbd_payout_value < STEEMIT_MIN_PAYOUT_SBD )
if( util::is_comment_payout_dust( get_feed_history().current_median_history, payout ) )
payout = 0;

payout = std::min( payout, uint64_t( max_steem.amount.value ) );
Expand Down
26 changes: 26 additions & 0 deletions libraries/chain/include/steemit/chain/util/asset.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <steemit/protocol/asset.hpp>

namespace steemit { namespace chain { namespace util {

using steemit::protocol::asset;
using steemit::protocol::price;

inline asset to_sbd( const price& p, const asset& steem )
{
FC_ASSERT( steem.symbol == STEEM_SYMBOL );
if( p.is_null() )
return asset( 0, SBD_SYMBOL );
return steem * p;
}

inline asset to_steem( const price& p, const asset& sbd )
{
FC_ASSERT( sbd.symbol == SBD_SYMBOL );
if( p.is_null() )
return asset( 0, STEEM_SYMBOL );
return sbd * p;
}

} } }
14 changes: 14 additions & 0 deletions libraries/chain/include/steemit/chain/util/reward.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <steemit/chain/util/asset.hpp>

#include <steemit/protocol/config.hpp>

namespace steemit { namespace chain { namespace util {

inline bool is_comment_payout_dust( const price& p, uint64_t steem_payout )
{
return to_sbd( p, asset( steem_payout, STEEM_SYMBOL ) ) < STEEMIT_MIN_PAYOUT_SBD;
}

} } }

0 comments on commit 4f6dca7

Please sign in to comment.