예제 #1
0
파일: keygen.py 프로젝트: starkovalera/lit
def generate_matching_address(prefix, cores='all'):  # pragma: no cover

    for char in prefix:
        if char not in BASE58_ALPHABET:
            raise ValueError('{} is an invalid base58 encoded '
                             'character.'.format(char))

    if not prefix:
        return generate_key_address_pair()
    elif not prefix.startswith('1'):
        prefix = '1' + prefix

    available_cores = cpu_count()

    if cores == 'all':
        cores = available_cores
    elif 0 < int(cores) <= available_cores:
        cores = int(cores)
    else:
        cores = 1

    counter = Value('i')
    match = Event()
    queue = Queue()

    workers = []
    for _ in range(cores):
        workers.append(
            Process(
                target=generate_key_address_pairs,
                args=(prefix, counter, match, queue)
            )
        )

    for worker in workers:
        worker.start()

    keys_generated = 0
    while True:
        time.sleep(1)
        current = counter.value
        if current == keys_generated:
            if current == 0:
                continue
            break
        keys_generated = current
        s = 'Keys generated: {}\r'.format(keys_generated)
        sys.stdout.write(s)
        sys.stdout.flush()

    private_key, address = queue.get()
    print('\n\n'
          'WIF: {}\n'
          'Address: {}'.format(bytes_to_wif(private_key), address))
예제 #2
0
 def test_compressed_testnet(self):
     assert bytes_to_wif(
         PRIVATE_KEY_BYTES, version='test', compressed=True
     ) == WALLET_FORMAT_COMPRESSED_TEST
예제 #3
0
 def test_compressed(self):
     assert bytes_to_wif(PRIVATE_KEY_BYTES, compressed=True) == WALLET_FORMAT_COMPRESSED_MAIN
예제 #4
0
 def test_testnet(self):
     assert bytes_to_wif(PRIVATE_KEY_BYTES, version='test') == WALLET_FORMAT_TEST
예제 #5
0
 def test_mainnet(self):
     assert bytes_to_wif(PRIVATE_KEY_BYTES) == WALLET_FORMAT_MAIN
예제 #6
0
 def to_wif(self):
     return bytes_to_wif(self._pk.secret,
                         version='main',
                         compressed=self.is_compressed())
예제 #7
0
파일: keygen.py 프로젝트: starkovalera/lit
def generate_key_address_pair():  # pragma: no cover
    private_key = ECPrivateKey()
    address = public_key_to_address(private_key.public_key.format())
    return bytes_to_wif(private_key.secret), address