Update BlockChain to record NodeInfo (#95)

This commit is contained in:
Matt K
2017-12-07 13:32:16 -06:00
committed by GitHub
parent 18163f970e
commit 921bde1089
21 changed files with 276 additions and 45 deletions
+32
View File
@@ -0,0 +1,32 @@
package node
import (
"context"
"github.com/8thlight/vulcanizedb/pkg/core"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
)
func Retrieve(client *rpc.Client) core.Node {
var info p2p.NodeInfo
node := core.Node{}
client.CallContext(context.Background(), &info, "admin_nodeInfo")
for protocolName, protocol := range info.Protocols {
if protocolName == "eth" {
protocolMap, _ := protocol.(map[string]interface{})
node.GenesisBlock = getAttribute(protocolMap, "genesis").(string)
node.NetworkId = getAttribute(protocolMap, "network").(float64)
}
}
return node
}
func getAttribute(protocolMap map[string]interface{}, protocol string) interface{} {
for key, val := range protocolMap {
if key == protocol {
return val
}
}
return nil
}