From df384d053b478d6976f76a7d2186bcbf6ae796e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Roycourt?= Date: Thu, 29 Dec 2022 13:08:40 +0100 Subject: [PATCH] feat: add get_accounts to starknet-cli --- src/starkware/starknet/cli/starknet_cli.py | 6 ++++++ src/starkware/starknet/wallets/open_zeppelin.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/starkware/starknet/cli/starknet_cli.py b/src/starkware/starknet/cli/starknet_cli.py index ddca7c6a..55f9802c 100755 --- a/src/starkware/starknet/cli/starknet_cli.py +++ b/src/starkware/starknet/cli/starknet_cli.py @@ -233,6 +233,11 @@ async def deploy_with_invoke(args: argparse.Namespace): Transaction hash: {gateway_response['transaction_hash']}""" ) +async def get_accounts(args, command_args): + parser = argparse.ArgumentParser(description="Lists all accounts.") + parser.parse_args(command_args, namespace=args) + account = await load_account_from_args(args) + await account.list_accounts() async def new_account(args, command_args): parser = argparse.ArgumentParser(description="Initializes an account contract.") @@ -1491,6 +1496,7 @@ async def main(): "invoke": invoke, "new_account": new_account, "tx_status": tx_status, + "get_accounts": get_accounts, } parser = argparse.ArgumentParser(description="A tool to communicate with StarkNet.") parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}") diff --git a/src/starkware/starknet/wallets/open_zeppelin.py b/src/starkware/starknet/wallets/open_zeppelin.py index 27b784ad..0ed11be3 100644 --- a/src/starkware/starknet/wallets/open_zeppelin.py +++ b/src/starkware/starknet/wallets/open_zeppelin.py @@ -92,6 +92,15 @@ def _get_account_given_accounts(self, accounts: dict) -> JsonObject: ) return accounts_for_network[self.account_name] + def list_accounts(self, accounts_for_network: dict): + print("Accounts:") + for account_name, account in accounts_for_network.items(): + print(f" {account_name}:") + print(f" Address: 0x{int(account['address'], 16):064x}") + print(f" Deployed: {account['deployed']}") + print(f" Public key: 0x{int(account['public_key'], 16):064x}") + print(f" Private key: 0x{int(account['private_key'], 16):064x}") + def new_account(self) -> int: # Read the account file. accounts = self._get_accounts()