Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improves the drain-accounts script so that it funds more accounts #1988

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions mobilecoind/strategies/drain-accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def parse_args() -> argparse.ArgumentParser:
type=int,
default=20,
help="Amount less than the balance that we attempt to send")
parser.add_argument("--max-accounts",
parser.add_argument("--num-src-accounts",
type=int,
default=-1,
help="Number of accounts to pull from the account keys / destination accounts keys folders")
help="Number of accounts to pull from the source account keys dir (note: we always pull all the destination keys)")
parser.add_argument("--token-id",
type=int,
default=0,
Expand Down Expand Up @@ -141,20 +141,25 @@ def filename_key(filename):
for b58 in dest_b58addresses
]

# Go through each account and have all their friends transact to them
for i, (src_account, dest) in enumerate(zip(source_accounts, dest_addresses)):
# If we have already done max_accounts many accounts, then stop
if i == args.max_accounts:
break;
# Go through each destination account and pay it once from a source account,
# going round-robin through the source accounts (only first args.num_src_accounts source accounts)
n = len(dest_addresses)
m = len(source_accounts) if args.num_src_accounts == -1 else args.num_src_accounts
cbeck88 marked this conversation as resolved.
Show resolved Hide resolved
cbeck88 marked this conversation as resolved.
Show resolved Hide resolved
for i, dest in enumerate(dest_addresses):
src_account = source_accounts[i % n]
cbeck88 marked this conversation as resolved.
Show resolved Hide resolved

wait_for_accounts_sync(stub, [src_account.monitor_id], 3)
# Get starting balance
resp = stub.GetBalance(
mobilecoind_api_pb2.GetBalanceRequest(monitor_id=src_account.monitor_id, token_id=args.token_id))
balance = resp.balance
logging.info("Starting balance for account %s : %s", i, resp)
logging.info("Token-id %s balance for account %s : %s", args.token_id, i, resp)

amount = balance - args.fee
# This source account will be chosen for this many future iterations of the loop
num_payments_remaining = int((n - i) / m)
# Divide the remaining balance evenly across this payment and the remaining future payments
# but also subtract the fee we have to pay
amount = int(balance / (num_payments_remaining + 1)) - args.fee

# Create a pool of transfers to all other accounts
logging.info("Transferring %s to %s", amount, dest)
Expand Down