def send_message(self, cid, payload):
        row = self.db.execute("SELECT acked, their_channel_record_json"
                              " FROM addressbook WHERE id=?", (cid,)).fetchone()
        if not row["acked"] or not row["their_channel_record_json"]:
            raise ContactNotReadyError("cid %d is not ready for messages" % cid)
        self.db.insert("INSERT INTO outbound_messages"
                       " (cid, when_sent, payload_json)"
                       " VALUES (?,?,?)",
                       (cid, time.time(), json.dumps(payload)),
                       "outbound_messages")
        self.db.commit() # XXX ?. Or wait for c.send() to commit?
        c = channel.OutboundChannel(self.db, cid)
        return c.send(payload)
dataset/ETHPy150Open warner/petmail/petmail/agent.py/Agent.send_message/original