From 185862a881af142da52da44269429a3311e50e78 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Fri, 24 May 2024 09:06:32 -0400 Subject: [PATCH] Finished the BeaconApiProvider impl --- manager/beacon-interface.go | 79 +++++++++++++++++++++++++++++++------ server/add-validator.go | 2 +- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/manager/beacon-interface.go b/manager/beacon-interface.go index e1f65eb..0177df2 100644 --- a/manager/beacon-interface.go +++ b/manager/beacon-interface.go @@ -2,23 +2,11 @@ package manager import ( "context" + "fmt" "github.com/rocket-pool/node-manager-core/beacon/client" ) -func (m *BeaconMockManager) Node_Syncing(ctx context.Context) (client.SyncStatusResponse, error) { - // Get the slots - currentSlot := m.GetCurrentSlot() - highestSlot := m.GetHighestSlot() - - // Write the response - response := client.SyncStatusResponse{} - response.Data.IsSyncing = (currentSlot < highestSlot) - response.Data.HeadSlot = client.Uinteger(highestSlot) - response.Data.SyncDistance = client.Uinteger(highestSlot - currentSlot) - return response, nil -} - func (m *BeaconMockManager) Beacon_Validators(ctx context.Context, stateId string, ids []string) (client.ValidatorsResponse, error) { // Get the validators validators, err := m.GetValidators(ids) @@ -36,3 +24,68 @@ func (m *BeaconMockManager) Beacon_Validators(ctx context.Context, stateId strin } return response, nil } + +func (m *BeaconMockManager) Node_Syncing(ctx context.Context) (client.SyncStatusResponse, error) { + // Get the slots + currentSlot := m.GetCurrentSlot() + highestSlot := m.GetHighestSlot() + + // Write the response + response := client.SyncStatusResponse{} + response.Data.IsSyncing = (currentSlot < highestSlot) + response.Data.HeadSlot = client.Uinteger(highestSlot) + response.Data.SyncDistance = client.Uinteger(highestSlot - currentSlot) + return response, nil +} + +// =========== +// === NYI === +// =========== + +func (m *BeaconMockManager) Beacon_Attestations(ctx context.Context, blockId string) (client.AttestationsResponse, bool, error) { + return client.AttestationsResponse{}, false, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_Block(ctx context.Context, blockId string) (client.BeaconBlockResponse, bool, error) { + return client.BeaconBlockResponse{}, false, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_BlsToExecutionChanges_Post(ctx context.Context, request client.BLSToExecutionChangeRequest) error { + return fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_Committees(ctx context.Context, stateId string, epoch *uint64) (client.CommitteesResponse, error) { + return client.CommitteesResponse{}, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_FinalityCheckpoints(ctx context.Context, stateId string) (client.FinalityCheckpointsResponse, error) { + return client.FinalityCheckpointsResponse{}, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_Genesis(ctx context.Context) (client.GenesisResponse, error) { + return client.GenesisResponse{}, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_Header(ctx context.Context, blockId string) (client.BeaconBlockHeaderResponse, bool, error) { + return client.BeaconBlockHeaderResponse{}, false, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Beacon_VoluntaryExits_Post(ctx context.Context, request client.VoluntaryExitRequest) error { + return fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Config_DepositContract(ctx context.Context) (client.Eth2DepositContractResponse, error) { + return client.Eth2DepositContractResponse{}, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Config_Spec(ctx context.Context) (client.Eth2ConfigResponse, error) { + return client.Eth2ConfigResponse{}, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Validator_DutiesProposer(ctx context.Context, indices []string, epoch uint64) (client.ProposerDutiesResponse, error) { + return client.ProposerDutiesResponse{}, fmt.Errorf("not implemented") +} + +func (m *BeaconMockManager) Validator_DutiesSync_Post(ctx context.Context, indices []string, epoch uint64) (client.SyncDutiesResponse, error) { + return client.SyncDutiesResponse{}, fmt.Errorf("not implemented") +} diff --git a/server/add-validator.go b/server/add-validator.go index ccdd247..15cfacc 100644 --- a/server/add-validator.go +++ b/server/add-validator.go @@ -43,5 +43,5 @@ func (s *BeaconMockServer) addValidator(w http.ResponseWriter, r *http.Request) response := api.AddValidatorResponse{ Index: validator.Index, } - handleSuccess(w, s.logger, response) + handleSuccess(s.logger, w, response) }