Esempio n. 1
0
    def update_listings_index(self):
        """This method is responsible for updating the DHT index of your
           store's listings. There is a dictionary in the DHT that has an
           array of your listing IDs. This updates that listing index in
           the DHT, simply put.

        """
        # Store to marketplace listing index
        contract_index_key = hashlib.sha1('contracts-%s' %
                                          self.transport.guid).hexdigest()
        hashvalue = hashlib.new('ripemd160')
        hashvalue.update(contract_index_key)
        contract_index_key = hashvalue.hexdigest()

        # Calculate index of contracts
        contract_ids = self.db.selectEntries("contracts", {
            "market_id": self.transport.market_id,
            "deleted": 0
        })
        my_contracts = []
        for contract_id in contract_ids:
            my_contracts.append(contract_id['key'])

        self.log.debug("My Contracts: %s", my_contracts)

        # Sign listing index for validation and tamper resistance
        data_string = str({
            'guid': self.transport.guid,
            'contracts': my_contracts
        })
        cryptor = Cryptor(privkey_hex=self.transport.settings['secret'])
        signature = cryptor.sign(data_string)

        value = {
            'signature': signature.encode('hex'),
            'data': {
                'guid': self.transport.guid,
                'contracts': my_contracts
            }
        }

        # Pass off to thread to keep GUI snappy
        t = Thread(target=self.transport.store,
                   args=(
                       contract_index_key,
                       value,
                       self.transport.guid,
                   ))
        t.start()
Esempio n. 2
0
    def update_listings_index(self):
        """This method is responsible for updating the DHT index of your
           store's listings. There is a dictionary in the DHT that has an
           array of your listing IDs. This updates that listing index in
           the DHT, simply put.

        """
        # Store to marketplace listing index
        contract_index_key = hashlib.sha1('contracts-%s' %
                                          self.transport.guid).hexdigest()
        hashvalue = hashlib.new('ripemd160')
        hashvalue.update(contract_index_key)
        contract_index_key = hashvalue.hexdigest()

        # Calculate index of contracts
        contract_ids = self.db.selectEntries(
            "contracts",
            {"market_id": self.transport.market_id, "deleted": 0}
        )
        my_contracts = []
        for contract_id in contract_ids:
            my_contracts.append(contract_id['key'])

        self.log.debug("My Contracts: %s", my_contracts)

        # Sign listing index for validation and tamper resistance
        data_string = str({'guid': self.transport.guid,
                           'contracts': my_contracts})
        cryptor = Cryptor(privkey_hex=self.transport.settings['secret'])
        signature = cryptor.sign(data_string)

        value = {
            'signature': signature.encode('hex'),
            'data': {
                'guid': self.transport.guid,
                'contracts': my_contracts
            }
        }

        # Pass off to thread to keep GUI snappy
        t = Thread(
            target=self.transport.store,
            args=(
                contract_index_key,
                value,
                self.transport.guid,
                )
            )
        t.start()
Esempio n. 3
0
 def sign(self, data):
     cryptor = Cryptor(privkey_hex=self.transport.settings['secret'])
     return cryptor.sign(data)
Esempio n. 4
0
 def sign(self, data):
     cryptor = Cryptor(privkey_hex=self.transport.settings['secret'])
     return cryptor.sign(data)