Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework API #80

Merged
merged 15 commits into from
Oct 21, 2023
24 changes: 24 additions & 0 deletions api/aggregateattestationopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

import "github.com/attestantio/go-eth2-client/spec/phase0"

// AggregateAttestationOpts are the options for obtaining aggregate attestations.
type AggregateAttestationOpts struct {
// Slot is the slot for which the data is obtained.
Slot phase0.Slot
// AttestationDataRoot is the root for which the data is obtained.
AttestationDataRoot phase0.Root
}
24 changes: 24 additions & 0 deletions api/attestationdataopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

import "github.com/attestantio/go-eth2-client/spec/phase0"

// AttestationDataOpts are the options for obtaining attestation data.
type AttestationDataOpts struct {
// Slot is the slot for which the data is obtained.
Slot phase0.Slot
// CommitteeIndex is the committee index for which the data is obtained.
CommitteeIndex phase0.CommitteeIndex
}
17 changes: 7 additions & 10 deletions mock/stateroot.go → api/attestationpoolopts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Attestant Limited.
// Copyright © 2023 Attestant Limited.
// 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
Expand All @@ -11,15 +11,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package mock
package api

import (
"context"
import "github.com/attestantio/go-eth2-client/spec/phase0"

spec "github.com/attestantio/go-eth2-client/spec/phase0"
)

// BeaconStateRoot fetches a beacon state root given a state ID.
func (s *Service) BeaconStateRoot(_ context.Context, _ string) (*spec.Root, error) {
return &spec.Root{}, nil
// AttestationPoolOpts are the options for obtaining the attestation pool.
type AttestationPoolOpts struct {
// Slot is the slot for which the data is obtained.
Slot phase0.Slot
}
24 changes: 24 additions & 0 deletions api/attesterdutiesopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

import "github.com/attestantio/go-eth2-client/spec/phase0"

// AttesterDutiesOpts are the options for obtaining proposer duties.
type AttesterDutiesOpts struct {
// Epoch is the epoch for which the data is obtained.
Epoch phase0.Epoch
// Indices is a list of validators for which to obtain the duties.
Indices []phase0.ValidatorIndex
}
20 changes: 20 additions & 0 deletions api/beaconblockblobsopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// BeaconBlockBlobsOpts are the options for obtaining beacon block blobs.
type BeaconBlockBlobsOpts struct {
// Block is the ID of the block which the data is obtained.
Block string
}
20 changes: 20 additions & 0 deletions api/beaconblockheaderopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// BeaconBlockHeaderOpts are the options for obtaining beacon block headers.
type BeaconBlockHeaderOpts struct {
// Block is the ID of the block which the data is obtained.
Block string
}
29 changes: 29 additions & 0 deletions api/beaconblockproposalopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

import "github.com/attestantio/go-eth2-client/spec/phase0"

// BeaconBlockProposalOpts are the options for obtaining beacon block proposals.
type BeaconBlockProposalOpts struct {
// Slot is the slot for which the proposal should be fetched.
Slot phase0.Slot
// RandaoReveal is the RANDAO reveal for the proposal.
RandaoReveal phase0.BLSSignature
// Graffit is the graffiti to be included in the beacon block body.
Graffiti [32]byte
// SkipRandaoVerification is true if we do not want the server to verify our RANDAO reveal.
// If this is set then the RANDAO reveal should be passed as the point at infinity (0xc0…00)
SkipRandaoVerification bool
}
20 changes: 20 additions & 0 deletions api/beaconblockrootopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// BeaconBlockRootOpts are the options for obtaining the beacon block root.
type BeaconBlockRootOpts struct {
// Block is the ID of the block which the data is obtained.
Block string
}
26 changes: 26 additions & 0 deletions api/beaconcommitteesopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

import "github.com/attestantio/go-eth2-client/spec/phase0"

// BeaconCommitteesOpts are the options for obtaining proposer duties.
type BeaconCommitteesOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
// Epoch is the epoch at which the data is obtained.
// This is optional; if not supplied it will obtain the data at the epoch relating to the state.
Epoch *phase0.Epoch
}
21 changes: 21 additions & 0 deletions api/beaconstateopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// BeaconStateOpts are the options for obtaining the beacon state.
type BeaconStateOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
}
21 changes: 21 additions & 0 deletions api/beaconstaterandaoopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// BeaconStateRandaoOpts are the options for obtaining the beacon state RANDAO.
type BeaconStateRandaoOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
}
21 changes: 21 additions & 0 deletions api/beaconstaterootopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// BeaconStateRootOpts are the options for obtaining the beacon state root.
type BeaconStateRootOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
}
29 changes: 29 additions & 0 deletions api/blindedbeaconblockproposalopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

import "github.com/attestantio/go-eth2-client/spec/phase0"

// BlindedBeaconBlockProposalOpts are the options for obtaining blinded beacon block proposals.
type BlindedBeaconBlockProposalOpts struct {
// Slot is the slot for which the proposal should be fetched.
Slot phase0.Slot
// RandaoReveal is the RANDAO reveal for the proposal.
RandaoReveal phase0.BLSSignature
// Graffit is the graffiti to be included in the beacon block body.
Graffiti [32]byte
// SkipRandaoVerification is true if we do not want the server to verify our RANDAO reveal.
// If this is set then the RANDAO reveal should be passed as the point at infinity (0xc0…00)
SkipRandaoVerification bool
}
34 changes: 34 additions & 0 deletions api/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2020, 2023 Attestant Limited.
// 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.

package api

import (
"fmt"
)

// Error represents an API error.
type Error struct {
Method string
Endpoint string
StatusCode int
Data []byte
}

func (e Error) Error() string {
if len(e.Data) > 0 {
return fmt.Sprintf("%s failed with status %d: %s", e.Method, e.StatusCode, string(e.Data))
}

return fmt.Sprintf("%s failed with status %d", e.Method, e.StatusCode)
}
21 changes: 21 additions & 0 deletions api/forkopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2023 Attestant Limited.
// 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.

package api

// ForkOpts are the options for obtaining the fork.
type ForkOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
}
Loading
Loading