2022-02-09 10:31:29 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
|
|
|
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__), "..")))
|
2022-02-09 10:31:29 -08:00
|
|
|
import mango # nopep8
|
|
|
|
|
2022-02-09 11:31:50 -08:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Register a referrer ID for a Mango Account."
|
|
|
|
)
|
2022-02-09 10:31:29 -08:00
|
|
|
mango.ContextBuilder.add_command_line_parameters(parser)
|
|
|
|
mango.Wallet.add_command_line_parameters(parser)
|
2022-02-09 11:31:50 -08:00
|
|
|
parser.add_argument(
|
|
|
|
"--account-address",
|
|
|
|
type=PublicKey,
|
|
|
|
help="address of the specific account to use, if more than one available",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--id",
|
|
|
|
type=str,
|
|
|
|
required=True,
|
|
|
|
help="referrer ID to register - must be no longer than 32 characters",
|
|
|
|
)
|
2022-02-17 06:54:38 -08:00
|
|
|
parser.add_argument(
|
|
|
|
"--wait",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="wait until the transactions are confirmed",
|
|
|
|
)
|
2022-02-09 10:31:29 -08:00
|
|
|
args: argparse.Namespace = mango.parse_args(parser)
|
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
with mango.ContextBuilder.from_command_line_parameters(args) as context:
|
|
|
|
wallet = mango.Wallet.from_command_line_parameters_or_raise(args)
|
|
|
|
group = mango.Group.load(context, context.group_address)
|
|
|
|
account = mango.Account.load_for_owner_by_address(
|
|
|
|
context, wallet.address, group, args.account_address
|
|
|
|
)
|
2022-02-09 10:31:29 -08:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
all_instructions: mango.CombinableInstructions = (
|
|
|
|
mango.CombinableInstructions.from_signers([wallet.keypair])
|
|
|
|
)
|
2022-02-09 10:31:29 -08:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
referrer_record_address: PublicKey = group.derive_referrer_record_address(
|
|
|
|
context, args.id
|
|
|
|
)
|
|
|
|
set_delegate_instructions = mango.build_register_referrer_id_instructions(
|
|
|
|
context, wallet, group, account, referrer_record_address, args.id
|
|
|
|
)
|
|
|
|
all_instructions += set_delegate_instructions
|
|
|
|
|
|
|
|
signatures = all_instructions.execute(context)
|
2022-02-09 10:31:29 -08:00
|
|
|
|
2022-02-17 06:54:38 -08:00
|
|
|
if args.wait:
|
|
|
|
mango.output("Waiting on transaction signatures:")
|
|
|
|
mango.output(mango.indent_collection_as_str(signatures, 1))
|
|
|
|
results = mango.WebSocketTransactionMonitor.wait_for_all(
|
|
|
|
context.client.cluster_ws_url, signatures
|
|
|
|
)
|
|
|
|
mango.output("Transaction results:")
|
|
|
|
mango.output(mango.indent_collection_as_str(results, 1))
|
|
|
|
else:
|
|
|
|
mango.output("Transaction signatures:")
|
|
|
|
mango.output(mango.indent_collection_as_str(signatures, 1))
|