From f8ddc348eb419772a829ab8d1c7e1d47dfcafd1b Mon Sep 17 00:00:00 2001 From: SK0M0R0H Date: Fri, 11 Aug 2023 09:00:28 +0300 Subject: [PATCH] update input format, add instructions to readme #46 --- storage-proof-app/README.md | 9 +++++++++ storage-proof-app/mock_data.py | 14 +++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/storage-proof-app/README.md b/storage-proof-app/README.md index 873e12d..a5b6162 100644 --- a/storage-proof-app/README.md +++ b/storage-proof-app/README.md @@ -68,3 +68,12 @@ Historical data for blocks produced before Capella update is located in 'histori The newer data is located in `historical_summaries`. More information about Beacon State structure can be found [here](https://eth2book.info/capella/part3/containers/state/). +# How to use it? + +**To generate test data about account on Consensus Layer** + +Run +``` +python3 mock_data.py --output +``` + diff --git a/storage-proof-app/mock_data.py b/storage-proof-app/mock_data.py index 73f8285..0de2381 100644 --- a/storage-proof-app/mock_data.py +++ b/storage-proof-app/mock_data.py @@ -2,14 +2,22 @@ import json import sys import random +import argparse def slice_into_low_high(digest): - low = int.from_bytes(digest[:16], 'big') - high = int.from_bytes(digest[16:], 'big') + low = str(int.from_bytes(digest[:16], 'big')) + high = str(int.from_bytes(digest[16:], 'big')) return [low, high] if __name__ == "__main__": + parser = argparse.ArgumentParser( + prog='Dummy data generator for Consensus Layer Storage Proof', + description='Provides a Merkle path for an account into a state root from Consensus Layer.') + parser.add_argument('--output', help="Output file path", default="output.json") + + args = parser.parse_args() + index = random.randint(1, 16) state, tree = get_random_state() merkle_path = tree.prove_inclusion(index) @@ -17,6 +25,6 @@ def slice_into_low_high(digest): root = state.state_root[0] print(f"Preparing Merkle path for index {index - 1} and state root {root.hex()}") input = [{"array" : [slice_into_low_high(node) for node in merkle_path.path]}, {"vector": slice_into_low_high(leaf)}, {"vector" : slice_into_low_high(root)}] - with open("path.inp", 'w') as f: + with open(args.output, 'w') as f: sys.stdout = f print(json.dumps(input, indent=4))