// Copyright 2020 Prysmatic Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";

package ethereum.eth.service;

import "google/api/annotations.proto";
import "google/protobuf/descriptor.proto";
import "google/protobuf/empty.proto";

import "proto/eth/v1/beacon_block.proto";
import "proto/eth/v1/beacon_chain.proto";
import "proto/eth/v2/beacon_block.proto";
import "proto/eth/v2/beacon_state.proto";
import "proto/eth/v2/ssz.proto";
import "proto/eth/v2/sync_committee.proto";

option csharp_namespace = "Ethereum.Eth.Service";
option go_package = "github.com/prysmaticlabs/prysm/v4/proto/eth/service";
option java_multiple_files = true;
option java_outer_classname = "BeaconChainServiceProto";
option java_package = "org.ethereum.eth.service";
option php_namespace = "Ethereum\\Eth\\Service";

// Beacon Chain API
//
// The config API endpoints can be used to query the beacon chain state and information. Such as spec, current fork,
// blocks, and the validator spec.
//
// This service is defined in the upstream Ethereum consensus APIs repository (beacon-apis/apis/).
service BeaconChain {
  // Beacon state API related endpoints.

  // GetWeakSubjectivity is a new proposed endpoint to retrieve the details necessary to download
  // the ssz data needed to start a beacon node - checkpoint(epoch + block_root) and state_root
  // DEPRECATED: GetWeakSubjectivity endpoint will no longer be supported
  rpc GetWeakSubjectivity(google.protobuf.Empty) returns (v1.WeakSubjectivityResponse) {
    option deprecated = true;
    option (google.api.http) = {get: "/internal/eth/v1/beacon/weak_subjectivity"};
  }

  // GetStateRoot calculates HashTreeRoot for state with given 'stateId'. If stateId is root, same value will be returned.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getStateRoot
  rpc GetStateRoot(v1.StateRequest) returns (v1.StateRootResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/states/{state_id}/root"
    };
  }

  // ListSyncCommittees retrieves the sync committees for the given state at the given epoch.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getEpochSyncCommittees
  rpc ListSyncCommittees(v2.StateSyncCommitteesRequest) returns (v2.StateSyncCommitteesResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/states/{state_id}/sync_committees"
    };
  }

  // GetRandao fetches the RANDAO mix for the requested epoch from the state identified by state_id.
  // If an epoch is not specified then the RANDAO mix for the state's current epoch will be returned.
  // By adjusting the state_id parameter you can query for any historic value of the RANDAO mix.
  // Ordinarily states from the same epoch will mutate the RANDAO mix for that epoch as blocks are applied.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getStateRandao
  rpc GetRandao(v2.RandaoRequest) returns (v2.RandaoResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/states/{state_id}/randao"
    };
  }

  // GetBlock retrieves block details for given block id.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getBlock
  // DEPRECATED: GetBlock is deprecated in favor of GetBlockV2
  rpc GetBlock(v1.BlockRequest) returns (v1.BlockResponse) {
    option deprecated = true;
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/blocks/{block_id}"
    };
  }

  // GetBlockSSZ returns the SSZ-serialized version of block details for given block id.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getBlock
  // DEPRECATED: GetBlockSSZ is deprecated in favor of GetBlockV2SSZ
  rpc GetBlockSSZ(v1.BlockRequest) returns (v1.BlockSSZResponse) {
    option deprecated = true;
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/blocks/{block_id}/ssz"
    };
  }

  // GetBlockV2 retrieves block details for given block id.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getBlockV2
  rpc GetBlockV2(v2.BlockRequestV2) returns (v2.BlockResponseV2) {
    option (google.api.http) = {
      get: "/internal/eth/v2/beacon/blocks/{block_id}"
    };
  }

  // GetBlindedBlock retrieves blinded block for given block id.
  //
  // https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlindedBlock
  rpc GetBlindedBlock(v1.BlockRequest) returns (v2.BlindedBlockResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/blinded_blocks/{block_id}"
    };
  }

  // GetBlindedBlockSSZ returns the SSZ-serialized version of blinded block details for given block id.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlindedBlock
  rpc GetBlindedBlockSSZ(v1.BlockRequest) returns (v2.SSZContainer) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/blinded_blocks/{block_id}/ssz"
    };
  }

  // GetBlockSSZV2 returns the SSZ-serialized version of block details for given block id.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getBlockV2
  rpc GetBlockSSZV2(v2.BlockRequestV2) returns (v2.SSZContainer) {
    option (google.api.http) = {
      get: "/internal/eth/v2/beacon/blocks/{block_id}/ssz"
    };
  }

  // ListBlockAttestations retrieves attestation included in requested block.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getBlockAttestations
  rpc ListBlockAttestations(v1.BlockRequest) returns (v1.BlockAttestationsResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/blocks/{block_id}/attestations"
    };
  }

  // Beacon pools API related endpoints.

  // ListPoolAttesterSlashings retrieves attester slashings known by the node but
  // not necessarily incorporated into any block.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getPoolAttesterSlashings
  rpc ListPoolAttesterSlashings(google.protobuf.Empty) returns (v1.AttesterSlashingsPoolResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/pool/attester_slashings"
    };
  }

  // SubmitAttesterSlashing submits AttesterSlashing object to node's pool and
  // if passes validation node MUST broadcast it to network.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/submitPoolAttesterSlashings
  rpc SubmitAttesterSlashing(v1.AttesterSlashing) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/internal/eth/v1/beacon/pool/attester_slashings"
      body: "*"
    };
  }

  // ListPoolProposerSlashings retrieves proposer slashings known by the node
  // but not necessarily incorporated into any block.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/getPoolProposerSlashings
  rpc ListPoolProposerSlashings(google.protobuf.Empty) returns (v1.ProposerSlashingPoolResponse) {
    option (google.api.http) = {
      get: "/internal/eth/v1/beacon/pool/proposer_slashings"
    };
  }

  // SubmitProposerSlashing submits AttesterSlashing object to node's pool and if
  // passes validation node MUST broadcast it to network.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Beacon/submitPoolProposerSlashings
  rpc SubmitProposerSlashing(v1.ProposerSlashing) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/internal/eth/v1/beacon/pool/proposer_slashings"
      body: "*"
    };
  }

  // Beacon config API related endpoints.

  // GetForkSchedule retrieve all scheduled upcoming forks this node is aware of.
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Config/getForkSchedule
  rpc GetForkSchedule(google.protobuf.Empty) returns (v1.ForkScheduleResponse) {
    option (google.api.http) = {get: "/internal/eth/v1/config/fork_schedule"};
  }

  // Spec retrieves specification configuration (without Phase 1 params) used on this node. Specification params list
  // Values are returned with following format:
  // - any value starting with 0x in the spec is returned as a hex string
  // - all other values are returned as number
  //
  // Spec: https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.3.0#/Config/getSpec
  rpc GetSpec(google.protobuf.Empty) returns (v1.SpecResponse) {
    option (google.api.http) = {get: "/internal/eth/v1/config/spec"};
  }
}
