mango-explorer/bin/show-address

46 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import os
import os.path
import sys
import typing
from solana.publickey import PublicKey
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import mango # nopep8
parser = argparse.ArgumentParser(
description="Shows the on-chain data of a particular account."
)
mango.ContextBuilder.add_command_line_parameters(parser)
parser.add_argument(
"--address",
type=PublicKey,
required=True,
help="Address of the Solana account to watch",
)
parser.add_argument(
"--account-type",
type=str,
default="AccountInfo",
help="Underlying object type of the data in the AccountInfo",
)
args: argparse.Namespace = mango.parse_args(parser)
context = mango.ContextBuilder.from_command_line_parameters(args)
converter: typing.Callable[
[mango.AccountInfo], typing.Any
] = lambda account_info: account_info
if args.account_type.upper() != "ACCOUNTINFO":
converter = mango.build_account_info_converter(context, args.account_type)
account_info: typing.Optional[mango.AccountInfo] = mango.AccountInfo.load(
context, args.address
)
if account_info is None:
raise Exception(f"No account found at address: {args.address}")
mango.output(converter(account_info))