# Buggy code
async def jsonrpc_wallet_send(
    self,
    amount,
    addresses,
    wallet_id=None,
    change_account_id=None,
    funding_account_ids=None,
    preview=False,
):
    """
    Send the same number of credits to multiple addresses using all accounts in wallet to
    fund the transaction and the default account to receive any change.

    Usage:
        wallet_send <amount> <addresses>... [--wallet_id=<wallet_id>] [--preview]
                    [--change_account_id=None] [--funding_account_ids=<funding_account_ids>...]

    Options:
        --wallet_id=<wallet_id>         : (str) restrict operation to specific wallet
        --change_account_id=<wallet_id> : (str) account where change will go
        --funding_account_ids=<funding_account_ids> : (str) accounts to fund the transaction
        --preview                  : (bool) do not broadcast the transaction

    Returns: {Transaction}
    """
    wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
    assert not wallet.is_locked, "Cannot spend funds with locked wallet, unlock first."
    account = wallet.get_account_or_default(change_account_id)
    accounts = wallet.get_accounts_or_all(funding_account_ids)

    amount = self.get_dewies_or_error("amount", amount)

    if addresses and not isinstance(addresses, list):
        addresses = [addresses]

    outputs = []
    for address in addresses:
        self.valid_address_or_error(address)
        outputs.append(
            Output.pay_pubkey_hash(amount, self.ledger.address_to_hash160(address))
        )

    tx = await Transaction.create([], outputs, accounts, account)

    if not preview:
        await self.ledger.broadcast(tx)
        await self.analytics_manager.send_credits_sent()
    else:
        await self.ledger.release_tx(tx)

    return tx


# Traceback (AttributeError)
2019-08-01 18:18:06,916 INFO     lbry.stream.reflector.client:119: Sent reflector blob e5828b7e
2019-08-01 18:18:29,221 INFO     lbry.stream.reflector.client:119: Sent reflector blob 867d1a2c
2019-08-01 18:18:51,545 INFO     lbry.stream.reflector.client:119: Sent reflector blob 6e365367
2019-08-01 18:18:58,400 INFO     lbry.extras.daemon.Daemon:2330: publishing: name: xxxx params: {'title': 'xxxx', 'description': 'xxxxxx', 'bid': '0.10000000', 'languages': ['en'], 'tags': ['xxxxx'], 'thumbnail_url': 'https://spee.ch/8/xxxxxxxxx', 'license': 'All rights reserved   Published With Permission', 'release_time': 1564696220, 'channel_id': 'xxxxxxxxxxxx', 'fee_currency': 'LBC', 'fee_amount': '1.00000000', 'file_path': 'C:\\Users\\David T\\Desktop\\GMCZ0549_VID_1280x720x1500kbs_HCVC549.mp4'}
2019-08-01 18:19:22,348 ERROR    lbry.extras.daemon.Daemon:586: error handling api request
Traceback (most recent call last):
File "lbry\extras\daemon\Daemon.py", line 580, in _process_rpc_call
File "lbry\extras\daemon\Daemon.py", line 2342, in jsonrpc_publish
File "lbry\extras\daemon\Daemon.py", line 2659, in jsonrpc_stream_update
File "lbry\stream\stream_manager.py", line 232, in delete_stream
AttributeError: 'NoneType' object has no attribute 'stop_tasks'
2019-08-01 18:19:37,886 INFO     lbry.stream.reflector.client:119: Sent reflector blob f5b10e7b
2019-08-01 18:20:00,717 INFO     lbry.stream.reflector.client:119: Sent reflector blob d5ffe375

# Fixed code
async def jsonrpc_wallet_send(
    self,
    amount,
    addresses,
    wallet_id=None,
    change_account_id=None,
    funding_account_ids=None,
    preview=False,
):
    """
    Send the same number of credits to multiple addresses using all accounts in wallet to
    fund the transaction and the default account to receive any change.

    Usage:
        wallet_send <amount> <addresses>... [--wallet_id=<wallet_id>] [--preview]
                    [--change_account_id=None] [--funding_account_ids=<funding_account_ids>...]

    Options:
        --wallet_id=<wallet_id>         : (str) restrict operation to specific wallet
        --change_account_id=<wallet_id> : (str) account where change will go
        --funding_account_ids=<funding_account_ids> : (str) accounts to fund the transaction
        --preview                  : (bool) do not broadcast the transaction

    Returns: {Transaction}
    """
    wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
    assert not wallet.is_locked, "Cannot spend funds with locked wallet, unlock first."
    account = wallet.get_account_or_default(change_account_id)
    accounts = wallet.get_accounts_or_all(funding_account_ids)

    amount = self.get_dewies_or_error("amount", amount)

    if addresses and not isinstance(addresses, list):
        addresses = [addresses]

    outputs = []
    for address in addresses:
        self.valid_address_or_error(address)
        outputs.append(
            Output.pay_pubkey_hash(amount, self.ledger.address_to_hash160(address))
        )

    tx = await Transaction.create([], outputs, accounts, account)

    if not preview:
        await self.ledger.broadcast(tx)
        self.component_manager.loop.create_task(
            self.analytics_manager.send_credits_sent()
        )
    else:
        await self.ledger.release_tx(tx)

    return tx