-2

I am trying to make a loop so that the script generates hash constantly

from bitcoin import *
import os
import hashlib
import base58

while True:
    priv =  random_key()
    pubkey = privtopub(priv)
    compress_pubkey = False
    
 
    if (compress_pubkey):
    if (ord(pubkey[-2:].decode('hex')) % 2 == 0):
        pubkey_compressed = '02'
    else:
        pubkey_compressed = '03'
    pubkey_compressed += pubkey[2:66]
    hex_str = bytearray.fromhex(pubkey_compressed)
    else:
        hex_str = bytearray.fromhex(pubkey)
 
key_hash = hash160(hex_str)

I am using Python 3 and I am getting the error:

    if (ord(pubkey[-2:].decode('hex')) % 2 == 0):
     ^
IndentationError: expected an indented block
FOLBY
  • 11
  • 1
  • 3
  • TL:DR Select this if and the line below and press TAB on your keyboard. Python needs indentation for code inside an if block – solid.py Sep 13 '20 at 09:09

1 Answers1

0

You are getting an error because first if statement does not have anything in it, you can use pass keyword to remove an error or remove the if statement if you don't need it(see comments in code)

from bitcoin import *
import os
import hashlib
import base58

while True:
    priv =  random_key()
    pubkey = privtopub(priv)
    compress_pubkey = False
    
 
    if (compress_pubkey): #error
        pass #add something hereor add pass keyword to remove error
    if (ord(pubkey[-2:].decode('hex')) % 2 == 0):
        pubkey_compressed = '02'
    else:
        pubkey_compressed = '03'
        hex_str = bytearray.fromhex(pubkey) # you can't have more than one else
    pubkey_compressed += pubkey[2:66]
    hex_str = bytearray.fromhex(pubkey_compressed)
 
key_hash = hash160(hex_str)
Sarthak Kumar
  • 304
  • 5
  • 16