prysm-pulse/validator/rpc/apimiddleware/endpoint_factory.go
terencechain d17996f8b0
Update to V4 🚀 (#12134)
* Update V3 from V4

* Fix build v3 -> v4

* Update ssz

* Update beacon_chain.pb.go

* Fix formatter import

* Update update-mockgen.sh comment to v4

* Fix conflicts. Pass build and tests

* Fix test
2023-03-17 18:52:56 +00:00

56 lines
2.0 KiB
Go

package apimiddleware
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware"
)
// ValidatorEndpointFactory creates endpoints used for running validator API calls through the API Middleware.
type ValidatorEndpointFactory struct {
}
func (f *ValidatorEndpointFactory) IsNil() bool {
return f == nil
}
// Paths is a collection of all valid validator API paths.
func (*ValidatorEndpointFactory) Paths() []string {
return []string{
"/eth/v1/keystores",
"/eth/v1/remotekeys",
"/eth/v1/validator/{pubkey}/feerecipient",
"/eth/v1/validator/{pubkey}/gas_limit",
}
}
// Create returns a new endpoint for the provided API path.
func (*ValidatorEndpointFactory) Create(path string) (*apimiddleware.Endpoint, error) {
endpoint := apimiddleware.DefaultEndpoint()
switch path {
case "/eth/v1/keystores":
endpoint.GetResponse = &ListKeystoresResponseJson{}
endpoint.PostRequest = &ImportKeystoresRequestJson{}
endpoint.PostResponse = &ImportKeystoresResponseJson{}
endpoint.DeleteRequest = &DeleteKeystoresRequestJson{}
endpoint.DeleteResponse = &DeleteKeystoresResponseJson{}
case "/eth/v1/remotekeys":
endpoint.GetResponse = &ListRemoteKeysResponseJson{}
endpoint.PostRequest = &ImportRemoteKeysRequestJson{}
endpoint.PostResponse = &ImportRemoteKeysResponseJson{}
endpoint.DeleteRequest = &DeleteRemoteKeysRequestJson{}
endpoint.DeleteResponse = &DeleteRemoteKeysResponseJson{}
case "/eth/v1/validator/{pubkey}/feerecipient":
endpoint.GetResponse = &GetFeeRecipientByPubkeyResponseJson{}
endpoint.PostRequest = &SetFeeRecipientByPubkeyRequestJson{}
endpoint.DeleteRequest = &DeleteFeeRecipientByPubkeyRequestJson{}
case "/eth/v1/validator/{pubkey}/gas_limit":
endpoint.GetResponse = &GetGasLimitResponseJson{}
endpoint.PostRequest = &SetGasLimitRequestJson{}
endpoint.DeleteRequest = &DeleteGasLimitRequestJson{}
default:
return nil, errors.New("invalid path")
}
endpoint.Path = path
return &endpoint, nil
}