コード例 #1
0
 def deliver_tx(self, tx) -> ResponseDeliverTx:
     end_point = '/send_tx'
     data = {'tx': tx}
     try:
         request(end_point, 'POST', data=data)
         return ResponseDeliverTx(code=CodeTypeOk)
     except Exception as e:
         print(e)
         return ResponseDeliverTx(code=1)
コード例 #2
0
    def deliver_tx(self, raw_tx):
        """ Mutate state if valid Tx """

        try:  # Handle unvalid txn
            tx = utils.Transaction(raw_tx)
        except Exception:
            return ResponseDeliverTx(log='txn syntax invalid', code=1)

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

        return ResponseDeliverTx(code=CodeTypeOk)
コード例 #3
0
ファイル: SimpleABCI.py プロジェクト: co4524/Benchmarking
 def deliver_tx(self, tx) -> ResponseDeliverTx:
     '''
     end_point = '/send_tx'
     data = {'tx': tx}
     try:
         request(end_point, 'POST', data=data)
         return ResponseDeliverTx(code=CodeTypeOk)
     except Exception as e:
         print(e)
         return ResponseDeliverTx(code=1)
     '''
     if tx in self.done:
         print("I am not doing and U R IDIOT")
         return ResponseDeliverTx(code=1)
     else:
         self.txIndex += 1
         return ResponseDeliverTx(code=CodeTypeOk)
コード例 #4
0
ファイル: server.py プロジェクト: kevlubkcm/tenderpotato
    def deliver_tx(self, state: State, message: Message) -> Tuple[State, ResponseDeliverTx]:
        assert type(message.data) is TossPotato

        if message.sender != state.players[state.potato_holder]:
            return state, ResponseDeliverTx(code=1, info='Not holding the potato')

        if message.data.receiver not in state.players:
            return state, ResponseDeliverTx(code=1, info='Target player does not exist')

        idx = state.players.index(message.data.receiver)
        return State(
            state.players,
            state.losses,
            idx,
            state.blow_up_height,
            state.last_block_height
        ), ResponseDeliverTx(code=0)
コード例 #5
0
ファイル: core.py プロジェクト: todun/vimana
    def deliver_tx(self, tx):
        """Validate the transaction before mutating the state.

        Args:
            raw_tx: a raw string (in bytes) transaction.
        Returns: output to be send to the node in string after encoding.
        """
        transaction = decode_transaction(tx)
        logger.debug(transaction)

        method = get_transaction_method(transaction)

        if not method or method not in method_list:
            raise ValueError('Mode must be one of the following {}.'.format(
                ', '.join(method_list)))

        # UPDATE DOCS: -1 is an indication of no response.
        response_encoded = -1

        if (method == method_query):
            # calculate hash of the input.
            key = self.state.get_transaction_hash(transaction, method_query)

            # get model output
            value = self.state.get_model_output(transaction)

            logger.info("✅ Transaction recived %s = %s", key, value)

            self.state.db.set(prefix_key(key), value)
            self.state.size += 1

            response_encoded = encode_output(value)

        elif (method == method_upload):
            """name, hash and url from where to be downloaded
            """

            logger.info(method + "📦!!")
            # get the hash key of the model from the tx
            model_name, key, url_of_model = self.state.get_transaction_hash(
                transaction, method_upload)

            # no need to check if model exists already, tendermint does by default

            # get the relative location of the model inside the Model folder, this part downloads the model.
            location = get_model(model_name, key, url_of_model)

            logger.debug("Transaction recived model of %s hash 🛳", key)

            self.state.db.set(prefix_model(key), location)
            self.state.size += 1

            response_encoded = encode_output_str(location)
            logger.info(response_encoded)

        logger.info("😍 Wow! Transaction delivered succesfully ")

        return ResponseDeliverTx(code=CodeTypeOk, data=response_encoded)
コード例 #6
0
ファイル: server.py プロジェクト: kevlubkcm/tenderpotato
    def deliver_tx(self, state: State, message: Message) -> Tuple[State, ResponseDeliverTx]:
        if message.sender in state.players:
            return state, ResponseDeliverTx(code=1, info='Already playing')

        if len(state.players) == 1:  # We have enough players to start
            blowup = -1
            holder = 1
        else:
            blowup = state.blow_up_height
            holder = state.potato_holder

        return State(
            state.players + (message.sender, ),
            state.losses + (0, ),
            holder,
            blowup,
            state.last_block_height,
        ), ResponseDeliverTx(code=0)
コード例 #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)
コード例 #8
0
    def deliver_tx(self, tx) -> ResponseDeliverTx:
        """Simply increment the state"""
        # value = decode_number(tx)
        # self.txCount += 1
        # log.info("Got DeliverTx {}, so txCount increase to {}".format(tx))
        log.info("Got DeliverTx  {}".format(tx))
        value = eval(tx.decode())
        # log.info(value)

        self.controller.tx_manager(value)
        log.info("Delivery ok")

        return ResponseDeliverTx(code=CodeTypeOk)
コード例 #9
0
ファイル: kvstore.py プロジェクト: morteza404/tendermint
    def deliver_tx(self, tx):
        """Validate the transaction before mutating the state.
        Args:
            raw_tx: a raw string (in bytes) transaction.
        """
        logger.info("Transaction recived %s", tx)

        parts = tx.split(b'=')
        if len(parts) == 2:
            key, value = parts[0], parts[1]
        else:
            key, value = tx
        self.state.db.set(prefix_key(key), value)
        self.state.size += 1

        logger.info("Transaction delivered succesfully")
        return ResponseDeliverTx(code=CodeTypeOk)
コード例 #10
0
ファイル: counter.py プロジェクト: morteza404/tendermint
 def deliver_tx(self, tx) -> ResponseDeliverTx:
     """Simply increment the state"""
     self.txCount += 1
     return ResponseDeliverTx(code=CodeTypeOk)
コード例 #11
0
 def deliver_tx(self, raw_transaction):
     self.parallel_validator.validate(raw_transaction)
     return ResponseDeliverTx(code=CodeTypeOk)