From 02efb5559cae5ec0865d889527e1ed237543bb10 Mon Sep 17 00:00:00 2001 From: ABW <andrzejl@syncad.com> Date: Mon, 24 Aug 2020 20:42:26 +0200 Subject: [PATCH] [ABW]: curator_payout_value/total_payout_value now have '0.000 HBD' default to always have asset in value (ultimately they should be changed to numeric columns) removed columns that we don't intend to update as they would hold irrelevant data: children_abs_rshares, reward_weight; also removed from queries hive_posts_view no longer has parent_permlink - replaced with parent_permlink_or_category as that's what was in original comment data and what is expected fixed order by time in list_comments_by_last_update, list_comments_by_author_last_update (newer first) fixed payout update date - each operation that is part of payout has its own date as (at least some) can be from different blocks fixed author_rewards - it is a sum of partial rewards for the comment when payout operations are processed they no longer incorrectly overwrite each other's data 1969 year in date recognized as timestamp::max and replaced by infinity (and the other way when producing results) - fixes corner case of time ordering in by_cashout_time commented out checks in run_tests.sh as they fail when address contains '-' like in 'hive-3.pl.syncad.com' --- hive/db/schema.py | 62 ++++++++-------- hive/indexer/blocks.py | 17 ++--- hive/indexer/posts.py | 101 +++++++++++++-------------- hive/server/bridge_api/methods.py | 2 +- hive/server/bridge_api/objects.py | 4 +- hive/server/bridge_api/thread.py | 2 +- hive/server/common/helpers.py | 3 +- hive/server/condenser_api/cursor.py | 2 +- hive/server/condenser_api/methods.py | 4 +- hive/server/condenser_api/objects.py | 10 +-- hive/server/database_api/methods.py | 10 +-- hive/server/database_api/objects.py | 25 +++---- hive/utils/post.py | 4 +- hive/version.py | 2 +- scripts/run_tests.sh | 4 +- tests/tests_api | 2 +- 16 files changed, 123 insertions(+), 131 deletions(-) diff --git a/hive/db/schema.py b/hive/db/schema.py index 7b04e94b2..10d71bac3 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -107,23 +107,21 @@ def build_metadata(): sa.Column('sc_trend', sa.Float(precision=6), nullable=False, server_default='0'), sa.Column('sc_hot', sa.Float(precision=6), nullable=False, server_default='0'), - sa.Column('total_payout_value', sa.String(30), nullable=False, server_default=''), + sa.Column('total_payout_value', sa.String(30), nullable=False, server_default='0.000 HBD'), sa.Column('author_rewards', sa.BigInteger, nullable=False, server_default='0'), sa.Column('author_rewards_hive', sa.BigInteger, nullable=False, server_default='0'), sa.Column('author_rewards_hbd', sa.BigInteger, nullable=False, server_default='0'), sa.Column('author_rewards_vests', sa.BigInteger, nullable=False, server_default='0'), - sa.Column('children_abs_rshares', sa.BigInteger, nullable=False, server_default='0'), sa.Column('abs_rshares', sa.BigInteger, nullable=False, server_default='0'), sa.Column('vote_rshares', sa.BigInteger, nullable=False, server_default='0'), sa.Column('total_vote_weight', sa.Numeric, nullable=False, server_default='0'), sa.Column('active', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'), sa.Column('cashout_time', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'), sa.Column('percent_hbd', sa.Integer, nullable=False, server_default='10000'), - sa.Column('reward_weight', sa.Integer, nullable=False, server_default='10000'), # Seems to be always 10000 - sa.Column('curator_payout_value', sa.String(30), nullable=False, server_default=''), + sa.Column('curator_payout_value', sa.String(30), nullable=False, server_default='0.000 HBD'), sa.Column('max_accepted_payout', sa.String(30), nullable=False, server_default='1000000.000 HBD'), sa.Column('allow_votes', BOOLEAN, nullable=False, server_default='1'), sa.Column('allow_curation_rewards', BOOLEAN, nullable=False, server_default='1'), @@ -610,7 +608,10 @@ def setup(db): hp.total_vote_weight, hp.flag_weight, ha_pp.name AS parent_author, - hpd_pp.permlink AS parent_permlink, + ( CASE hp.depth > 0 + WHEN True THEN hpd_pp.permlink + ELSE hcd.category + END ) AS parent_permlink_or_category, hp.curator_payout_value, ha_rp.name AS root_author, hpd_rp.permlink AS root_permlink, @@ -646,9 +647,7 @@ def setup(db): WHERE v.post_id = hp.id AND NOT v.rshares = 0 GROUP BY v.post_id ), 0 - ) AS abs_rshares, - '1969-12-31T23:59:59'::timestamp AS max_cashout_time, - hp.reward_weight + ) AS abs_rshares FROM hive_posts hp JOIN hive_posts pp ON pp.id = hp.parent_id JOIN hive_posts rp ON rp.id = COALESCE( hp.root_id, hp.id ) @@ -784,7 +783,7 @@ def setup(db): total_vote_weight NUMERIC, flag_weight REAL, parent_author VARCHAR(16), - parent_permlink VARCHAR(255), + parent_permlink_or_category VARCHAR(255), curator_payout_value VARCHAR(30), root_author VARCHAR(16), root_permlink VARCHAR(255), @@ -798,9 +797,7 @@ def setup(db): root_title VARCHAR(512), abs_rshares NUMERIC, active TIMESTAMP, - author_rewards BIGINT, - max_cashout_time TIMESTAMP, - reward_weight INT + author_rewards BIGINT ) ; @@ -824,10 +821,10 @@ def setup(db): hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout, hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json, hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight, hp.flag_weight, - hp.parent_author, hp.parent_permlink, hp.curator_payout_value, hp.root_author, hp.root_permlink, + hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes, hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares, - hp.active, hp.author_rewards, hp.max_cashout_time, hp.reward_weight + hp.active, hp.author_rewards FROM hive_posts_view hp WHERE @@ -862,10 +859,10 @@ def setup(db): hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout, hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json, hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight, hp.flag_weight, - hp.parent_author, hp.parent_permlink, hp.curator_payout_value, hp.root_author, hp.root_permlink, + hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes, hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares, - hp.active, hp.author_rewards, hp.max_cashout_time, hp.reward_weight + hp.active, hp.author_rewards FROM hive_posts_view hp WHERE @@ -907,10 +904,10 @@ def setup(db): hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout, hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json, hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight, hp.flag_weight, - hp.parent_author, hp.parent_permlink, hp.curator_payout_value, hp.root_author, hp.root_permlink, + hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes, hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares, - hp.active, hp.author_rewards, hp.max_cashout_time, hp.reward_weight + hp.active, hp.author_rewards FROM hive_posts_view hp WHERE @@ -951,21 +948,21 @@ def setup(db): hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout, hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json, hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight, hp.flag_weight, - hp.parent_author, hp.parent_permlink, hp.curator_payout_value, hp.root_author, hp.root_permlink, + hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes, hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares, - hp.active, hp.author_rewards, hp.max_cashout_time, hp.reward_weight + hp.active, hp.author_rewards FROM hive_posts_view hp WHERE NOT hp.is_muted AND hp.counter_deleted = 0 AND parent_author > _parent_author OR - parent_author = _parent_author AND ( parent_permlink > _parent_permlink OR - parent_permlink = _parent_permlink AND hp.id >= __post_id ) + parent_author = _parent_author AND ( parent_permlink_or_category > _parent_permlink OR + parent_permlink_or_category = _parent_permlink AND hp.id >= __post_id ) ORDER BY parent_author ASC, - parent_permlink ASC, + parent_permlink_or_category ASC, id ASC LIMIT _limit @@ -996,21 +993,21 @@ def setup(db): hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout, hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json, hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight, hp.flag_weight, - hp.parent_author, hp.parent_permlink, hp.curator_payout_value, hp.root_author, hp.root_permlink, + hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes, hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares, - hp.active, hp.author_rewards, hp.max_cashout_time, hp.reward_weight + hp.active, hp.author_rewards FROM hive_posts_view hp WHERE NOT hp.is_muted AND hp.counter_deleted = 0 AND hp.parent_author > _parent_author OR - hp.parent_author = _parent_author AND ( hp.updated_at > _updated_at OR + hp.parent_author = _parent_author AND ( hp.updated_at < _updated_at OR hp.updated_at = _updated_at AND hp.id >= __post_id ) ORDER BY hp.parent_author ASC, - hp.updated_at ASC, + hp.updated_at DESC, hp.id ASC LIMIT _limit @@ -1041,23 +1038,22 @@ def setup(db): hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout, hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json, hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight, hp.flag_weight, - hp.parent_author, hp.parent_permlink, hp.curator_payout_value, hp.root_author, hp.root_permlink, + hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes, hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares, - hp.active, hp.author_rewards, hp.max_cashout_time, hp.reward_weight + hp.active, hp.author_rewards FROM hive_posts_view hp WHERE NOT hp.is_muted AND hp.counter_deleted = 0 AND - -- ABW: wrong! fat node required _start_post_author+_start_post_permlink to exist (when given) and sorted just like - -- in case of by_last_update (bug in fat node) but should by ( _author, updated_at, comment_id ) + -- fat node used wrong index (by_last_update) so the results are vastly different hp.author > _author OR - hp.author = _author AND ( hp.updated_at > _updated_at OR + hp.author = _author AND ( hp.updated_at < _updated_at OR hp.updated_at = _updated_at AND hp.id >= __post_id ) ORDER BY hp.author ASC, - hp.updated_at ASC, + hp.updated_at DESC, hp.id ASC LIMIT _limit diff --git a/hive/indexer/blocks.py b/hive/indexer/blocks.py index cf5e085ae..e7c9660b0 100644 --- a/hive/indexer/blocks.py +++ b/hive/indexer/blocks.py @@ -120,32 +120,33 @@ class Blocks: if op_type == 'author_reward_operation': if key not in comment_payout_ops: - comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None, 'date' : date } + comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None } - comment_payout_ops[key][op_type] = op_value + comment_payout_ops[key][op_type] = ( op_value, date ) elif op_type == 'comment_reward_operation': if key not in comment_payout_ops: - comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None, 'date' : date } + comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None } comment_payout_ops[key]['effective_comment_vote_operation'] = None - comment_payout_ops[key][op_type] = op_value + comment_payout_ops[key][op_type] = ( op_value, date ) elif op_type == 'effective_comment_vote_operation': key_vote = "{}/{}/{}".format(op_value['voter'], op_value['author'], op_value['permlink']) vote_ops[ key_vote ] = op_value if key not in comment_payout_ops: - comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None, 'date' : date } + comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None } - comment_payout_ops[key][op_type] = op_value + comment_payout_ops[key][op_type] = ( op_value, date ) elif op_type == 'comment_payout_update_operation': if key not in comment_payout_ops: - comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None, 'date' : date } + comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None } + + comment_payout_ops[key][op_type] = ( op_value, date ) - comment_payout_ops[key][op_type] = op_value elif op_type == 'ineffective_delete_comment_operation': ineffective_deleted_ops[key] = {} diff --git a/hive/indexer/posts.py b/hive/indexer/posts.py index 329ce40a2..08cc01c2a 100644 --- a/hive/indexer/posts.py +++ b/hive/indexer/posts.py @@ -155,7 +155,7 @@ class Posts: UPDATE hive_posts AS ihp SET total_payout_value = COALESCE( data_source.total_payout_value, ihp.total_payout_value ), curator_payout_value = COALESCE( data_source.curator_payout_value, ihp.curator_payout_value ), - author_rewards = COALESCE( CAST( data_source.author_rewards as BIGINT ), ihp.author_rewards ), + author_rewards = CAST( data_source.author_rewards as BIGINT ) + ihp.author_rewards, author_rewards_hive = COALESCE( CAST( data_source.author_rewards_hive as BIGINT ), ihp.author_rewards_hive ), author_rewards_hbd = COALESCE( CAST( data_source.author_rewards_hbd as BIGINT ), ihp.author_rewards_hbd ), author_rewards_vests = COALESCE( CAST( data_source.author_rewards_vests as BIGINT ), ihp.author_rewards_vests ), @@ -231,14 +231,14 @@ class Posts: permlink = None # author payouts - author_rewards = None + 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 + #curators_vesting_payout = None total_payout_value = None; curator_payout_value = None; #beneficiary_payout_value = None; @@ -254,71 +254,70 @@ class Posts: total_vote_weight = None - date = v[ 'date' ] - + # final payout indicator - by default all rewards are zero, but might be overwritten by other operations + if v[ 'comment_payout_update_operation' ] is not None: + value, date = v[ 'comment_payout_update_operation' ] + if author is None: + author = value['author'] + permlink = value['permlink'] + is_paidout = True + payout_at = date + last_payout_at = date + cashout_time = "infinity" + + author_rewards_hive = 0 + author_rewards_hbd = 0 + author_rewards_vests = 0 + + total_payout_value = "0.000 HBD" + curator_payout_value = "0.000 HBD" + + payout = 0 + pending_payout = 0 + + # author rewards in current (final or nonfinal) payout (always comes with comment_reward_operation) if v[ 'author_reward_operation' ] is not None: - value = v[ 'author_reward_operation' ] - 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'] + value, date = v[ 'author_reward_operation' ] if author is None: - author = value['author'] - permlink = value['permlink'] - + 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[ 'comment_reward_operation' ] is not None: - value = v[ 'comment_reward_operation' ] - #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'] + value, date = v[ 'comment_reward_operation' ] + 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 - if author is None: - author = value['author'] - permlink = value['permlink'] - + # estimated pending_payout from vote (if exists with actual payout the value comes from vote cast after payout) if v[ 'effective_comment_vote_operation' ] is not None: - value = v[ 'effective_comment_vote_operation' ] - pending_payout = sbd_amount( value['pending_payout'] ) - total_vote_weight = value['total_vote_weight'] + value, date = v[ 'effective_comment_vote_operation' ] if author is None: - author = value['author'] - permlink = value['permlink'] + author = value['author'] + permlink = value['permlink'] + pending_payout = sbd_amount( value['pending_payout'] ) + total_vote_weight = value['total_vote_weight'] - if v[ 'comment_payout_update_operation' ] is not None: - value = v[ 'comment_payout_update_operation' ] - is_paidout = True - - #Payout didn't generate any payments - if v[ 'comment_reward_operation' ] is None: - author_rewards = 0 - total_payout_value = "0.000 HBD" - curator_payout_value = "0.000 HBD" - - payout = 0 - pending_payout = 0 - - if author is None: - author = value['author'] - permlink = value['permlink'] - - #Calculations of all dates - if ( is_paidout is not None ): - payout_at = date - last_payout_at = date - cashout_time = "1969-12-31T23:59:59" cls._comment_payout_ops.append("('{}', '{}', {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})".format( author, 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) ) ), - "NULL" if ( author_rewards is None ) else author_rewards, + 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, diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index 9ad119184..56ac22f5a 100644 --- a/hive/server/bridge_api/methods.py +++ b/hive/server/bridge_api/methods.py @@ -29,7 +29,7 @@ SQL_TEMPLATE = """ hp.percent_hbd, hp.url, hp.permlink, - hp.parent_permlink, + hp.parent_permlink_or_category, hp.title, hp.body, hp.category, diff --git a/hive/server/bridge_api/objects.py b/hive/server/bridge_api/objects.py index 5c15878c9..3fbd54343 100644 --- a/hive/server/bridge_api/objects.py +++ b/hive/server/bridge_api/objects.py @@ -72,7 +72,7 @@ async def load_posts_keyed(db, ids, truncate_body=0): hp.total_votes, hp.flag_weight, hp.parent_author, - hp.parent_permlink, + hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, @@ -273,7 +273,7 @@ def _bridge_post_object(row, truncate_body=0): # TODO: re-evaluate if row['depth'] > 0: post['parent_author'] = row['parent_author'] - post['parent_permlink'] = row['parent_permlink'] + post['parent_permlink'] = row['parent_permlink_or_category'] post['title'] = 'RE: ' + row['root_title'] # PostSummary & comment context return post diff --git a/hive/server/bridge_api/thread.py b/hive/server/bridge_api/thread.py index 3f50d9a33..e0f68db19 100644 --- a/hive/server/bridge_api/thread.py +++ b/hive/server/bridge_api/thread.py @@ -68,7 +68,7 @@ async def get_discussion(context, author, permlink, observer=None): hpv.root_author, hpv.root_permlink, hpv.parent_author, - hpv.parent_permlink, + hpv.parent_permlink_or_category, hpv.allow_replies, hpv.allow_votes, hpv.allow_curation_rewards, diff --git a/hive/server/common/helpers.py b/hive/server/common/helpers.py index 6edbb81f6..2db68fe34 100644 --- a/hive/server/common/helpers.py +++ b/hive/server/common/helpers.py @@ -4,6 +4,7 @@ import re from functools import wraps import traceback import logging +import datetime log = logging.getLogger(__name__) @@ -50,7 +51,7 @@ def return_error_info(function): def json_date(date=None): """Given a db datetime, return a steemd/json-friendly version.""" - if not date: return '1969-12-31T23:59:59' + if not date or date == datetime.datetime.max: return '1969-12-31T23:59:59' return 'T'.join(str(date).split(' ')) def valid_account(name, allow_empty=False): diff --git a/hive/server/condenser_api/cursor.py b/hive/server/condenser_api/cursor.py index ea0d23ae8..5cb95dc2a 100644 --- a/hive/server/condenser_api/cursor.py +++ b/hive/server/condenser_api/cursor.py @@ -216,7 +216,7 @@ async def pids_by_query(db, sort, start_author, start_permlink, limit, tag): hp.total_votes, hp.flag_weight, hp.parent_author, - hp.parent_permlink, + hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, diff --git a/hive/server/condenser_api/methods.py b/hive/server/condenser_api/methods.py index f5c5127ea..48115839d 100644 --- a/hive/server/condenser_api/methods.py +++ b/hive/server/condenser_api/methods.py @@ -48,7 +48,7 @@ SQL_TEMPLATE = """ hp.total_votes, hp.flag_weight, hp.parent_author, - hp.parent_permlink, + hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, @@ -175,7 +175,7 @@ async def get_content_replies(context, author: str, permlink: str): #force copy sql = str(SQL_TEMPLATE) sql += """ - hp.counter_deleted = 0 AND hp.parent_author = :author AND hp.parent_permlink = :permlink + hp.counter_deleted = 0 AND hp.parent_author = :author AND hp.parent_permlink_or_category = :permlink ORDER BY hp.id LIMIT :limit """ diff --git a/hive/server/condenser_api/objects.py b/hive/server/condenser_api/objects.py index f4218a8a0..14ecaf82e 100644 --- a/hive/server/condenser_api/objects.py +++ b/hive/server/condenser_api/objects.py @@ -67,7 +67,7 @@ async def load_posts_keyed(db, ids, truncate_body=0): hp.total_votes, hp.flag_weight, hp.parent_author, - hp.parent_permlink, + hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, @@ -209,12 +209,8 @@ def _condenser_post_object(row, truncate_body=0): post['body_length'] = len(row['body']) post['author_reputation'] = rep_to_raw(row['author_rep']) - if row['depth'] > 0: - post['parent_author'] = row['parent_author'] - post['parent_permlink'] = row['parent_permlink'] - else: - post['parent_author'] = '' - post['parent_permlink'] = row['category'] + post['parent_author'] = row['parent_author'] + post['parent_permlink'] = row['parent_permlink_or_category'] post['url'] = row['url'] post['root_title'] = row['root_title'] diff --git a/hive/server/database_api/methods.py b/hive/server/database_api/methods.py index 640a6f97e..4afc1843c 100644 --- a/hive/server/database_api/methods.py +++ b/hive/server/database_api/methods.py @@ -5,6 +5,8 @@ from hive.server.common.helpers import return_error_info, valid_limit, valid_acc from hive.server.database_api.objects import database_post_object from hive.utils.normalize import rep_to_raw, number_to_json_value, time_string_with_t +import datetime + @return_error_info async def list_comments(context, start: list, limit: int, order: str): """Returns all comments, starting with the specified options.""" @@ -18,6 +20,8 @@ async def list_comments(context, start: list, limit: int, order: str): if order == 'by_cashout_time': assert len(start) == 3, "Expecting three arguments" cashout_time = start[0] + if cashout_time[0:4] == '1969': + cashout_time = "infinity" author = start[1] permlink = start[2] sql = "SELECT * FROM list_comments_by_cashout_time(:cashout_time, :author, :permlink, :limit)" @@ -99,7 +103,7 @@ async def find_comments(context, comments: list): hp.total_vote_weight, hp.flag_weight, hp.parent_author, - hp.parent_permlink, + hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink, @@ -113,9 +117,7 @@ async def find_comments(context, comments: list): hp.root_title, hp.abs_rshares, hp.active, - hp.author_rewards, - hp.max_cashout_time, - hp.reward_weight + hp.author_rewards FROM hive_posts_view hp JOIN (VALUES {}) AS t (author, permlink) ON hp.author = t.author AND hp.permlink = t.permlink diff --git a/hive/server/database_api/objects.py b/hive/server/database_api/objects.py index 4e45fc6a8..1f24700ca 100644 --- a/hive/server/database_api/objects.py +++ b/hive/server/database_api/objects.py @@ -31,11 +31,13 @@ def database_post_object(row, truncate_body=0): post['last_payout'] = json_date(row['last_payout_at']) post['cashout_time'] = json_date(row['cashout_time']) - post['max_cashout_time'] = json_date(row['max_cashout_time']) - post['total_payout_value'] = to_nai(_amount(row['payout'] if paid else 0)) - post['curator_payout_value'] = to_nai(_amount(0)) + post['max_cashout_time'] = json_date(None) # ABW: only relevant up to HF17, timestamp::max for all posts later (and also all paid) - post['reward_weight'] = row['reward_weight'] + curator_payout = sbd_amount(row['curator_payout_value']) + post['curator_payout_value'] = to_nai(_amount(curator_payout)) + post['total_payout_value'] = to_nai(_amount(row['payout'] - curator_payout)) + + post['reward_weight'] = 10000 # ABW: only relevant between HF12 and HF17 and we don't have access to correct value post['root_author'] = row['root_author'] post['root_permlink'] = row['root_permlink'] @@ -44,12 +46,8 @@ def database_post_object(row, truncate_body=0): post['allow_votes'] = row['allow_votes'] post['allow_curation_rewards'] = row['allow_curation_rewards'] - if row['depth'] > 0: - post['parent_author'] = row['parent_author'] - post['parent_permlink'] = row['parent_permlink'] - else: - post['parent_author'] = '' - post['parent_permlink'] = row['category'] + post['parent_author'] = row['parent_author'] + post['parent_permlink'] = row['parent_permlink_or_category'] post['beneficiaries'] = row['beneficiaries'] post['max_accepted_payout'] = to_nai(row['max_accepted_payout']) @@ -57,12 +55,9 @@ def database_post_object(row, truncate_body=0): post['net_votes'] = row['net_votes'] if paid: - curator_payout = sbd_amount(row['curator_payout_value']) - post['curator_payout_value'] = to_nai(_amount(curator_payout)) - post['total_payout_value'] = to_nai(_amount(row['payout'] - curator_payout)) post['total_vote_weight'] = 0 post['vote_rshares'] = 0 - post['net_rshares'] = 0 if row['rshares'] > 0 else row['rshares'] + post['net_rshares'] = 0 # if row['rshares'] > 0 else row['rshares'] ABW: used to be like this but after HF19 cashouts disappear and all give 0 post['abs_rshares'] = 0 post['children_abs_rshares'] = 0 else: @@ -70,6 +65,6 @@ def database_post_object(row, truncate_body=0): post['vote_rshares'] = ( row['rshares'] + row['abs_rshares'] ) // 2 # effectively sum of all positive rshares post['net_rshares'] = row['rshares'] post['abs_rshares'] = row['abs_rshares'] - post['children_abs_rshares'] = 0 # TODO + post['children_abs_rshares'] = 0 # TODO - ABW: I'm not sure about that, it is costly and useless (used to be part of mechanism to determine cashout time) return post diff --git a/hive/utils/post.py b/hive/utils/post.py index d07408681..d1fbcd71c 100644 --- a/hive/utils/post.py +++ b/hive/utils/post.py @@ -4,6 +4,7 @@ import re import math import ujson as json +import datetime from funcy.seqs import first, distinct from hive.utils.normalize import sbd_amount, rep_log10, safe_img_url, parse_time, utc_timestamp @@ -150,7 +151,8 @@ def post_basic(post): body = body.replace('\x00', '[NUL]') # payout date is last_payout if paid, and cashout_time if pending. - is_paidout = (post['cashout_time'][0:4] == '1969') + cashout_year = post['cashout_time'][0:4] + is_paidout = (cashout_year == '1969' or cashout_year == datetime.MAXYEAR) # depending on source it could be one or the other payout_at = post['last_payout'] if is_paidout else post['cashout_time'] # payout is declined if max_payout = 0, or if 100% is burned diff --git a/hive/version.py b/hive/version.py index 5a0e4fa19..377556c85 100644 --- a/hive/version.py +++ b/hive/version.py @@ -1,4 +1,4 @@ # generated by setup.py # contents will be overwritten VERSION = '0.0.1' -GIT_REVISION = '10bc3ad' \ No newline at end of file +GIT_REVISION = 'ab21d88' \ No newline at end of file diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 0bf8a31e0..c7ac8e64b 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -52,8 +52,8 @@ then exit 0 fi -check_address $1 -check_port $2 +#check_address $1 +#check_port $2 #cd .. diff --git a/tests/tests_api b/tests/tests_api index bae23397a..a32162906 160000 --- a/tests/tests_api +++ b/tests/tests_api @@ -1 +1 @@ -Subproject commit bae23397a6538852645dc8f3c4f08eca06f18144 +Subproject commit a3216290630c60fd6cc7fa132ca8c03486fbfe09 -- GitLab