Esempio n. 1
0
    def check_tx(self, req):
        # Decode Tx
        decoded_tx = self.__decode_incoming_tx(req.check_tx.tx)

        # Get the account for the sender
        # We use unconfirmed cache to allow multiple Tx per block
        if not decoded_tx.sender:
            return Result.error(code=InternalError,
                                log="No Sender - is the Tx signed?")

        acct = self._storage.unconfirmed.get_account(decoded_tx.sender)
        if not acct:
            return Result.error(code=InternalError, log="Account not found")

        # Check the nonce
        if acct.nonce != decoded_tx.nonce:
            return Result.error(code=InternalError, log="Bad nonce")

        # increment the account nonce
        self._storage.unconfirmed.increment_nonce(decoded_tx.sender)

        # verify the signature
        if not Key.verify(acct.pubkey, decoded_tx.signature):
            return Result.error(code=InternalError, log="Invalid Signature")

        # Check if this is a value transfer, if so make sure sender has an
        # acct balance > tx.value
        if decoded_tx.value > 0 and acct.balance < decoded_tx.value:
            return Result.error(code=InternalError,
                                log="Insufficient balance for transfer")

        return Result.ok()
Esempio n. 2
0
    def deliver_tx(self, req):
        tx = self.__decode_incoming_tx(req.deliver_tx.tx)
        if not tx.call in self._tx_handlers:
            return Result.error(code=InternalError,
                                log="No matching Tx handler")

        if not self._tx_handlers[tx.call](tx, self._storage.confirmed):
            return Result.error(code=InternalError,
                                log="Tx Handler returned false or None")

        return Result.ok()
Esempio n. 3
0
    def deliver_tx(self, tx):
        """ Mutate state if valid Tx """
        if not self.__valid_input(tx):
            return Result.error(log='bad count')

        self.txCount += 1
        return Result.ok()
Esempio n. 4
0
    def check_tx(self, raw_tx):
        """Validate the Tx before entry into the mempool"""

        try:  # Check txn syntax
            tx = utils.Transaction(raw_tx)
        except Exception:
            return Result.error(log='txn syntax invalid')

        # Check "sender" account has enough coins
        if int(self.db.get_address_info(tx.sender)['balance']) < tx.amount:
            return Result.error(log='insufficient funds')

        if tx.signature_invalid:  # Check txn signature
            return Result.error(log='signature invalid')

        if tx.timestamp_invalid:  # Check timestamp for a big delay
            return Result.error(log='lag time is more than 2 hours')

        # Hooray!
        return Result.ok()
Esempio n. 5
0
    def deliver_tx(self, raw_tx):
        """ Mutate state if valid Tx """

        try:  # Handle unvalid txn
            tx = utils.Transaction(raw_tx)
        except Exception:
            return Result.error(log='txn syntax invalid')

        self.new_block_txs.append(tx)
        self.db.update_state(tx=tx)

        return Result.ok()
Esempio n. 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."""
        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()
Esempio n. 7
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.validate_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.bigchaindb.store_transaction(transaction)
            self.block_txn_ids.append(transaction.id)
            self.block_transactions.append(transaction)
            return Result.ok()
Esempio n. 8
0
    def check_tx(self, tx):
        """ Validate the Tx before entry into the mempool """
        if not self.__valid_input(tx):
            return Result.error(log='bad count')

        return Result.ok(log='thumbs up')