mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 04:03:49 +00:00
8e3ac8a21c
* Erigon2 upgrade 2 prototype * Latest erigon-lib * Fixes * Fix print * Fix maxSpan * Reduce maxSpan * Remove duplicate joins * TxNum * Fix resuming * first draft of history22 * Introduce historical reads * Update to erigon-lib * Update erigon-lib * Update erigon-lib * Fixes and tracing for checkChangeSets * More trace * Print account details * fix getHeader * Update to erigon-lib main * Add tracer indices and event log indices * Fix calltracer * Fix calltracer * Duplicate rpcdaemon into rpcdaemon22 * Fix tests * Fix tests * Fix tests * Update to latest erigon-lib Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p"
|
|
"github.com/ledgerwatch/erigon/turbo/rpchelper"
|
|
)
|
|
|
|
// 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 rpchelper.ApiBackend
|
|
}
|
|
|
|
// NewAdminAPI returns AdminAPIImpl instance.
|
|
func NewAdminAPI(eth rpchelper.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)
|
|
}
|