Пример #1
0
class GetBlockHeadersV65Exchange(BaseGetBlockHeadersV65Exchange):
    _normalizer = DefaultNormalizer(BlockHeadersV65, Tuple[BlockHeaderAPI, ...])
    tracker_class = GetBlockHeadersTracker

    _request_command_type = GetBlockHeadersV65
    _response_command_type = BlockHeadersV65

    async def __call__(  # type: ignore
            self,
            block_number_or_hash: BlockIdentifier,
            max_headers: int = None,
            skip: int = 0,
            reverse: bool = True,
            timeout: float = None) -> Tuple[BlockHeaderAPI, ...]:

        original_request_args = (block_number_or_hash, max_headers, skip, reverse)
        validator = GetBlockHeadersValidator(*original_request_args)
        request = GetBlockHeadersV65(BlockHeadersQuery(*original_request_args))

        return await self.get_result(
            request,
            self._normalizer,
            validator,
            noop_payload_validator,
            timeout,
        )
Пример #2
0
class GetPooledTransactionsV65Exchange(BasePooledTransactionsV65Exchange):
    _normalizer = DefaultNormalizer(PooledTransactionsV65, Tuple[SignedTransactionAPI, ...])
    tracker_class = GetPooledTransactionsTracker

    _request_command_type = GetPooledTransactionsV65
    _response_command_type = PooledTransactionsV65

    async def __call__(self,  # type: ignore
                       transaction_hashes: Sequence[Hash32],
                       timeout: float = None) -> Tuple[SignedTransactionAPI, ...]:
        validator = GetPooledTransactionsValidator(transaction_hashes)
        request = GetPooledTransactionsV65(tuple(transaction_hashes))
        return await self.get_result(
            request,
            self._normalizer,
            validator,
            noop_payload_validator,
            timeout,
        )
Пример #3
0
class GetBlockHeadersExchange(BaseGetBlockHeadersExchange):
    _normalizer = DefaultNormalizer(
        BlockHeaders,
        tuple,
        # Tuple[BlockHeaderAPI, ...],
        normalize_fn=lambda res: res.payload.headers)
    tracker_class = GetBlockHeadersTracker

    _request_command_type = GetBlockHeaders
    _response_command_type = BlockHeaders

    async def __call__(  # type: ignore
            self,
            block_number_or_hash: BlockIdentifier,
            max_headers: int = None,
            skip: int = 0,
            reverse: bool = True,
            timeout: float = None) -> Tuple[BlockHeaderAPI, ...]:

        original_request_args = (block_number_or_hash, max_headers, skip,
                                 reverse)
        validator = GetBlockHeadersValidator(*original_request_args)

        query = BlockHeadersQuery(
            block_number_or_hash=block_number_or_hash,
            max_headers=max_headers,
            skip=skip,
            reverse=reverse,
        )
        payload = GetBlockHeadersPayload(
            request_id=gen_request_id(),
            query=query,
        )
        request = GetBlockHeaders(payload)

        return tuple(await self.get_result(
            request,
            self._normalizer,
            validator,
            match_payload_request_id,
            timeout,
        ))
Пример #4
0
class BlockWitnessHashesExchange(
        BaseExchange[GetBlockWitnessHashes, BlockWitnessHashes, BlockWitnessHashesPayload]):

    _request_command_type = GetBlockWitnessHashes
    _response_command_type = BlockWitnessHashes
    _normalizer = DefaultNormalizer(BlockWitnessHashes, BlockWitnessHashesPayload)
    tracker_class = GetBlockWitnessHashesTracker

    def __init__(self) -> None:
        super().__init__()
        self.logger = get_logger('trinity.protocol.wit.api.BlockWitnessHashesExchange')

    async def __call__(  # type: ignore
            self, block_hash: Hash32, timeout: float = None) -> Tuple[Hash32, ...]:
        validator = GetBlockWitnessHashesValidator()
        request = GetBlockWitnessHashes(GetBlockWitnessHashesPayload(gen_request_id(), block_hash))
        result = await self.get_result(
            request,
            self._normalizer,
            validator,
            match_payload_request_id,
            timeout,
        )
        return result.node_hashes