2021-10-08 10:15:40 -07:00
|
|
|
#!/usr/bin/env python3
|
2021-08-19 03:00:39 -07:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.abspath(
|
|
|
|
os.path.join(os.path.dirname(__file__), '..')))
|
|
|
|
import mango # nopep8
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Ensure a Mango account exists for the wallet and group.")
|
|
|
|
mango.ContextBuilder.add_command_line_parameters(parser)
|
|
|
|
mango.Wallet.add_command_line_parameters(parser)
|
|
|
|
parser.add_argument("--wait", action="store_true", default=False,
|
|
|
|
help="wait until the transaction is confirmed")
|
2021-09-13 06:05:19 -07:00
|
|
|
args: argparse.Namespace = mango.parse_args(parser)
|
2021-08-19 03:00:39 -07:00
|
|
|
|
|
|
|
context = mango.ContextBuilder.from_command_line_parameters(args)
|
|
|
|
wallet = mango.Wallet.from_command_line_parameters_or_raise(args)
|
|
|
|
|
|
|
|
group = mango.Group.load(context)
|
|
|
|
accounts = mango.Account.load_all_for_owner(context, wallet.address, group)
|
|
|
|
|
|
|
|
if len(accounts) > 0:
|
|
|
|
print(f"At least one account already exists for group {group.address} and wallet {wallet.address}")
|
|
|
|
else:
|
|
|
|
signers: mango.CombinableInstructions = mango.CombinableInstructions.from_wallet(wallet)
|
|
|
|
init = mango.build_create_account_instructions(context, wallet, group)
|
|
|
|
all_instructions = signers + init
|
|
|
|
transaction_ids = all_instructions.execute(context)
|
|
|
|
|
|
|
|
print("Created account.")
|
|
|
|
if args.wait:
|
|
|
|
print("Waiting on transaction IDs:", transaction_ids)
|
|
|
|
context.client.wait_for_confirmation(transaction_ids)
|
2021-08-28 04:13:03 -07:00
|
|
|
accounts = mango.Account.load_all_for_owner(context, wallet.address, group)
|
|
|
|
|
|
|
|
for account in accounts:
|
|
|
|
print(account)
|