pyblock/Python-BlockClock.py

186 lines
5.1 KiB
Python
Raw Normal View History

2020-05-10 21:11:21 -03:00
#Developer: Curly60e
#Python BlockClock its a clock of the Bitcoin blockchain.
2020-05-15 07:42:17 -03:00
#Version: 0.0.4
2020-05-10 21:11:21 -03:00
2020-05-06 16:34:55 -03:00
import os
import time as t
from art import *
2020-05-06 16:34:55 -03:00
def getblock(): # get access to bitcoin-cli with the command getblockchaininfo
bitcoincli = " getblockchaininfo"
os.system(path + bitcoincli)
def getblockcount(): # get access to bitcoin-cli with the command getblockcount
bitcoincli = " getblockcount"
os.system(path + bitcoincli)
def clear(): # clear the screen
2020-05-06 16:34:55 -03:00
os.system('cls' if os.name=='nt' else 'clear')
2020-05-10 21:11:21 -03:00
def getgenesis():
bitcoincli = " getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 0 | xxd -r -p | hexyl -n 256"
os.system(path + bitcoincli)
2020-05-10 21:11:21 -03:00
#-------------------From this line the program starts----------------------
def connected(info): # here we complete the connection to the external node
if info == "Y" or info == "y":
2020-05-13 19:47:58 -03:00
clear()
prt()
print("\nAdd your node information\n")
menuUserConn()
else:
2020-05-13 19:47:58 -03:00
menu()
def nodeinfo():
connected(input("Are you sure you want to connect to a node? Y/n: ")) # call 'connected' function to make the connection with the node information
2020-05-13 19:47:58 -03:00
def artist(): # here we convert the result of the command 'getblockcount' on a random art design
custom = input("Do you want random designs? Y/n: ")
if custom == "Y" or custom == "y":
while True:
clear()
2020-05-10 21:11:21 -03:00
design()
tmp()
else:
while True:
clear()
getblockcount()
tmp()
2020-05-10 21:11:21 -03:00
def design():
bitcoinclient = path + " getblockcount"
block = os.popen(str(bitcoinclient)).read() # 'getblockcount' convert to string
b = block
tprint(b, font="rnd-large")
2020-05-10 21:11:21 -03:00
def userconn():
option = input("Select option: ")
if option == "A" or option == "a":
user = input("USER@NODE: ")
s = input("Do you want to continue Y/n: ")
if s == "Y" or s == "y":
clear()
c = input("Do you want to see custom design? Y/n: ")
if c == "Y" or c == "y":
while True: # connection via ssh
clear()
sshb = "ssh " + user + " '" + "{}".format(path) + "'" + " getblockcount"
sshc = os.popen(str(sshb)).read()
sshd = sshc
tprint(sshd, font="rnd-large")
tmp()
else:
menu()
else:
while True: # connection via ssh
clear()
sshb = "ssh " + user + " '" + "{}".format(path) + "'" + " getblockchaininfo"
os.system(sshb)
tmp()
2020-05-10 21:11:21 -03:00
else:
2020-05-13 19:47:58 -03:00
menu()
elif option == "B" or option == "b":
user = input("USER@NODE: ")
while True:
2020-05-13 19:47:58 -03:00
clear()
prt()
sshb = "ssh " + user + " '" + "{}".format(path) + "'" + " getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 0 | xxd -r -p | hexyl -n 256"
2020-05-13 19:47:58 -03:00
os.system(sshb)
a = input("Do you want to return to the Node Connection Menu? Y/n: ")
if a == "Y" or a == "y":
menuUserConn()
else:
b = input("Do you want to exit? Y/n: ")
if b == "Y" or b == "y":
exit()
else:
menuUserConn()
2020-05-13 19:47:58 -03:00
tmp()
elif option == "C" or option == "c":
menu()
def tmp():
2020-05-10 18:34:30 -03:00
t.sleep(15)
2020-05-13 19:47:58 -03:00
def menu():
clear()
prt()
print("""\t\t
Python BlockClock Menu
Version 0.0.4
2020-05-13 19:47:58 -03:00
A. Connect to an external node through SSH
B. Show Blockchain information in your own node
C. Run BlockClock in your own node
D. Show the Genesis Block
E. Exit
2020-05-13 19:47:58 -03:00
\n\n""")
menuA(input("Select option: "))
def menuUserConn():
clear()
prt()
print("""\t\t
Python BlockClock Menu
Version 0.0.4
A. Run BlockClock in this external node
B. Show the Genesis Block
C. Return Main Menu
\n\n""")
userconn()
2020-05-13 19:47:58 -03:00
def menuA(menuS):
if menuS == "A" or menuS == "a":
2020-05-13 19:47:58 -03:00
nodeinfo()
elif menuS == "B" or menuS == "b":
2020-05-13 19:47:58 -03:00
while True:
clear()
getblock()
tmp()
elif menuS == "C" or menuS == "c":
2020-05-13 19:47:58 -03:00
artist()
elif menuS == "D" or menuS == "d":
clear()
prt()
getgenesis()
a = input("Do you want to return to the Main Menu? Y/n: ")
if a == "Y" or a == "y":
menu()
else:
b = input("Do you want to exit? Y/n: ")
if b == "Y" or b == "y":
exit()
else:
menu()
elif menuS == "E" or menuS == "e":
exit()
2020-05-13 19:47:58 -03:00
def prt():
tprint("BlockClock", font="rnd-large") # random title design
while True: # Loop
clear() # call clear function that clears the screen
2020-05-13 19:47:58 -03:00
prt()
print("Welcome to Python BlockClock\n\n")
path = input("Insert the Path to Bitcoin-Cli: ") # path to the bitcoin-cli
2020-05-13 19:47:58 -03:00
clear()
menu()