Example #1
0
    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
        }
Example #2
0
    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 != 'SBD':
            return  # only care about SBD 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)
        if not Accounts.exists(author):
            return

        post_id = Posts.get_id(author, permlink)
        if not post_id:
            log.debug("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
        }
Example #3
0
    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()
Example #4
0
 def _load_noids(cls):
     from hive.indexer.posts import Posts
     noids = cls._noids - set(cls._ids.keys())
     tuples = [(Posts.get_id(*url.split('/')), url) for url in noids]
     for pid, url in tuples:
         assert pid, "WARNING: missing id for %s" % url
         cls._ids[url] = pid
     cls._noids = set()
     return len(tuples)
Example #5
0
    def _read_permlink(self):
        assert self.account, 'permlink requires named account'
        _permlink = read_key_str(self.op, 'permlink', 256)
        assert _permlink, 'must name a permlink'

        from hive.indexer.posts import Posts
        _pid = Posts.get_id(self.account, _permlink)
        assert _pid, 'invalid post: %s/%s' % (self.account, _permlink)

        sql = """SELECT community_id FROM hive_posts WHERE id = :id LIMIT 1"""
        _comm = DB.query_one(sql, id=_pid)
        assert self.community_id == _comm, 'post does not belong to community'

        self.permlink = _permlink
        self.post_id = _pid
Example #6
0
    def _load_noids(cls):
        """Load ids for posts we don't know the ids of.

        When posts are marked dirty, specifying the id is optional
        because a successive call might be able to provide it "for
        free". Before flushing changes this method should be called
        to fill in any gaps.
        """
        from hive.indexer.posts import Posts
        noids = cls._noids - set(cls._ids.keys())
        tuples = [(Posts.get_id(*url.split('/')), url) for url in noids]
        for pid, url in tuples:
            assert pid, "WARNING: missing id for %s" % url
            cls._ids[url] = pid
        cls._noids = set()
        return len(tuples)