Search in sources :

Example 1 with MetadataMessageHandler

use of tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler in project teku by ConsenSys.

the class BeaconChainMethods method createMetadata.

private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(final Spec spec, final AsyncRunner asyncRunner, final MetadataMessagesFactory metadataMessagesFactory, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
    final MetadataMessageHandler messageHandler = new MetadataMessageHandler(spec, metadataMessagesFactory);
    final EmptyMessageSchema requestType = EmptyMessage.SSZ_SCHEMA;
    final boolean expectResponse = true;
    final SszSchema<MetadataMessage> phase0MetadataSchema = SszSchema.as(MetadataMessage.class, spec.forMilestone(SpecMilestone.PHASE0).getSchemaDefinitions().getMetadataMessageSchema());
    final RpcContextCodec<?, MetadataMessage> phase0ContextCodec = RpcContextCodec.noop(phase0MetadataSchema);
    final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v1Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GET_METADATA, 1, rpcEncoding, requestType, expectResponse, phase0ContextCodec, messageHandler, peerLookup);
    if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
        final SszSchema<MetadataMessage> altairMetadataSchema = SszSchema.as(MetadataMessage.class, spec.forMilestone(SpecMilestone.ALTAIR).getSchemaDefinitions().getMetadataMessageSchema());
        final RpcContextCodec<?, MetadataMessage> altairContextCodec = RpcContextCodec.noop(altairMetadataSchema);
        final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v2Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GET_METADATA, 2, rpcEncoding, requestType, expectResponse, altairContextCodec, messageHandler, peerLookup);
        return VersionedEth2RpcMethod.create(rpcEncoding, requestType, expectResponse, List.of(v2Method, v1Method));
    } else {
        return v1Method;
    }
}
Also used : MetadataMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler) SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) EmptyMessageSchema(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage.EmptyMessageSchema) EmptyMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage)

Aggregations

MetadataMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler)1 SingleProtocolEth2RpcMethod (tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod)1 EmptyMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage)1 EmptyMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage.EmptyMessageSchema)1 MetadataMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage)1