async def announce(tx):
    address = models.PublicAccount.create_from_public_key(
        tx.signer, tx.network_type).address

    # Create listener and subscribe to confirmed / unconfirmed transactions and error status
    # Subscription should occur prior to announcing the transaction
    async with client.Listener(f'{endpoint}/ws') as listener:
        await listener.confirmed(address)
        await listener.status(address)
        await listener.unconfirmed_added(address)

        # Announce the transaction to the network
        print(f"Sending a message to {bob.address.address}\n")
        with client.TransactionHTTP(endpoint) as http:
            http.announce(tx)

        # Listener gets all messages regarding the address given but we care only
        # about our transaciton
        async for m in listener:
            if ((m.channel_name == 'status')
                    and (m.message.hash == tx.hash.upper())):
                # An error occured and the transaction was rejected by the node
                raise errors.TransactionError(m.message)
            elif ((m.channel_name == 'unconfirmedAdded')
                  and (m.message.transaction_info.hash == tx.hash.upper())):
                # The transaction was accepted by the node and is about to be included in a block
                print(
                    f"Unconfirmed transaction {m.message.transaction_info.hash}"
                )
                print("Waiting for confirmation\n")
            elif ((m.channel_name == 'confirmedAdded')
                  and (m.message.transaction_info.hash == tx.hash.upper())):
                # The transaction was included in a block
                return m.message
    async def func(self):
        async with client.Listener(f'{responses.ENDPOINT}/ws') as listener:
            # Subscribe to the desired channels.
            for subscription in test['subscriptions']:
                await getattr(listener, subscription)()

            # Iterate over all the messages.
            count = len(test['validation'])
            messages = [i async for i in aitertools.aslice(listener, count)]
            for message, validators in zip(messages, test['validation']):
                for validator in validators:
                    self.assertEqual(*validator(message))
    async def func(self):
        async with client.Listener(f'{responses.ENDPOINT}/ws') as listener:
            # Get the UID for the websockets client..
            with websockets.default_response(
                [json.dumps({'uid': test['uid']})]):
                self.assertEqual(await listener.uid, test['uid'])

            # Subscribe to the desired channels.
            for subscription in test['subscriptions']:
                await getattr(listener, subscription)()

            # Iterate over all the messages.
            with websockets.default_response(test['response']):
                count = len(test['validation'])
                messages = [
                    i async for i in aitertools.aslice(listener, count)
                ]
                for message, validators in zip(messages, test['validation']):
                    for validator in validators:
                        self.assertEqual(*validator(message))
async def announce(tx):
    async with client.Listener(f'{config.ENDPOINT}/ws',
                               network_type=config.network_type) as listener:
        address = models.PublicAccount.create_from_public_key(
            tx.signer, config.network_type).address

        await listener.confirmed(address)
        await listener.status(address)

        async with client.AsyncTransactionHTTP(
                config.ENDPOINT, network_type=config.network_type) as http:
            await http.announce(tx)

        async for m in listener:
            if ((m.channel_name == 'status')
                    and (m.message.hash == tx.hash.upper())):
                raise errors.TransactionError(m.message)
            elif ((m.channel_name == 'confirmedAdded')
                  and (m.message.transaction_info.hash == tx.hash.upper())):
                return m.message