diff --git a/hive/db/schema.py b/hive/db/schema.py index 7b04e94b266ec57ca7da3fa3b576c78efefacb8f..10d71bac3ebc5ff05e1332a16a5efea110668d1e 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 cf5e085aeac22f5d672f1ac9385e38af419a07b8..e7c9660b0cb91493610f7825c15842528820d45b 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 329ce40a28ae3d38a1b76f45bc5a6fd22c0f7b7c..08cc01c2ae49f0da7bde1c52e3c5c60a92652c40 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 9ad119184777ef15fa6e33d44153f701aea70f78..56ac22f5ab4cf71ecfcb812b3eefb3dc0a929d8c 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 5c15878c9d6c95ddc250fcd65d3c0899f5e106f4..3fbd5434327fbe4a75922a97dc5f9908600a136f 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 3f50d9a3388c790a0416285a3715a6d1501accf1..e0f68db198131bef42c83a1ebeabfcb5a7a49479 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 6edbb81f6763f36b3ec809cfa7abb2f4f2cd10ea..2db68fe342e3ef2a0714bbf0a630e0c9bb7836ac 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 ea0d23ae848604112a92206ff90e57a1319766bb..5cb95dc2ab96ee8135765d744d4ee0a9bd26e830 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 f5c5127ea65b50f22865511393ca9e987bd78429..48115839d055eb2a3bf0b49f2c8ef100cca239d0 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 f4218a8a08f548a35ef130d2e9dc05c188692466..14ecaf82e9c5d94e3bb18b78b8acb2f50a964cf8 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 640a6f97ee6f90a8a7e3bd987011669c754dcd07..4afc1843c83e52dcb0a6882c0800c0bb2d1a8965 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 4e45fc6a8e981ee51a174a299b36d117278785c3..1f24700cad58222cb0eb70e4d6d98a9b62a1c1de 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 d074086819631c8292bd3f9ca1aeb97df9a1fdb7..d1fbcd71c41be41d592e18254dee5968cd7c8066 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 5a0e4fa19d68f4133a10465401cc87f4cf5c9fed..377556c85a343d8c662a7eb6275ddb39375e35ac 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 0bf8a31e0e5d42019243c93a34fbd42dc0c9273a..c7ac8e64ba9ddcde880fec6cb2e0cd1540cc5a16 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 bae23397a6538852645dc8f3c4f08eca06f18144..a3216290630c60fd6cc7fa132ca8c03486fbfe09 160000 --- a/tests/tests_api +++ b/tests/tests_api @@ -1 +1 @@ -Subproject commit bae23397a6538852645dc8f3c4f08eca06f18144 +Subproject commit a3216290630c60fd6cc7fa132ca8c03486fbfe09