diff --git a/docs/scripts/main.py b/docs/scripts/main.py new file mode 100644 index 0000000..c9eb5cc --- /dev/null +++ b/docs/scripts/main.py @@ -0,0 +1,105 @@ +import os +import re +import subprocess +import time + +import requests + +# current file location +curr_dir = os.path.dirname(os.path.realpath(__file__)) +parent_dir = os.path.dirname(curr_dir) + +# Commands which block the process +BLOCKING_START_COMMANDS = ["local-ic start", "make testnet", "make sh-testnet"] +ignore_commands = ["gh repo create"] + +START_PID = -1 +DEBUGGING = False + +def main(): + demos = os.path.join(parent_dir, "versioned_docs", "version-v0.50.x", "03-demos") + with open(os.path.join(demos, "03-tokenfactory.md"), "r") as f: + parse_docs(f.read()) + +def poll_for_start(API_URL: str, pid=-1, waitSeconds=300): + for i in range(waitSeconds + 1): + try: + requests.get(API_URL) + return + except Exception: + # if i % 5 == 0: + print(f"waiting for server to start (iter:{i}) ({API_URL})") + time.sleep(1) + + if pid != -1: + print(f"Killing process with pid for failing to start: {pid}") + os.system(f"kill {pid}") + + raise Exception("Server did not start") + +def clean_lines(text: str) -> list[str]: + # remove comment lines + sec = [line for line in text.split("\n") if not line.startswith("#")] + + for l in sec: + l = l.strip() + # if l starts with any in ignore-commands, remove the line from the section + if any([l.startswith(cmd) for cmd in ignore_commands]): + sec.remove(l) + + # remove blank lines + return [line for line in sec if line.strip() != ""] + +def get_env_variables_from_lines(lines: list[str]) -> dict[str, str]: + env_vars = {} + for line in lines: + # DENOM=factory/roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87/mytoken + match = re.match(r"([A-Z_]+)=(.*)", line) + if match: + env_vars[match.group(1)] = match.group(2) + + return env_vars + +def parse_docs(text: str): + global START_PID + + # split the text by ```bash + sections = text.split("```bash") + for section in sections[1:]: # first section has nothing we want + end = section.find("```") + sec = clean_lines(section[:end]) + + if len(sec) == 0: + # print("debugging: empty (commands are ignored / there is nothing here)") + continue + + secStr = "\n".join(sec) + + print("="*20, "\n", secStr, "\n", "="*20) + + # run sec as the os terminal + if not DEBUGGING: + # if sec contains anything from within BLOCKING_START_COMMANDS, it should run in its + # own terminal + + # TODO: keep up with these globally and unset at end? so we dont polute test + envs = get_env_variables_from_lines(sec) + for k, v in envs.items(): + os.environ[k] = v + print(f"{k}={v}") + + if any([cmd in sec for cmd in BLOCKING_START_COMMANDS]): + START_PID = subprocess.Popen(secStr, shell=True).pid + print(f"Started process with pid: {START_PID}") + poll_for_start("http://127.0.0.1:26657", START_PID, waitSeconds=60) + else: + os.system(secStr) + time.sleep(2) + + # input("--- Press Enter to continue...") + + # TODO: verification logic here + # Kill / cleanup the instance (direct from pid would be nice, or just a killall ) + +if __name__ == '__main__': + main() diff --git a/docs/versioned_docs/version-v0.50.x/03-demos/03-tokenfactory.md b/docs/versioned_docs/version-v0.50.x/03-demos/03-tokenfactory.md index 8421d19..c3614bc 100644 --- a/docs/versioned_docs/version-v0.50.x/03-demos/03-tokenfactory.md +++ b/docs/versioned_docs/version-v0.50.x/03-demos/03-tokenfactory.md @@ -66,7 +66,7 @@ The `denom_creation_fee` is a cost the application can set for creating new toke The `denom_creation_gas_consume` is the amount of indirect resource cost to consume for creating a new token. It is a more indirect approach to charging and is a better experience overall for developers on a network. -```bash +```text params: denom_creation_fee: [] denom_creation_gas_consume: "100000" @@ -92,7 +92,7 @@ rolld q tokenfactory denoms-from-creator $(rolld keys show acc0 -a)
denoms-from-creator output -```bash +```text denoms: - factory/roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87/mytoken ``` @@ -129,7 +129,7 @@ rolld q bank denom-metadata $DENOM
bank denom-metadata output -```bash +```text metadata: base: factory/roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87/mytoken denom_units: @@ -162,7 +162,7 @@ rolld q bank balances $(rolld keys show acc0 -a)
bank balances output -```bash +```text balances: - amount: "5000000" denom: factory/roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87/mytoken @@ -189,7 +189,7 @@ rolld q bank balances $(rolld keys show acc1 -a)
mint-to output -```bash +```text balances: - amount: "1000000" denom: factory/roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87/mytoken @@ -206,7 +206,7 @@ note, you can check for just a specific token balance with rolld q bank balance $(rolld keys show acc0 -a) $DENOM ``` -```bash +```text balance: amount: "5000000" denom: factory/roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87/mytoken