feat: add interactive deployment and switch to poetry #2

Merged
williamluke merged 19 commits from lum/easy-token-deployment into master 2022-03-16 06:37:49 +01:00
3 changed files with 46 additions and 38 deletions
Showing only changes of commit 0dc25002f6 - Show all commits

View File

@ -50,7 +50,6 @@ ExtraArgs = {"skip_gen": str, "skip_deploy": str, "target": str, "path": str, "p
def execute(config: Config, eargs: ExtraArgs): def execute(config: Config, eargs: ExtraArgs):
print(f"eargs: {eargs}")
directory = eargs.path directory = eargs.path
target = eargs.target target = eargs.target
skip_gen = eargs.skip_gen skip_gen = eargs.skip_gen
@ -66,8 +65,12 @@ def execute(config: Config, eargs: ExtraArgs):
print(contract) print(contract)
print(f"Meta: {config.get('META_URL')}")
print(f"ChainSpec: {config.get('CHAIN_SPEC', contract.network.chain_spec(target))}")
print(f"RPC: {config.get('RPC_PROVIDER')}\n")
if not skip_deploy: if not skip_deploy:
ready_to_deploy = input("Ready to deploy? (y/n): ") ready_to_deploy = input("Are you ready to Deploy? (y/n): ")
if ready_to_deploy == "y": if ready_to_deploy == "y":
deploy_contract( deploy_contract(
config=config, config=config,
@ -76,7 +79,7 @@ def execute(config: Config, eargs: ExtraArgs):
) )
print("Deployed") print("Deployed")
else: else:
print("Not deploying") print("Skipping deployment")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -3,25 +3,25 @@ import importlib
import json import json
import logging import logging
import os import os
from typing import List, TYPE_CHECKING from typing import TYPE_CHECKING, List
import requests import requests
from chainlib.chain import ChainSpec
from chainlib.cli.config import Config
from cic.contract.components.attachment import Attachment
from cic.contract.components.meta import Meta
from cic.contract.components.proof import Proof
from cic.contract.components.token import Token
from cic.contract.helpers import init_writers_from_config
from cic.contract.network import Network
# Local Modules
from cic.contract.processor import ContractProcessor
from cic.writers import HTTPWriter, KeyedWriterFactory, MetadataWriter, OutputWriter
# external imports # external imports
from cic_types.ext.metadata import MetadataRequestsHandler from cic_types.ext.metadata import MetadataRequestsHandler
from cic_types.ext.metadata.signer import Signer as MetadataSigner from cic_types.ext.metadata.signer import Signer as MetadataSigner
from chainlib.cli.config import Config
from chainlib.chain import ChainSpec
# Local Modules
from cic.contract.processor import ContractProcessor
from cic.contract.components.attachment import Attachment
from cic.contract.components.meta import Meta
from cic.contract.network import Network
from cic.contract.components.proof import Proof
from cic.contract.components.token import Token
from cic.contract.helpers import init_writers_from_config
from cic.writers import HTTPWriter, KeyedWriterFactory, OutputWriter, MetadataWriter
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -45,12 +45,12 @@ class Contract:
def __str__(self): def __str__(self):
s = "" s = ""
s += f"[cic.header]\nversion = {self.proof.version()}\n" s += f"\n[cic.header]\nversion = {self.proof.version()}\n\n"
s += f"[cic.token]\n{self.token}" s += f"[cic.token]\n{self.token}\n"
s += f"[cic.proof]\n{self.proof}" s += f"[cic.proof]\n{self.proof}\n"
s += f"[cic.meta]\n{self.meta}" s += f"[cic.meta]\n{self.meta}\n"
s += f"[cic.attachment]\n{self.attachment}" s += f"[cic.attachment]\n{self.attachment}\n"
s += f"[cic.network]\n{self.network}" s += f"[cic.network]\n{self.network}\n"
return s return s
@ -76,10 +76,10 @@ def generate_contract(
) -> Contract: ) -> Contract:
if os.path.exists(directory): if os.path.exists(directory):
contine = input( contine = input(
"Directory already exists, Would you like to delete it? (y/n): " f"Directory {directory} already exists, Would you like to delete it? (y/n): "
) )
if contine.lower() != "y": if contine.lower() != "y":
print("Trying to load existing contract") log.debug("Trying to load existing contract")
return load_contract(directory) return load_contract(directory)
else: else:
print(f"Deleted {directory}") print(f"Deleted {directory}")
@ -117,16 +117,20 @@ def generate_contract(
cmd_mod = importlib.import_module(modname) cmd_mod = importlib.import_module(modname)
signer_hint = config.get("WALLET_KEY_FILE") signer_hint = config.get("WALLET_KEY_FILE")
keys = cmd_mod.list_keys(config, signer_hint) keys = cmd_mod.list_keys(config, signer_hint)
for idx, key in enumerate(keys): if len(keys) > 1:
print(f"{idx} - {key} ") print(f"More than one key found, please select one:")
selecting_key = True for idx, key in enumerate(keys):
while selecting_key: print(f"{idx} - {key} ")
idx = int(input("Select key: ")) selecting_key = True
if keys[idx] is not None: while selecting_key:
key_account_address = keys[idx] idx = int(input("Select key: "))
selecting_key = False if keys[idx] is not None:
else: key_account_address = keys[idx]
print("Invalid key, try again") selecting_key = False
else:
print("Invalid key, try again")
else:
key_account_address = keys[0]
m = importlib.import_module(f"cic.ext.{target}.start") m = importlib.import_module(f"cic.ext.{target}.start")
m.extension_start( m.extension_start(
@ -134,7 +138,7 @@ def generate_contract(
registry_address=config.get("CIC_REGISTRY_ADDRESS"), registry_address=config.get("CIC_REGISTRY_ADDRESS"),
chain_spec=ChainSpec.from_chain_str(config.get("CHAIN_SPEC")), chain_spec=ChainSpec.from_chain_str(config.get("CHAIN_SPEC")),
rpc_provider=config.get("RPC_PROVIDER"), rpc_provider=config.get("RPC_PROVIDER"),
key_account_address=key_account_address key_account_address=key_account_address,
) )
network.load() network.load()
@ -197,7 +201,6 @@ def deploy_contract(
chain_spec = cn.chain_spec chain_spec = cn.chain_spec
config.add(chain_spec, "CHAIN_SPEC", exists_ok=True) config.add(chain_spec, "CHAIN_SPEC", exists_ok=True)
log.debug(f"using CHAIN_SPEC: {str(chain_spec)} from network") log.debug(f"using CHAIN_SPEC: {str(chain_spec)} from network")
print(chain_spec)
signer_hint = config.get("WALLET_KEY_FILE") signer_hint = config.get("WALLET_KEY_FILE")
(rpc, signer) = cmd_mod.parse_adapter(config, signer_hint) (rpc, signer) = cmd_mod.parse_adapter(config, signer_hint)

View File

@ -132,10 +132,12 @@ class Network(Data):
def __str__(self): def __str__(self):
s = '' s = ''
for resource in self.resources.keys(): for resource in self.resources.keys():
chainspec = ChainSpec.from_dict(self.resources[resource]['chain_spec'])
s += f'{resource}.chain_spec: {str(chainspec)}\n'
for content_key in self.resources[resource]['contents'].keys(): for content_key in self.resources[resource]['contents'].keys():
content_value = self.resources[resource]['contents'][content_key] content_value = self.resources[resource]['contents'][content_key]
if content_value is None: if content_value is None:
content_value = '' content_value = ''
s += f'{resource}.{content_key} = {content_value}\n' s += f'{resource}.contents.{content_key} = {json.dumps(content_value, indent=4, sort_keys=True)}\n'
return s return s