2021-10-08 10:15:40 -07:00
|
|
|
#!/usr/bin/env python3
|
2021-07-22 07:18:37 -07:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
2021-07-22 07:58:00 -07:00
|
|
|
import typing
|
2021-07-22 07:18:37 -07:00
|
|
|
|
|
|
|
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.")
|
2021-07-23 02:20:44 -07:00
|
|
|
mango.ContextBuilder.add_command_line_parameters(parser)
|
2021-07-22 07:18:37 -07:00
|
|
|
parser.add_argument("--address", type=PublicKey, required=True, help="Address of the Solana account to watch")
|
2021-07-22 07:58:00 -07:00
|
|
|
parser.add_argument("--account-type", type=str, default="AccountInfo",
|
2021-07-22 07:18:37 -07:00
|
|
|
help="Underlying object type of the data in the AccountInfo")
|
2021-09-13 06:05:19 -07:00
|
|
|
args: argparse.Namespace = mango.parse_args(parser)
|
2021-07-22 07:18:37 -07:00
|
|
|
|
2021-07-23 02:20:44 -07:00
|
|
|
context = mango.ContextBuilder.from_command_line_parameters(args)
|
|
|
|
converter: typing.Callable[[mango.AccountInfo], typing.Any] = lambda account_info: account_info
|
2021-07-22 07:58:00 -07:00
|
|
|
if args.account_type.upper() != "ACCOUNTINFO":
|
|
|
|
converter = mango.build_account_info_converter(context, args.account_type)
|
2021-07-22 07:18:37 -07:00
|
|
|
|
2021-07-22 07:58:00 -07:00
|
|
|
account_info: typing.Optional[mango.AccountInfo] = mango.AccountInfo.load(context, args.address)
|
2021-07-22 07:18:37 -07:00
|
|
|
if account_info is None:
|
|
|
|
raise Exception(f"No account found at address: {args.address}")
|
|
|
|
|
|
|
|
print(converter(account_info))
|