Remove admin api dependency (#126)
This commit is contained in:
parent
54c4f0c2fe
commit
14e1fc4213
@ -58,6 +58,10 @@ func convertTransactionsToCore(gethBlock *types.Block, client GethClient) []core
|
|||||||
|
|
||||||
func appendReceiptToTransaction(client GethClient, transaction core.Transaction) (core.Transaction, error) {
|
func appendReceiptToTransaction(client GethClient, transaction core.Transaction) (core.Transaction, error) {
|
||||||
gethReceipt, err := client.TransactionReceipt(context.Background(), common.HexToHash(transaction.Hash))
|
gethReceipt, err := client.TransactionReceipt(context.Background(), common.HexToHash(transaction.Hash))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return transaction, err
|
||||||
|
}
|
||||||
receipt := ReceiptToCoreReceipt(gethReceipt)
|
receipt := ReceiptToCoreReceipt(gethReceipt)
|
||||||
transaction.Receipt = receipt
|
transaction.Receipt = receipt
|
||||||
return transaction, err
|
return transaction, err
|
||||||
|
@ -3,30 +3,26 @@ package node
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Retrieve(client *rpc.Client) core.Node {
|
func Retrieve(client *rpc.Client) core.Node {
|
||||||
var info p2p.NodeInfo
|
|
||||||
node := core.Node{}
|
node := core.Node{}
|
||||||
client.CallContext(context.Background(), &info, "admin_nodeInfo")
|
|
||||||
for protocolName, protocol := range info.Protocols {
|
var version string
|
||||||
if protocolName == "eth" {
|
client.CallContext(context.Background(), &version, "net_version")
|
||||||
protocolMap, _ := protocol.(map[string]interface{})
|
node.NetworkId, _ = strconv.ParseFloat(version, 64)
|
||||||
node.GenesisBlock = getAttribute(protocolMap, "genesis").(string)
|
|
||||||
node.NetworkId = getAttribute(protocolMap, "network").(float64)
|
var protocolVersion string
|
||||||
}
|
client.CallContext(context.Background(), &protocolVersion, "eth_protocolVersion")
|
||||||
}
|
|
||||||
|
var header *types.Header
|
||||||
|
client.CallContext(context.Background(), &header, "eth_getBlockByNumber", "0x0", false)
|
||||||
|
node.GenesisBlock = header.Hash().Hex()
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAttribute(protocolMap map[string]interface{}, protocol string) interface{} {
|
|
||||||
for key, val := range protocolMap {
|
|
||||||
if key == protocol {
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user