github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/rpc/apimiddleware/structs.go (about)

     1  package apimiddleware
     2  
     3  import "github.com/prysmaticlabs/prysm/shared/gateway"
     4  
     5  // genesisResponseJson is used in /beacon/genesis API endpoint.
     6  type genesisResponseJson struct {
     7  	Data *genesisResponse_GenesisJson `json:"data"`
     8  }
     9  
    10  // genesisResponse_GenesisJson is used in /beacon/genesis API endpoint.
    11  type genesisResponse_GenesisJson struct {
    12  	GenesisTime           string `json:"genesis_time" time:"true"`
    13  	GenesisValidatorsRoot string `json:"genesis_validators_root" hex:"true"`
    14  	GenesisForkVersion    string `json:"genesis_fork_version" hex:"true"`
    15  }
    16  
    17  // stateRootResponseJson is used in /beacon/states/{state_id}/root API endpoint.
    18  type stateRootResponseJson struct {
    19  	Data *stateRootResponse_StateRootJson `json:"data"`
    20  }
    21  
    22  // stateRootResponse_StateRootJson is used in /beacon/states/{state_id}/root API endpoint.
    23  type stateRootResponse_StateRootJson struct {
    24  	StateRoot string `json:"root" hex:"true"`
    25  }
    26  
    27  // stateForkResponseJson is used in /beacon/states/{state_id}/fork API endpoint.
    28  type stateForkResponseJson struct {
    29  	Data *forkJson `json:"data"`
    30  }
    31  
    32  // stateFinalityCheckpointResponseJson is used in /beacon/states/{state_id}/finality_checkpoints API endpoint.
    33  type stateFinalityCheckpointResponseJson struct {
    34  	Data *stateFinalityCheckpointResponse_StateFinalityCheckpointJson `json:"data"`
    35  }
    36  
    37  // stateFinalityCheckpointResponse_StateFinalityCheckpointJson is used in /beacon/states/{state_id}/finality_checkpoints API endpoint.
    38  type stateFinalityCheckpointResponse_StateFinalityCheckpointJson struct {
    39  	PreviousJustified *checkpointJson `json:"previous_justified"`
    40  	CurrentJustified  *checkpointJson `json:"current_justified"`
    41  	Finalized         *checkpointJson `json:"finalized"`
    42  }
    43  
    44  // stateValidatorResponseJson is used in /beacon/states/{state_id}/validators API endpoint.
    45  type stateValidatorsResponseJson struct {
    46  	Data []*validatorContainerJson `json:"data"`
    47  }
    48  
    49  // stateValidatorResponseJson is used in /beacon/states/{state_id}/validators/{validator_id} API endpoint.
    50  type stateValidatorResponseJson struct {
    51  	Data *validatorContainerJson `json:"data"`
    52  }
    53  
    54  // validatorBalancesResponseJson is used in /beacon/states/{state_id}/validator_balances API endpoint.
    55  type validatorBalancesResponseJson struct {
    56  	Data []*validatorBalanceJson `json:"data"`
    57  }
    58  
    59  // stateCommitteesResponseJson is used in /beacon/states/{state_id}/committees API endpoint.
    60  type stateCommitteesResponseJson struct {
    61  	Data []*committeeJson `json:"data"`
    62  }
    63  
    64  // blockHeadersResponseJson is used in /beacon/headers API endpoint.
    65  type blockHeadersResponseJson struct {
    66  	Data []*blockHeaderContainerJson `json:"data"`
    67  }
    68  
    69  // blockHeaderResponseJson is used in /beacon/headers/{block_id} API endpoint.
    70  type blockHeaderResponseJson struct {
    71  	Data *blockHeaderContainerJson `json:"data"`
    72  }
    73  
    74  // blockResponseJson is used in /beacon/blocks/{block_id} API endpoint.
    75  type blockResponseJson struct {
    76  	Data *beaconBlockContainerJson `json:"data"`
    77  }
    78  
    79  // blockRootResponseJson is used in /beacon/blocks/{block_id}/root API endpoint.
    80  type blockRootResponseJson struct {
    81  	Data *blockRootContainerJson `json:"data"`
    82  }
    83  
    84  // blockAttestationsResponseJson is used in /beacon/blocks/{block_id}/attestations API endpoint.
    85  type blockAttestationsResponseJson struct {
    86  	Data []*attestationJson `json:"data"`
    87  }
    88  
    89  // attestationsPoolResponseJson is used in /beacon/pool/attestations GET API endpoint.
    90  type attestationsPoolResponseJson struct {
    91  	Data []*attestationJson `json:"data"`
    92  }
    93  
    94  // submitAttestationRequestJson is used in /beacon/pool/attestations POST API endpoint.
    95  type submitAttestationRequestJson struct {
    96  	Data []*attestationJson `json:"data"`
    97  }
    98  
    99  // attesterSlashingsPoolResponseJson is used in /beacon/pool/attester_slashings API endpoint.
   100  type attesterSlashingsPoolResponseJson struct {
   101  	Data []*attesterSlashingJson `json:"data"`
   102  }
   103  
   104  // proposerSlashingsPoolResponseJson is used in /beacon/pool/proposer_slashings API endpoint.
   105  type proposerSlashingsPoolResponseJson struct {
   106  	Data []*proposerSlashingJson `json:"data"`
   107  }
   108  
   109  // voluntaryExitsPoolResponseJson is used in /beacon/pool/voluntary_exits API endpoint.
   110  type voluntaryExitsPoolResponseJson struct {
   111  	Data []*signedVoluntaryExitJson `json:"data"`
   112  }
   113  
   114  // identityResponseJson is used in /node/identity API endpoint.
   115  type identityResponseJson struct {
   116  	Data *identityJson `json:"data"`
   117  }
   118  
   119  // peersResponseJson is used in /node/peers API endpoint.
   120  type peersResponseJson struct {
   121  	Data []*peerJson `json:"data"`
   122  }
   123  
   124  // peerResponseJson is used in /node/peers/{peer_id} API endpoint.
   125  type peerResponseJson struct {
   126  	Data *peerJson `json:"data"`
   127  }
   128  
   129  // peerCountResponseJson is used in /node/peer_count API endpoint.
   130  type peerCountResponseJson struct {
   131  	Data peerCountResponse_PeerCountJson `json:"data"`
   132  }
   133  
   134  // peerCountResponse_PeerCountJson is used in /node/peer_count API endpoint.
   135  type peerCountResponse_PeerCountJson struct {
   136  	Disconnected  string `json:"disconnected"`
   137  	Connecting    string `json:"connecting"`
   138  	Connected     string `json:"connected"`
   139  	Disconnecting string `json:"disconnecting"`
   140  }
   141  
   142  // versionResponseJson is used in /node/version API endpoint.
   143  type versionResponseJson struct {
   144  	Data *versionJson `json:"data"`
   145  }
   146  
   147  // syncingResponseJson is used in /node/syncing API endpoint.
   148  type syncingResponseJson struct {
   149  	Data *syncInfoJson `json:"data"`
   150  }
   151  
   152  // beaconStateResponseJson is used in /debug/beacon/states/{state_id} API endpoint.
   153  type beaconStateResponseJson struct {
   154  	Data *beaconStateJson `json:"data"`
   155  }
   156  
   157  // forkChoiceHeadsResponseJson is used in /debug/beacon/heads API endpoint.
   158  type forkChoiceHeadsResponseJson struct {
   159  	Data []*forkChoiceHeadJson `json:"data"`
   160  }
   161  
   162  // forkScheduleResponseJson is used in /config/fork_schedule API endpoint.
   163  type forkScheduleResponseJson struct {
   164  	Data []*forkJson `json:"data"`
   165  }
   166  
   167  // depositContractResponseJson is used in /config/deposit_contract API endpoint.
   168  type depositContractResponseJson struct {
   169  	Data *depositContractJson `json:"data"`
   170  }
   171  
   172  // specResponseJson is used in /config/spec API endpoint.
   173  type specResponseJson struct {
   174  	Data interface{} `json:"data"`
   175  }
   176  
   177  //----------------
   178  // Reusable types.
   179  //----------------
   180  
   181  // checkpointJson is a JSON representation of a checkpoint.
   182  type checkpointJson struct {
   183  	Epoch string `json:"epoch"`
   184  	Root  string `json:"root" hex:"true"`
   185  }
   186  
   187  // blockRootContainerJson is a JSON representation of a block root container.
   188  type blockRootContainerJson struct {
   189  	Root string `json:"root" hex:"true"`
   190  }
   191  
   192  // beaconBlockContainerJson is a JSON representation of a beacon block container.
   193  type beaconBlockContainerJson struct {
   194  	Message   *beaconBlockJson `json:"message"`
   195  	Signature string           `json:"signature" hex:"true"`
   196  }
   197  
   198  // beaconBlockJson is a JSON representation of a beacon block.
   199  type beaconBlockJson struct {
   200  	Slot          string               `json:"slot"`
   201  	ProposerIndex string               `json:"proposer_index"`
   202  	ParentRoot    string               `json:"parent_root" hex:"true"`
   203  	StateRoot     string               `json:"state_root" hex:"true"`
   204  	Body          *beaconBlockBodyJson `json:"body"`
   205  }
   206  
   207  // beaconBlockBodyJson is a JSON representation of a beacon block body.
   208  type beaconBlockBodyJson struct {
   209  	RandaoReveal      string                     `json:"randao_reveal" hex:"true"`
   210  	Eth1Data          *eth1DataJson              `json:"eth1_data"`
   211  	Graffiti          string                     `json:"graffiti" hex:"true"`
   212  	ProposerSlashings []*proposerSlashingJson    `json:"proposer_slashings"`
   213  	AttesterSlashings []*attesterSlashingJson    `json:"attester_slashings"`
   214  	Attestations      []*attestationJson         `json:"attestations"`
   215  	Deposits          []*depositJson             `json:"deposits"`
   216  	VoluntaryExits    []*signedVoluntaryExitJson `json:"voluntary_exits"`
   217  }
   218  
   219  // blockHeaderContainerJson is a JSON representation of a block header container.
   220  type blockHeaderContainerJson struct {
   221  	Root      string                          `json:"root" hex:"true"`
   222  	Canonical bool                            `json:"canonical"`
   223  	Header    *beaconBlockHeaderContainerJson `json:"header"`
   224  }
   225  
   226  // beaconBlockHeaderContainerJson is a JSON representation of a beacon block header container.
   227  type beaconBlockHeaderContainerJson struct {
   228  	Message   *beaconBlockHeaderJson `json:"message"`
   229  	Signature string                 `json:"signature" hex:"true"`
   230  }
   231  
   232  // signedBeaconBlockHeaderJson is a JSON representation of a signed beacon block header.
   233  type signedBeaconBlockHeaderJson struct {
   234  	Header    *beaconBlockHeaderJson `json:"message"`
   235  	Signature string                 `json:"signature" hex:"true"`
   236  }
   237  
   238  // beaconBlockHeaderJson is a JSON representation of a beacon block header.
   239  type beaconBlockHeaderJson struct {
   240  	Slot          string `json:"slot"`
   241  	ProposerIndex string `json:"proposer_index"`
   242  	ParentRoot    string `json:"parent_root" hex:"true"`
   243  	StateRoot     string `json:"state_root" hex:"true"`
   244  	BodyRoot      string `json:"body_root" hex:"true"`
   245  }
   246  
   247  // eth1DataJson is a JSON representation of eth1data.
   248  type eth1DataJson struct {
   249  	DepositRoot  string `json:"deposit_root" hex:"true"`
   250  	DepositCount string `json:"deposit_count"`
   251  	BlockHash    string `json:"block_hash" hex:"true"`
   252  }
   253  
   254  // proposerSlashingJson is a JSON representation of a proposer slashing.
   255  type proposerSlashingJson struct {
   256  	Header_1 *signedBeaconBlockHeaderJson `json:"signed_header_1"`
   257  	Header_2 *signedBeaconBlockHeaderJson `json:"signed_header_2"`
   258  }
   259  
   260  // attesterSlashingJson is a JSON representation of an attester slashing.
   261  type attesterSlashingJson struct {
   262  	Attestation_1 *indexedAttestationJson `json:"attestation_1"`
   263  	Attestation_2 *indexedAttestationJson `json:"attestation_2"`
   264  }
   265  
   266  // indexedAttestationJson is a JSON representation of an indexed attestation.
   267  type indexedAttestationJson struct {
   268  	AttestingIndices []string             `json:"attesting_indices"`
   269  	Data             *attestationDataJson `json:"data"`
   270  	Signature        string               `json:"signature" hex:"true"`
   271  }
   272  
   273  // attestationJson is a JSON representation of an attestation.
   274  type attestationJson struct {
   275  	AggregationBits string               `json:"aggregation_bits" hex:"true"`
   276  	Data            *attestationDataJson `json:"data"`
   277  	Signature       string               `json:"signature" hex:"true"`
   278  }
   279  
   280  // attestationDataJson is a JSON representation of attestation data.
   281  type attestationDataJson struct {
   282  	Slot            string          `json:"slot"`
   283  	CommitteeIndex  string          `json:"index"`
   284  	BeaconBlockRoot string          `json:"beacon_block_root" hex:"true"`
   285  	Source          *checkpointJson `json:"source"`
   286  	Target          *checkpointJson `json:"target"`
   287  }
   288  
   289  // depositJson is a JSON representation of a deposit.
   290  type depositJson struct {
   291  	Proof []string          `json:"proof" hex:"true"`
   292  	Data  *deposit_DataJson `json:"data"`
   293  }
   294  
   295  // deposit_DataJson is a JSON representation of deposit data.
   296  type deposit_DataJson struct {
   297  	PublicKey             string `json:"pubkey" hex:"true"`
   298  	WithdrawalCredentials string `json:"withdrawal_credentials" hex:"true"`
   299  	Amount                string `json:"amount"`
   300  	Signature             string `json:"signature" hex:"true"`
   301  }
   302  
   303  // signedVoluntaryExitJson is a JSON representation of a signed voluntary exit.
   304  type signedVoluntaryExitJson struct {
   305  	Exit      *voluntaryExitJson `json:"message"`
   306  	Signature string             `json:"signature" hex:"true"`
   307  }
   308  
   309  // voluntaryExitJson is a JSON representation of a voluntary exit.
   310  type voluntaryExitJson struct {
   311  	Epoch          string `json:"epoch"`
   312  	ValidatorIndex string `json:"validator_index"`
   313  }
   314  
   315  // identityJson is a JSON representation of a peer's identity.
   316  type identityJson struct {
   317  	PeerId             string        `json:"peer_id"`
   318  	Enr                string        `json:"enr"`
   319  	P2PAddresses       []string      `json:"p2p_addresses"`
   320  	DiscoveryAddresses []string      `json:"discovery_addresses"`
   321  	Metadata           *metadataJson `json:"metadata"`
   322  }
   323  
   324  // metadataJson is a JSON representation of p2p metadata.
   325  type metadataJson struct {
   326  	SeqNumber string `json:"seq_number"`
   327  	Attnets   string `json:"attnets" hex:"true"`
   328  }
   329  
   330  // peerJson is a JSON representation of a peer.
   331  type peerJson struct {
   332  	PeerId    string `json:"peer_id"`
   333  	Enr       string `json:"enr"`
   334  	Address   string `json:"last_seen_p2p_address"`
   335  	State     string `json:"state" enum:"true"`
   336  	Direction string `json:"direction" enum:"true"`
   337  }
   338  
   339  // versionJson is a JSON representation of the system's version.
   340  type versionJson struct {
   341  	Version string `json:"version"`
   342  }
   343  
   344  // beaconStateJson is a JSON representation of the beacon state.
   345  type beaconStateJson struct {
   346  	GenesisTime                 string                    `json:"genesis_time"`
   347  	GenesisValidatorsRoot       string                    `json:"genesis_validators_root" hex:"true"`
   348  	Slot                        string                    `json:"slot"`
   349  	Fork                        *forkJson                 `json:"fork"`
   350  	LatestBlockHeader           *beaconBlockHeaderJson    `json:"latest_block_header"`
   351  	BlockRoots                  []string                  `json:"block_roots" hex:"true"`
   352  	StateRoots                  []string                  `json:"state_roots" hex:"true"`
   353  	HistoricalRoots             []string                  `json:"historical_roots" hex:"true"`
   354  	Eth1Data                    *eth1DataJson             `json:"eth1_data"`
   355  	Eth1DataVotes               []*eth1DataJson           `json:"eth1_data_votes"`
   356  	Eth1DepositIndex            string                    `json:"eth1_deposit_index"`
   357  	Validators                  []*validatorJson          `json:"validators"`
   358  	Balances                    []string                  `json:"balances"`
   359  	RandaoMixes                 []string                  `json:"randao_mixes" hex:"true"`
   360  	Slashings                   []string                  `json:"slashings"`
   361  	PreviousEpochAttestations   []*pendingAttestationJson `json:"previous_epoch_attestations"`
   362  	CurrentEpochAttestations    []*pendingAttestationJson `json:"current_epoch_attestations"`
   363  	JustificationBits           string                    `json:"justification_bits" hex:"true"`
   364  	PreviousJustifiedCheckpoint *checkpointJson           `json:"previous_justified_checkpoint"`
   365  	CurrentJustifiedCheckpoint  *checkpointJson           `json:"current_justified_checkpoint"`
   366  	FinalizedCheckpoint         *checkpointJson           `json:"finalized_checkpoint"`
   367  }
   368  
   369  // forkJson is a JSON representation of a fork.
   370  type forkJson struct {
   371  	PreviousVersion string `json:"previous_version" hex:"true"`
   372  	CurrentVersion  string `json:"current_version" hex:"true"`
   373  	Epoch           string `json:"epoch"`
   374  }
   375  
   376  // validatorContainerJson is a JSON representation of a validator container.
   377  type validatorContainerJson struct {
   378  	Index     string         `json:"index"`
   379  	Balance   string         `json:"balance"`
   380  	Status    string         `json:"status" enum:"true"`
   381  	Validator *validatorJson `json:"validator"`
   382  }
   383  
   384  // validatorJson is a JSON representation of a validator.
   385  type validatorJson struct {
   386  	PublicKey                  string `json:"pubkey" hex:"true"`
   387  	WithdrawalCredentials      string `json:"withdrawal_credentials" hex:"true"`
   388  	EffectiveBalance           string `json:"effective_balance"`
   389  	Slashed                    bool   `json:"slashed"`
   390  	ActivationEligibilityEpoch string `json:"activation_eligibility_epoch"`
   391  	ActivationEpoch            string `json:"activation_epoch"`
   392  	ExitEpoch                  string `json:"exit_epoch"`
   393  	WithdrawableEpoch          string `json:"withdrawable_epoch"`
   394  }
   395  
   396  // validatorBalanceJson is a JSON representation of a validator's balance.
   397  type validatorBalanceJson struct {
   398  	Index   string `json:"index"`
   399  	Balance string `json:"balance"`
   400  }
   401  
   402  // committeeJson is a JSON representation of a committee
   403  type committeeJson struct {
   404  	Index      string   `json:"index"`
   405  	Slot       string   `json:"slot"`
   406  	Validators []string `json:"validators"`
   407  }
   408  
   409  // pendingAttestationJson is a JSON representation of a pending attestation.
   410  type pendingAttestationJson struct {
   411  	AggregationBits string               `json:"aggregation_bits" hex:"true"`
   412  	Data            *attestationDataJson `json:"data"`
   413  	InclusionDelay  string               `json:"inclusion_delay"`
   414  	ProposerIndex   string               `json:"proposer_index"`
   415  }
   416  
   417  // forkChoiceHeadJson is a JSON representation of a fork choice head.
   418  type forkChoiceHeadJson struct {
   419  	Root string `json:"root" hex:"true"`
   420  	Slot string `json:"slot"`
   421  }
   422  
   423  // depositContractJson is a JSON representation of the deposit contract.
   424  type depositContractJson struct {
   425  	ChainId string `json:"chain_id"`
   426  	Address string `json:"address"`
   427  }
   428  
   429  // syncInfoJson is a JSON representation of the sync info.
   430  type syncInfoJson struct {
   431  	HeadSlot     string `json:"head_slot"`
   432  	SyncDistance string `json:"sync_distance"`
   433  	IsSyncing    bool   `json:"is_syncing"`
   434  }
   435  
   436  //----------------
   437  // SSZ
   438  // ---------------
   439  
   440  // sszResponseJson is a common abstraction over all SSZ responses.
   441  type sszResponseJson interface {
   442  	SSZData() string
   443  }
   444  
   445  // blockSSZResponseJson is used in /beacon/blocks/{block_id} API endpoint.
   446  type blockSSZResponseJson struct {
   447  	Data string `json:"data"`
   448  }
   449  
   450  func (ssz *blockSSZResponseJson) SSZData() string {
   451  	return ssz.Data
   452  }
   453  
   454  // beaconStateSSZResponseJson is used in /debug/beacon/states/{state_id} API endpoint.
   455  type beaconStateSSZResponseJson struct {
   456  	Data string `json:"data"`
   457  }
   458  
   459  func (ssz *beaconStateSSZResponseJson) SSZData() string {
   460  	return ssz.Data
   461  }
   462  
   463  // TODO: Documentation
   464  // ---------------
   465  // Events.
   466  // ---------------
   467  
   468  type eventHeadJson struct {
   469  	Slot                      string `json:"slot"`
   470  	Block                     string `json:"block" hex:"true"`
   471  	State                     string `json:"state" hex:"true"`
   472  	EpochTransition           bool   `json:"epoch_transition"`
   473  	PreviousDutyDependentRoot string `json:"previous_duty_dependent_root" hex:"true"`
   474  	CurrentDutyDependentRoot  string `json:"current_duty_dependent_root" hex:"true"`
   475  }
   476  
   477  type receivedBlockDataJson struct {
   478  	Slot  string `json:"slot"`
   479  	Block string `json:"block" hex:"true"`
   480  }
   481  
   482  type aggregatedAttReceivedDataJson struct {
   483  	Aggregate *attestationJson `json:"aggregate"`
   484  }
   485  
   486  type eventFinalizedCheckpointJson struct {
   487  	Block string `json:"block" hex:"true"`
   488  	State string `json:"state" hex:"true"`
   489  	Epoch string `json:"epoch"`
   490  }
   491  
   492  type eventChainReorgJson struct {
   493  	Slot         string `json:"slot"`
   494  	Depth        string `json:"depth"`
   495  	OldHeadBlock string `json:"old_head_block" hex:"true"`
   496  	NewHeadBlock string `json:"old_head_state" hex:"true"`
   497  	OldHeadState string `json:"new_head_block" hex:"true"`
   498  	NewHeadState string `json:"new_head_state" hex:"true"`
   499  	Epoch        string `json:"epoch"`
   500  }
   501  
   502  // ---------------
   503  // Error handling.
   504  // ---------------
   505  
   506  // submitAttestationsErrorJson is a JSON representation of the error returned when submitting attestations.
   507  type submitAttestationsErrorJson struct {
   508  	gateway.DefaultErrorJson
   509  	Failures []*singleAttestationVerificationFailureJson `json:"failures"`
   510  }
   511  
   512  // singleAttestationVerificationFailureJson is a JSON representation of a failure when verifying a single submitted attestation.
   513  type singleAttestationVerificationFailureJson struct {
   514  	Index   int    `json:"index"`
   515  	Message string `json:"message"`
   516  }
   517  
   518  type eventErrorJson struct {
   519  	StatusCode int    `json:"status_code"`
   520  	Message    string `json:"message"`
   521  }