From dc87181e0a4f50dd079367dfb587716c60689b20 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Sat, 30 Nov 2024 11:46:55 +0300 Subject: [PATCH] parse json from ge-publish --- parse.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/parse.py b/parse.py index 3bc86ed..fea0bfc 100644 --- a/parse.py +++ b/parse.py @@ -381,21 +381,21 @@ def voucher_create_handler(cmd): if privatekey.startswith("0x"): private_key = privatekey[2:] - command = f'ge-publish --private-key {private_key} ' \ + command = f'ge-publish --private-key {private_key} --json ' \ f'--rpc {rpc} --gas-fee-cap {gasCap} --chainid {chainId} ' \ f'p erc20 --name "{name}" --symbol "{symbol}"' result = subprocess.run(command, shell=True, capture_output=True, text=True) if result.returncode != 0: raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr) - output = result.stderr.strip().split("\n") - contract_address = None - - for word in output[1].split(): - if "contract_address=" in word: - contract_address = word.split("=")[1] - print("Voucher created with Address:",contract_address) - store_voucher(privatekey,symbol,remove_ansi_escape_codes(contract_address)) + output_lines = result.stderr.strip().split("\n") + deployment_result = output_lines[1] + try: + data = json.loads(deployment_result) + contract_address = data.get('contract_address', None) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + print("Voucher created with contract address:",contract_address) return contract_address def voucher_transfer_handler(cmd):