Ejemplo n.º 1
0
    def _generate_addresses(self, count):
        """
        Generate addresses for user

        :param count:
        """
        index_list = [-1]
        for i in range(0, len(self.addresses)):
            index_list.append(self.addresses[i].index)

        if max(index_list) == -1:
            start_index = 0
        else:
            start_index = max(index_list) + 1

        generator = AddressGenerator(self.seed)
        generated = generator.get_addresses(start_index, count)
        i = 0

        while i < count:
            index = start_index + i
            address = address_checksum(str(generated[i]))
            balance = address_balance(current_app.config['IOTA_HOST'], address)
            addr = IOTAAddress(index=index,
                               address=str(address),
                               balance=balance,
                               checksum=str(get_checksum(address, self.seed)))
            addr.save()
            self.addresses.append(addr)
            i += 1
        self.save()
Ejemplo n.º 2
0
    def generate_addresses(self, count):
        """
        Generates one or more addresses and saves them in the account file

        :param count:
        :return:
        """
        index_list = [-1]
        for data in self._data['account_data'][0]['address_data']:
            index = data["index"]
            index_list.append(index)

        if max(index_list) == -1:
            start_index = 0
        else:
            start_index = max(index_list) + 1
        generator = AddressGenerator(self._seed)
        addresses = generator.get_addresses(
            start_index,
            count)  # This is the actual function to generate the address.
        i = 0

        while i < count:
            index = start_index + i
            address = addresses[i]
            balance = address_balance(
                self._data['account_data'][0]['settings'][0]['host'], address)
            self._write_address_data(index, str(address), balance)
            i += 1

        self._update_fal_balance()
Ejemplo n.º 3
0
 def update_balance(self):
     """
     Update address balance
     """
     self.balance = address_balance(current_app.config['IOTA_HOST'],
                                    self.address)
     self.save()
Ejemplo n.º 4
0
    def update_addresses_balance(self, start_index=0):
        """
        Checks all addresses that are saved in the account file and updates there balance
        start_index can be set in order to ignore all addresses before the start index

        :param start_index:
        :return:
        """
        max_index = 0
        for data in self._data['account_data'][0]['address_data']:
            index = data["index"]
            if start_index <= index:
                address = str(data["address"])
                balance = address_balance(
                    self._data['account_data'][0]['settings'][0]['host'],
                    address)
                self._write_address_data(index, address, balance)

            if max_index < index:
                max_index = index

        if max_index < start_index:
            self._logger.error(
                "Start index was not found. You should generate more addresses or use a lower start index"
            )