You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
866 B
30 lines
866 B
5 years ago
|
package apiv1
|
||
6 years ago
|
|
||
|
import (
|
||
6 years ago
|
"fmt"
|
||
|
|
||
6 years ago
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||
6 years ago
|
"github.com/harmony-one/harmony/p2p"
|
||
6 years ago
|
)
|
||
|
|
||
|
// PublicNetAPI offers network related RPC methods
|
||
|
type PublicNetAPI struct {
|
||
6 years ago
|
net p2p.Host
|
||
|
networkVersion uint64
|
||
6 years ago
|
}
|
||
|
|
||
|
// NewPublicNetAPI creates a new net API instance.
|
||
6 years ago
|
func NewPublicNetAPI(net p2p.Host, networkVersion uint64) *PublicNetAPI {
|
||
|
return &PublicNetAPI{net, networkVersion}
|
||
6 years ago
|
}
|
||
|
|
||
|
// PeerCount returns the number of connected peers
|
||
|
func (s *PublicNetAPI) PeerCount() hexutil.Uint {
|
||
6 years ago
|
return hexutil.Uint(s.net.GetPeerCount())
|
||
|
}
|
||
|
|
||
6 years ago
|
// Version returns the network version, i.e. network ID identifying which network we are using
|
||
6 years ago
|
func (s *PublicNetAPI) Version() string {
|
||
|
return fmt.Sprintf("%d", s.networkVersion) // TODO(ricl): we should add support for network id (https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version)
|
||
6 years ago
|
}
|