diff --git a/src/bt_auto_dumper/_v2/__main__.py b/src/bt_auto_dumper/_v2/__main__.py index 0ac79e8..b1a0676 100644 --- a/src/bt_auto_dumper/_v2/__main__.py +++ b/src/bt_auto_dumper/_v2/__main__.py @@ -20,6 +20,15 @@ def main(apiver: str | None = None): apiver = apiver or pathlib.Path(__file__).parent.name parser = argparse.ArgumentParser(description=f"BT Auto Dumper CLI {apiver}") parser.add_argument("--note", help="Comment or note for the operation", type=str, default="") + parser.add_argument("subnet_identifier", help="Subnet Identifier", type=str) + parser.add_argument("autovalidator_address", help="AutoValidator Address", type=str) + parser.add_argument( + "subnet_realm", + help="Subnet Realm", + type=str, + choices=["testnet", "mainnet", "devnet"], + default="mainnet", + ) parser.add_argument("--set-autovalidator-address", help="Set a new autovalidator address", type=str) parser.add_argument("--set-codename", help="Set a new Subnet Identifier codename", type=str) @@ -46,19 +55,21 @@ def main(apiver: str | None = None): ) print(f"Configuration updated successfully at {config_path}") - autovalidator_address, subnet_identifier = load_config(config_path=config_path) - dump_and_upload(subnet_identifier, autovalidator_address, args.note) + if not (subnet_identifier := args.subnet_identifier) or not (autovalidator_address := args.autovalidator_address): + autovalidator_address, subnet_identifier = load_config(config_path=config_path) + dump_and_upload(subnet_identifier, args.subnet_realm, autovalidator_address, args.note) -def dump_and_upload(subnet_identifier: str, autovalidator_address: str, note: str): +def dump_and_upload(subnet_identifier: str, subnet_realm: str, autovalidator_address: str, note: str): """ Dump and upload the output of the commands to the AutoValidator Args: subnet_identifier: Subnet Identifier + subnet_realm: Subnet Realm autovalidator_address: AutoValidator Address note: Comment or note for the operation Example: - dump_and_upload("computehorde", "http://localhost:8000", "Test") + dump_and_upload("computehorde", "mainnet", "http://localhost:8000", "Test") """ subnets = { "computehorde": ["echo 'Mainnet Command 1'", "echo 'Mainnet Command 2'"], @@ -67,6 +78,7 @@ def dump_and_upload(subnet_identifier: str, autovalidator_address: str, note: st wallet = bt.wallet(name="validator", hotkey="validator-hotkey") normalized_subnet_identifier = re.sub(r"[_\-.]", "", str.lower(subnet_identifier)) + commands = {} if normalized_subnet_identifier in subnets: commands = {normalized_subnet_identifier: subnets[normalized_subnet_identifier]} @@ -87,10 +99,12 @@ def dump_and_upload(subnet_identifier: str, autovalidator_address: str, note: st with zipfile.ZipFile(zip_filename, "w") as zipf: for file in output_files: zipf.write(file) - send_to_autovalidator(zip_filename, wallet, autovalidator_address, note, normalized_subnet_identifier) + send_to_autovalidator(zip_filename, wallet, autovalidator_address, note, normalized_subnet_identifier, subnet_realm) -def make_signed_request(method: str, url: str, headers: dict, file_path: str, wallet: bt.wallet) -> requests.Response: +def make_signed_request( + method: str, url: str, headers: dict, file_path: str, wallet: bt.wallet, subnet_realm: str +) -> requests.Response: """ Make a signed request to the AutoValidator Args: @@ -112,6 +126,7 @@ def make_signed_request(method: str, url: str, headers: dict, file_path: str, wa """ headers["Nonce"] = str(time.time()) headers["Hotkey"] = wallet.hotkey.ss58_address + headers["Realm"] = subnet_realm files = {"file": open(file_path, "rb")} file = files.get("file") file_content = b"" @@ -130,7 +145,12 @@ def make_signed_request(method: str, url: str, headers: dict, file_path: str, wa def send_to_autovalidator( - zip_filename: str, wallet: bt.wallet, autovalidator_address: str, note: str, subnet_identifier: str + zip_filename: str, + wallet: bt.wallet, + autovalidator_address: str, + note: str, + subnet_identifier: str, + subnet_realm: str, ): """ Send the dump file to the AutoValidator @@ -149,7 +169,7 @@ def send_to_autovalidator( "Note": note, "SubnetID": subnet_identifier, } - response = make_signed_request("POST", url, headers, zip_filename, wallet) + response = make_signed_request("POST", url, headers, zip_filename, wallet, subnet_realm) if response.status_code == 201: print("File successfully uploaded and resource created.") elif response.status_code == 200: