def rpc_get_listings(self, sender): self.log.info("serving store listings to %s" % sender) self.router.addContact(sender) try: p = Profile(self.db).get() l = Listings() l.ParseFromString(self.db.ListingsStore().get_proto()) l.handle = p.handle l.avatar_hash = p.avatar_hash return [l.SerializeToString(), self.signing_key.sign(l.SerializeToString())[:64]] except Exception: self.log.warning("could not find any listings in the database") return None
def rpc_get_listings(self, sender): self.log.info("serving store listings to %s" % sender) self.audit.record(sender.id.encode("hex"), "GET_LISTINGS") self.router.addContact(sender) try: p = Profile(self.db).get() l = Listings() l.ParseFromString(self.db.listings.get_proto()) l.handle = p.handle l.avatar_hash = p.avatar_hash for listing in l.listing: if listing.hidden: l.listing.remove(listing) return [ l.SerializeToString(), self.signing_key.sign(l.SerializeToString())[:64] ] except Exception: self.log.warning("could not find any listings in the database") return None
def delete_listing(self, hash_value): cursor = self.db.cursor() ser = self.get_proto() if ser is None: return l = Listings() l.ParseFromString(ser) for listing in l.listing: if listing.contract_hash == hash_value: l.listing.remove(listing) cursor.execute('''INSERT OR REPLACE INTO listings(id, serializedListings) VALUES (?,?)''', (1, l.SerializeToString())) self.db.commit()
def add_listing(self, proto): """ Will also update an existing listing if the contract hash is the same. """ cursor = self.db.cursor() l = Listings() ser = self.get_proto() if ser is not None: l.ParseFromString(ser) for listing in l.listing: if listing.contract_hash == proto.contract_hash: l.listing.remove(listing) l.listing.extend([proto]) cursor.execute('''INSERT OR REPLACE INTO listings(id, serializedListings) VALUES (?,?)''', (1, l.SerializeToString())) self.db.commit()