mirror of
https://github.com/wealdtech/ethdo.git
synced 2026-01-10 06:28:07 -05:00
Update dependencies.
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
eth2client "github.com/attestantio/go-eth2-client"
|
||||
"github.com/attestantio/go-eth2-client/api"
|
||||
apiv1 "github.com/attestantio/go-eth2-client/api/v1"
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
)
|
||||
@@ -50,18 +51,18 @@ func (b *BeaconBlockHeaderCache) Fetch(ctx context.Context,
|
||||
) {
|
||||
entry, exists := b.entries[slot]
|
||||
if !exists {
|
||||
header, err := b.beaconBlockHeadersProvider.BeaconBlockHeader(ctx, fmt.Sprintf("%d", slot))
|
||||
response, err := b.beaconBlockHeadersProvider.BeaconBlockHeader(ctx, &api.BeaconBlockHeaderOpts{Block: fmt.Sprintf("%d", slot)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if header == nil {
|
||||
if response.Data == nil {
|
||||
entry = &beaconBlockHeaderEntry{
|
||||
present: false,
|
||||
}
|
||||
} else {
|
||||
entry = &beaconBlockHeaderEntry{
|
||||
present: true,
|
||||
value: header,
|
||||
value: response.Data,
|
||||
}
|
||||
}
|
||||
b.entries[slot] = entry
|
||||
|
||||
@@ -15,7 +15,7 @@ package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"encoding/hex"
|
||||
|
||||
eth2client "github.com/attestantio/go-eth2-client"
|
||||
"github.com/pkg/errors"
|
||||
@@ -45,14 +45,11 @@ func Network(ctx context.Context, eth2Client eth2client.Service) (string, error)
|
||||
if !isProvider {
|
||||
return "", errors.New("client does not provide deposit contract address")
|
||||
}
|
||||
config, err := provider.Spec(ctx)
|
||||
specResponse, err := provider.Spec(ctx)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to obtain chain specification")
|
||||
}
|
||||
if config == nil {
|
||||
return "", errors.New("failed to return chain specification")
|
||||
}
|
||||
depositContractAddress, exists := config["DEPOSIT_CONTRACT_ADDRESS"]
|
||||
depositContractAddress, exists := specResponse.Data["DEPOSIT_CONTRACT_ADDRESS"]
|
||||
if exists {
|
||||
address = depositContractAddress.([]byte)
|
||||
}
|
||||
@@ -62,7 +59,7 @@ func Network(ctx context.Context, eth2Client eth2client.Service) (string, error)
|
||||
|
||||
// network returns a network given an Ethereum 1 contract address.
|
||||
func network(address []byte) string {
|
||||
if network, exists := networks[fmt.Sprintf("%x", address)]; exists {
|
||||
if network, exists := networks[hex.EncodeToString(address)]; exists {
|
||||
return network
|
||||
}
|
||||
return "Unknown"
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
eth2client "github.com/attestantio/go-eth2-client"
|
||||
"github.com/attestantio/go-eth2-client/api"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/wealdtech/ethdo/testutil"
|
||||
"github.com/wealdtech/ethdo/util"
|
||||
@@ -39,9 +40,12 @@ func (c *specETH2Client) Address() string {
|
||||
}
|
||||
|
||||
// Spec provides the spec information of the chain.
|
||||
func (c *specETH2Client) Spec(ctx context.Context) (map[string]interface{}, error) {
|
||||
return map[string]interface{}{
|
||||
"DEPOSIT_CONTRACT_ADDRESS": c.address,
|
||||
func (c *specETH2Client) Spec(ctx context.Context) (*api.Response[map[string]any], error) {
|
||||
return &api.Response[map[string]any]{
|
||||
Data: map[string]any{
|
||||
"DEPOSIT_CONTRACT_ADDRESS": c.address,
|
||||
},
|
||||
Metadata: make(map[string]any),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
consensusclient "github.com/attestantio/go-eth2-client"
|
||||
"github.com/attestantio/go-eth2-client/api"
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/pkg/errors"
|
||||
e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2"
|
||||
@@ -67,12 +68,15 @@ func accountToIndex(ctx context.Context, account e2wtypes.Account, client consen
|
||||
|
||||
pubKeys := make([]phase0.BLSPubKey, 1)
|
||||
copy(pubKeys[0][:], pubKey.Marshal())
|
||||
validators, err := client.(consensusclient.ValidatorsProvider).ValidatorsByPubKey(ctx, "head", pubKeys)
|
||||
validatorsResponse, err := client.(consensusclient.ValidatorsProvider).Validators(ctx, &api.ValidatorsOpts{
|
||||
State: "head",
|
||||
PubKeys: pubKeys,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
for index := range validators {
|
||||
for index := range validatorsResponse.Data {
|
||||
return index, nil
|
||||
}
|
||||
return 0, errors.New("validator not found")
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
|
||||
eth2client "github.com/attestantio/go-eth2-client"
|
||||
"github.com/attestantio/go-eth2-client/api"
|
||||
apiv1 "github.com/attestantio/go-eth2-client/api/v1"
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/pkg/errors"
|
||||
@@ -47,11 +48,11 @@ func ParseValidators(ctx context.Context, validatorsProvider eth2client.Validato
|
||||
for index := low; index <= high; index++ {
|
||||
indices = append(indices, phase0.ValidatorIndex(index))
|
||||
}
|
||||
rangeValidators, err := validatorsProvider.Validators(ctx, stateID, indices)
|
||||
response, err := validatorsProvider.Validators(ctx, &api.ValidatorsOpts{State: stateID, Indices: indices})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("failed to obtain validators %s", validatorsStr[i]))
|
||||
}
|
||||
for _, validator := range rangeValidators {
|
||||
for _, validator := range response.Data {
|
||||
validators = append(validators, validator)
|
||||
}
|
||||
} else {
|
||||
@@ -79,10 +80,14 @@ func ParseValidator(ctx context.Context,
|
||||
// Could be a simple index.
|
||||
index, err := strconv.ParseUint(validatorStr, 10, 64)
|
||||
if err == nil {
|
||||
validators, err = validatorsProvider.Validators(ctx, stateID, []phase0.ValidatorIndex{phase0.ValidatorIndex(index)})
|
||||
response, err := validatorsProvider.Validators(ctx, &api.ValidatorsOpts{
|
||||
State: stateID,
|
||||
Indices: []phase0.ValidatorIndex{phase0.ValidatorIndex(index)},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to obtain validator information")
|
||||
}
|
||||
validators = response.Data
|
||||
} else {
|
||||
// Some sort of specifier.
|
||||
account, err := ParseAccount(ctx, validatorStr, nil, false)
|
||||
@@ -96,13 +101,14 @@ func ParseValidator(ctx context.Context,
|
||||
}
|
||||
pubKey := phase0.BLSPubKey{}
|
||||
copy(pubKey[:], accPubKey.Marshal())
|
||||
validators, err = validatorsProvider.ValidatorsByPubKey(ctx,
|
||||
stateID,
|
||||
[]phase0.BLSPubKey{pubKey},
|
||||
)
|
||||
validatorsResponse, err := validatorsProvider.Validators(ctx, &api.ValidatorsOpts{
|
||||
State: stateID,
|
||||
PubKeys: []phase0.BLSPubKey{pubKey},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to obtain validator information")
|
||||
}
|
||||
validators = validatorsResponse.Data
|
||||
}
|
||||
|
||||
// Validator is first and only entry in the map.
|
||||
|
||||
Reference in New Issue
Block a user