diff --git a/chinstrap/repl/__init__.py b/chinstrap/repl/__init__.py index ddf04aa..738577f 100644 --- a/chinstrap/repl/__init__.py +++ b/chinstrap/repl/__init__.py @@ -55,8 +55,10 @@ def sandbox( if args.stop: return _sandbox.halt() - _sandbox.initialize() - _sandbox.run() + if not _sandbox.isRunning(args.port): + _sandbox.initialize() + _sandbox.run() + return _sandbox @@ -155,7 +157,7 @@ def originate( @helpers.handleException() def sandboxAccounts(): - sandbox.Sandbox.listAccounts() + Sandbox.Sandbox.listAccounts() @helpers.handleException() @@ -185,7 +187,7 @@ def launchRepl(args): pretty.install() if args.network == "development": - _sandbox = sandbox.Sandbox(args) + _sandbox = Sandbox.Sandbox(args) _sandbox.args.detach = True _sandbox.initialize() _sandbox.run() diff --git a/chinstrap/sandbox/__init__.py b/chinstrap/sandbox/__init__.py index 7cfaf89..088c0d3 100644 --- a/chinstrap/sandbox/__init__.py +++ b/chinstrap/sandbox/__init__.py @@ -70,6 +70,7 @@ def __str__(self): class Sandbox: def __init__(self, args) -> None: self.args = args + self.loadState() def initialize(self): self.state = {"accounts": {}, "port": self.args.port} @@ -88,6 +89,9 @@ def download(self): spinner.succeed("Flextesa sandbox ready to use") + def loadState(self): + self.state = Sandbox.getSandboxState() + @staticmethod @IsChinstrapProject() def dumpSandboxState(state): @@ -125,6 +129,7 @@ def isRunning(port=None): f"Sandbox is already {container.status} \ on port: {helpers.RED}{port}{helpers.RST}" ) + else: print( f"Sandbox is already {container.status} \ @@ -190,6 +195,9 @@ def halt(self): spinner.succeed("Halted the sandbox") def generateAccount(self, index=0): + if not index: + index = len(self.state["accounts"]) + name = giveMeAName(index) cmd = f"flextesa key {name}" container = runInFlextesaContainerCli(cmd, detach=False) @@ -203,16 +211,21 @@ def generateAccount(self, index=0): return name, privateKey, line - def generateAccounts(self): + def generateAccounts(self, num_of_accounts=None): + if not num_of_accounts: + num_of_accounts = self.args.num_of_accounts + spinner = halo.Halo( - text=f"Creating {self.args.num_of_accounts} accounts...", spinner="dots" + text=f"Creating {num_of_accounts} accounts...", spinner="dots" ) spinner.start() self.accounts = [] - for i in range(self.args.num_of_accounts): - name, privateKey, account = self.generateAccount(i) + index = len(self.state["accounts"]) + + for i in range(num_of_accounts): + name, privateKey, account = self.generateAccount(i + index) self.accounts.append(f"{account}") spinner.succeed(text="Accounts created!\n") @@ -240,6 +253,8 @@ def generateAccounts(self): f"{helpers.RED}WARNING:{helpers.RST} Please do not use these accounts on mainnet!" ) + self.dumpSandboxState(self.state) + def launchSandbox(self): spinner = halo.Halo(text="Starting sandbox", spinner="dots") spinner.start() diff --git a/chinstrap/version.py b/chinstrap/version.py index d2cf6e5..ec09259 100644 --- a/chinstrap/version.py +++ b/chinstrap/version.py @@ -1 +1 @@ -version = "1.0.9" +version = "1.0.10"