chore: download contracts to tmp dir
This commit is contained in:
parent
525aab8c77
commit
9ae198f0f6
@ -56,7 +56,8 @@ def execute(config: Config, eargs: ExtraArgs):
|
||||
skip_gen = eargs.skip_gen
|
||||
skip_deploy = eargs.skip_deploy
|
||||
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:
|
||||
contract = generate_contract(directory, [target], config, interactive=True)
|
||||
|
@ -5,6 +5,8 @@ import sys
|
||||
import json
|
||||
import requests
|
||||
import importlib
|
||||
import tempfile
|
||||
import hashlib
|
||||
|
||||
# local imports
|
||||
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",
|
||||
"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
|
||||
def download_file(url: str, directory: str, filename=None) -> (str, bytes):
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
def download_file(url: str, filename=None) -> (str, bytes):
|
||||
directory = tempfile.gettempdir()
|
||||
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):
|
||||
log.debug(f"Downloading {filename}")
|
||||
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
|
||||
|
||||
@ -50,15 +59,14 @@ def select_contract():
|
||||
val = input("Select contract (C,0,1..): ")
|
||||
if val.isdigit() and int(val) < len(CONTRACTS):
|
||||
contract = CONTRACTS[int(val)]
|
||||
directory = f"./contracts/{contract['name']}"
|
||||
bin_path = os.path.abspath(download_file(contract["url"] + ".bin", directory))
|
||||
json_path = download_file(contract["url"] + ".json", directory)
|
||||
bin_path = os.path.abspath(download_file(contract["url"] + ".bin"))
|
||||
json_path = download_file(contract["url"] + ".json")
|
||||
|
||||
elif val == "C":
|
||||
possible_bin_location = input("Enter a path or url to a contract.bin: ")
|
||||
if possible_bin_location.startswith('http'):
|
||||
# possible_bin_location is url
|
||||
bin_path = download_file(possible_bin_location, directory)
|
||||
bin_path = download_file(possible_bin_location)
|
||||
else:
|
||||
# possible_bin_location is path
|
||||
if os.path.exists(possible_bin_location):
|
||||
|
Loading…
Reference in New Issue
Block a user