kopia lustrzana https://github.com/bugout-dev/dao
Added batch minting ability to scripts/mint_batch.py
This also adds the ability to read recipients from file.pull/68/head
rodzic
ab3ba566cd
commit
a7a802fa99
|
@ -26,7 +26,12 @@ parser.add_argument(
|
||||||
help="ID of Terminus pool representing the badge",
|
help="ID of Terminus pool representing the badge",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--recipients", nargs="+", help="Addresses that badge should be minted to"
|
"--recipients", nargs="*", help="Addresses that badge should be minted to"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--recipients-file",
|
||||||
|
type=argparse.FileType("r"),
|
||||||
|
help="(Optional) File containing addresses to mint badges to, one address per line. The addresses in this file are added to the addresses passed with the --recipients argument.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-y",
|
"-y",
|
||||||
|
@ -34,6 +39,12 @@ parser.add_argument(
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Set this flag to signal y on all confirmation prompts",
|
help="Set this flag to signal y on all confirmation prompts",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--batch-size",
|
||||||
|
type=int,
|
||||||
|
default=200,
|
||||||
|
help="Number of recipients to mint badges to per transaction.",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -42,36 +53,46 @@ if args.address is None:
|
||||||
"Please specify the address of a Terminus contract using the --address argument."
|
"Please specify the address of a Terminus contract using the --address argument."
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args.recipients) > 200:
|
if args.batch_size > 200:
|
||||||
raise ValueError("This script can process at most 200 recipients at a time.")
|
raise ValueError("This script can process at most 200 recipients per batch.")
|
||||||
|
|
||||||
network.connect(args.network)
|
network.connect(args.network)
|
||||||
|
|
||||||
recipients = list(set(args.recipients))
|
recipients = list(set(args.recipients))
|
||||||
|
|
||||||
|
batches = []
|
||||||
|
for i in range(0, len(recipients), args.batch_size):
|
||||||
|
batches.append(recipients[i : i + args.batch_size])
|
||||||
|
|
||||||
terminus = TerminusFacet.TerminusFacet(args.address)
|
terminus = TerminusFacet.TerminusFacet(args.address)
|
||||||
pool_uri = terminus.uri(args.pool_id)
|
pool_uri = terminus.uri(args.pool_id)
|
||||||
balances = zip(
|
|
||||||
recipients,
|
|
||||||
terminus.balance_of_batch(recipients, [args.pool_id for _ in recipients]),
|
|
||||||
)
|
|
||||||
|
|
||||||
valid_recipients = [recipient for recipient, balance in balances if balance == 0]
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Badge information -- Terminus address: {args.address}, pool ID: {args.pool_id}, pool URI: {pool_uri}"
|
f"Badge information -- Terminus address: {args.address}, pool ID: {args.pool_id}, pool URI: {pool_uri}"
|
||||||
)
|
)
|
||||||
print("\n- ".join(["Intended recipients:"] + valid_recipients))
|
|
||||||
|
|
||||||
if not args.yes:
|
for i, batch in enumerate(batches):
|
||||||
permission_check = input("Proceed? (y/N)")
|
balances = zip(
|
||||||
if permission_check.strip().lower() != "y":
|
batch,
|
||||||
raise Exception("You did not wish to proceed")
|
terminus.balance_of_batch(recipients, [args.pool_id for _ in recipients]),
|
||||||
|
)
|
||||||
|
|
||||||
amounts = [1 for _ in valid_recipients]
|
valid_recipients = [recipient for recipient, balance in balances if balance == 0]
|
||||||
transaction_config = TerminusFacet.get_transaction_config(args)
|
if not valid_recipients:
|
||||||
transaction_info = terminus.pool_mint_batch(
|
print("No valid recipients in this batch")
|
||||||
args.pool_id, valid_recipients, amounts, transaction_config
|
continue
|
||||||
)
|
|
||||||
|
|
||||||
print(transaction_info)
|
print("\n- ".join([f"Batch {i} -- intended recipients:"] + valid_recipients))
|
||||||
|
|
||||||
|
if not args.yes:
|
||||||
|
permission_check = input("Proceed? (y/N)")
|
||||||
|
if permission_check.strip().lower() != "y":
|
||||||
|
raise Exception("You did not wish to proceed")
|
||||||
|
|
||||||
|
amounts = [1 for _ in valid_recipients]
|
||||||
|
transaction_config = TerminusFacet.get_transaction_config(args)
|
||||||
|
transaction_info = terminus.pool_mint_batch(
|
||||||
|
args.pool_id, valid_recipients, amounts, transaction_config
|
||||||
|
)
|
||||||
|
|
||||||
|
print(transaction_info)
|
||||||
|
|
Ładowanie…
Reference in New Issue