def _validated(cls, op, tx_idx, num, date): """Validate and normalize the transfer op.""" # pylint: disable=unused-argument if op['to'] != 'null': return # only care about payments to null amount, token = parse_amount(op['amount']) if token != 'HBD': return # only care about HBD payments url = op['memo'] if not cls._validate_url(url): log.debug("invalid url: %s", url) return # invalid url author, permlink = cls._split_url(url) author_id = Accounts.get_id_noexept(author) if not author_id: return return [{ 'id': None, 'block_num': num, 'tx_idx': tx_idx, 'from_account': Accounts.get_id(op['from']), 'to_account': Accounts.get_id(op['to']), 'amount': amount, 'token': token }, author_id, permlink]
def _validated(cls, op, tx_idx, num, date): if op['to'] != 'null': return # only care about payments to null amount, token = parse_amount(op['amount']) if token != 'SBD': return # only care about SBD payments url = op['memo'] if not cls._validate_url(url): print("invalid url: {}".format(url)) return # invalid url author, permlink = cls._split_url(url) if not Accounts.exists(author): return post_id = Posts.get_id(author, permlink) if not post_id: print("post does not exist: %s" % url) return return { 'id': None, 'block_num': num, 'tx_idx': tx_idx, 'post_id': post_id, 'from_account': Accounts.get_id(op['from']), 'to_account': Accounts.get_id(op['to']), 'amount': amount, 'token': token }
def check_ad_payment(cls, op, date, num): """Triggers an adFund operation for validated Native Ads transfers.""" memo = op['memo'] try: payment = cls._valid_payment(memo) if payment: amount, token = parse_amount(op['amount'], bypass_nai_lookup=True) params = { 'amount': amount, 'token': token, 'to_account': op['to'], 'community_name': payment['community_name'] } from hive.indexer.accounts import Accounts from hive.indexer.posts import Posts _post_id = Posts.get_id(op['from'], payment['permlink']) assert _post_id, 'post not found: @%s/%s' % ( op['from'], payment['permlink']) _account_id = Accounts.get_id(op['from']) _community_id = payment['community_id'] ad_op = NativeAdOp(_community_id, _post_id, _account_id, { 'action': 'adFund', 'params': params }, num) ad_op.validate_op() ad_op.process() except AssertionError as e: payload = str(e) Notify('error', dst_id=_account_id, when=date, payload=payload).write()
def _get_feed_price(self): # 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']]) if 'TBD' in units and 'TESTS' in units: price = units['TBD'] / units['TESTS'] else: price = units['HBD'] / units['HIVE'] return "%.6f" % price
def _get_feed_price(self): # 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'] return "%.6f" % price
def test_parse_amount(): nai = [1231121, 6, '@@000000037'] assert parse_amount(nai, 'VESTS') == Decimal('1.231121')