2020-05-10 21:11:21 -03:00
#Developer: Curly60e
#Python BlockClock its a clock of the Bitcoin blockchain.
2020-05-20 20:32:31 -03:00
#Version: 0.0.8
2020-05-10 21:11:21 -03:00
2020-05-06 16:34:55 -03:00
import os
2020-05-16 00:21:47 -03:00
import os . path
2020-05-06 16:34:55 -03:00
import time as t
2020-05-16 00:21:47 -03:00
import pickle
2020-05-20 20:32:31 -03:00
from donation import *
2020-05-08 08:37:26 -03:00
from art import *
2020-05-18 22:25:55 -03:00
from logos import *
2020-05-06 16:34:55 -03:00
2020-05-09 18:22:43 -03:00
2020-05-08 08:37:26 -03:00
def getblock ( ) : # get access to bitcoin-cli with the command getblockchaininfo
2020-05-07 10:59:47 -03:00
bitcoincli = " getblockchaininfo "
os . system ( path + bitcoincli )
2020-05-08 08:37:26 -03:00
def getblockcount ( ) : # get access to bitcoin-cli with the command getblockcount
2020-05-07 10:59:47 -03:00
bitcoincli = " getblockcount "
2020-05-06 17:04:20 -03:00
os . system ( path + bitcoincli )
2020-05-08 08:37:26 -03:00
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
2020-05-16 00:21:47 -03:00
def getgenesis ( ) : # get and decode Genesis block
2020-05-15 07:41:42 -03:00
bitcoincli = " getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 0 | xxd -r -p | hexyl -n 256 "
os . system ( path + bitcoincli )
2020-05-18 22:25:55 -03:00
def console ( ) : # get into the console from bitcoin-cli
print ( " \t This is Bitcoin-cli ' s console. Type your respective commands you want to display. \n \n " )
while True :
cle = input ( " console $>: " )
lsd = os . popen ( str ( path + " " + cle ) ) . read ( )
print ( lsd )
2020-05-10 21:11:21 -03:00
#-------------------From this line the program starts----------------------
2020-05-06 17:04:20 -03:00
2020-05-09 18:22:43 -03:00
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 ( " \n Add your node information \n " )
2020-05-15 07:41:42 -03:00
menuUserConn ( )
2020-05-09 18:22:43 -03:00
else :
2020-05-13 19:47:58 -03:00
menu ( )
2020-05-15 07:41:42 -03:00
2020-05-09 18:22:43 -03:00
2020-05-16 00:21:47 -03:00
def nodeinfo ( ) :
print ( " \n WARNING! This is not a safe method of connection. The best method is doing this locally. \n " )
connected ( input ( " WARNING! 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
2020-05-09 18:22:43 -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 :
2020-05-16 12:51:30 -03:00
try :
clear ( )
close ( )
design ( )
tmp ( )
except ( KeyboardInterrupt , SystemExit ) :
menu ( )
raise
2020-05-07 10:59:47 -03:00
else :
2020-05-09 18:22:43 -03:00
while True :
2020-05-16 12:51:30 -03:00
try :
clear ( )
close ( )
getblockcount ( )
tmp ( )
except ( KeyboardInterrupt , SystemExit ) :
menu ( )
raise
def close ( ) :
2020-05-18 22:25:55 -03:00
print ( " <<< Back to the Main Menu Press Control + C. \n \n " )
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
2020-05-15 07:41:42 -03:00
tprint ( b , font = " rnd-large " )
2020-05-10 21:11:21 -03:00
2020-05-16 00:21:47 -03:00
#------------------------------------------- SSH connection external node --------------------------------------------
def userconn ( ) : # All the connection to a remote node
2020-05-15 07:41:42 -03:00
option = input ( " Select option: " )
2020-05-16 00:21:47 -03:00
if option == " A " or option == " a " : # Execution of the secondary Menu menuUserConn
2020-05-15 07:41:42 -03:00
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 " :
2020-05-16 12:51:30 -03:00
while True : # connection via ssh
try :
clear ( )
close ( )
sshb = " ssh " + user + " ' " + " {} " . format ( path ) + " ' " + " getblockcount "
sshc = os . popen ( str ( sshb ) ) . read ( )
sshd = sshc
tprint ( sshd , font = " rnd-large " )
tmp ( )
except ( KeyboardInterrupt , SystemExit ) :
menuUserConn ( )
raise
2020-05-15 07:41:42 -03:00
else :
2020-05-16 00:21:47 -03:00
menu ( )
2020-05-15 07:41:42 -03:00
else :
while True : # connection via ssh
2020-05-16 12:51:30 -03:00
try :
clear ( )
close ( )
sshb = " ssh " + user + " ' " + " {} " . format ( path ) + " ' " + " getblockchaininfo "
os . system ( sshb )
tmp ( )
except ( KeyboardInterrupt , SystemExit ) :
menuUserConn ( )
raise
2020-05-10 21:11:21 -03:00
else :
2020-05-16 00:21:47 -03:00
menu ( )
elif option == " B " or option == " b " : # Decode Block 0 on HEX for external node
2020-05-15 07:41:42 -03:00
user = input ( " USER@NODE: " )
while True :
2020-05-13 19:47:58 -03:00
clear ( )
2020-05-15 07:41:42 -03:00
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 )
2020-05-15 07:41:42 -03:00
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 :
2020-05-16 00:21:47 -03:00
menuUserConn ( )
2020-05-13 19:47:58 -03:00
tmp ( )
2020-05-16 00:21:47 -03:00
elif option == " C " or option == " c " : # Block decoder to HEX for external node
readHexBlockSsh ( )
while True :
m = input ( " Do you want to continue decoding? Y/n: " )
if m == " Y " or m == " y " :
readHexBlockSsh ( )
else :
menuUserConn ( )
elif option == " D " or option == " d " :
2020-05-16 12:51:30 -03:00
readHexTXSsh ( )
while True :
m = input ( " Do you want to continue decoding? Y/n: " )
if m == " Y " or m == " y " :
readHexTXSsh ( )
else :
menuUserConn ( )
2020-05-18 22:25:55 -03:00
elif option == " R " or option == " r " :
2020-05-15 07:41:42 -03:00
menu ( )
2020-05-16 12:51:30 -03:00
2020-05-16 00:21:47 -03:00
#------------------------------------------- End SSH connection external node --------------------------------------------
2020-05-07 10:59:47 -03:00
2020-05-16 00:21:47 -03:00
#--------------------------------- Hex Block Decoder Functions -------------------------------------
def readHexBlock ( ) : # Hex Decoder using Hexyl on local node
hexa = input ( " Add the Block Hash you want to decode: " )
blocknumber = input ( " Add the Block number: " )
decodeBlock = path + " getblock {} {} " . format ( hexa , blocknumber ) + " | xxd -r -p | hexyl -n 256 "
os . system ( decodeBlock )
def readHexBlockSsh ( ) : # Hex Decoder using Hexyl on an external node
user = input ( " USER@NODE: " )
clear ( )
prt ( )
hexa = input ( " Add the Block Hash you want to decode: " )
blocknumber = input ( " Add the Block number: " )
decodeBlock = " ssh " + user + " ' " + " {} " . format ( path ) + " ' " + " getblock {} {} " . format ( hexa , blocknumber ) + " | xxd -r -p | hexyl -n 256 "
clear ( )
prt ( )
os . system ( decodeBlock )
2020-05-16 12:51:30 -03:00
def readHexTx ( ) : # Hex Decoder using Hexyl on an external node
hexa = input ( " Add the Transaction ID. you want to decode: " )
decodeTX = path + " getrawtransaction {} " . format ( hexa ) + " | xxd -r -p | hexyl -n 256 "
os . system ( decodeTX )
def readHexTXSsh ( ) : # Hex Decoder using Hexyl on an external node
user = input ( " USER@NODE: " )
clear ( )
prt ( )
hexa = input ( " Add the Transaction ID. you want to decode: " )
decodeTX = " ssh " + user + " ' " + " {} " . format ( path ) + " ' " + " getrawtransaction {} " . format ( hexa ) + " | xxd -r -p | hexyl -n 256 "
clear ( )
prt ( )
os . system ( decodeTX )
2020-05-16 00:21:47 -03:00
#--------------------------------- End Hex Block Decoder Functions -------------------------------------
#--------------------------------- Menu section -----------------------------------
def menu ( ) : #Main Menu
2020-05-13 19:47:58 -03:00
clear ( )
prt ( )
print ( """ \t \t
Python BlockClock Menu
2020-05-20 20:32:31 -03:00
Version 0.0 .8
2020-05-13 19:47:58 -03:00
2020-05-16 12:51:30 -03:00
A . Run BlockClock in your own node
2020-05-13 19:47:58 -03:00
B . Show Blockchain information in your own node
2020-05-16 12:51:30 -03:00
C . Show the Genesis Block
D . Decode in HEX any block
E . Decode in HEX any transaction
F . Connect to an external node through SSH
2020-05-18 22:30:54 -03:00
G . Advanced
2020-05-20 20:32:31 -03:00
X . Donate
2020-05-18 22:25:55 -03:00
Q . Exit
2020-05-13 19:47:58 -03:00
\n \n """ )
menuA ( input ( " Select option: " ) )
2020-05-16 00:21:47 -03:00
def menuUserConn ( ) : #Menu before connection over ssh
2020-05-15 07:41:42 -03:00
clear ( )
prt ( )
print ( """ \t \t
2020-05-18 22:25:55 -03:00
Python BlockClock External Node Menu
2020-05-20 20:32:31 -03:00
Version 0.0 .8
2020-05-15 07:41:42 -03:00
A . Run BlockClock in this external node
B . Show the Genesis Block
2020-05-16 00:21:47 -03:00
C . Decode in HEX any block
2020-05-16 12:51:30 -03:00
D . Decode in HEX any transaction
2020-05-18 22:25:55 -03:00
R . Return Main Menu
2020-05-15 07:41:42 -03:00
\n \n """ )
userconn ( )
2020-05-18 22:25:55 -03:00
def advanceMenu ( ) :
clear ( )
prt ( )
print ( """ \t \t
Python BlockClock Advance Menu
2020-05-20 20:32:31 -03:00
Version 0.0 .8
2020-05-18 22:25:55 -03:00
A . Bitconi - cli Console
B . FunB
2020-05-20 20:32:31 -03:00
C . Show QR from a Bitcoin Address
2020-05-18 22:25:55 -03:00
R . Return Main Menu
\n \n """ )
menuB ( input ( " Select option: " ) )
2020-05-15 07:41:42 -03:00
2020-05-20 20:32:31 -03:00
def dnt ( ) :
clear ( )
prt ( )
print ( """ \t \t
Python BlockClock Advance Menu
Version 0.0 .8
A . PayNym
B . Bitcoin Address
C . Lightning Network
D . Return Main Menu
\n \n """ )
menuC ( input ( " Select option: " ) )
2020-05-16 00:21:47 -03:00
#--------------------------------- End Menu section -----------------------------------
2020-05-16 12:51:30 -03:00
#--------------------------------- Main Menu execution --------------------------------
2020-05-16 00:21:47 -03:00
def menuA ( menuS ) : #Execution of the Main Menu options
2020-05-15 07:41:42 -03:00
if menuS == " A " or menuS == " a " :
2020-05-16 12:51:30 -03:00
artist ( )
2020-05-15 07:41:42 -03:00
elif menuS == " B " or menuS == " b " :
2020-05-13 19:47:58 -03:00
while True :
2020-05-16 12:51:30 -03:00
try :
clear ( )
close ( )
getblock ( )
tmp ( )
except ( KeyboardInterrupt , SystemExit ) :
menu ( )
raise
2020-05-15 07:41:42 -03:00
elif menuS == " C " or menuS == " c " :
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 ( )
2020-05-16 12:51:30 -03:00
elif menuS == " D " or menuS == " d " :
2020-05-16 00:21:47 -03:00
clear ( )
prt ( )
readHexBlock ( )
while True :
r = input ( " Do you want to continue decoding? Y/n: " )
if r == " Y " or r == " y " :
clear ( )
prt ( )
readHexBlock ( )
else :
2020-05-16 12:51:30 -03:00
menu ( )
elif menuS == " E " or menuS == " e " :
clear ( )
prt ( )
readHexTx ( )
while True :
r = input ( " Do you want to continue decoding? Y/n: " )
if r == " Y " or r == " y " :
clear ( )
prt ( )
readHexTx ( )
else :
menu ( )
2020-05-16 00:21:47 -03:00
elif menuS == " F " or menuS == " f " :
2020-05-16 12:51:30 -03:00
nodeinfo ( )
2020-05-18 22:25:55 -03:00
elif menuS == " Q " or menuS == " q " :
2020-05-15 07:41:42 -03:00
exit ( )
2020-05-18 22:25:55 -03:00
elif menuS == " G " or menuS == " g " :
2020-05-20 20:32:31 -03:00
advanceMenu ( )
elif menuS == " X " or menuS == " x " :
dnt ( )
2020-05-18 22:25:55 -03:00
def menuB ( menuR ) :
if menuR == " A " or menuR == " a " :
while True :
try :
clear ( )
prt ( )
close ( )
console ( )
t . sleep ( 5 )
except ( KeyboardInterrupt , SystemExit ) :
advanceMenu ( )
raise
elif menuR == " B " or menuR == " b " :
while True :
try :
clear ( )
prt ( )
close ( )
logoA ( )
tmp ( )
clear ( )
prt ( )
close ( )
logoB ( )
tmp ( )
clear ( )
prt ( )
close ( )
logoC ( )
tmp ( )
except ( KeyboardInterrupt , SystemExit ) :
advanceMenu ( )
raise
2020-05-20 20:32:31 -03:00
elif menuR == " C " or menuR == " c " :
while True :
try :
clear ( )
prt ( )
close ( )
decodeQR ( )
t . sleep ( 50 )
except ( KeyboardInterrupt , SystemExit ) :
advanceMenu ( )
raise
2020-05-18 22:25:55 -03:00
elif menuR == " R " or menuR == " r " :
menu ( )
2020-05-20 20:32:31 -03:00
def menuC ( menuO ) :
if menuO == " A " or menuO == " a " :
try :
clear ( )
prt ( )
close ( )
donationPN ( )
t . sleep ( 50 )
except ( KeyboardInterrupt , SystemExit ) :
menu ( )
raise
elif menuO == " B " or menuO == " b " :
try :
clear ( )
prt ( )
close ( )
donationAddr ( )
t . sleep ( 50 )
except ( KeyboardInterrupt , SystemExit ) :
menu ( )
raise
elif menuO == " C " or menuO == " c " :
try :
clear ( )
prt ( )
close ( )
donationLN ( )
t . sleep ( 50 )
except ( KeyboardInterrupt , SystemExit ) :
menu ( )
raise
elif menuO == " D " or menuO == " d " :
menu ( )
2020-05-16 12:51:30 -03:00
#--------------------------------- End Main Menu execution --------------------------------
2020-05-13 19:47:58 -03:00
def prt ( ) :
tprint ( " BlockClock " , font = " rnd-large " ) # random title design
2020-05-16 00:21:47 -03:00
def tmp ( ) :
t . sleep ( 15 )
2020-05-13 19:47:58 -03:00
2020-05-16 00:21:47 -03:00
2020-05-09 18:22:43 -03:00
while True : # Loop
clear ( ) # call clear function that clears the screen
2020-05-16 00:21:47 -03:00
path = " "
if os . path . isfile ( ' bclock.conf ' ) : # Check if the file 'bclock.conf' is in the same folder
pathv = pickle . load ( open ( " bclock.conf " , " rb " ) ) # Load the file 'bclock.conf'
path = pathv # Copy the variable pathv to 'path'
clear ( )
menu ( )
else :
prt ( )
print ( " Welcome to Python BlockClock \n \n " )
path = input ( " Insert the Path to Bitcoin-Cli: " ) # path to the bitcoin-cli
pickle . dump ( path , open ( " bclock.conf " , " wb " ) ) # Save the file 'bclock.conf'
clear ( )
menu ( )
2020-05-13 19:47:58 -03:00