2021-10-08 10:15:40 -07:00
|
|
|
#!/usr/bin/env python3
|
2021-07-21 08:35:38 -07:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import rx
|
|
|
|
import rx.operators
|
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
|
|
|
|
from solana.publickey import PublicKey
|
|
|
|
|
2022-02-09 11:31:50 -08:00
|
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
2021-07-21 08:35:38 -07:00
|
|
|
import mango # nopep8
|
|
|
|
|
2022-02-09 11:31:50 -08:00
|
|
|
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-21 08:35:38 -07:00
|
|
|
mango.Wallet.add_command_line_parameters(parser)
|
2022-02-09 11:31:50 -08:00
|
|
|
parser.add_argument(
|
|
|
|
"--address",
|
|
|
|
type=PublicKey,
|
|
|
|
required=True,
|
|
|
|
help="Address of the Solana account to watch",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--account-type",
|
|
|
|
type=str,
|
|
|
|
required=True,
|
|
|
|
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-21 08:35:38 -07:00
|
|
|
|
2022-02-23 02:48:25 -08:00
|
|
|
with mango.ContextBuilder.from_command_line_parameters(
|
|
|
|
args
|
|
|
|
) as context, mango.Disposable() as disposer:
|
2022-02-17 06:54:38 -08:00
|
|
|
manager = mango.IndividualWebSocketSubscriptionManager(context)
|
|
|
|
disposer.add_disposable(manager)
|
2021-07-21 08:35:38 -07:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
converter = mango.build_account_info_converter(context, args.account_type)
|
2021-07-21 08:35:38 -07:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
converting_subscription = mango.WebSocketAccountSubscription(
|
|
|
|
context, args.address, converter
|
|
|
|
)
|
|
|
|
manager.add(converting_subscription)
|
|
|
|
publisher = converting_subscription.publisher.pipe(
|
|
|
|
rx.operators.filter(lambda item: isinstance(item, list) and len(item) > 0),
|
|
|
|
rx.operators.flat_map(
|
|
|
|
lambda item: rx.from_iterable(item)
|
|
|
|
if isinstance(item, list)
|
|
|
|
else rx.from_iterable([item])
|
|
|
|
),
|
|
|
|
)
|
2021-07-22 07:18:37 -07:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
subscription = publisher.subscribe(mango.PrintingObserverSubscriber(False))
|
|
|
|
disposer.add_disposable(subscription)
|
2021-07-21 08:35:38 -07:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
manager.open()
|
2021-07-21 08:35:38 -07:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
# Wait - don't exit. Exiting will be handled by signals/interrupts.
|
|
|
|
waiter = threading.Event()
|
|
|
|
try:
|
|
|
|
waiter.wait()
|
|
|
|
except:
|
|
|
|
pass
|
2021-07-21 08:35:38 -07:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
logging.info("Shutting down...")
|
2022-02-23 02:48:25 -08:00
|
|
|
logging.info("Shutdown complete.")
|