Created
September 2, 2021 23:19
-
-
Save adraffy/b4aaebfde3c85421a4f8b9d0aabd8b1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import struct | |
# chia stuff | |
from chia.wallet.derive_keys import master_sk_to_local_sk | |
from chia.plotting.util import parse_plot_info | |
from chia.types.blockchain_format.proof_of_space import ProofOfSpace | |
# see: chiapos/src/plotter_disk.hpp WriteHeader() | |
PLOT_H1 = struct.Struct('>19s32sBH') | |
PLOT_H2 = struct.Struct('>H') | |
def read_struct(fh, st): | |
return st.unpack_from(fh.read(st.size)) | |
def parse_plot_header(src): | |
with open(src, 'rb') as fh: | |
prefix, plot_id, k, desc_len = read_struct(fh, PLOT_H1) | |
desc = fh.read(desc_len) | |
memo_len, = read_struct(fh, PLOT_H2) | |
memo = fh.read(memo_len) | |
pool, farmer_public_key, local_master_sk = parse_plot_info(memo) | |
local_sk = master_sk_to_local_sk(local_master_sk) | |
plot_key = ProofOfSpace.generate_plot_public_key(local_sk.get_g1(), farmer_public_key) | |
return { | |
"plot_id": plot_id, | |
"k": k, | |
"desc": desc, | |
"memo": memo, | |
"pool": pool, | |
"farmer_public_key": farmer_public_key, | |
"plot_key": plot_key | |
} | |
def find_plot_files(v): | |
files = [] | |
for x in v: | |
if os.path.isdir(x): | |
files += find_plot_files([os.path.join(x, s) for s in os.listdir(x)]) | |
elif x.endswith('.plot'): | |
files.append(x) | |
return files | |
for f in find_plot_files(sys.argv[1:]): | |
header = parse_plot_header(f) | |
print([f, header['pool']]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment