feat: add interactive deployment and switch to poetry #2
| @ -56,7 +56,8 @@ def execute(config: Config, eargs: ExtraArgs): | |||||||
|     skip_gen = eargs.skip_gen |     skip_gen = eargs.skip_gen | ||||||
|     skip_deploy = eargs.skip_deploy |     skip_deploy = eargs.skip_deploy | ||||||
|     wallet_keystore = eargs.y |     wallet_keystore = eargs.y | ||||||
|     config.add(wallet_keystore, "WALLET_KEY_FILE", exists_ok=True) |     if wallet_keystore: | ||||||
|  |         config.add(wallet_keystore, "WALLET_KEY_FILE", exists_ok=True) | ||||||
| 
 | 
 | ||||||
|     if not skip_gen: |     if not skip_gen: | ||||||
|         contract = generate_contract(directory, [target], config, interactive=True) |         contract = generate_contract(directory, [target], config, interactive=True) | ||||||
|  | |||||||
| @ -5,6 +5,8 @@ import sys | |||||||
| import json | import json | ||||||
| import requests | import requests | ||||||
| import importlib | import importlib | ||||||
|  | import tempfile | ||||||
|  | import hashlib | ||||||
| 
 | 
 | ||||||
| # local imports | # local imports | ||||||
| from cic.writers import OutputWriter | from cic.writers import OutputWriter | ||||||
| @ -21,17 +23,24 @@ CONTRACTS = [ | |||||||
|         "url": "https://gitlab.com/cicnet/erc20-demurrage-token/-/raw/master/python/erc20_demurrage_token/data/DemurrageTokenSingleNocap", |         "url": "https://gitlab.com/cicnet/erc20-demurrage-token/-/raw/master/python/erc20_demurrage_token/data/DemurrageTokenSingleNocap", | ||||||
|         "name": "Demurrage Token Single No Cap", |         "name": "Demurrage Token Single No Cap", | ||||||
|     }, |     }, | ||||||
|  |     { | ||||||
|  |         "url":"https://gitlab.com/cicnet/erc20-demurrage-token/-/raw/lash/gas-safety-valve/python/erc20_demurrage_token/data/DemurrageTokenSingleNocap", | ||||||
|  |         "name": "Demurrage Token Single No Cap (gas-safety-valve)", | ||||||
|  | |||||||
|  |     } | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| # Download File from Url | # Download File from Url | ||||||
| def download_file(url: str, directory: str, filename=None) -> (str, bytes): | def download_file(url: str, filename=None) -> (str, bytes): | ||||||
|     os.makedirs(directory, exist_ok=True) |     directory = tempfile.gettempdir() | ||||||
|     filename = filename if filename else url.split("/")[-1] |     filename = filename if filename else url.split("/")[-1] | ||||||
|     path = os.path.join(directory, filename) |     hash_object = hashlib.md5(url.encode()) | ||||||
|  |     path = os.path.join(directory, hash_object.hexdigest()) | ||||||
|  |     log.debug(f"Downloading {filename} to {path}") | ||||||
|     if not os.path.exists(path): |     if not os.path.exists(path): | ||||||
|         log.debug(f"Downloading {filename}") |         log.debug(f"Downloading {filename}") | ||||||
|         r = requests.get(url, allow_redirects=True) |         r = requests.get(url, allow_redirects=True) | ||||||
|         open(path, "wb").write(r.content) |         with open(path, "wb") as f: | ||||||
|  |             f.write(r.content) | ||||||
|         return path |         return path | ||||||
|     return path |     return path | ||||||
| 
 | 
 | ||||||
| @ -50,15 +59,14 @@ def select_contract(): | |||||||
|     val = input("Select contract (C,0,1..): ") |     val = input("Select contract (C,0,1..): ") | ||||||
|     if val.isdigit() and int(val) < len(CONTRACTS): |     if val.isdigit() and int(val) < len(CONTRACTS): | ||||||
|         contract = CONTRACTS[int(val)] |         contract = CONTRACTS[int(val)] | ||||||
|         directory = f"./contracts/{contract['name']}" |         bin_path = os.path.abspath(download_file(contract["url"] + ".bin")) | ||||||
|         bin_path = os.path.abspath(download_file(contract["url"] + ".bin", directory)) |         json_path = download_file(contract["url"] + ".json") | ||||||
|         json_path = download_file(contract["url"] + ".json", directory) |  | ||||||
| 
 | 
 | ||||||
|     elif val == "C": |     elif val == "C": | ||||||
|         possible_bin_location = input("Enter a path or url to a contract.bin: ") |         possible_bin_location = input("Enter a path or url to a contract.bin: ") | ||||||
|         if possible_bin_location.startswith('http'): |         if possible_bin_location.startswith('http'): | ||||||
|             # possible_bin_location is url |             # possible_bin_location is url | ||||||
|             bin_path = download_file(possible_bin_location, directory) |             bin_path = download_file(possible_bin_location) | ||||||
|         else: |         else: | ||||||
|             # possible_bin_location is path |             # possible_bin_location is path | ||||||
|             if os.path.exists(possible_bin_location): |             if os.path.exists(possible_bin_location): | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
This should be a tmp dir