client

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2024 License: GPL-3.0 Imports: 18 Imported by: 8

Documentation

Index

Constants

View Source
const (
	RequestUrlFormat   = "%s%s"
	RequestContentType = "application/json"

	RequestSyncStatusPath                  = "/eth/v1/node/syncing"
	RequestEth2ConfigPath                  = "/eth/v1/config/spec"
	RequestEth2DepositContractMethod       = "/eth/v1/config/deposit_contract"
	RequestCommitteePath                   = "/eth/v1/beacon/states/%s/committees"
	RequestGenesisPath                     = "/eth/v1/beacon/genesis"
	RequestFinalityCheckpointsPath         = "/eth/v1/beacon/states/%s/finality_checkpoints"
	RequestForkPath                        = "/eth/v1/beacon/states/%s/fork"
	RequestValidatorsPath                  = "/eth/v1/beacon/states/%s/validators"
	RequestVoluntaryExitPath               = "/eth/v1/beacon/pool/voluntary_exits"
	RequestAttestationsPath                = "/eth/v1/beacon/blocks/%s/attestations"
	RequestBeaconBlockPath                 = "/eth/v2/beacon/blocks/%s"
	RequestBeaconBlockHeaderPath           = "/eth/v1/beacon/headers/%s"
	RequestValidatorSyncDuties             = "/eth/v1/validator/duties/sync/%s"
	RequestValidatorProposerDuties         = "/eth/v1/validator/duties/proposer/%s"
	RequestWithdrawalCredentialsChangePath = "/eth/v1/beacon/pool/bls_to_execution_changes"

	MaxRequestValidatorsCount = 600
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Attestation

type Attestation struct {
	AggregationBits string `json:"aggregation_bits"`
	Data            struct {
		Slot  Uinteger `json:"slot"`
		Index Uinteger `json:"index"`
	} `json:"data"`
}

type AttestationsResponse

type AttestationsResponse struct {
	Data []Attestation `json:"data"`
}

type BLSToExecutionChangeMessage

type BLSToExecutionChangeMessage struct {
	ValidatorIndex     string    `json:"validator_index"`
	FromBLSPubkey      ByteArray `json:"from_bls_pubkey"`
	ToExecutionAddress ByteArray `json:"to_execution_address"`
}

type BLSToExecutionChangeRequest

type BLSToExecutionChangeRequest struct {
	Message   BLSToExecutionChangeMessage `json:"message"`
	Signature ByteArray                   `json:"signature"`
}

type BeaconBlockHeaderResponse added in v0.2.0

type BeaconBlockHeaderResponse struct {
	Finalized bool `json:"finalized"`
	Data      struct {
		Root      string `json:"root"`
		Canonical bool   `json:"canonical"`
		Header    struct {
			Message struct {
				Slot          Uinteger `json:"slot"`
				ProposerIndex string   `json:"proposer_index"`
			} `json:"message"`
		} `json:"header"`
	} `json:"data"`
}

type BeaconBlockResponse

type BeaconBlockResponse struct {
	Data struct {
		Message struct {
			Slot          Uinteger `json:"slot"`
			ProposerIndex string   `json:"proposer_index"`
			Body          struct {
				Eth1Data struct {
					DepositRoot  ByteArray `json:"deposit_root"`
					DepositCount Uinteger  `json:"deposit_count"`
					BlockHash    ByteArray `json:"block_hash"`
				} `json:"eth1_data"`
				Attestations     []Attestation `json:"attestations"`
				ExecutionPayload *struct {
					FeeRecipient ByteArray `json:"fee_recipient"`
					BlockNumber  Uinteger  `json:"block_number"`
				} `json:"execution_payload"`
			} `json:"body"`
		} `json:"message"`
	} `json:"data"`
}

type BeaconHttpProvider added in v0.4.0

type BeaconHttpProvider struct {
	// contains filtered or unexported fields
}

func NewBeaconHttpProvider added in v0.4.0

func NewBeaconHttpProvider(providerAddress string, timeout time.Duration) *BeaconHttpProvider

func (*BeaconHttpProvider) Beacon_Attestations added in v0.4.0

func (p *BeaconHttpProvider) Beacon_Attestations(ctx context.Context, blockId string) (AttestationsResponse, bool, error)

func (*BeaconHttpProvider) Beacon_Block added in v0.4.0

func (p *BeaconHttpProvider) Beacon_Block(ctx context.Context, blockId string) (BeaconBlockResponse, bool, error)

func (*BeaconHttpProvider) Beacon_BlsToExecutionChanges_Post added in v0.4.0

func (p *BeaconHttpProvider) Beacon_BlsToExecutionChanges_Post(ctx context.Context, request BLSToExecutionChangeRequest) error

func (*BeaconHttpProvider) Beacon_Committees added in v0.4.0

func (p *BeaconHttpProvider) Beacon_Committees(ctx context.Context, stateId string, epoch *uint64) (CommitteesResponse, error)

func (*BeaconHttpProvider) Beacon_FinalityCheckpoints added in v0.4.0

func (p *BeaconHttpProvider) Beacon_FinalityCheckpoints(ctx context.Context, stateId string) (FinalityCheckpointsResponse, error)

func (*BeaconHttpProvider) Beacon_Genesis added in v0.4.0

func (p *BeaconHttpProvider) Beacon_Genesis(ctx context.Context) (GenesisResponse, error)

func (*BeaconHttpProvider) Beacon_Header added in v0.4.0

func (p *BeaconHttpProvider) Beacon_Header(ctx context.Context, blockId string) (BeaconBlockHeaderResponse, bool, error)

func (*BeaconHttpProvider) Beacon_Validators added in v0.4.0

func (p *BeaconHttpProvider) Beacon_Validators(ctx context.Context, stateId string, ids []string) (ValidatorsResponse, error)

func (*BeaconHttpProvider) Beacon_VoluntaryExits_Post added in v0.4.0

func (p *BeaconHttpProvider) Beacon_VoluntaryExits_Post(ctx context.Context, request VoluntaryExitRequest) error

func (*BeaconHttpProvider) Config_DepositContract added in v0.4.0

func (p *BeaconHttpProvider) Config_DepositContract(ctx context.Context) (Eth2DepositContractResponse, error)

func (*BeaconHttpProvider) Config_Spec added in v0.4.0

func (*BeaconHttpProvider) Node_Syncing added in v0.4.0

func (p *BeaconHttpProvider) Node_Syncing(ctx context.Context) (SyncStatusResponse, error)

func (*BeaconHttpProvider) Validator_DutiesProposer added in v0.4.0

func (p *BeaconHttpProvider) Validator_DutiesProposer(ctx context.Context, indices []string, epoch uint64) (ProposerDutiesResponse, error)

func (*BeaconHttpProvider) Validator_DutiesSync_Post added in v0.4.0

func (p *BeaconHttpProvider) Validator_DutiesSync_Post(ctx context.Context, indices []string, epoch uint64) (SyncDutiesResponse, error)

type ByteArray added in v0.4.0

type ByteArray []byte

Byte array type

func (ByteArray) MarshalJSON added in v0.4.0

func (b ByteArray) MarshalJSON() ([]byte, error)

func (*ByteArray) UnmarshalJSON added in v0.4.0

func (b *ByteArray) UnmarshalJSON(data []byte) error

type Committee added in v0.2.0

type Committee struct {
	Index      Uinteger `json:"index"`
	Slot       Uinteger `json:"slot"`
	Validators []string `json:"validators"`
}

func (*Committee) UnmarshalJSON added in v0.2.0

func (c *Committee) UnmarshalJSON(body []byte) error

type CommitteesResponse added in v0.2.0

type CommitteesResponse struct {
	Data []Committee `json:"data"`
}

func (*CommitteesResponse) Count added in v0.2.0

func (c *CommitteesResponse) Count() int

func (*CommitteesResponse) Index added in v0.2.0

func (c *CommitteesResponse) Index(idx int) uint64

func (*CommitteesResponse) Release added in v0.2.0

func (c *CommitteesResponse) Release()

func (*CommitteesResponse) Slot added in v0.2.0

func (c *CommitteesResponse) Slot(idx int) uint64

func (*CommitteesResponse) Validators added in v0.2.0

func (c *CommitteesResponse) Validators(idx int) []string

type Eth2ConfigResponse

type Eth2ConfigResponse struct {
	Data struct {
		SecondsPerSlot               Uinteger  `json:"SECONDS_PER_SLOT"`
		SlotsPerEpoch                Uinteger  `json:"SLOTS_PER_EPOCH"`
		EpochsPerSyncCommitteePeriod Uinteger  `json:"EPOCHS_PER_SYNC_COMMITTEE_PERIOD"`
		CapellaForkVersion           ByteArray `json:"CAPELLA_FORK_VERSION"`
	} `json:"data"`
}

type Eth2DepositContractResponse

type Eth2DepositContractResponse struct {
	Data struct {
		ChainID Uinteger       `json:"chain_id"`
		Address common.Address `json:"address"`
	} `json:"data"`
}

type FinalityCheckpointsResponse

type FinalityCheckpointsResponse struct {
	Data struct {
		PreviousJustified struct {
			Epoch Uinteger `json:"epoch"`
		} `json:"previous_justified"`
		CurrentJustified struct {
			Epoch Uinteger `json:"epoch"`
		} `json:"current_justified"`
		Finalized struct {
			Epoch Uinteger `json:"epoch"`
		} `json:"finalized"`
	} `json:"data"`
}

type ForkResponse

type ForkResponse struct {
	Data struct {
		PreviousVersion ByteArray `json:"previous_version"`
		CurrentVersion  ByteArray `json:"current_version"`
		Epoch           Uinteger  `json:"epoch"`
	} `json:"data"`
}

type GenesisResponse

type GenesisResponse struct {
	Data struct {
		GenesisTime           Uinteger  `json:"genesis_time"`
		GenesisForkVersion    ByteArray `json:"genesis_fork_version"`
		GenesisValidatorsRoot ByteArray `json:"genesis_validators_root"`
	} `json:"data"`
}

type IBeaconApiProvider added in v0.4.0

type IBeaconApiProvider interface {
	Beacon_Attestations(ctx context.Context, blockId string) (AttestationsResponse, bool, error)
	Beacon_Block(ctx context.Context, blockId string) (BeaconBlockResponse, bool, error)
	Beacon_BlsToExecutionChanges_Post(ctx context.Context, request BLSToExecutionChangeRequest) error
	Beacon_Committees(ctx context.Context, stateId string, epoch *uint64) (CommitteesResponse, error)
	Beacon_FinalityCheckpoints(ctx context.Context, stateId string) (FinalityCheckpointsResponse, error)
	Beacon_Genesis(ctx context.Context) (GenesisResponse, error)
	Beacon_Header(ctx context.Context, blockId string) (BeaconBlockHeaderResponse, bool, error)
	Beacon_Validators(ctx context.Context, stateId string, ids []string) (ValidatorsResponse, error)
	Beacon_VoluntaryExits_Post(ctx context.Context, request VoluntaryExitRequest) error
	Config_DepositContract(ctx context.Context) (Eth2DepositContractResponse, error)
	Config_Spec(ctx context.Context) (Eth2ConfigResponse, error)
	Node_Syncing(ctx context.Context) (SyncStatusResponse, error)
	Validator_DutiesProposer(ctx context.Context, indices []string, epoch uint64) (ProposerDutiesResponse, error)
	Validator_DutiesSync_Post(ctx context.Context, indices []string, epoch uint64) (SyncDutiesResponse, error)
}

type ProposerDutiesResponse

type ProposerDutiesResponse struct {
	Data []ProposerDuty `json:"data"`
}

type ProposerDuty

type ProposerDuty struct {
	ValidatorIndex string `json:"validator_index"`
}

type StandardClient added in v0.4.0

type StandardClient struct {
	// contains filtered or unexported fields
}

Beacon client using the standard Beacon HTTP REST API (https://ethereum.github.io/beacon-APIs/)

func NewStandardClient added in v0.4.0

func NewStandardClient(provider IBeaconApiProvider) *StandardClient

Create a new client instance

func (*StandardClient) ChangeWithdrawalCredentials added in v0.4.0

func (c *StandardClient) ChangeWithdrawalCredentials(ctx context.Context, validatorIndex string, fromBlsPubkey beacon.ValidatorPubkey, toExecutionAddress common.Address, signature beacon.ValidatorSignature) error

Perform a withdrawal credentials change on a validator

func (*StandardClient) Close added in v0.4.0

func (c *StandardClient) Close(ctx context.Context) error

Close the client connection

func (*StandardClient) ExitValidator added in v0.4.0

func (c *StandardClient) ExitValidator(ctx context.Context, validatorIndex string, epoch uint64, signature beacon.ValidatorSignature) error

Perform a voluntary exit on a validator

func (*StandardClient) GetAttestations added in v0.4.0

func (c *StandardClient) GetAttestations(ctx context.Context, blockId string) ([]beacon.AttestationInfo, bool, error)

func (*StandardClient) GetBeaconBlock added in v0.4.0

func (c *StandardClient) GetBeaconBlock(ctx context.Context, blockId string) (beacon.BeaconBlock, bool, error)

func (*StandardClient) GetBeaconBlockHeader added in v0.4.0

func (c *StandardClient) GetBeaconBlockHeader(ctx context.Context, blockId string) (beacon.BeaconBlockHeader, bool, error)

func (*StandardClient) GetBeaconHead added in v0.4.0

func (c *StandardClient) GetBeaconHead(ctx context.Context) (beacon.BeaconHead, error)

Get the beacon head

func (*StandardClient) GetCommitteesForEpoch added in v0.4.0

func (c *StandardClient) GetCommitteesForEpoch(ctx context.Context, epoch *uint64) (beacon.Committees, error)

Get the attestation committees for the given epoch, or the current epoch if nil

func (*StandardClient) GetDomainData added in v0.4.0

func (c *StandardClient) GetDomainData(ctx context.Context, domainType []byte, epoch uint64, useGenesisFork bool) ([]byte, error)

Get domain data for a domain type at a given epoch

func (*StandardClient) GetEth1DataForEth2Block added in v0.4.0

func (c *StandardClient) GetEth1DataForEth2Block(ctx context.Context, blockId string) (beacon.Eth1Data, bool, error)

Get the ETH1 data for the target beacon block

func (*StandardClient) GetEth2Config added in v0.4.0

func (c *StandardClient) GetEth2Config(ctx context.Context) (beacon.Eth2Config, error)

Get the eth2 config

func (*StandardClient) GetEth2DepositContract added in v0.4.0

func (c *StandardClient) GetEth2DepositContract(ctx context.Context) (beacon.Eth2DepositContract, error)

Get the eth2 deposit contract info

func (*StandardClient) GetSyncStatus added in v0.4.0

func (c *StandardClient) GetSyncStatus(ctx context.Context) (beacon.SyncStatus, error)

Get the node's sync status

func (*StandardClient) GetValidatorIndex added in v0.4.0

func (c *StandardClient) GetValidatorIndex(ctx context.Context, pubkey beacon.ValidatorPubkey) (string, error)

Get a validator's index

func (*StandardClient) GetValidatorProposerDuties added in v0.4.0

func (c *StandardClient) GetValidatorProposerDuties(ctx context.Context, indices []string, epoch uint64) (map[string]uint64, error)

Sums proposer duties per validators for a given epoch

func (*StandardClient) GetValidatorStatus added in v0.4.0

Get a validator's status

func (*StandardClient) GetValidatorStatusByIndex added in v0.4.0

func (c *StandardClient) GetValidatorStatusByIndex(ctx context.Context, index string, opts *beacon.ValidatorStatusOptions) (beacon.ValidatorStatus, error)

func (*StandardClient) GetValidatorStatuses added in v0.4.0

Get multiple validators' statuses

func (*StandardClient) GetValidatorSyncDuties added in v0.4.0

func (c *StandardClient) GetValidatorSyncDuties(ctx context.Context, indices []string, epoch uint64) (map[string]bool, error)

Get whether validators have sync duties to perform at given epoch

type StandardHttpClient

type StandardHttpClient struct {
	*StandardClient
}

func NewStandardHttpClient

func NewStandardHttpClient(providerAddress string, timeout time.Duration) *StandardHttpClient

Create a new client instance

type SyncDutiesResponse

type SyncDutiesResponse struct {
	Data []SyncDuty `json:"data"`
}

type SyncDuty

type SyncDuty struct {
	Pubkey               ByteArray  `json:"pubkey"`
	ValidatorIndex       string     `json:"validator_index"`
	SyncCommitteeIndices []Uinteger `json:"validator_sync_committee_indices"`
}

type SyncStatusResponse

type SyncStatusResponse struct {
	Data struct {
		IsSyncing    bool     `json:"is_syncing"`
		HeadSlot     Uinteger `json:"head_slot"`
		SyncDistance Uinteger `json:"sync_distance"`
	} `json:"data"`
}

Response types

type Uinteger added in v0.4.0

type Uinteger uint64

Unsigned integer type

func (Uinteger) MarshalJSON added in v0.4.0

func (i Uinteger) MarshalJSON() ([]byte, error)

func (*Uinteger) UnmarshalJSON added in v0.4.0

func (i *Uinteger) UnmarshalJSON(data []byte) error

type Validator

type Validator struct {
	Index     string   `json:"index"`
	Balance   Uinteger `json:"balance"`
	Status    string   `json:"status"`
	Validator struct {
		Pubkey                     ByteArray `json:"pubkey"`
		WithdrawalCredentials      ByteArray `json:"withdrawal_credentials"`
		EffectiveBalance           Uinteger  `json:"effective_balance"`
		Slashed                    bool      `json:"slashed"`
		ActivationEligibilityEpoch Uinteger  `json:"activation_eligibility_epoch"`
		ActivationEpoch            Uinteger  `json:"activation_epoch"`
		ExitEpoch                  Uinteger  `json:"exit_epoch"`
		WithdrawableEpoch          Uinteger  `json:"withdrawable_epoch"`
	} `json:"validator"`
}

type ValidatorsResponse

type ValidatorsResponse struct {
	Data []Validator `json:"data"`
}

type VoluntaryExitMessage

type VoluntaryExitMessage struct {
	Epoch          Uinteger `json:"epoch"`
	ValidatorIndex string   `json:"validator_index"`
}

Request types

type VoluntaryExitRequest

type VoluntaryExitRequest struct {
	Message   VoluntaryExitMessage `json:"message"`
	Signature ByteArray            `json:"signature"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL