def remove_funds(author_id: Union[AccountId, str], account_id: Union[AccountId,
                                                                     str],
                 amount: Fraction, server: Server):
    """Remove funds from an account. Rules applying to
       print_money apply.
       """
    if amount <= 0:
        raise ValueCommandException(amount)

    author = _get_account(author_id, server)
    account = _get_account(account_id, server)
    _assert_authorized(author, None)

    server.remove_funds(author_id, account, amount)
Exemple #2
0
def process_remove_funds(author: AccountId, message: str, server: Server,
                         **kwargs):
    author_account = assert_authorized(author, server, Authorization.ADMIN)
    parsed = parse_remove_funds(message)
    if parsed is None:
        raise CommandException(
            'Bad formatting; Expected `remove-funds` `AMOUNT` `BENEFICIARY`')
    amount, beneficiary = parsed
    if amount < 0:
        raise CommandException('I can\'t remove negative amounts of funds')
    beneficiary_account = assert_is_account(beneficiary, server)
    if amount != 0:
        server.remove_funds(author_account, beneficiary_account, amount)
    return "Success"