Пример #1
0
def LESV2PeerPairFactory(
    *,
    alice_peer_context: ChainContext = None,
    alice_remote: kademlia.Node = None,
    alice_private_key: keys.PrivateKey = None,
    alice_client_version: str = 'alice',
    bob_peer_context: ChainContext = None,
    bob_remote: kademlia.Node = None,
    bob_private_key: keys.PrivateKey = None,
    bob_client_version: str = 'bob',
    cancel_token: CancelToken = None,
    event_bus: EndpointAPI = None,
) -> AsyncContextManager[Tuple[LESPeer, LESPeer]]:
    if alice_peer_context is None:
        alice_peer_context = ChainContextFactory()
    if bob_peer_context is None:
        bob_peer_context = ChainContextFactory()

    return cast(
        AsyncContextManager[Tuple[LESPeer, LESPeer]],
        PeerPairFactory(
            alice_peer_context=alice_peer_context,
            alice_peer_factory_class=LESPeerFactory,
            bob_peer_context=bob_peer_context,
            bob_peer_factory_class=LESPeerFactory,
            alice_remote=alice_remote,
            alice_private_key=alice_private_key,
            alice_client_version=alice_client_version,
            bob_remote=bob_remote,
            bob_private_key=bob_private_key,
            bob_client_version=bob_client_version,
            cancel_token=cancel_token,
            event_bus=event_bus,
        ))
Пример #2
0
def LESV1PeerPairFactory(
    *,
    alice_peer_context: ChainContext = None,
    alice_remote: kademlia.Node = None,
    alice_private_key: keys.PrivateKey = None,
    alice_client_version: str = 'alice',
    bob_peer_context: ChainContext = None,
    bob_remote: kademlia.Node = None,
    bob_private_key: keys.PrivateKey = None,
    bob_client_version: str = 'bob',
    event_bus: EndpointAPI = None,
) -> AsyncContextManager[Tuple[LESV1Peer, LESV1Peer]]:
    if alice_peer_context is None:
        alice_peer_context = ChainContextFactory()
    if bob_peer_context is None:
        alice_genesis = alice_peer_context.headerdb.get_canonical_block_header_by_number(
            BlockNumber(GENESIS_BLOCK_NUMBER), )
        bob_peer_context = ChainContextFactory(
            headerdb__genesis_params={'timestamp': alice_genesis.timestamp}, )

    return cast(
        AsyncContextManager[Tuple[LESV1Peer, LESV1Peer]],
        PeerPairFactory(
            alice_peer_context=alice_peer_context,
            alice_peer_factory_class=LESV1PeerFactory,
            bob_peer_context=bob_peer_context,
            bob_peer_factory_class=LESV1PeerFactory,
            alice_remote=alice_remote,
            alice_private_key=alice_private_key,
            alice_client_version=alice_client_version,
            bob_remote=bob_remote,
            bob_private_key=bob_private_key,
            bob_client_version=bob_client_version,
            event_bus=event_bus,
        ))