diff --git a/README.md b/README.md index 49b4641..15f7b8a 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,14 @@ To generate the wasm artifacts that can be attached to the governance proposal, earhtly +build ``` -You can install `earthly` following the official guide [here](https://earthly.dev/get-earthly). \ No newline at end of file +You can install `earthly` following the official guide [here](https://earthly.dev/get-earthly). + +# How to generate a proposal +Use the python script `build_proposal.py` inside the build directory to build any of the 5 phases proposals: +``` +python3 builder/build_proposal.py -d -o +``` +To build the phase1 to phase2 proposal: +``` +python3 builder/build_proposal.py -d builder/parameters/block-party.json -o proposal.json +``` \ No newline at end of file diff --git a/builder/build_proposal.py b/builder/build_proposal.py new file mode 100644 index 0000000..7ac1f57 --- /dev/null +++ b/builder/build_proposal.py @@ -0,0 +1,127 @@ +from typing import Dict +from datetime import datetime +import argparse +import json +import os + +GOVERNANCE_GENESIS_PARAMETERS = { + "max_proposal_code_size": 300000, + "min_proposal_voting_period": 3, + "max_proposal_period": 27, + "max_proposal_content_size": 10000, + "min_proposal_grace_epochs": 2, + "max_proposal_latency": 30 +} + +def validate_data(data: Dict[str, str]) -> bool: + start_epoch = data['voting_start_epoch'] + end_epoch = data['voting_end_epoch'] + activation_epoch = data['grace_epoch'] + proposal_content = len(json.dumps(data)) + wasm_size = os.path.getsize(data['wasm_path']) / 1024 # in kibibytes + + if end_epoch <= start_epoch or activation_epoch <= end_epoch: + print("invalid epochs") + return False + + if end_epoch - start_epoch < GOVERNANCE_GENESIS_PARAMETERS['min_proposal_voting_period']: + print("invalid start epoch") + return False + + if activation_epoch - end_epoch < GOVERNANCE_GENESIS_PARAMETERS['min_proposal_grace_epochs']: + print("invalid activation epoch") + return False + + if proposal_content > GOVERNANCE_GENESIS_PARAMETERS['max_proposal_content_size']: + print("invalid content") + return False + + if wasm_size > GOVERNANCE_GENESIS_PARAMETERS['max_proposal_code_size']: + print("invalid wasm") + return False + + return True + + + +def build_proposal( + content: Dict[str, str], + author: str, + start_epoch: int, + end_epoch: int, + activation_epoch: int, + data_path: str) -> str: + return { + "proposal": { + "content": content, + "author": author, + "voting_start_epoch": start_epoch, + "voting_end_epoch": end_epoch, + "grace_epoch": activation_epoch + }, + "data": list(open(data_path, "rb").read()) + } + +def build_proposal_content( + title: str, + authors: str, + discussions_to: str, + licence: str, + abstract: str, + motivation: str, + details: str, + requires: str, +) -> Dict[str, str]: + return { + "title": title, + "authors": authors, + "discussions-to": discussions_to, + "created": datetime.now().isoformat(), + "license": licence, + "abstract": abstract, + "motivation": motivation, + "details": details, + "requires": requires + } + +def main(data_path: str, output_path: str): + data = json.load(open(data_path, 'r')) + + validation_res = validate_data(data) + + if not validation_res: + print("Invalid proposal data") + exit(1) + + proposal_content = build_proposal_content( + data["title"], + data["authors"], + data["discussions-to"], + data["license"], + data["abstract"], + data["motivation"], + data["details"], + data["requires"] + ) + + proposal = build_proposal( + proposal_content, + data["author"], + data["voting_start_epoch"], + data["voting_end_epoch"], + data["grace_epoch"], + data["wasm_path"], + ) + + with open(output_path, 'w') as f: + json.dump(proposal, f, ensure_ascii=False, indent=4) + + +if __name__=="__main__": + parser = argparse.ArgumentParser() + parser.add_argument('-d', "--proposal-data-path", help="Path to the json file describing the proposal data", required=True) + parser.add_argument('-o', "--output", help="Path to the generate proposal", required=True) + + args = parser.parse_args() + + main(args.proposal_data_path, args.output) \ No newline at end of file diff --git a/builder/parameters/block-party.json b/builder/parameters/block-party.json new file mode 100644 index 0000000..ee0351e --- /dev/null +++ b/builder/parameters/block-party.json @@ -0,0 +1,15 @@ +{ + "title": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eget ex id erat interdum dictum vel ac libero. Cras vitae porta velit, vel interdum odio. Phasellus quis sem finibus, luctus neque in, vestibulum lectus. Maecenas at nulla dapibus, condimentum sem vitae, ullamcorper nisi. Pellentesque tristique tempus tellus, nec sollicitudin velit facilisis at. Vivamus porta nibh sit amet eros tempor, vestibulum lacinia est pulvinar. Maecenas libero mauris, blandit sit amet tempus in, elementum quis nunc. ", + "authors": "Bob The Builer ", + "discussions-to": "www.bob-the-builder.forum.rock", + "license": "SPQR", + "abstract": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", + "motivation": " Vivamus eget ex id erat interdum dictum vel ac libero.", + "details": "Phasellus quis sem finibus, luctus neque in, vestibulum lectus.", + "requires": "-1", + "author": "author", + "voting_start_epoch": 5, + "voting_end_epoch": 10, + "grace_epoch": 12, + "wasm_path": "artifacts/block_party.wasm" +} \ No newline at end of file