def convert_to_did(self, data): items = self.convert_to_did_items() if items and len(items) > 0: if isinstance(data, list): address = [] for row in data: for item in items: address.append(row['attributes'][item]) alldid = Did.query(self.session).filter( Did.address.in_(address)).all() did_map = dict([(did.address, did.did) for did in alldid]) for row in data: for item in items: if row['attributes'][item] in did_map: row['attributes'][ item + '_source'] = row['attributes'][item] row['attributes'][item] = did_map[row['attributes'] [item]] else: for item in items: did = Did.query(self.session).filter_by( address=data['attributes'][item]).first() if did: data['attributes'][ item + '_source'] = data['attributes'][item] data['attributes'][item] = did.did return data
def apply_filters(self, query, params): if params.get('filter[signed]'): query = query.filter_by(signed=params.get('filter[signed]')) if params.get('filter[module_id]'): query = query.filter_by(module_id=params.get('filter[module_id]')) if params.get('filter[call_id]'): query = query.filter_by(call_id=params.get('filter[call_id]')) if params.get('filter[address]'): if params.get('filter[address]')[0:2] == '0x': account_id = params.get('filter[address]')[2:] elif params.get('filter[address]')[0:3] == 'did': did = Did.query(self.session).filter_by(did=params.get('filter[address]')).first() account_id = ss58_decode(did.address, SUBSTRATE_ADDRESS_TYPE) else: account_id = ss58_decode(params.get( 'filter[address]'), SUBSTRATE_ADDRESS_TYPE) query = query.filter_by(address=account_id) return query
def get_item(self, item_id): if item_id[0:2] == '0x': return Account.query(self.session).filter_by(id=item_id[2:]).first() elif item_id[0:3] == 'did': did = Did.query(self.session).filter_by(did=item_id).first() return Account.query(self.session).filter_by(address = did.address).first() else: return Account.query(self.session).filter_by(address=item_id).first()
def get_query(self,did_hash): return Did.query(self.session).filter_by(superior = did_hash)
def get_item(self, item_id): return Did.query(self.session).filter_by(social_account_hash=item_id).first()
def get_item(self, item_id): if item_id and item_id.startswith('0x'): return Did.query(self.session).filter_by(did_hash=item_id[2:]).first() else: return Did.query(self.session).get(item_id)
def get_query(self): return Did.query(self.session)