예제 #1
0
async def _get_props_lite(db):
    """Return a minimal version of get_dynamic_global_properties data."""
    raw = json.loads(await db.query_one("SELECT dgpo FROM hive_state"))

    # convert NAI amounts to legacy
    nais = ['virtual_supply', 'current_supply', 'current_sbd_supply',
            'pending_rewarded_vesting_steem', 'pending_rewarded_vesting_shares',
            'total_vesting_fund_steem', 'total_vesting_shares']
    for k in nais:
        if k in raw:
            raw[k] = legacy_amount(raw[k])

    return dict(
        time=raw['time'], #*
        sbd_print_rate=raw['sbd_print_rate'],
        sbd_interest_rate=raw['sbd_interest_rate'],
        head_block_number=raw['head_block_number'], #*
        total_vesting_shares=raw['total_vesting_shares'],
        total_vesting_fund_steem=raw['total_vesting_fund_steem'],
        last_irreversible_block_num=raw['last_irreversible_block_num'], #*
    )
예제 #2
0
 def comment_options_op(cls, op):
     """ Process comment_options_operation """
     max_accepted_payout = legacy_amount(
         op['max_accepted_payout']
     ) if 'max_accepted_payout' in op else '1000000.000 HBD'
     allow_votes = op['allow_votes'] if 'allow_votes' in op else True
     allow_curation_rewards = op[
         'allow_curation_rewards'] if 'allow_curation_rewards' in op else True
     percent_hbd = op['percent_hbd'] if 'percent_hbd' in op else 10000
     extensions = op['extensions'] if 'extensions' in op else []
     beneficiaries = []
     for ex in extensions:
         if 'type' in ex and ex[
                 'type'] == 'comment_payout_beneficiaries' and 'beneficiaries' in ex[
                     'value']:
             beneficiaries = ex['value']['beneficiaries']
     sql = """
         UPDATE
             hive_posts hp
         SET
             max_accepted_payout = :max_accepted_payout,
             percent_hbd = :percent_hbd,
             allow_votes = :allow_votes,
             allow_curation_rewards = :allow_curation_rewards,
             beneficiaries = :beneficiaries
         WHERE
         hp.author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND
         hp.permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink)
     """
     DB.query(sql,
              author=op['author'],
              permlink=op['permlink'],
              max_accepted_payout=max_accepted_payout,
              percent_hbd=percent_hbd,
              allow_votes=allow_votes,
              allow_curation_rewards=allow_curation_rewards,
              beneficiaries=dumps(beneficiaries))
def test_legacy_amount():
    nai = [1231121, 6, '@@000000037']
    assert legacy_amount(nai) == '1.231121 VESTS'
예제 #4
0
    def comment_payout_op(cls):
        values_limit = 1000
        """ Process comment payment operations """
        for k, v in cls.comment_payout_ops.items():
            author = None
            permlink = None

            # author payouts
            author_rewards = 0
            author_rewards_hive = None
            author_rewards_hbd = None
            author_rewards_vests = None

            # total payout for comment
            #comment_author_reward     = None
            #curators_vesting_payout   = None
            total_payout_value = None
            curator_payout_value = None
            #beneficiary_payout_value  = None;

            payout = None
            pending_payout = None

            payout_at = None
            last_payout_at = None
            cashout_time = None

            is_paidout = None

            total_vote_weight = None

            # [final] payout indicator - by default all rewards are zero, but might be overwritten by other operations
            # ABW: prior to some early HF that was not necessarily final payout since those were discussion driven so new comment/vote could trigger new cashout window, see f.e.
            # soulsistashakti/re-emily-cook-let-me-introduce-myself-my-name-is-emily-cook-and-i-m-the-producer-and-presenter-of-a-monthly-film-show-film-focus-20160701t012330329z
            # it emits that "final" operation at blocks: 2889020, 3053237, 3172559 and 4028469
            if v[VirtualOperationType.CommentPayoutUpdate] is not None:
                value, date = v[VirtualOperationType.CommentPayoutUpdate]
                if author is None:
                    author = value['author']
                    permlink = value['permlink']
                is_paidout = True
                payout_at = date
                last_payout_at = date
                cashout_time = "infinity"

                pending_payout = 0
                total_vote_weight = 0

            # author rewards in current (final or nonfinal) payout (always comes with comment_reward_operation)
            if v[VirtualOperationType.AuthorReward] is not None:
                value, date = v[VirtualOperationType.AuthorReward]
                if author is None:
                    author = value['author']
                    permlink = value['permlink']
                author_rewards_hive = value['hive_payout']['amount']
                author_rewards_hbd = value['hbd_payout']['amount']
                author_rewards_vests = value['vesting_payout']['amount']
                #curators_vesting_payout = value['curators_vesting_payout']['amount']

            # summary of comment rewards in current (final or nonfinal) payout (always comes with author_reward_operation)
            if v[VirtualOperationType.CommentReward] is not None:
                value, date = v[VirtualOperationType.CommentReward]
                if author is None:
                    author = value['author']
                    permlink = value['permlink']
                #comment_author_reward   = value['payout']
                author_rewards = value['author_rewards']
                total_payout_value = value['total_payout_value']
                curator_payout_value = value['curator_payout_value']
                #beneficiary_payout_value = value['beneficiary_payout_value']

                payout = sum([
                    sbd_amount(total_payout_value),
                    sbd_amount(curator_payout_value)
                ])
                pending_payout = 0
                last_payout_at = date

            # estimated pending_payout from vote (if exists with actual payout the value comes from vote cast after payout)
            if v[VirtualOperationType.EffectiveCommentVote] is not None:
                value, date = v[VirtualOperationType.EffectiveCommentVote]
                if author is None:
                    author = value['author']
                    permlink = value['permlink']
                pending_payout = sbd_amount(value['pending_payout'])
                total_vote_weight = value['total_vote_weight']

            cls._comment_payout_ops.append(
                "('{}', {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})"
                .format(
                    author, escape_characters(permlink), "NULL" if
                    (total_payout_value is None) else
                    ("'{}'".format(legacy_amount(total_payout_value))),
                    "NULL" if (curator_payout_value is None) else
                    ("'{}'".format(legacy_amount(curator_payout_value))),
                    author_rewards, "NULL" if
                    (author_rewards_hive is None) else author_rewards_hive,
                    "NULL" if
                    (author_rewards_hbd is None) else author_rewards_hbd,
                    "NULL" if
                    (author_rewards_vests is None) else author_rewards_vests,
                    "NULL" if (payout is None) else payout, "NULL" if
                    (pending_payout is None) else pending_payout, "NULL" if
                    (payout_at is None) else
                    ("'{}'::timestamp".format(payout_at)), "NULL" if
                    (last_payout_at is None) else
                    ("'{}'::timestamp".format(last_payout_at)), "NULL" if
                    (cashout_time is None) else
                    ("'{}'::timestamp".format(cashout_time)), "NULL" if
                    (is_paidout is None) else is_paidout, "NULL" if
                    (total_vote_weight is None) else total_vote_weight))

        n = len(cls.comment_payout_ops)
        cls.comment_payout_ops.clear()
        return n