2017-12-07 19:32:16 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-01-08 20:19:42 +00:00
|
|
|
"strconv"
|
|
|
|
|
2017-12-07 19:32:16 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
2018-01-08 20:19:42 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2018-01-10 21:54:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2017-12-07 19:32:16 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
)
|
|
|
|
|
2018-01-10 21:54:36 +00:00
|
|
|
func Info(client *rpc.Client) core.Node {
|
2017-12-07 19:32:16 +00:00
|
|
|
node := core.Node{}
|
2018-01-10 21:54:36 +00:00
|
|
|
node.NetworkId = NetworkId(client)
|
|
|
|
node.GenesisBlock = GenesisBlock(client)
|
|
|
|
node.Id, node.ClientName = IdClientName(client)
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
func IdClientName(client *rpc.Client) (string, string) {
|
|
|
|
var info p2p.NodeInfo
|
|
|
|
modules, _ := client.SupportedModules()
|
|
|
|
if _, ok := modules["admin"]; ok {
|
|
|
|
client.CallContext(context.Background(), &info, "admin_nodeInfo")
|
|
|
|
return info.ID, info.Name
|
|
|
|
}
|
|
|
|
return "", ""
|
|
|
|
}
|
2017-12-07 19:32:16 +00:00
|
|
|
|
2018-01-10 21:54:36 +00:00
|
|
|
func NetworkId(client *rpc.Client) float64 {
|
2018-01-08 20:19:42 +00:00
|
|
|
var version string
|
|
|
|
client.CallContext(context.Background(), &version, "net_version")
|
2018-01-10 21:54:36 +00:00
|
|
|
networkId, _ := strconv.ParseFloat(version, 64)
|
|
|
|
return networkId
|
|
|
|
}
|
2018-01-08 20:19:42 +00:00
|
|
|
|
2018-01-10 21:54:36 +00:00
|
|
|
func ProtocolVersion(client *rpc.Client) string {
|
2018-01-08 20:19:42 +00:00
|
|
|
var protocolVersion string
|
|
|
|
client.CallContext(context.Background(), &protocolVersion, "eth_protocolVersion")
|
2018-01-10 21:54:36 +00:00
|
|
|
return protocolVersion
|
|
|
|
}
|
2018-01-08 20:19:42 +00:00
|
|
|
|
2018-01-10 21:54:36 +00:00
|
|
|
func GenesisBlock(client *rpc.Client) string {
|
2018-01-08 20:19:42 +00:00
|
|
|
var header *types.Header
|
|
|
|
client.CallContext(context.Background(), &header, "eth_getBlockByNumber", "0x0", false)
|
2018-01-10 21:54:36 +00:00
|
|
|
return header.Hash().Hex()
|
2017-12-07 19:32:16 +00:00
|
|
|
}
|