Esempio n. 1
0
    def test_generator_checksum(self):
        """
    Creating a generator with checksums on the addresses.
    """
        ag = AddressGenerator(
            self.seed_2,
            security_level=AddressGenerator.DEFAULT_SECURITY_LEVEL,
            checksum=True)

        generator = ag.create_iterator()

        # noinspection SpellCheckingInspection
        self.assertEqual(
            next(generator),
            Address(
                b'FNKCVJPUANHNWNBAHFBTCONMCUBC9KCZ9EKREBCJ'
                b'AFMABCTEPLGGXDJXVGPXDCFOUCRBWFJFLEAVOEUPY'
                b'ADHVCBXFD', ),
        )

        # noinspection SpellCheckingInspection
        self.assertEqual(
            next(generator),
            Address(
                b'MSYILYYZLSJ99TDMGQHDOBWGHTBARCBGJZE9PIMQ'
                b'LTEXJXKTDREGVTPA9NDGGLQHTMGISGRAKSLYPGWMB'
                b'WIKQRCIOD', ),
        )
Esempio n. 2
0
  def test_generator_with_offset(self):
    """
    Creating a generator that starts at an offset greater than 0.
    """
    ag = AddressGenerator(self.seed_1)

    generator = ag.create_iterator(start=1, step=2)

    # noinspection SpellCheckingInspection
    self.assertEqual(
      next(generator),

      Address(
        b'PNLOTLFSALMICK9PSW9ZWLE9KJAKPKGJZQJDAFMO'
        b'VLHXMJCJXFPVHOTTOYDIAUAYELXKZWZUITCQBIQKY',
      ),
    )

    # noinspection SpellCheckingInspection
    self.assertEqual(
      next(generator),

      Address(
        b'IWWMMHBFWCWOZQLBNXDJ9OOTIGXXU9WNUHFGUZWR'
        b'9FWGIUUUQUECHPKXJLIEKZBOVSEA9BCT9DLOCNCEC',
      ),
    )
Esempio n. 3
0
  def test_generator_checksum(self):
    """
    Creating a generator with checksums on the addresses.
    """
    ag = AddressGenerator(
       self.seed_2,
       security_level=AddressGenerator.DEFAULT_SECURITY_LEVEL,
       checksum=True
    )

    generator = ag.create_iterator()

    # noinspection SpellCheckingInspection
    self.assertEqual(
      next(generator),

      Address(
        b'FNKCVJPUANHNWNBAHFBTCONMCUBC9KCZ9EKREBCJ'
        b'AFMABCTEPLGGXDJXVGPXDCFOUCRBWFJFLEAVOEUPY'
        b'ADHVCBXFD',
      ),
    )

    # noinspection SpellCheckingInspection
    self.assertEqual(
      next(generator),

      Address(
        b'MSYILYYZLSJ99TDMGQHDOBWGHTBARCBGJZE9PIMQ'
        b'LTEXJXKTDREGVTPA9NDGGLQHTMGISGRAKSLYPGWMB'
        b'WIKQRCIOD',
      ),
    )
Esempio n. 4
0
    def _find_addresses(self, seed, index, count, security_level, checksum):
        # type: (Seed, int, Optional[int], int, bool) -> List[Address]
        """
        Find addresses matching the command parameters.
        """
        generator = AddressGenerator(seed, security_level, checksum)

        if count is None:
            # Connect to Tangle and find the first unused address.
            for addy in generator.create_iterator(start=index):
                # We use addy.address here because the commands do
                # not work on an address with a checksum
                response = WereAddressesSpentFromCommand(self.adapter)(
                    addresses=[addy.address], )
                if response['states'][0]:
                    continue

                response = FindTransactionsCommand(self.adapter)(
                    addresses=[addy.address], )
                if response.get('hashes'):
                    continue

                return [addy]

        return generator.get_addresses(start=index, count=count)
Esempio n. 5
0
  def test_generator(self):
    """
    Creating a generator.
    """
    ag = AddressGenerator(self.seed_2)

    generator = ag.create_iterator()

    # noinspection SpellCheckingInspection
    self.assertEqual(
      next(generator),

      Address(
        b'FNKCVJPUANHNWNBAHFBTCONMCUBC9KCZ9EKREBCJ'
        b'AFMABCTEPLGGXDJXVGPXDCFOUCRBWFJFLEAVOEUPY',
      ),
    )

    # noinspection SpellCheckingInspection
    self.assertEqual(
      next(generator),

      Address(
        b'MSYILYYZLSJ99TDMGQHDOBWGHTBARCBGJZE9PIMQ'
        b'LTEXJXKTDREGVTPA9NDGGLQHTMGISGRAKSLYPGWMB',
      ),
    )
Esempio n. 6
0
    async def _find_addresses(self, seed: Seed, index: int,
                              count: Optional[int], security_level: int,
                              checksum: bool) -> List[Address]:
        """
        Find addresses matching the command parameters.
        """
        generator = AddressGenerator(seed, security_level, checksum)

        if count is None:
            # Connect to Tangle and find the first unused address.
            for addy in generator.create_iterator(start=index):
                # We use addy.address here because the commands do
                # not work on an address with a checksum
                # Execute two checks concurrently
                responses = await asyncio.gather(
                    WereAddressesSpentFromCommand(self.adapter)(
                        addresses=[addy.address], ),
                    FindTransactionsCommand(self.adapter)(
                        addresses=[addy.address], ),
                )
                # responses[0] -> was it spent from?
                # responses[1] -> any transaction found?
                if responses[0]['states'][0] or responses[1].get('hashes'):
                    continue

                return [addy]

        return generator.get_addresses(start=index, count=count)
Esempio n. 7
0
    def test_generator_with_offset(self):
        """
    Creating a generator that starts at an offset greater than 0.
    """
        # Seed is not important for this test; it is only used by
        # :py:class:`KeyGenerator`, which we will mock in this test.
        ag = AddressGenerator(seed=b'')

        # noinspection PyUnresolvedReferences
        with patch.object(ag, '_get_digest', self._mock_get_digest):
            generator = ag.create_iterator(start=1, step=2)

            self.assertEqual(next(generator), self.addy1)
            self.assertEqual(next(generator), self.addy3)
Esempio n. 8
0
    def _find_addresses(self, seed, index, count):
        """
    Find addresses matching the command parameters.
    """
        # type: (Seed, int, Optional[int]) -> List[Address]
        generator = AddressGenerator(seed)

        if count is None:
            # Connect to Tangle and find the first address without any
            # transactions.
            for addy in generator.create_iterator(start=index):
                response = FindTransactionsCommand(
                    self.adapter)(addresses=[addy])

                if not response.get('hashes'):
                    return [addy]

        return generator.get_addresses(start=index, count=count)
Esempio n. 9
0
  def _find_addresses(self, seed, index, count, security_level, checksum):
    # type: (Seed, int, Optional[int], int, bool) -> List[Address]
    """
    Find addresses matching the command parameters.
    """
    generator = AddressGenerator(seed, security_level, checksum)

    if count is None:
      # Connect to Tangle and find the first address without any
      # transactions.
      for addy in generator.create_iterator(start=index):
        # We use addy.address here because FindTransactions does
        # not work on an address with a checksum
        response = FindTransactionsCommand(self.adapter)(
           addresses=[addy.address]
        )

        if not response.get('hashes'):
          return [addy]

    return generator.get_addresses(start=index, count=count)
Esempio n. 10
0
    def test_generator_with_offset(self):
        """
    Creating a generator that starts at an offset greater than 0.
    """
        ag = AddressGenerator(self.seed_1)

        generator = ag.create_iterator(start=1, step=2)

        self.assertEqual(
            next(generator),
            Address(
                b'PNLOTLFSALMICK9PSW9ZWLE9KJAKPKGJZQJDAFMO'
                b'VLHXMJCJXFPVHOTTOYDIAUAYELXKZWZUITCQBIQKY', ),
        )

        self.assertEqual(
            next(generator),
            Address(
                b'IWWMMHBFWCWOZQLBNXDJ9OOTIGXXU9WNUHFGUZWR'
                b'9FWGIUUUQUECHPKXJLIEKZBOVSEA9BCT9DLOCNCEC', ),
        )
Esempio n. 11
0
    def test_generator(self):
        """
    Creating a generator.
    """
        ag = AddressGenerator(self.seed_2)

        generator = ag.create_iterator()

        self.assertEqual(
            next(generator),
            Address(
                b'FNKCVJPUANHNWNBAHFBTCONMCUBC9KCZ9EKREBCJ'
                b'AFMABCTEPLGGXDJXVGPXDCFOUCRBWFJFLEAVOEUPY', ),
        )

        self.assertEqual(
            next(generator),
            Address(
                b'MSYILYYZLSJ99TDMGQHDOBWGHTBARCBGJZE9PIMQ'
                b'LTEXJXKTDREGVTPA9NDGGLQHTMGISGRAKSLYPGWMB', ),
        )
Esempio n. 12
0
    def test_generator_with_offset(self):
        """
    Creating a generator that starts at an offset greater than 0.
    """
        ag = AddressGenerator(self.seed_1)

        generator = ag.create_iterator(start=1, step=2)

        # noinspection SpellCheckingInspection
        self.assertEqual(
            next(generator),
            Address(
                b'DUOVVF9WCNAEOHHWUYUFSYOOWZPDVVD9JKFLQN9Z'
                b'DPAKKHSBKLTRFHD9UHIWGKSGAWCOMDG9GBPYISPWR', ),
        )

        # noinspection SpellCheckingInspection
        self.assertEqual(
            next(generator),
            Address(
                b'ZFIRBTDSLFAEDRAFORR9LETRUNRHTACYQPBV9VHR'
                b'EGVIGSKFQABGVLQPLFTAD9OHLPMAVKWBBDIKZSAOG', ),
        )
Esempio n. 13
0
    def test_generator(self):
        """
    Creating a generator.
    """
        ag = AddressGenerator(self.seed_2)

        generator = ag.create_iterator()

        # noinspection SpellCheckingInspection
        self.assertEqual(
            next(generator),
            Address(
                b'SZWZMYQYWGXWAAVQSDTIOFGTZP9PWIDDUHHNGRDP'
                b'RCGNSXRNYWBEZIORKNNLNZHJ9QYMFYZIJJ9RFPBJT', ),
        )

        # noinspection SpellCheckingInspection
        self.assertEqual(
            next(generator),
            Address(
                b'N9KY9HCT9VTI99FFRIIBHQZIJOVSLFVWPOIFSHWL'
                b'CCIVYLIDBKJLVQFYJNPIUNATUUCIRHUHNLFBCAXIY', ),
        )
Esempio n. 14
0
            return True
    print('False That')
    return False


api = Iota(
    'http://node06.iotatoken.nl:14265',
    'JH9XBWVXAJVXVRKRQZDPETYCCHREOHJADCBBQMOEFXFWXZEEMMYGLQ9KLJRSVU9FODWCR99EVWQWNSHW9'
)
addresstobeused = object()

generator = AddressGenerator(
    seed=
    b'JH9XBWVXAJVXVRKRQZDPETYCCHREOHJADCBBQMOEFXFWXZEEMMYGLQ9KLJRSVU9FODWCR99EVWQWNSHW9'
)
iterator = generator.create_iterator(start=0)
for address in iterator:
    if check_if_already_used(api, address):
        print('Inside true')
        addresstobeused = iterator.__next__().with_valid_checksum()
        break
    else:
        addresstobeused = address
        break

print(addresstobeused)
# print (api.were_addresses_spent_from(['FRGLJMPWMXIBNMGGLMPTYDIJCBZURAACTAIGFUZKEBZSJTULWZQLQGRTPTEEYFSMXFHNFQ9ILJLACLBZC'])['states'][0])

# accountData = api.get_account_data()
# bundles = accountData['bundles']
#