def create_recurring_transfer(author_id: Union[AccountId, str], sender_id: Union[AccountId, str], destination_id: Union[AccountId, str], amount: Fraction, tick_count: int, server: Server): """Create a recurring transfer.""" author = _get_account(author_id, server) sender = _get_account(sender_id, server) destination = _get_account(destination_id, server) _assert_authorized(author, sender) transfer = server.create_recurring_transfer(author_id, sender, destination, amount * tick_count, tick_count) return transfer
def process_create_recurring_transfer(author: AccountId, message: str, server: Server, **kwargs): """Processes a request to set up a recurring transfer.""" parse_result = parse_create_recurring_transfer(message) if parse_result is None: return 'Request formatted incorrectly. Expected `create-recurring-transfer AMOUNT_PER_TICK BENEFICIARY TICK_COUNT`.' amount, destination_name, tick_count = parse_result author_account = assert_is_account(author, server) dest_account = assert_is_account(destination_name, server) transfer = server.create_recurring_transfer(author, author_account, dest_account, amount * tick_count, tick_count) return 'Recurring transfer set up with ID `%s`.' % transfer.get_id()
def process_admin_create_recurring_transfer(author: AccountId, message: str, server: Server, **kwargs): """Processes a request to set up an arbitrary recurring transfer.""" assert_authorized(author, server, Authorization.ADMIN) parse_result = parse_admin_create_recurring_transfer(message) if parse_result is None: return 'Request formatted incorrectly. Expected `admin-create-recurring-transfer AMOUNT_PER_TICK SENDER BENEFICIARY TICK_COUNT`.' amount, sender_name, destination_name, tick_count = parse_result assert_is_account(author, server) sender_account = assert_is_account(sender_name, server) dest_account = assert_is_account(destination_name, server) transfer = server.create_recurring_transfer(author, sender_account, dest_account, amount * tick_count, tick_count) return 'Recurring transfer set up with ID `%s`.' % transfer.get_id()