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()
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()
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()
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 check_tx(self, tx): """ Validate the Tx before entry into the mempool """ txdecoded = tx.decode() logger.info("CHECKING TX: " + txdecoded) txdict = decode_tx(txdecoded) tx = Transaction.from_dict(txdict) return Result.ok(log='thumbs up')
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()
def deliver_tx(self, tx): """ Mutate state if valid Tx """ txdecoded = tx.decode() logger.info("CHECKING TX: " + txdecoded) txdict = decode_tx(txdecoded) tx = Transaction.from_dict(txdict) self.handle_tx(tx) self.txCount += 1 return Result.ok(log="delivered eshta")
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()
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()
def commit(self): """Store the new height and along with block hash.""" # register a new block only when new transactions are received if self.block_txn_ids: self.bigchaindb.store_bulk_transactions(self.block_transactions) block = Block(app_hash=self.block_txn_hash, height=self.new_height, transactions=self.block_txn_ids) self.bigchaindb.store_block(block._asdict()) data = self.block_txn_hash.encode('utf-8') return Result.ok(data=data)
def commit(self): """Store the new height and along with block hash.""" data = self.block_txn_hash.encode('utf-8') # register a new block only when new transactions are received if self.block_txn_ids: self.bigchaindb.store_bulk_transactions(self.block_transactions) block = Block(app_hash=self.block_txn_hash, height=self.new_height, transactions=self.block_txn_ids) # NOTE: storing the block should be the last operation during commit # this effects crash recovery. Refer BEP#8 for details self.bigchaindb.store_block(block._asdict()) return Result.ok(data=data)
def commit(self): """Return the current encode state value to tendermint""" h = struct.pack('>Q', self.txCount) return Result.ok(data=h)
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')
def commit(self, req): apphash = self._storage.commit() return Result.ok(data=h)
def commit(self): logger.info("COMMITTING"+str(self.stats())) """Return the current encode state value to tendermint""" h = struct.pack('>Q', self.txCount) return Result.ok(data=h)
def commit(self): """Return the current encode state value to tendermint""" h = self.db.get_block_app_hash().encode() return Result.ok(data=h)