Python Forum
Hi all any help with this python code please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hi all any help with this python code please
#1
Hi all hope every one is very well, its been a very long time since i done any programming over 10
years ago atleast, im looking to make a application its a bitcoin wallet, but i want to learn a few steps
before i dive deep into the whole btc thing, i want to try and familiarize myself with python again.

I was wondering if any one could possibly point out the obvious im looking at this code below and was
wondering if any one would be able to help me implement a main.loop() of some type and also how can
i make decisions based on the value returned if the btc address in the below code is not an actual
address it will print false to the interpreter window, and true if the string is a valid bitcoin address

what i would like to do for starters is have the code loop without using too much memory when i tried
this last night it was just eating my cpu 70-80% my implementation of looping the bitcoin checking
function over and over again seemed to bog my system down allot.

What im hoping to learn and implement from this code a main loop when either and exception is hit
or if the value returned false i would like it too print "1" and when false is returned i would like
it too go back to the beginning of the start of the btc check function and keep looping until a valid
address is found once it is found print "1".

I did manage to get a working version last night but really did eat allot of cpu i was wondering if any
one would be able to implement the above into this code just as an example, Mine was very poor and just
ate resources.

Or even something simple like if True is returned do this if false is returned do that ?Any help would be very much appreciated.It could be the way its structured but after 2hrs of messing around i had a working example
was embarrassing lol but it worked but just sat and ate cpu.

from hashlib import sha256
 
digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
 
def decode_base58(bc, length):
    n = 0
    for char in bc:
        n = n * 58 + digits58.index(char)
    return n.to_bytes(length, 'big')
def check_bc(bc):
    try:
        bcbytes = decode_base58(bc, 25)
        return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digest()[:4]
    except Exception:
        return False
 
print(check_bc('1AGNa15ZQXAZUgFiqJ3i7Z2DPU2J6hW62i'))
print(check_bc("17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j"))
Or if some one could run through the code with my too better understand what is going on
thank you in advance.obviously this takes two hardcoded strings returns true for the correct
btc address and false is address is not a btc address, and the exception or even none gets returned
if there is an issue.Any help would be Vmuch appreciated.

It could be the way its formatted in the above example as to why im struggling to get it two do A if true
is returned and B if false is returned and if true loop back to the beginning again.

Credit to rosettacode.org for the above code.
Reply


Messages In This Thread
Hi all any help with this python code please - by BooohWhooo2018 - Mar-21-2018, 03:35 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020