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)
def check_tx(self, raw_transaction): """Validate the transaction before entry into the mempool. Args: raw_tx: a raw string (in bytes) transaction.""" logger.debug('check_tx: %s', raw_transaction) transaction = decode_transaction(raw_transaction) if self.bigchaindb.validate_transaction(transaction): logger.debug('check_tx: VALID') return Result.ok() else: logger.debug('check_tx: INVALID') return Result.error()
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 Result.error(log='Invalid transaction') else: logger.debug('storing tx') self.block_txn_ids.append(transaction.id) self.block_transactions.append(transaction) return Result.ok()
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 Result.ok() else: logger.debug('check_tx: INVALID') logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id']) return Result.error()