diff --git a/hive/indexer/payments.py b/hive/indexer/payments.py index ee3f82b175a6d15640508f94a0e75671feeb377c..08892070b8da7d939cf21f78df406d3330f75aa1 100644 --- a/hive/indexer/payments.py +++ b/hive/indexer/payments.py @@ -52,8 +52,8 @@ class Payments: return # only care about payments to null amount, token = parse_amount(op['amount']) - if token != 'SBD': - return # only care about SBD payments + if token != 'HBD': + return # only care about HBD payments url = op['memo'] if not cls._validate_url(url): diff --git a/hive/server/bridge_api/objects.py b/hive/server/bridge_api/objects.py index 13ee2b114efc57389f9a6ba2d0c8182a7e74d05a..9846e3f4f2308c54b4b5aa256f6701deb717ef64 100644 --- a/hive/server/bridge_api/objects.py +++ b/hive/server/bridge_api/objects.py @@ -242,10 +242,10 @@ def _condenser_post_object(row, truncate_body=0): return post -def _amount(amount, asset='SBD'): +def _amount(amount, asset='HBD'): """Return a steem-style amount string given a (numeric, asset-str).""" - assert asset == 'SBD', 'unhandled asset %s' % asset - return "%.3f SBD" % amount + assert asset == 'HBD', 'unhandled asset %s' % asset + return "%.3f HBD" % amount def _hydrate_active_votes(vote_csv): """Convert minimal CSV representation into steemd-style object.""" diff --git a/hive/server/bridge_api/support.py b/hive/server/bridge_api/support.py index 4d446eb495682b68835feb4bcb9904c8ebd8be01..b71b4017992a755b144ae19546ccf3ef16a95e18 100644 --- a/hive/server/bridge_api/support.py +++ b/hive/server/bridge_api/support.py @@ -64,7 +64,10 @@ async def normalize_post(context, post): post['gray'] = core['is_muted'] post['hide'] = not core['is_valid'] - promoted = sbd_amount(post['promoted']) if post['promoted'] != '0.000 STEEM' else None + # TODO: there is a bug in steemd.. promoted value returned as 0.000 LIQUID + # until it's promoted.. then returned as X.XXX STABLE. So here we + # ignore the non-promoted case because sbd_amount asserts proper input units. + promoted = sbd_amount(post['promoted']) if post['promoted'] != '0.000 HIVE' else None # convert to internal object row = None diff --git a/hive/server/condenser_api/get_state.py b/hive/server/condenser_api/get_state.py index 95f271c89f1f8a8624ae611b663a865753571175..a66502d545021def091e636a94379d970c5cddca 100644 --- a/hive/server/condenser_api/get_state.py +++ b/hive/server/condenser_api/get_state.py @@ -282,7 +282,7 @@ async def _load_discussion(db, author, permlink): async def _get_feed_price(db): """Get a steemd-style ratio object representing feed price.""" price = await db.query_one("SELECT usd_per_steem FROM hive_state") - return {"base": "%.3f SBD" % price, "quote": "1.000 STEEM"} + return {"base": "%.3f HBD" % price, "quote": "1.000 HIVE"} @cached(ttl=1800, timeout=1200) async def _get_props_lite(db): diff --git a/hive/server/condenser_api/objects.py b/hive/server/condenser_api/objects.py index d3142f55005d00ec1a3308a23a38d5f683c33d89..78d342a59419abcc3ad6ec51b5f9d6b00b53da1f 100644 --- a/hive/server/condenser_api/objects.py +++ b/hive/server/condenser_api/objects.py @@ -143,7 +143,7 @@ def _condenser_post_object(row, truncate_body=0): post['total_payout_value'] = _amount(row['payout'] if paid else 0) post['curator_payout_value'] = _amount(0) post['pending_payout_value'] = _amount(0 if paid else row['payout']) - post['promoted'] = "%.3f SBD" % row['promoted'] + post['promoted'] = _amount(row['promoted']) post['replies'] = [] post['body_length'] = len(row['body']) @@ -181,10 +181,10 @@ def _condenser_post_object(row, truncate_body=0): return post -def _amount(amount, asset='SBD'): +def _amount(amount, asset='HBD'): """Return a steem-style amount string given a (numeric, asset-str).""" - assert asset == 'SBD', 'unhandled asset %s' % asset - return "%.3f SBD" % amount + assert asset == 'HBD', 'unhandled asset %s' % asset + return "%.3f HBD" % amount def _hydrate_active_votes(vote_csv): """Convert minimal CSV representation into steemd-style object.""" diff --git a/hive/server/condenser_api/tags.py b/hive/server/condenser_api/tags.py index 3151669cae76200e1a5c5ca4652c83592f0cc156..9a4f5b5b3384a5dd004940dfbddcc163cbc0d5fe 100644 --- a/hive/server/condenser_api/tags.py +++ b/hive/server/condenser_api/tags.py @@ -56,6 +56,6 @@ async def get_trending_tags(context, start_tag: str = '', limit: int = 250): 'name': row['category'], 'comments': row['total_posts'] - row['top_posts'], 'top_posts': row['top_posts'], - 'total_payouts': "%.3f SBD" % row['total_payouts']}) + 'total_payouts': "%.3f HBD" % row['total_payouts']}) return out diff --git a/hive/steem/client.py b/hive/steem/client.py index cb1a44535c04d0f2af667a773eeb12c73ce5300c..265df3c7ee9cb8e24fae1d7968765d84bc391079 100644 --- a/hive/steem/client.py +++ b/hive/steem/client.py @@ -112,7 +112,7 @@ class SteemClient: # TODO: add latest feed price: get_feed_history.price_history[0] feed = self.__exec('get_feed_history')['current_median_history'] units = dict([parse_amount(feed[k])[::-1] for k in ['base', 'quote']]) - price = units['SBD'] / units['STEEM'] + price = units['HBD'] / units['HIVE'] return "%.6f" % price def _get_steem_price(self): diff --git a/hive/utils/normalize.py b/hive/utils/normalize.py index 55434f4a306721a3af34caa22b67b1942d88c204..4c8158535a25522d9889b5fc5b3f2cb2217e9c98 100644 --- a/hive/utils/normalize.py +++ b/hive/utils/normalize.py @@ -8,8 +8,8 @@ from pytz import utc import ujson as json NAI_MAP = { - '@@000000013': 'SBD', - '@@000000021': 'STEEM', + '@@000000013': 'HBD', + '@@000000021': 'HIVE', '@@000000037': 'VESTS', } @@ -18,12 +18,12 @@ def vests_amount(value): return parse_amount(value, 'VESTS') def steem_amount(value): - """Returns a decimal amount, asserting units are STEEM""" - return parse_amount(value, 'STEEM') + """Returns a decimal amount, asserting units are HIVE""" + return parse_amount(value, 'HIVE') def sbd_amount(value): - """Returns a decimal amount, asserting units are SBD""" - return parse_amount(value, 'SBD') + """Returns a decimal amount, asserting units are HBD""" + return parse_amount(value, 'HBD') def parse_amount(value, expected_unit=None): """Parse steemd-style amout/asset value, return (decimal, name).""" @@ -32,6 +32,10 @@ def parse_amount(value, expected_unit=None): if isinstance(value, str): raw_amount, unit = value.split(' ') + if unit == 'SBD': + unit = 'HBD' + elif unit == 'STEEM': + unit = 'HIVE' dec_amount = decimal.Decimal(raw_amount) elif isinstance(value, list): @@ -59,7 +63,7 @@ def legacy_amount(value): if isinstance(value, str): return value # already legacy amt, asset = parse_amount(value) - prec = {'SBD': 3, 'STEEM': 3, 'VESTS': 6}[asset] + prec = {'HBD': 3, 'HIVE': 3, 'VESTS': 6}[asset] tmpl = ("%%.%df %%s" % prec) return tmpl % (amt, asset) diff --git a/tests/utils/test_utils_normalize.py b/tests/utils/test_utils_normalize.py index 9609e5e5234939bb454d0a622e991d686120290a..b3098d5c892a9feb02ed51b8f9512bb34e09b68d 100644 --- a/tests/utils/test_utils_normalize.py +++ b/tests/utils/test_utils_normalize.py @@ -41,10 +41,10 @@ def test_vests_amount(): assert vests_amount('4.549292 VESTS') == Decimal('4.549292') def test_steem_amount(): - assert steem_amount('1.234567 STEEM') == Decimal('1.234567') + assert steem_amount('1.234567 HIVE') == Decimal('1.234567') def test_sbd_amount(): - assert sbd_amount('1.001 SBD') == Decimal('1.001') + assert sbd_amount('1.001 HBD') == Decimal('1.001') def test_parse_amount(): nai = [1231121, 6, '@@000000037'] diff --git a/tests/utils/test_utils_post.py b/tests/utils/test_utils_post.py index 48782dfcf12dc56e31ea2169df0c67aa6328ce5c..be5159db1abc33056a71eae0b0b8cbc0e09e714f 100644 --- a/tests/utils/test_utils_post.py +++ b/tests/utils/test_utils_post.py @@ -60,22 +60,22 @@ POST_1 = { "children": 0, "children_abs_rshares": 0, "created": "2017-06-20T15:53:51", - "curator_payout_value": "0.000 SBD", + "curator_payout_value": "0.000 HBD", "depth": 0, "id": 4437869, "json_metadata": "{\"tags\":[\"spam\"],\"image\":[\"ddd\", \"https://pbs.twimg.com/media/DBgNm3jXoAAioyE.jpg\",\"https://example.com/image.jpg\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}", "last_payout": "2017-06-27T15:53:51", "last_update": "2017-06-20T15:53:51", - "max_accepted_payout": "1000000.000 SBD", + "max_accepted_payout": "1000000.000 HBD", "max_cashout_time": "1969-12-31T23:59:59", "net_rshares": 0, "net_votes": 4, "parent_author": "", "parent_permlink": "spam", - "pending_payout_value": "0.000 SBD", + "pending_payout_value": "0.000 HBD", "percent_steem_dollars": 10000, "permlink": "june-spam", - "promoted": "0.000 SBD", + "promoted": "0.000 HBD", "reblogged_by": [], "replies": [], "reward_weight": 10000, @@ -83,8 +83,8 @@ POST_1 = { "root_permlink": "june-spam", "root_title": "June Spam", "title": "June Spam", - "total_payout_value": "0.044 SBD", - "total_pending_payout_value": "0.000 STEEM", + "total_payout_value": "0.044 HBD", + "total_pending_payout_value": "0.000 HIVE", "total_vote_weight": 0, "url": "/spam/@test-safari/june-spam", "vote_rshares": 0 @@ -108,22 +108,22 @@ POST_2 = { "children": 0, "children_abs_rshares": 0, "created": "2017-06-20T15:53:51", - "curator_payout_value": "0.000 SBD", + "curator_payout_value": "0.000 HBD", "depth": 0, "id": 4437869, "json_metadata": "{\"tags\":[\"steemit\",\"steem\",\"\",\"abc\",\"bcd\",\"cde\"]}", "last_payout": "2017-06-27T15:53:51", "last_update": "2017-06-20T15:53:51", - "max_accepted_payout": "1000000.000 SBD", + "max_accepted_payout": "1000000.000 HBD", "max_cashout_time": "1969-12-31T23:59:59", "net_rshares": 0, "net_votes": 4, "parent_author": "", "parent_permlink": "spam", - "pending_payout_value": "0.000 SBD", + "pending_payout_value": "0.000 HBD", "percent_steem_dollars": 10000, "permlink": "june-spam", - "promoted": "0.000 SBD", + "promoted": "0.000 HBD", "reblogged_by": [], "replies": [], "reward_weight": 10000, @@ -131,8 +131,8 @@ POST_2 = { "root_permlink": "june-spam", "root_title": "June Spam", "title": "June Spam", - "total_payout_value": "0.044 SBD", - "total_pending_payout_value": "0.000 STEEM", + "total_payout_value": "0.044 HBD", + "total_pending_payout_value": "0.000 HIVE", "total_vote_weight": 0, "url": "/spam/@test-safari/june-spam", "vote_rshares": 0 @@ -177,9 +177,9 @@ def test_post_legacy(): 'allow_replies': True, 'allow_votes': True, 'beneficiaries': [], - 'curator_payout_value': '0.000 SBD', + 'curator_payout_value': '0.000 HBD', 'id': 4437869, - 'max_accepted_payout': '1000000.000 SBD', + 'max_accepted_payout': '1000000.000 HBD', 'parent_author': '', 'parent_permlink': 'spam', 'percent_steem_dollars': 10000,