net api service (#933)

This commit is contained in:
Evgeny Danilenko 2020-08-17 18:27:29 +03:00 committed by GitHub
parent 081d02920d
commit 6976f58f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 2 deletions

View File

@ -139,6 +139,7 @@ func GetAPI(db ethdb.KV, eth ethdb.Backend, enabledApis []string) []rpc.API {
dbReader := ethdb.NewObjectDatabase(db)
chainContext := NewChainContext(dbReader)
apiImpl := NewAPI(db, dbReader, chainContext, eth)
netImpl := NewNetAPIImpl(eth)
dbgAPIImpl := NewPrivateDebugAPI(db, dbReader, chainContext)
for _, enabledAPI := range enabledApis {
@ -157,6 +158,13 @@ func GetAPI(db ethdb.KV, eth ethdb.Backend, enabledApis []string) []rpc.API {
Service: PrivateDebugAPI(dbgAPIImpl),
Version: "1.0",
})
case "net":
rpcAPI = append(rpcAPI, rpc.API{
Namespace: "net",
Public: true,
Service: NetAPI(netImpl),
Version: "1.0",
})
default:
log.Error("Unrecognised", "api", enabledAPI)

View File

@ -17,7 +17,6 @@ import (
// EthAPI is a collection of functions that are exposed in the
type EthAPI interface {
Coinbase(ctx context.Context) (common.Address, error)
NetVersion(ctx context.Context) uint64
BlockNumber(ctx context.Context) (hexutil.Uint64, error)
GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)
GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)

View File

@ -0,0 +1,22 @@
package commands
import (
"context"
"github.com/ledgerwatch/turbo-geth/ethdb"
)
type NetAPI interface {
Version(ctx context.Context) uint64
}
type NetAPIImpl struct {
ethBackend ethdb.Backend
}
// NwtNetAPIImpl returns NetAPIImplImpl instance
func NewNetAPIImpl(eth ethdb.Backend) *NetAPIImpl {
return &NetAPIImpl{
ethBackend: eth,
}
}

View File

@ -4,6 +4,6 @@ import (
"context"
)
func (api *APIImpl) NetVersion(_ context.Context) uint64 {
func (api *NetAPIImpl) Version(_ context.Context) uint64 {
return api.ethBackend.NetVersion()
}