Esempio n. 1
0
 def get_group_messages(self):
     if self.wallet_mode:
         self.rid_transactions = GU().get_transactions_by_rid(
             self.rids,
             bulletin_secret=self.config.username_signature,
             rid=True,
             raw=True,
             returnheight=True)
     else:
         my_bulletin_secret = self.config.username_signature
         posts = []
         blocked = [
             x['username'] for x in self.mongo.db.blocked_users.find(
                 {'bulletin_secret': self.bulletin_secret})
         ]
         flagged = [
             x['id'] for x in self.mongo.db.flagged_content.find(
                 {'bulletin_secret': self.bulletin_secret})
         ]
         for x in GU().get_posts(self.rid):
             rids = sorted(
                 [str(my_bulletin_secret),
                  str(x.get('bulletin_secret'))],
                 key=str.lower)
             rid = hashlib.sha256(
                 (str(rids[0]) +
                  str(rids[1])).encode('utf-8')).digest().hex()
             if rid in self.rid_usernames:
                 x['username'] = self.rid_usernames[rid]
                 if x['username'] not in blocked and x['id'] not in flagged:
                     posts.append(x)
         self.posts = posts
Esempio n. 2
0
 def get_lookup_rids(self):
     lookup_rids = [
         self.rid,
     ]
     lookup_rids.extend(
         [x['rid'] for x in GU().get_friend_requests(self.rid)])
     lookup_rids.extend(
         [x['rid'] for x in GU().get_sent_friend_requests(self.rid)])
     return list(set(lookup_rids))
Esempio n. 3
0
    def get_request_rids_for_rid(self):
        lookup_rids = {}
        for x in GU().get_friend_requests(self.rid):
            if x['rid'] not in lookup_rids:
                lookup_rids[x['rid']] = []
            lookup_rids[x['rid']].append(x['requester_rid'])

        for x in GU().get_sent_friend_requests(self.rid):
            if x['rid'] not in lookup_rids:
                lookup_rids[x['rid']] = []
            lookup_rids[x['rid']].append(x['requested_rid'])

        return lookup_rids
Esempio n. 4
0
    async def get_reacts(self):
        if self.wallet_mode:
            self.reacts = []
            return

        my_bulletin_secret = self.config.username_signature
        reacts = []
        blocked = [x['username'] for x in self.mongo.db.blocked_users.find({'bulletin_secret': self.bulletin_secret})]
        flagged = [x['id'] for x in self.mongo.db.flagged_content.find({'bulletin_secret': self.bulletin_secret})]
        out = {}
        if not self.ids:
            return json.dumps({})
        for x in GU().get_reacts(self.rid, self.ids):
            if x['relationship'].get('id') not in out:
                out[x['relationship'].get('id')] = []

            rids = sorted([str(my_bulletin_secret), str(x.get('bulletin_secret'))], key=str.lower)
            rid = hashlib.sha256((str(rids[0]) + str(rids[1])).encode('utf-8')).digest().hex()
            
            if rid in self.rid_usernames:
                x['username'] = self.rid_usernames[rid]
                if x['username'] not in blocked and x['id'] not in flagged:
                    reacts.append(x)
            x['id'] = str(x['id'])
            if x['username'] not in blocked:
                out[x['relationship'].get('id')].append(x)
        self.reacts = out
Esempio n. 5
0
 async def get_messages(self, not_mine=False):
     if self.wallet_mode:
         for transaction in self.mongo.db.miner_transactions.find({"relationship": {"$ne": ""}}):
             try:
                 decrypted = self.config.cipher.decrypt(transaction['relationship'])
                 relationship = json.loads(decrypted.decode('latin1'))
                 transaction['relationship'] = relationship
             except:
                 pass
         rid_transactions = GU().get_transactions_by_rid(
             self.rids,
             bulletin_secret=self.config.username_signature,
             rid=True,
             raw=True,
             returnheight=True,
             requested_rid=True
         )
         self.messages = []
         used_ids = []
         for x in rid_transactions:
             if x.get('id') not in used_ids and x['rid'] and x['relationship']:
                 self.messages.append(x)
                 used_ids.append(x.get('id'))
         if not_mine:
             messages = []
             for x in self.messages:
                 if x['public_key'] != self.config.public_key:
                     messages.append(x)
             self.messages = messages
     else:
         rids = self.get_lookup_rids() + self.rids
         self.messages = [x for x in GU().get_messages(rids)]
     res = await self.config.mongo.async_db.miner_transactions.find({
         'relationship': {'$ne': ''},
         '$or': [
             {'rid': {'$in': self.rids}},
             {'requester_rid': {'$in': self.rids}},
             {'requested_rid': {'$in': self.rids}}
         ]
     }, {
         '_id': 0
     }).to_list(length=1000)
     for txn in res:
         txn['pending'] = True
         self.messages.append(txn)
     
     await self.assign_usernames(self.messages, lam=lambda x: x.get('requested_rid') or x.get('requester_rid') or x.get('rid'))
Esempio n. 6
0
    def __init__(self, config, mongo, bulletin_secret, ids, rids, key_or_wif=None):
        self.config = config
        self.mongo = mongo
        self.app_log = logging.getLogger('tornado.application')
        self.friend_requests = []
        self.sent_friend_requests = []
        self.friends = []
        self.posts = []
        self.logins = []
        self.messages = []
        self.new_messages = []
        self.reacts = []
        self.comments = []
        self.comment_reacts = []
        self.already_added_messages = []
        self.bulletin_secret = str(bulletin_secret)
        self.ids = ids
        self.rids = rids
        self.server_bulletin_secret = str(config.username_signature)
        bulletin_secrets = sorted([str(config.username_signature), str(bulletin_secret)], key=str.lower)
        rid = hashlib.sha256((str(bulletin_secrets[0]) + str(bulletin_secrets[1])).encode('utf-8')).digest().hex()
        self.rid = rid
        self.username = self.config.username

        if key_or_wif in [config.private_key, config.wif]:
            self.wallet_mode = True
        else:
            self.wallet_mode = False
            nodes = GU().get_transactions_by_rid(bulletin_secret, config.username_signature, raw=True, returnheight=True, inc_mempool=True)
            me = None
            them = None
            for node in nodes:
                if node.get('dh_public_key') and self.rid == node.get('rid'):
                    if node.get('public_key') != self.config.public_key:
                        them = node
                        self.friends.append(node)
                    elif node.get('public_key') == self.config.public_key:
                        me = node
                        self.friends.append(node)
                if them and me:
                    break

            if them and me:
                for x in self.friends:
                    for y in x['outputs']:
                        if y['to'] != config.address:
                            self.mongo.site_db.usernames.update({
                                'rid': self.rid,
                                'username': self.username,
                                },
                                {
                                'rid': self.rid,
                                'username': self.username,
                                'to': y['to'],
                                'relationship': {
                                    'bulletin_secret': bulletin_secret
                                }
                            },
                            upsert=True)
Esempio n. 7
0
    async def get_sent_friend_requests(self):
        self.sent_friend_requests = []
        if self.wallet_mode:
            res = await self.config.mongo.async_db.miner_transactions.find({
                'public_key': self.config.public_key,
                'relationship': {'$ne': ''},
                'rid': {'$ne': ''}
            }, {
                '_id': 0
            }).to_list(length=1000)
            for txn in res:
                txn['pending'] = True
                self.sent_friend_requests.append(txn)
            self.all_relationships = [x for x in GU().get_all_usernames()]
            rids = []
            rids.extend([x['rid'] for x in self.all_relationships if 'rid' in x and x['rid']])
            rids.extend([x['requested_rid'] for x in self.all_relationships if 'requested_rid' in x and x['requested_rid']])
            rids.extend([x['requester_rid'] for x in self.all_relationships if 'requester_rid' in x and x['requester_rid']])
            rids.append(self.rid)
            rids = list(set(rids))
            self.rid_transactions = GU().get_transactions_by_rid(
                rids,
                bulletin_secret=self.config.username_signature,
                rid=True,
                raw=True,
                returnheight=True
            )
            self.sent_friend_requests += [x for x in self.rid_transactions if x['rid'] and x['public_key'] == self.config.public_key]

        else:
            self.sent_friend_requests += [x for x in GU().get_sent_friend_requests(self.rid)]
        
        res = await self.config.mongo.async_db.miner_transactions.find({
            'dh_public_key': {'$ne': ''},
            'relationship': {'$ne': ''},
            'requester_rid': self.rid
        }, {
            '_id': 0
        }).to_list(length=1000)
        for txn in res:
            txn['pending'] = True
            self.sent_friend_requests.append(txn)
        
        await self.assign_usernames(self.sent_friend_requests, lam=lambda x: x.get('requested_rid') or x.get('rid'))