mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-04 01:54:28 +00:00
fc3eecae5e
* RPC: admin.peers() This RPC method returns information about the connected remote nodes. https://geth.ethereum.org/docs/rpc/ns-admin#admin_peers The peers are collected from all configured sentries. See: https://github.com/ledgerwatch/interfaces/pull/102 Test with: curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "admin_peers", "params": [], "id":1}' localhost:8545 * save * liner fix Co-authored-by: alex.sharov <AskAlexSharov@gmail.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
|
|
"github.com/ledgerwatch/erigon/p2p"
|
|
)
|
|
|
|
// AdminAPI the interface for the admin_* RPC commands.
|
|
type AdminAPI interface {
|
|
// NodeInfo returns a collection of metadata known about the host.
|
|
NodeInfo(ctx context.Context) (*p2p.NodeInfo, error)
|
|
|
|
// Peers returns information about the connected remote nodes.
|
|
// https://geth.ethereum.org/docs/rpc/ns-admin#admin_peers
|
|
Peers(ctx context.Context) ([]*p2p.PeerInfo, error)
|
|
}
|
|
|
|
// AdminAPIImpl data structure to store things needed for admin_* commands.
|
|
type AdminAPIImpl struct {
|
|
ethBackend services.ApiBackend
|
|
}
|
|
|
|
// NewAdminAPI returns AdminAPIImpl instance.
|
|
func NewAdminAPI(eth services.ApiBackend) *AdminAPIImpl {
|
|
return &AdminAPIImpl{
|
|
ethBackend: eth,
|
|
}
|
|
}
|
|
|
|
func (api *AdminAPIImpl) NodeInfo(ctx context.Context) (*p2p.NodeInfo, error) {
|
|
nodes, err := api.ethBackend.NodeInfo(ctx, 1)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("node info request error: %w", err)
|
|
}
|
|
|
|
if len(nodes) == 0 {
|
|
return nil, errors.New("empty nodesInfo response")
|
|
}
|
|
|
|
return &nodes[0], nil
|
|
}
|
|
|
|
func (api *AdminAPIImpl) Peers(ctx context.Context) ([]*p2p.PeerInfo, error) {
|
|
return api.ethBackend.Peers(ctx)
|
|
}
|