hivemind icon indicating copy to clipboard operation
hivemind copied to clipboard

calc pending payout locally, on write

Open roadscape opened this issue 6 years ago • 2 comments

This logic currently lives in steemd's condenser_api, but will need to be implemented in hive.

It's also a requirement for switching to the new find_comments API.

roadscape avatar Jun 15 '18 16:06 roadscape

https://github.com/steemit/steem/blob/develop/libraries/plugins/apis/condenser_api/condenser_api.cpp#L1985

Boils down to something like:

   void condenser_api_impl::set_pending_payout( discussion& d )
   {
      const auto& props = _db.get_dynamic_global_properties();
      const auto& hist  = _db.get_feed_history();
      asset pot = _db.get_reward_fund( _db.get_comment( d.author, d.permlink ) ).reward_balance;

      if( !hist.current_median_history.is_null() ) pot = pot * hist.current_median_history;

      total_r2 = _db.get_reward_fund( _db.get_comment( d.author, d.permlink ) ).recent_claims;
    
      if( total_r2 > 0 )
      {
         uint128_t vshares;
         const auto& rf = _db.get_reward_fund( _db.get_comment( d.author, d.permlink ) );
         vshares = 0
         if(d.net_rshares.value > 0)
            vshares = chain::util::evaluate_reward_curve( d.net_rshares.value, rf.author_reward_curve, rf.content_constant );

         u256 r2 = chain::util::to256( vshares );
         r2 *= pot.amount.value;
         r2 /= total_r2;
         d.pending_payout_value = legacy_asset::from_asset( asset( static_cast<uint64_t>(r2), pot.symbol ) );
      }
   }

roadscape avatar Jun 15 '18 16:06 roadscape

https://developers.steem.io/tutorials-recipes/estimate_upvote

roadscape avatar Jun 21 '18 20:06 roadscape