Skip to content

Commit

Permalink
Move to256() to new header chain/util/uint256.hpp steemit#782
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Jan 13, 2017
1 parent 4f6dca7 commit bf258c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
14 changes: 4 additions & 10 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

#include <fc/smart_ref_impl.hpp>
#include <fc/uint128.hpp>
Expand Down Expand Up @@ -68,13 +69,6 @@ namespace steemit { namespace chain {

using boost::container::flat_set;

inline u256 to256( const fc::uint128& t ) {
u256 v(t.hi);
v <<= 64;
v += t.lo;
return v;
}

class database_impl
{
public:
Expand Down Expand Up @@ -1930,7 +1924,7 @@ share_type database::pay_discussions( const comment_object& c, share_type max_re

if( cur.net_rshares > 0 )
{
auto claim = static_cast< uint64_t >( ( to256( calculate_vshares( cur.net_rshares.value ) ) * max_rewards.value ) / to256( total_rshares2 ) );
auto claim = static_cast< uint64_t >( ( util::to256( calculate_vshares( cur.net_rshares.value ) ) * max_rewards.value ) / util::to256( total_rshares2 ) );
unclaimed_rewards -= claim;

if( claim > 0 )
Expand Down Expand Up @@ -2461,9 +2455,9 @@ share_type database::claim_rshare_reward( share_type rshares, uint16_t reward_we

u256 rs(rshares.value);
u256 rf(props.total_reward_fund_steem.amount.value);
u256 total_rshares2 = to256( props.total_reward_shares2 );
u256 total_rshares2 = util::to256( props.total_reward_shares2 );

u256 rs2 = to256( calculate_vshares( rshares.value ) );
u256 rs2 = util::to256( calculate_vshares( rshares.value ) );
rs2 = ( rs2 * reward_weight ) / STEEMIT_100_PERCENT;

u256 payout_u256 = ( rf * rs2 ) / total_rshares2;
Expand Down
17 changes: 17 additions & 0 deletions libraries/chain/include/steemit/chain/util/uint256.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <steemit/protocol/types.hpp>

#include <fc/uint128.hpp>

namespace steemit { namespace chain { namespace util {

inline u256 to256( const fc::uint128& t )
{
u256 v(t.hi);
v <<= 64;
v += t.lo;
return v;
}

} } }

0 comments on commit bf258c2

Please sign in to comment.