Esempio n. 1
0
    def __init__(self,
                 opts,
                 node_ssl_service: Optional[NodeSSLService] = None,
                 block_queueing_cls=BtcBlockQueuingService):
        if opts.use_extensions:
            helpers.set_extensions_parallelism()
        if node_ssl_service is None:
            node_ssl_service = MockNodeSSLService(self.NODE_TYPE, MagicMock())
        super(MockGatewayNode, self).__init__(opts, node_ssl_service)

        self.broadcast_messages = []
        self.broadcast_to_nodes_messages = []
        self._tx_service = GatewayTransactionService(self, 0)
        self.block_cleanup_service = self._get_cleanup_service()
        self.block_queuing_service = block_queueing_cls(self)
        self.message_converter = MockMessageConverter()
        if opts.use_extensions:
            from bxgateway.services.extension_gateway_transaction_service import ExtensionGatewayTransactionService
            self._tx_service = ExtensionGatewayTransactionService(
                self, self.network_num)
        else:
            self._tx_service = GatewayTransactionService(
                self, self.network_num)
        self.opts.has_fully_updated_tx_service = True
        self.requester = MagicMock()
        self.has_active_blockchain_peer = MagicMock(return_value=True)
        self.min_tx_from_node_gas_price = MagicMock()
Esempio n. 2
0
    def process_transactions_message_from_node(
        self,
        msg,
        min_tx_network_fee: int,
        enable_transaction_validation: bool
    ) -> List[ProcessTransactionMessageFromNodeResult]:
        opts = self.node.opts
        msg_bytes = msg.rawbytes()

        if (isinstance(self.node, OntGatewayNode) or isinstance(self.node, EthGatewayNode)) and \
                opts.process_node_txs_in_extension:
            ext_processing_results = memoryview(self.proxy.process_gateway_transaction_from_node(
                tpe.InputBytes(msg_bytes),
                min_tx_network_fee,
                enable_transaction_validation
            ))
        else:
            return GatewayTransactionService.process_transactions_message_from_node(
                self, msg, min_tx_network_fee, enable_transaction_validation
            )

        result = []

        offset = 0

        txs_count, = struct.unpack_from("<I", ext_processing_results, offset)
        offset += constants.UL_INT_SIZE_IN_BYTES

        while offset < len(ext_processing_results):
            seen, = struct.unpack_from("<?", ext_processing_results, offset)
            offset += 1

            tx_hash = Sha256Hash(ext_processing_results[offset:offset + crypto.SHA256_HASH_LEN])
            offset += crypto.SHA256_HASH_LEN
            tx_offset, = struct.unpack_from("<I", ext_processing_results, offset)
            offset += constants.UL_INT_SIZE_IN_BYTES
            tx_len, = struct.unpack_from("<I", ext_processing_results, offset)
            offset += constants.UL_INT_SIZE_IN_BYTES
            tx_validation_status, = struct.unpack_from("<I", ext_processing_results, offset)
            offset += constants.UL_INT_SIZE_IN_BYTES

            tx_contents = msg_bytes[tx_offset:tx_offset + tx_len]

            result.append(
                ProcessTransactionMessageFromNodeResult(
                    seen,
                    tx_hash,
                    tx_contents,
                    TxMessage(message_hash=tx_hash, network_num=self.network_num, tx_val=tx_contents),
                    TxValidationStatus(tx_validation_status)
                )
            )

            if not seen:
                transaction_cache_key = self._tx_hash_to_cache_key(tx_hash)
                self.set_transaction_contents_base(tx_hash, transaction_cache_key, False, 0, False, tx_contents, tx_len)

        assert txs_count == len(result)

        return result
    def process_transactions_message_from_node(
            self, msg) -> List[ProcessTransactionMessageFromNodeResult]:
        opts = cast(GatewayOpts, self.node.opts)
        msg_bytes = msg.rawbytes()

        if isinstance(self.node,
                      OntGatewayNode) and opts.process_node_txs_in_extension:
            ext_processing_results = memoryview(
                self.proxy.process_gateway_transaction_from_node(
                    BlockchainProtocol.ONTOLOGY.value,
                    tpe.InputBytes(msg_bytes)))
        elif isinstance(self.node,
                        EthGatewayNode) and opts.process_node_txs_in_extension:
            ext_processing_results = memoryview(
                self.proxy.process_gateway_transaction_from_node(
                    BlockchainProtocol.ETHEREUM.value,
                    tpe.InputBytes(msg_bytes)))
        else:
            return GatewayTransactionService.process_transactions_message_from_node(
                self, msg)

        result = []

        offset = 0

        txs_count, = struct.unpack_from("<I", ext_processing_results, offset)
        offset += constants.UL_INT_SIZE_IN_BYTES

        while offset < len(ext_processing_results):
            seen, = struct.unpack_from("<?", ext_processing_results, offset)
            offset += 1

            tx_hash = Sha256Hash(
                ext_processing_results[offset:offset + crypto.SHA256_HASH_LEN])
            offset += crypto.SHA256_HASH_LEN
            tx_offset, = struct.unpack_from("<I", ext_processing_results,
                                            offset)
            offset += constants.UL_INT_SIZE_IN_BYTES
            tx_len, = struct.unpack_from("<I", ext_processing_results, offset)
            offset += constants.UL_INT_SIZE_IN_BYTES

            tx_contents = msg_bytes[tx_offset:tx_offset + tx_len]

            result.append(
                ProcessTransactionMessageFromNodeResult(
                    seen, tx_hash, tx_contents,
                    TxMessage(message_hash=tx_hash,
                              network_num=self.network_num,
                              tx_val=tx_contents)))

            if not seen:
                transaction_cache_key = self._tx_hash_to_cache_key(tx_hash)
                self.set_transaction_contents_base(tx_hash,
                                                   transaction_cache_key,
                                                   tx_contents, False, 0,
                                                   False)

        assert txs_count == len(result)

        return result
Esempio n. 4
0
 def _get_transaction_service(self) -> GatewayTransactionService:
     return GatewayTransactionService(self.mock_node, 0)