Ejemplo n.º 1
0
    def _sendtxn(self, minfo):
        """
        Build a transaction for the update, wrap it in a message with all
        of the appropriate signatures and post it to the validator
        """

        txn = XoTransaction(minfo=minfo)

        # add the last transaction submitted to ensure that the ordering
        # in the journal matches the order in which we generated them
        if self.LastTransaction:
            txn.Dependencies = [self.LastTransaction]

        txn.sign_from_node(self.LocalNode)
        txnid = txn.Identifier

        txn.check_valid(self._current_state.State)
        if not txn.is_valid(self._current_state.State):
            raise XoClientException('transaction failed to apply')

        msg = XoTransactionMessage()
        msg.Transaction = txn
        msg.SenderID = self.LocalNode.Identifier
        msg.sign_from_node(self.LocalNode)

        try:
            LOGGER.debug('Posting transaction: %s', txnid)
            result = self.postmsg(msg.MessageType, msg.dump())

        except MessageException:
            return None

        except:
            LOGGER.debug('message post failed for some unusual reason')
            return None

        # if there was no exception thrown then all transactions should return
        # a value which is a dictionary with the message that was sent
        assert result

        # if the message was successfully posted, then save the transaction
        # id for future dependencies this could be a problem if the transaction
        # fails during application
        self.LastTransaction = txnid
        txn.apply(self._current_state.State)

        return txnid