示例#1
0
    def process_ops(cls, ops, block_num, block_date):
        """Given a list of operation in block, filter and process them."""
        for op in ops:
            if op['id'] not in ['follow', 'com.steemit.community']:
                continue

            # we assume `required_posting_auths` is always used and length 1.
            # it may be that some ops require `required_active_auths` instead.
            # (e.g. if we use that route for admin action of acct creation)
            # if op['required_active_auths']:
            #    log.warning("unexpected active auths: %s" % op)
            if len(op['required_posting_auths']) != 1:
                log.warning("unexpected auths: %s", op)
                continue

            account = op['required_posting_auths'][0]
            op_json = load_json_key(op, 'json')

            if op['id'] == 'follow':
                if block_num < 6000000 and not isinstance(op_json, list):
                    op_json = ['follow', op_json]  # legacy compat
                cls._process_legacy(account, op_json, block_date)
            elif op['id'] == 'com.steemit.community':
                if block_num > 23e6:
                    process_json_community_op(account, op_json, block_date)
示例#2
0
 def _get_op_community(cls, comment):
     md = load_json_key(comment, 'json_metadata')
     if not md or not isinstance(md, dict) or 'community' not in md:
         return None
     community = md['community']
     if not isinstance(community, str):
         return None
     if not Accounts.exists(community):
         return None
     return community
示例#3
0
    def _get_op_community(cls, comment, date):
        """Given a comment op, safely read 'community' field from json.

        Ensures value is readable and referenced account exists.
        """

        # short-circuit pre-launch
        if date < '2018-07-01':
            return None

        md = load_json_key(comment, 'json_metadata')
        if (not md or not isinstance(md, dict) or not 'community' in md
                or not isinstance(md['community'], str)
                or not Accounts.exists(md['community'])):
            return None

        return md['community']
示例#4
0
    def process_ops(cls, ops, block_num, block_date):
        """Given a list of operation in block, filter and process them."""
        for op in ops:
            if op['id'] not in ['follow', 'com.steemit.community']:
                continue

            account = _get_auth(op)
            if not account:
                continue

            op_json = load_json_key(op, 'json')
            if op['id'] == 'follow':
                if block_num < 6000000 and not isinstance(op_json, list):
                    op_json = ['follow', op_json]  # legacy compat
                cls._process_legacy(account, op_json, block_date)
            elif op['id'] == 'com.steemit.community':
                if block_num > 30e6:
                    process_json_community_op(account, op_json, block_date)
示例#5
0
    def process_op(cls, op, block_num, block_date):
        opName = str(op['id']) + ('-ignored' if op['id'] not in [
            'follow', 'community', 'notify', 'reblog'
        ] else '')

        account = _get_auth(op)
        if not account:
            return

        op_json = load_json_key(op, 'json')
        if op['id'] == 'follow':
            if block_num < 6000000 and not isinstance(op_json, list):
                op_json = ['follow', op_json]  # legacy compat
            cls._process_legacy(account, op_json, block_date, block_num)
        elif op['id'] == 'reblog':
            if block_num < 6000000 and not isinstance(op_json, list):
                op_json = ['reblog', op_json]  # legacy compat
            cls._process_legacy(account, op_json, block_date, block_num)
        elif op['id'] == 'community':
            if block_num > Community.start_block:
                process_json_community_op(account, op_json, block_date,
                                          block_num)
        elif op['id'] == 'notify':
            cls._process_notify(account, op_json, block_date)
def test_load_json_key():
    obj = {'profile':'{"foo":"bar"}'}
    loaded = load_json_key(obj, 'profile')
    assert loaded
    print(loaded, "===============SSSSSSSSSSS")
    assert loaded['foo'] == 'bar'