Exemple #1
0
def test_encode_decode_transaction(b):
    from bigchaindb.tendermint_utils import (encode_transaction,
                                             decode_transaction)

    asset = {'value': 'key'}

    encode_tx = encode_transaction(asset)
    new_encode_tx = base64.b64encode(
        json.dumps(asset).encode('utf8')).decode('utf8')

    assert encode_tx == new_encode_tx

    de64 = base64.b64decode(encode_tx)
    assert asset == decode_transaction(de64)
Exemple #2
0
def test_encode_decode_transaction(b):
    from bigchaindb.tendermint_utils import (encode_transaction,
                                             decode_transaction)

    asset = {
        'value': 'key'
    }

    encode_tx = encode_transaction(asset)
    new_encode_tx = base64.b64encode(json.dumps(asset).
                                     encode('utf8')).decode('utf8')

    assert encode_tx == new_encode_tx

    de64 = base64.b64decode(encode_tx)
    assert asset == decode_transaction(de64)
Exemple #3
0
    def deliver_tx(self, raw_transaction):
        """Validate the transaction before mutating the state.

        Args:
            raw_tx: a raw string (in bytes) transaction."""
        logger.debug('deliver_tx: %s', raw_transaction)
        transaction = self.bigchaindb.is_valid_transaction(
            decode_transaction(raw_transaction), self.block_transactions)

        if not transaction:
            logger.debug('deliver_tx: INVALID')
            return ResponseDeliverTx(code=CodeTypeError)
        else:
            logger.debug('storing tx')
            self.block_txn_ids.append(transaction.id)
            self.block_transactions.append(transaction)
            return ResponseDeliverTx(code=CodeTypeOk)
Exemple #4
0
    def check_tx(self, raw_transaction):
        """Validate the transaction before entry into
        the mempool.

        Args:
            raw_tx: a raw string (in bytes) transaction.
        """

        self.abort_if_abci_chain_is_not_synced()

        logger.debug('check_tx: %s', raw_transaction)
        transaction = decode_transaction(raw_transaction)
        if self.bigchaindb.is_valid_transaction(transaction):
            logger.debug('check_tx: VALID')
            return ResponseCheckTx(code=CodeTypeOk)
        else:
            logger.debug('check_tx: INVALID')
            return ResponseCheckTx(code=CodeTypeError)
Exemple #5
0
    def check_tx(self, raw_transaction):
        """Validate the transaction before entry into
        the mempool.

        Args:
            raw_tx: a raw string (in bytes) transaction."""

        logger.benchmark('CHECK_TX_INIT')
        logger.debug('check_tx: %s', raw_transaction)
        transaction = decode_transaction(raw_transaction)
        if self.bigchaindb.is_valid_transaction(transaction):
            logger.debug('check_tx: VALID')
            logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
            return ResponseCheckTx(code=CodeTypeOk)
        else:
            logger.debug('check_tx: INVALID')
            logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
            return ResponseCheckTx(code=CodeTypeError)
Exemple #6
0
    def check_tx(self, raw_transaction):
        """Validate the transaction before entry into
        the mempool.

        Args:
            raw_tx: a raw string (in bytes) transaction.
        """

        self.abort_if_abci_chain_is_not_synced()

        logger.debug('check_tx: %s', raw_transaction)
        transaction = decode_transaction(raw_transaction)
        if self.bigchaindb.is_valid_transaction(transaction):
            logger.debug('check_tx: VALID')
            return ResponseCheckTx(code=CodeTypeOk)
        else:
            logger.debug('check_tx: INVALID')
            return ResponseCheckTx(code=CodeTypeError)
Exemple #7
0
    def deliver_tx(self, raw_transaction):
        """Validate the transaction before mutating the state.

        Args:
            raw_tx: a raw string (in bytes) transaction.
        """

        self.abort_if_abci_chain_is_not_synced()

        logger.debug('deliver_tx: %s', raw_transaction)
        transaction = self.bigchaindb.is_valid_transaction(
            decode_transaction(raw_transaction), self.block_transactions)

        if not transaction:
            logger.debug('deliver_tx: INVALID')
            return ResponseDeliverTx(code=CodeTypeError)
        else:
            logger.debug('storing tx')
            self.block_txn_ids.append(transaction.id)
            self.block_transactions.append(transaction)
            return ResponseDeliverTx(code=CodeTypeOk)
 def validate(self, raw_transaction):
     dict_transaction = decode_transaction(raw_transaction)
     index = int(dict_transaction['id'], 16) % self.number_of_workers
     self.routing_queues[index].put(
         (self.transaction_index, dict_transaction))
     self.transaction_index += 1
 def validate(self, raw_transaction):
     dict_transaction = decode_transaction(raw_transaction)
     index = int(dict_transaction['id'], 16) % self.number_of_workers
     self.routing_queues[index].put((self.transaction_index, dict_transaction))
     self.transaction_index += 1