Files
carrotcoin/list-block-messages.py
2025-12-13 23:41:07 +01:00

38 lines
1.1 KiB
Python
Executable File

#! /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(293)
if len(block) != 293:
break
if block[0] == 3:
# Reveal Transaction, skip the associated data
f.read(5376)
timestamp = int.from_bytes(block[245:253], "big")
time_info = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(timestamp))
message = prepare_message(block[149:181])
print(f"[{time_info}] {message}")
except FileNotFoundError:
print("Found no blockchain file", file=sys.stderr)
exit(1)
if __name__ == '__main__':
main()