Add a script to show all block messages
This commit is contained in:
34
list-block-messages.py
Executable file
34
list-block-messages.py
Executable file
@@ -0,0 +1,34 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
import sys, time
|
||||
|
||||
def prepare_message(bin_message):
|
||||
length = 32
|
||||
while length > 0 and bin_message[length-1] == 0:
|
||||
length -= 1
|
||||
bin_message = bin_message[0:length]
|
||||
for byte in bin_message:
|
||||
if byte < 32:
|
||||
return "<some binary blob>"
|
||||
try:
|
||||
return bin_message.decode()
|
||||
except UnicodeDecodeError:
|
||||
return "<some binary blob>"
|
||||
|
||||
def main():
|
||||
try:
|
||||
with open("blockchain", "rb") as f:
|
||||
while True:
|
||||
block = f.read(292)
|
||||
if len(block) != 292:
|
||||
break
|
||||
timestamp = int.from_bytes(block[244:252], "big")
|
||||
time_info = time.strftime("%d.%m.%Y %H:%M.%S", time.localtime(timestamp))
|
||||
message = prepare_message(block[148:180])
|
||||
print(f"[{time_info}] {message}")
|
||||
except FileNotFoundError:
|
||||
print("Found no blockchain file", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user