ethnode

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(w io.Writer)

SetLogger overrides the log writer for this package.

Types

type EthNode

type EthNode interface {
	ContractBackend() bind.ContractBackend

	// Kind returns the kind of node this is.
	Kind() NodeKind
	// Enode returns this node's enode://...
	Enode(ctx context.Context) (string, error)
	// AddTrustedPeer adds a nodeID to a set of nodes that can always connect, even
	// if the maximum number of connections is reached.
	AddTrustedPeer(ctx context.Context, nodeID string) error
	// RemoveTrustedPeer removes a nodeID from the trusted node set.
	RemoveTrustedPeer(ctx context.Context, nodeID string) error
	// ConnectPeer prompts a connection to the given nodeURI.
	ConnectPeer(ctx context.Context, nodeURI string) error
	// DisconnectPeer disconnects from the given nodeID, if connected.
	DisconnectPeer(ctx context.Context, nodeID string) error
	// Peers returns the list of connected peers
	Peers(ctx context.Context) ([]PeerInfo, error)
	// BlockNumber returns the current sync'd block number.
	BlockNumber(ctx context.Context) (uint64, error)
}

EthNode is the normalized interface between different kinds of nodes.

func Dial

func Dial(ctx context.Context, uri string) (EthNode, error)

Dial is a wrapper around go-ethereum/rpc.Dial with client detection.

func RemoteNode

func RemoteNode(client *rpc.Client) (EthNode, error)

RemoteNode autodetects the node kind and returns the appropriate EthNode implementation.

type NetworkID added in v0.2.2

type NetworkID int
const (
	Mainnet NetworkID = 1
	Morden  NetworkID = 2
	Ropsten NetworkID = 3
	Rinkeby NetworkID = 4
	Kovan   NetworkID = 42
)

func (NetworkID) Is added in v0.2.3

func (id NetworkID) Is(network string) bool

Is compares the ID to a network name.

func (NetworkID) String added in v0.2.3

func (id NetworkID) String() string

type NodeKind

type NodeKind int

NodeKind represents the different kinds of node implementations we know about.

const (
	Unknown NodeKind = iota // We'll treat unknown as Geth, just in case.
	Geth
	Parity
)

func (NodeKind) String

func (n NodeKind) String() string

type PeerInfo

type PeerInfo struct {
	ID   string `json:"id"`   // Unique node identifier (also the encryption pubkey)
	Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
}

PeerInfo stores the node ID and client metadata about a peer.

type UserAgent added in v0.2.2

type UserAgent struct {
	Version     string // Result of web3_clientVersion
	EthProtocol string // Result of eth_protocolVersion

	// Parsed/derived values
	Kind       NodeKind  // Node implementation
	Network    NetworkID // Network ID
	IsFullNode bool      // Is this a full node? (or a light client?)
}

UserAgent is the metadata about node client.

func DetectClient

func DetectClient(client *rpc.Client) (*UserAgent, error)

DetectClient queries the RPC API to determine which kind of node is running.

func ParseUserAgent added in v0.2.2

func ParseUserAgent(clientVersion, protocolVersion, netVersion string) (*UserAgent, error)

ParseUserAgent takes string values as output from the web3 RPC for web3_clientVersion, eth_protocolVersion, and net_version. It returns a parsed user agent metadata.

Jump to

Keyboard shortcuts

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