155 lines
4.2 KiB
Python
155 lines
4.2 KiB
Python
from __future__ import annotations
|
|
|
|
# standard import
|
|
import importlib
|
|
import json
|
|
import logging
|
|
import os
|
|
from typing import TYPE_CHECKING, List
|
|
|
|
import requests
|
|
|
|
# external imports
|
|
from chainlib.chain import ChainSpec
|
|
|
|
# local imports
|
|
from cic.contract.components.proof import Proof
|
|
from cic.contract.components.attachment import Attachment
|
|
from cic.contract.components.meta import Meta
|
|
from cic.contract.components.network import Network
|
|
from cic.contract.components.token import Token
|
|
from cic.contract.contract import generate_contract, load_contract, deploy_contract
|
|
|
|
if TYPE_CHECKING:
|
|
from chainlib.cli.config import Config
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def process_args(argparser):
|
|
argparser.add_argument(
|
|
"--skip-gen", action="store_true", default=False, help="Skip Generation"
|
|
)
|
|
argparser.add_argument(
|
|
"--skip-deploy",
|
|
action="store_true",
|
|
help="Skip Deployment",
|
|
)
|
|
argparser.add_argument(
|
|
"--target",
|
|
default="eth",
|
|
help="Contract Target (eth)",
|
|
)
|
|
argparser.add_argument(
|
|
"path",
|
|
type=str,
|
|
help="Path to generate/use contract deployment info",
|
|
)
|
|
argparser.add_argument(
|
|
"-p",
|
|
type=str,
|
|
help="RPC Provider (http://localhost:8545)",
|
|
)
|
|
argparser.add_argument(
|
|
"-y",
|
|
type=str,
|
|
help="Wallet Keystore",
|
|
)
|
|
|
|
|
|
def validate_args(_args):
|
|
pass
|
|
|
|
|
|
|
|
def get_options(config: Config, eargs):
|
|
# Defaults
|
|
default_contract_registry = config.get(
|
|
"CIC_REGISTRY_ADDRESS"
|
|
) # Comes from /home/will/grassroots/cic-staff-installer/var/cic-staff-client/CIC_REGISTRY_ADDRESS
|
|
default_key_account = config.get("AUTH_KEY")
|
|
# https://meta.grassrootseconomics.net
|
|
# https://auth.grassrootseconomics.net Authenticated Meta
|
|
|
|
default_metadata_endpoint = config.get("META_URL")
|
|
# Keyring folder needs to be dumped out as a private key file from $HOME/.config/cic/staff-client/.gnupg
|
|
default_wallet_keyfile = eargs.y or config.get(
|
|
"WALLET_KEY_FILE"
|
|
) # Show possible wallet keys
|
|
|
|
# Should be an input???
|
|
default_wallet_passphrase = config.get("WALLET_PASSPHRASE", "merman")
|
|
default_chain_spec = config.get("CHAIN_SPEC")
|
|
default_rpc_provider = config.get("RPC_PROVIDER")
|
|
|
|
contract_registry = (
|
|
input(f"Enter Contract Registry ({default_contract_registry}): ")
|
|
or default_contract_registry
|
|
)
|
|
rpc_provider = (
|
|
input(f"Enter RPC Provider ({default_rpc_provider}): ") or default_rpc_provider
|
|
)
|
|
chain_spec = ChainSpec.from_chain_str(
|
|
(input(f"Enter ChainSpec ({default_chain_spec}): ") or default_chain_spec)
|
|
)
|
|
key_account = (
|
|
input(f"Enter KeyAccount ({default_key_account}): ") or default_key_account
|
|
)
|
|
metadata_endpoint = (
|
|
input(f"Enter Metadata Endpoint ({default_metadata_endpoint}): ")
|
|
or default_metadata_endpoint
|
|
)
|
|
auth_passphrase = config.get("AUTH_PASSPHRASE")
|
|
auth_keyfile_path = config.get("AUTH_KEYFILE_PATH")
|
|
auth_db_path = config.get("AUTH_DB_PATH")
|
|
|
|
options = [
|
|
auth_db_path,
|
|
auth_keyfile_path,
|
|
auth_passphrase,
|
|
contract_registry,
|
|
key_account,
|
|
chain_spec,
|
|
rpc_provider,
|
|
metadata_endpoint,
|
|
default_wallet_keyfile,
|
|
default_wallet_passphrase,
|
|
]
|
|
print(options)
|
|
return options
|
|
|
|
|
|
ExtraArgs = {"skip_gen": str, "skip_deploy": str, "target": str, "path": str, "p": str}
|
|
|
|
|
|
def execute(config, eargs: ExtraArgs):
|
|
print(f"eargs: {eargs}")
|
|
directory = eargs.path
|
|
target = eargs.target
|
|
skip_gen = eargs.skip_gen
|
|
skip_deploy = eargs.skip_deploy
|
|
|
|
if not skip_gen:
|
|
contract = generate_contract(directory, [target], config, interactive=True)
|
|
else:
|
|
contract = load_contract(directory)
|
|
|
|
print(contract)
|
|
|
|
if not skip_deploy:
|
|
ready_to_deploy = input("Ready to deploy? (y/n): ")
|
|
if ready_to_deploy == "y":
|
|
deploy_contract(
|
|
config=config,
|
|
contract_directory=directory,
|
|
target=target,
|
|
)
|
|
print("Deployed")
|
|
else:
|
|
print("Not deploying")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# execute()
|
|
print("Not Implemented")
|