Unverified Commit 10dc5dce authored by lightclient's avatar lightclient Committed by GitHub

all: remove concept of public/private API definitions (#25053)

* internal/ethapi: rename PublicEthereumAPI to EthereumAPI

* eth: rename PublicEthereumAPI to EthereumAPI

* internal/ethapi: rename PublicTxPoolAPI to TxPoolAPI

* internal/ethapi: rename PublicAccountAPI to EthereumAccountAPI

* internal/ethapi: rename PrivateAccountAPI to PersonalAccountAPI

* internal/ethapi: rename PublicBlockChainAPI to BlockChainAPI

* internal/ethapi: rename PublicTransactionPoolAPI to TransactionAPI

* internal/ethapi: rename PublicDebugAPI to DebugAPI

* internal/ethapi: move PrivateDebugAPI methods to DebugAPI

* internal/ethapi: rename PublicNetAPI to NetAPI

* les: rename PrivateLightServerAPI to LightServerAPI

* les: rename PrivateLightAPI to LightAPI

* les: rename PrivateDebugAPI to DebugAPI

* les: rename PublicDownloaderAPI to DownloaderAPI

* eth,les: rename PublicFilterAPI to FilterAPI

* eth: rename PublicMinerAPI to MinerAPI

* eth: rename PublicDownloaderAPI to DownloaderAPI

* eth: move PrivateMinerAPI methods to MinerAPI

* eth: rename PrivateAdminAPI to AdminAPI

* eth: rename PublicDebugAPI to DebugAPI

* eth: move PrivateDebugAPI methods to DebugAPI

* node: rename publicAdminAPI to adminAPI

* node: move privateAdminAPI methods to adminAPI

* node: rename publicWeb3API to web3API

* eth,internal/ethapi: sync comments with previous renamings
parent 241dd273
This diff is collapsed.
...@@ -94,7 +94,7 @@ type Ethereum struct { ...@@ -94,7 +94,7 @@ type Ethereum struct {
etherbase common.Address etherbase common.Address
networkID uint64 networkID uint64
netRPCService *ethapi.PublicNetAPI netRPCService *ethapi.NetAPI
p2pServer *p2p.Server p2pServer *p2p.Server
...@@ -266,7 +266,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { ...@@ -266,7 +266,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
} }
// Start the RPC service // Start the RPC service
eth.netRPCService = ethapi.NewPublicNetAPI(eth.p2pServer, config.NetworkId) eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, config.NetworkId)
// Register the backend on the node // Register the backend on the node
stack.RegisterAPIs(eth.APIs()) stack.RegisterAPIs(eth.APIs())
...@@ -309,41 +309,32 @@ func (s *Ethereum) APIs() []rpc.API { ...@@ -309,41 +309,32 @@ func (s *Ethereum) APIs() []rpc.API {
{ {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: NewPublicEthereumAPI(s), Service: NewEthereumAPI(s),
Public: true, Public: true,
}, { }, {
Namespace: "eth", Namespace: "miner",
Version: "1.0", Version: "1.0",
Service: NewPublicMinerAPI(s), Service: NewMinerAPI(s),
Public: true, Public: true,
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: downloader.NewPublicDownloaderAPI(s.handler.downloader, s.eventMux), Service: downloader.NewDownloaderAPI(s.handler.downloader, s.eventMux),
Public: true, Public: true,
}, {
Namespace: "miner",
Version: "1.0",
Service: NewPrivateMinerAPI(s),
Public: false,
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: filters.NewPublicFilterAPI(s.APIBackend, false, 5*time.Minute), Service: filters.NewFilterAPI(s.APIBackend, false, 5*time.Minute),
Public: true, Public: true,
}, { }, {
Namespace: "admin", Namespace: "admin",
Version: "1.0", Version: "1.0",
Service: NewPrivateAdminAPI(s), Service: NewAdminAPI(s),
}, { }, {
Namespace: "debug", Namespace: "debug",
Version: "1.0", Version: "1.0",
Service: NewPublicDebugAPI(s), Service: NewDebugAPI(s),
Public: true, Public: true,
}, {
Namespace: "debug",
Version: "1.0",
Service: NewPrivateDebugAPI(s),
}, { }, {
Namespace: "net", Namespace: "net",
Version: "1.0", Version: "1.0",
......
...@@ -25,21 +25,21 @@ import ( ...@@ -25,21 +25,21 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
// PublicDownloaderAPI provides an API which gives information about the current synchronisation status. // DownloaderAPI provides an API which gives information about the current synchronisation status.
// It offers only methods that operates on data that can be available to anyone without security risks. // It offers only methods that operates on data that can be available to anyone without security risks.
type PublicDownloaderAPI struct { type DownloaderAPI struct {
d *Downloader d *Downloader
mux *event.TypeMux mux *event.TypeMux
installSyncSubscription chan chan interface{} installSyncSubscription chan chan interface{}
uninstallSyncSubscription chan *uninstallSyncSubscriptionRequest uninstallSyncSubscription chan *uninstallSyncSubscriptionRequest
} }
// NewPublicDownloaderAPI create a new PublicDownloaderAPI. The API has an internal event loop that // NewDownloaderAPI create a new DownloaderAPI. The API has an internal event loop that
// listens for events from the downloader through the global event mux. In case it receives one of // listens for events from the downloader through the global event mux. In case it receives one of
// these events it broadcasts it to all syncing subscriptions that are installed through the // these events it broadcasts it to all syncing subscriptions that are installed through the
// installSyncSubscription channel. // installSyncSubscription channel.
func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI { func NewDownloaderAPI(d *Downloader, m *event.TypeMux) *DownloaderAPI {
api := &PublicDownloaderAPI{ api := &DownloaderAPI{
d: d, d: d,
mux: m, mux: m,
installSyncSubscription: make(chan chan interface{}), installSyncSubscription: make(chan chan interface{}),
...@@ -53,7 +53,7 @@ func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAP ...@@ -53,7 +53,7 @@ func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAP
// eventLoop runs a loop until the event mux closes. It will install and uninstall new // eventLoop runs a loop until the event mux closes. It will install and uninstall new
// sync subscriptions and broadcasts sync status updates to the installed sync subscriptions. // sync subscriptions and broadcasts sync status updates to the installed sync subscriptions.
func (api *PublicDownloaderAPI) eventLoop() { func (api *DownloaderAPI) eventLoop() {
var ( var (
sub = api.mux.Subscribe(StartEvent{}, DoneEvent{}, FailedEvent{}) sub = api.mux.Subscribe(StartEvent{}, DoneEvent{}, FailedEvent{})
syncSubscriptions = make(map[chan interface{}]struct{}) syncSubscriptions = make(map[chan interface{}]struct{})
...@@ -90,7 +90,7 @@ func (api *PublicDownloaderAPI) eventLoop() { ...@@ -90,7 +90,7 @@ func (api *PublicDownloaderAPI) eventLoop() {
} }
// Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished. // Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.
func (api *PublicDownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error) { func (api *DownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error) {
notifier, supported := rpc.NotifierFromContext(ctx) notifier, supported := rpc.NotifierFromContext(ctx)
if !supported { if !supported {
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
...@@ -133,7 +133,7 @@ type uninstallSyncSubscriptionRequest struct { ...@@ -133,7 +133,7 @@ type uninstallSyncSubscriptionRequest struct {
// SyncStatusSubscription represents a syncing subscription. // SyncStatusSubscription represents a syncing subscription.
type SyncStatusSubscription struct { type SyncStatusSubscription struct {
api *PublicDownloaderAPI // register subscription in event loop of this api instance api *DownloaderAPI // register subscription in event loop of this api instance
c chan interface{} // channel where events are broadcasted to c chan interface{} // channel where events are broadcasted to
unsubOnce sync.Once // make sure unsubscribe logic is executed once unsubOnce sync.Once // make sure unsubscribe logic is executed once
} }
...@@ -160,7 +160,7 @@ func (s *SyncStatusSubscription) Unsubscribe() { ...@@ -160,7 +160,7 @@ func (s *SyncStatusSubscription) Unsubscribe() {
// SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates. // SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates.
// The given channel must receive interface values, the result can either. // The given channel must receive interface values, the result can either.
func (api *PublicDownloaderAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription { func (api *DownloaderAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription {
api.installSyncSubscription <- status api.installSyncSubscription <- status
return &SyncStatusSubscription{api: api, c: status} return &SyncStatusSubscription{api: api, c: status}
} }
...@@ -43,9 +43,9 @@ type filter struct { ...@@ -43,9 +43,9 @@ type filter struct {
s *Subscription // associated subscription in event system s *Subscription // associated subscription in event system
} }
// PublicFilterAPI offers support to create and manage filters. This will allow external clients to retrieve various // FilterAPI offers support to create and manage filters. This will allow external clients to retrieve various
// information related to the Ethereum protocol such als blocks, transactions and logs. // information related to the Ethereum protocol such als blocks, transactions and logs.
type PublicFilterAPI struct { type FilterAPI struct {
backend Backend backend Backend
events *EventSystem events *EventSystem
filtersMu sync.Mutex filtersMu sync.Mutex
...@@ -53,9 +53,9 @@ type PublicFilterAPI struct { ...@@ -53,9 +53,9 @@ type PublicFilterAPI struct {
timeout time.Duration timeout time.Duration
} }
// NewPublicFilterAPI returns a new PublicFilterAPI instance. // NewFilterAPI returns a new FilterAPI instance.
func NewPublicFilterAPI(backend Backend, lightMode bool, timeout time.Duration) *PublicFilterAPI { func NewFilterAPI(backend Backend, lightMode bool, timeout time.Duration) *FilterAPI {
api := &PublicFilterAPI{ api := &FilterAPI{
backend: backend, backend: backend,
events: NewEventSystem(backend, lightMode), events: NewEventSystem(backend, lightMode),
filters: make(map[rpc.ID]*filter), filters: make(map[rpc.ID]*filter),
...@@ -68,7 +68,7 @@ func NewPublicFilterAPI(backend Backend, lightMode bool, timeout time.Duration) ...@@ -68,7 +68,7 @@ func NewPublicFilterAPI(backend Backend, lightMode bool, timeout time.Duration)
// timeoutLoop runs at the interval set by 'timeout' and deletes filters // timeoutLoop runs at the interval set by 'timeout' and deletes filters
// that have not been recently used. It is started when the API is created. // that have not been recently used. It is started when the API is created.
func (api *PublicFilterAPI) timeoutLoop(timeout time.Duration) { func (api *FilterAPI) timeoutLoop(timeout time.Duration) {
var toUninstall []*Subscription var toUninstall []*Subscription
ticker := time.NewTicker(timeout) ticker := time.NewTicker(timeout)
defer ticker.Stop() defer ticker.Stop()
...@@ -101,7 +101,7 @@ func (api *PublicFilterAPI) timeoutLoop(timeout time.Duration) { ...@@ -101,7 +101,7 @@ func (api *PublicFilterAPI) timeoutLoop(timeout time.Duration) {
// //
// It is part of the filter package because this filter can be used through the // It is part of the filter package because this filter can be used through the
// `eth_getFilterChanges` polling method that is also used for log filters. // `eth_getFilterChanges` polling method that is also used for log filters.
func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID { func (api *FilterAPI) NewPendingTransactionFilter() rpc.ID {
var ( var (
pendingTxs = make(chan []common.Hash) pendingTxs = make(chan []common.Hash)
pendingTxSub = api.events.SubscribePendingTxs(pendingTxs) pendingTxSub = api.events.SubscribePendingTxs(pendingTxs)
...@@ -134,7 +134,7 @@ func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID { ...@@ -134,7 +134,7 @@ func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID {
// NewPendingTransactions creates a subscription that is triggered each time a transaction // NewPendingTransactions creates a subscription that is triggered each time a transaction
// enters the transaction pool and was signed from one of the transactions this nodes manages. // enters the transaction pool and was signed from one of the transactions this nodes manages.
func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscription, error) { func (api *FilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscription, error) {
notifier, supported := rpc.NotifierFromContext(ctx) notifier, supported := rpc.NotifierFromContext(ctx)
if !supported { if !supported {
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
...@@ -169,7 +169,7 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su ...@@ -169,7 +169,7 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su
// NewBlockFilter creates a filter that fetches blocks that are imported into the chain. // NewBlockFilter creates a filter that fetches blocks that are imported into the chain.
// It is part of the filter package since polling goes with eth_getFilterChanges. // It is part of the filter package since polling goes with eth_getFilterChanges.
func (api *PublicFilterAPI) NewBlockFilter() rpc.ID { func (api *FilterAPI) NewBlockFilter() rpc.ID {
var ( var (
headers = make(chan *types.Header) headers = make(chan *types.Header)
headerSub = api.events.SubscribeNewHeads(headers) headerSub = api.events.SubscribeNewHeads(headers)
...@@ -201,7 +201,7 @@ func (api *PublicFilterAPI) NewBlockFilter() rpc.ID { ...@@ -201,7 +201,7 @@ func (api *PublicFilterAPI) NewBlockFilter() rpc.ID {
} }
// NewHeads send a notification each time a new (header) block is appended to the chain. // NewHeads send a notification each time a new (header) block is appended to the chain.
func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) { func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) {
notifier, supported := rpc.NotifierFromContext(ctx) notifier, supported := rpc.NotifierFromContext(ctx)
if !supported { if !supported {
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
...@@ -231,7 +231,7 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er ...@@ -231,7 +231,7 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er
} }
// Logs creates a subscription that fires for all new log that match the given filter criteria. // Logs creates a subscription that fires for all new log that match the given filter criteria.
func (api *PublicFilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subscription, error) { func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subscription, error) {
notifier, supported := rpc.NotifierFromContext(ctx) notifier, supported := rpc.NotifierFromContext(ctx)
if !supported { if !supported {
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
...@@ -284,7 +284,7 @@ type FilterCriteria ethereum.FilterQuery ...@@ -284,7 +284,7 @@ type FilterCriteria ethereum.FilterQuery
// again but with the removed property set to true. // again but with the removed property set to true.
// //
// In case "fromBlock" > "toBlock" an error is returned. // In case "fromBlock" > "toBlock" an error is returned.
func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) { func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
logs := make(chan []*types.Log) logs := make(chan []*types.Log)
logsSub, err := api.events.SubscribeLogs(ethereum.FilterQuery(crit), logs) logsSub, err := api.events.SubscribeLogs(ethereum.FilterQuery(crit), logs)
if err != nil { if err != nil {
...@@ -317,7 +317,7 @@ func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) { ...@@ -317,7 +317,7 @@ func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
} }
// GetLogs returns logs matching the given argument that are stored within the state. // GetLogs returns logs matching the given argument that are stored within the state.
func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) { func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) {
var filter *Filter var filter *Filter
if crit.BlockHash != nil { if crit.BlockHash != nil {
// Block filter requested, construct a single-shot filter // Block filter requested, construct a single-shot filter
...@@ -344,7 +344,7 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([ ...@@ -344,7 +344,7 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([
} }
// UninstallFilter removes the filter with the given filter id. // UninstallFilter removes the filter with the given filter id.
func (api *PublicFilterAPI) UninstallFilter(id rpc.ID) bool { func (api *FilterAPI) UninstallFilter(id rpc.ID) bool {
api.filtersMu.Lock() api.filtersMu.Lock()
f, found := api.filters[id] f, found := api.filters[id]
if found { if found {
...@@ -360,7 +360,7 @@ func (api *PublicFilterAPI) UninstallFilter(id rpc.ID) bool { ...@@ -360,7 +360,7 @@ func (api *PublicFilterAPI) UninstallFilter(id rpc.ID) bool {
// GetFilterLogs returns the logs for the filter with the given id. // GetFilterLogs returns the logs for the filter with the given id.
// If the filter could not be found an empty array of logs is returned. // If the filter could not be found an empty array of logs is returned.
func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Log, error) { func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Log, error) {
api.filtersMu.Lock() api.filtersMu.Lock()
f, found := api.filters[id] f, found := api.filters[id]
api.filtersMu.Unlock() api.filtersMu.Unlock()
...@@ -399,7 +399,7 @@ func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ty ...@@ -399,7 +399,7 @@ func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ty
// //
// For pending transaction and block filters the result is []common.Hash. // For pending transaction and block filters the result is []common.Hash.
// (pending)Log filters return []Log. // (pending)Log filters return []Log.
func (api *PublicFilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) { func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) {
api.filtersMu.Lock() api.filtersMu.Lock()
defer api.filtersMu.Unlock() defer api.filtersMu.Unlock()
......
...@@ -171,7 +171,7 @@ func TestBlockSubscription(t *testing.T) { ...@@ -171,7 +171,7 @@ func TestBlockSubscription(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
genesis = (&core.Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db) genesis = (&core.Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db)
chain, _ = core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 10, func(i int, gen *core.BlockGen) {}) chain, _ = core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 10, func(i int, gen *core.BlockGen) {})
chainEvents = []core.ChainEvent{} chainEvents = []core.ChainEvent{}
...@@ -223,7 +223,7 @@ func TestPendingTxFilter(t *testing.T) { ...@@ -223,7 +223,7 @@ func TestPendingTxFilter(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
transactions = []*types.Transaction{ transactions = []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil),
...@@ -278,7 +278,7 @@ func TestLogFilterCreation(t *testing.T) { ...@@ -278,7 +278,7 @@ func TestLogFilterCreation(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
testCases = []struct { testCases = []struct {
crit FilterCriteria crit FilterCriteria
...@@ -325,7 +325,7 @@ func TestInvalidLogFilterCreation(t *testing.T) { ...@@ -325,7 +325,7 @@ func TestInvalidLogFilterCreation(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
) )
// different situations where log filter creation should fail. // different situations where log filter creation should fail.
...@@ -347,7 +347,7 @@ func TestInvalidGetLogsRequest(t *testing.T) { ...@@ -347,7 +347,7 @@ func TestInvalidGetLogsRequest(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
blockHash = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111") blockHash = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")
) )
...@@ -372,7 +372,7 @@ func TestLogFilter(t *testing.T) { ...@@ -372,7 +372,7 @@ func TestLogFilter(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111") firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111")
secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222") secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222")
...@@ -486,7 +486,7 @@ func TestPendingLogsSubscription(t *testing.T) { ...@@ -486,7 +486,7 @@ func TestPendingLogsSubscription(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, deadline) api = NewFilterAPI(backend, false, deadline)
firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111") firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111")
secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222") secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222")
...@@ -670,7 +670,7 @@ func TestPendingTxFilterDeadlock(t *testing.T) { ...@@ -670,7 +670,7 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
backend = &testBackend{db: db} backend = &testBackend{db: db}
api = NewPublicFilterAPI(backend, false, timeout) api = NewFilterAPI(backend, false, timeout)
done = make(chan struct{}) done = make(chan struct{})
) )
......
This diff is collapsed.
...@@ -102,41 +102,37 @@ func GetAPIs(apiBackend Backend) []rpc.API { ...@@ -102,41 +102,37 @@ func GetAPIs(apiBackend Backend) []rpc.API {
{ {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: NewPublicEthereumAPI(apiBackend), Service: NewEthereumAPI(apiBackend),
Public: true, Public: true,
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: NewPublicBlockChainAPI(apiBackend), Service: NewBlockChainAPI(apiBackend),
Public: true, Public: true,
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), Service: NewTransactionAPI(apiBackend, nonceLock),
Public: true, Public: true,
}, { }, {
Namespace: "txpool", Namespace: "txpool",
Version: "1.0", Version: "1.0",
Service: NewPublicTxPoolAPI(apiBackend), Service: NewTxPoolAPI(apiBackend),
Public: true, Public: true,
}, { }, {
Namespace: "debug", Namespace: "debug",
Version: "1.0", Version: "1.0",
Service: NewPublicDebugAPI(apiBackend), Service: NewDebugAPI(apiBackend),
Public: true, Public: true,
}, {
Namespace: "debug",
Version: "1.0",
Service: NewPrivateDebugAPI(apiBackend),
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: NewPublicAccountAPI(apiBackend.AccountManager()), Service: NewEthereumAccountAPI(apiBackend.AccountManager()),
Public: true, Public: true,
}, { }, {
Namespace: "personal", Namespace: "personal",
Version: "1.0", Version: "1.0",
Service: NewPrivateAccountAPI(apiBackend, nonceLock), Service: NewPersonalAccountAPI(apiBackend, nonceLock),
Public: false, Public: false,
}, },
} }
......
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
) )
// DbGet returns the raw value of a key stored in the database. // DbGet returns the raw value of a key stored in the database.
func (api *PrivateDebugAPI) DbGet(key string) (hexutil.Bytes, error) { func (api *DebugAPI) DbGet(key string) (hexutil.Bytes, error) {
blob, err := common.ParseHexOrString(key) blob, err := common.ParseHexOrString(key)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -32,12 +32,12 @@ func (api *PrivateDebugAPI) DbGet(key string) (hexutil.Bytes, error) { ...@@ -32,12 +32,12 @@ func (api *PrivateDebugAPI) DbGet(key string) (hexutil.Bytes, error) {
// DbAncient retrieves an ancient binary blob from the append-only immutable files. // DbAncient retrieves an ancient binary blob from the append-only immutable files.
// It is a mapping to the `AncientReaderOp.Ancient` method // It is a mapping to the `AncientReaderOp.Ancient` method
func (api *PrivateDebugAPI) DbAncient(kind string, number uint64) (hexutil.Bytes, error) { func (api *DebugAPI) DbAncient(kind string, number uint64) (hexutil.Bytes, error) {
return api.b.ChainDb().Ancient(kind, number) return api.b.ChainDb().Ancient(kind, number)
} }
// DbAncients returns the ancient item numbers in the ancient store. // DbAncients returns the ancient item numbers in the ancient store.
// It is a mapping to the `AncientReaderOp.Ancients` method // It is a mapping to the `AncientReaderOp.Ancients` method
func (api *PrivateDebugAPI) DbAncients() (uint64, error) { func (api *DebugAPI) DbAncients() (uint64, error) {
return api.b.ChainDb().Ancients() return api.b.ChainDb().Ancients()
} }
...@@ -33,15 +33,15 @@ var ( ...@@ -33,15 +33,15 @@ var (
errUnknownBenchmarkType = errors.New("unknown benchmark type") errUnknownBenchmarkType = errors.New("unknown benchmark type")
) )
// PrivateLightServerAPI provides an API to access the LES light server. // LightServerAPI provides an API to access the LES light server.
type PrivateLightServerAPI struct { type LightServerAPI struct {
server *LesServer server *LesServer
defaultPosFactors, defaultNegFactors vfs.PriceFactors defaultPosFactors, defaultNegFactors vfs.PriceFactors
} }
// NewPrivateLightServerAPI creates a new LES light server API. // NewLightServerAPI creates a new LES light server API.
func NewPrivateLightServerAPI(server *LesServer) *PrivateLightServerAPI { func NewLightServerAPI(server *LesServer) *LightServerAPI {
return &PrivateLightServerAPI{ return &LightServerAPI{
server: server, server: server,
defaultPosFactors: defaultPosFactors, defaultPosFactors: defaultPosFactors,
defaultNegFactors: defaultNegFactors, defaultNegFactors: defaultNegFactors,
...@@ -61,7 +61,7 @@ func parseNode(node string) (enode.ID, error) { ...@@ -61,7 +61,7 @@ func parseNode(node string) (enode.ID, error) {
} }
// ServerInfo returns global server parameters // ServerInfo returns global server parameters
func (api *PrivateLightServerAPI) ServerInfo() map[string]interface{} { func (api *LightServerAPI) ServerInfo() map[string]interface{} {
res := make(map[string]interface{}) res := make(map[string]interface{})
res["minimumCapacity"] = api.server.minCapacity res["minimumCapacity"] = api.server.minCapacity
res["maximumCapacity"] = api.server.maxCapacity res["maximumCapacity"] = api.server.maxCapacity
...@@ -72,7 +72,7 @@ func (api *PrivateLightServerAPI) ServerInfo() map[string]interface{} { ...@@ -72,7 +72,7 @@ func (api *PrivateLightServerAPI) ServerInfo() map[string]interface{} {
} }
// ClientInfo returns information about clients listed in the ids list or matching the given tags // ClientInfo returns information about clients listed in the ids list or matching the given tags
func (api *PrivateLightServerAPI) ClientInfo(nodes []string) map[enode.ID]map[string]interface{} { func (api *LightServerAPI) ClientInfo(nodes []string) map[enode.ID]map[string]interface{} {
var ids []enode.ID var ids []enode.ID
for _, node := range nodes { for _, node := range nodes {
if id, err := parseNode(node); err == nil { if id, err := parseNode(node); err == nil {
...@@ -102,7 +102,7 @@ func (api *PrivateLightServerAPI) ClientInfo(nodes []string) map[enode.ID]map[st ...@@ -102,7 +102,7 @@ func (api *PrivateLightServerAPI) ClientInfo(nodes []string) map[enode.ID]map[st
// If maxCount limit is applied but there are more potential results then the ID // If maxCount limit is applied but there are more potential results then the ID
// of the next potential result is included in the map with an empty structure // of the next potential result is included in the map with an empty structure
// assigned to it. // assigned to it.
func (api *PrivateLightServerAPI) PriorityClientInfo(start, stop enode.ID, maxCount int) map[enode.ID]map[string]interface{} { func (api *LightServerAPI) PriorityClientInfo(start, stop enode.ID, maxCount int) map[enode.ID]map[string]interface{} {
res := make(map[enode.ID]map[string]interface{}) res := make(map[enode.ID]map[string]interface{})
ids := api.server.clientPool.GetPosBalanceIDs(start, stop, maxCount+1) ids := api.server.clientPool.GetPosBalanceIDs(start, stop, maxCount+1)
if len(ids) > maxCount { if len(ids) > maxCount {
...@@ -122,7 +122,7 @@ func (api *PrivateLightServerAPI) PriorityClientInfo(start, stop enode.ID, maxCo ...@@ -122,7 +122,7 @@ func (api *PrivateLightServerAPI) PriorityClientInfo(start, stop enode.ID, maxCo
} }
// clientInfo creates a client info data structure // clientInfo creates a client info data structure
func (api *PrivateLightServerAPI) clientInfo(peer *clientPeer, balance vfs.ReadOnlyBalance) map[string]interface{} { func (api *LightServerAPI) clientInfo(peer *clientPeer, balance vfs.ReadOnlyBalance) map[string]interface{} {
info := make(map[string]interface{}) info := make(map[string]interface{})
pb, nb := balance.GetBalance() pb, nb := balance.GetBalance()
info["isConnected"] = peer != nil info["isConnected"] = peer != nil
...@@ -140,7 +140,7 @@ func (api *PrivateLightServerAPI) clientInfo(peer *clientPeer, balance vfs.ReadO ...@@ -140,7 +140,7 @@ func (api *PrivateLightServerAPI) clientInfo(peer *clientPeer, balance vfs.ReadO
// setParams either sets the given parameters for a single connected client (if specified) // setParams either sets the given parameters for a single connected client (if specified)
// or the default parameters applicable to clients connected in the future // or the default parameters applicable to clients connected in the future
func (api *PrivateLightServerAPI) setParams(params map[string]interface{}, client *clientPeer, posFactors, negFactors *vfs.PriceFactors) (updateFactors bool, err error) { func (api *LightServerAPI) setParams(params map[string]interface{}, client *clientPeer, posFactors, negFactors *vfs.PriceFactors) (updateFactors bool, err error) {
defParams := client == nil defParams := client == nil
for name, value := range params { for name, value := range params {
errValue := func() error { errValue := func() error {
...@@ -191,7 +191,7 @@ func (api *PrivateLightServerAPI) setParams(params map[string]interface{}, clien ...@@ -191,7 +191,7 @@ func (api *PrivateLightServerAPI) setParams(params map[string]interface{}, clien
// SetClientParams sets client parameters for all clients listed in the ids list // SetClientParams sets client parameters for all clients listed in the ids list
// or all connected clients if the list is empty // or all connected clients if the list is empty
func (api *PrivateLightServerAPI) SetClientParams(nodes []string, params map[string]interface{}) error { func (api *LightServerAPI) SetClientParams(nodes []string, params map[string]interface{}) error {
var err error var err error
for _, node := range nodes { for _, node := range nodes {
var id enode.ID var id enode.ID
...@@ -215,7 +215,7 @@ func (api *PrivateLightServerAPI) SetClientParams(nodes []string, params map[str ...@@ -215,7 +215,7 @@ func (api *PrivateLightServerAPI) SetClientParams(nodes []string, params map[str
} }
// SetDefaultParams sets the default parameters applicable to clients connected in the future // SetDefaultParams sets the default parameters applicable to clients connected in the future
func (api *PrivateLightServerAPI) SetDefaultParams(params map[string]interface{}) error { func (api *LightServerAPI) SetDefaultParams(params map[string]interface{}) error {
update, err := api.setParams(params, nil, &api.defaultPosFactors, &api.defaultNegFactors) update, err := api.setParams(params, nil, &api.defaultPosFactors, &api.defaultNegFactors)
if update { if update {
api.server.clientPool.SetDefaultFactors(api.defaultPosFactors, api.defaultNegFactors) api.server.clientPool.SetDefaultFactors(api.defaultPosFactors, api.defaultNegFactors)
...@@ -227,7 +227,7 @@ func (api *PrivateLightServerAPI) SetDefaultParams(params map[string]interface{} ...@@ -227,7 +227,7 @@ func (api *PrivateLightServerAPI) SetDefaultParams(params map[string]interface{}
// So that already connected client won't be kicked out very soon and we can ensure all // So that already connected client won't be kicked out very soon and we can ensure all
// connected clients can have enough time to request or sync some data. // connected clients can have enough time to request or sync some data.
// When the input parameter `bias` < 0 (illegal), return error. // When the input parameter `bias` < 0 (illegal), return error.
func (api *PrivateLightServerAPI) SetConnectedBias(bias time.Duration) error { func (api *LightServerAPI) SetConnectedBias(bias time.Duration) error {
if bias < time.Duration(0) { if bias < time.Duration(0) {
return fmt.Errorf("bias illegal: %v less than 0", bias) return fmt.Errorf("bias illegal: %v less than 0", bias)
} }
...@@ -237,7 +237,7 @@ func (api *PrivateLightServerAPI) SetConnectedBias(bias time.Duration) error { ...@@ -237,7 +237,7 @@ func (api *PrivateLightServerAPI) SetConnectedBias(bias time.Duration) error {
// AddBalance adds the given amount to the balance of a client if possible and returns // AddBalance adds the given amount to the balance of a client if possible and returns
// the balance before and after the operation // the balance before and after the operation
func (api *PrivateLightServerAPI) AddBalance(node string, amount int64) (balance [2]uint64, err error) { func (api *LightServerAPI) AddBalance(node string, amount int64) (balance [2]uint64, err error) {
var id enode.ID var id enode.ID
if id, err = parseNode(node); err != nil { if id, err = parseNode(node); err != nil {
return return
...@@ -254,7 +254,7 @@ func (api *PrivateLightServerAPI) AddBalance(node string, amount int64) (balance ...@@ -254,7 +254,7 @@ func (api *PrivateLightServerAPI) AddBalance(node string, amount int64) (balance
// //
// Note: measurement time is adjusted for each pass depending on the previous ones. // Note: measurement time is adjusted for each pass depending on the previous ones.
// Therefore a controlled total measurement time is achievable in multiple passes. // Therefore a controlled total measurement time is achievable in multiple passes.
func (api *PrivateLightServerAPI) Benchmark(setups []map[string]interface{}, passCount, length int) ([]map[string]interface{}, error) { func (api *LightServerAPI) Benchmark(setups []map[string]interface{}, passCount, length int) ([]map[string]interface{}, error) {
benchmarks := make([]requestBenchmark, len(setups)) benchmarks := make([]requestBenchmark, len(setups))
for i, setup := range setups { for i, setup := range setups {
if t, ok := setup["type"].(string); ok { if t, ok := setup["type"].(string); ok {
...@@ -324,20 +324,20 @@ func (api *PrivateLightServerAPI) Benchmark(setups []map[string]interface{}, pas ...@@ -324,20 +324,20 @@ func (api *PrivateLightServerAPI) Benchmark(setups []map[string]interface{}, pas
return result, nil return result, nil
} }
// PrivateDebugAPI provides an API to debug LES light server functionality. // DebugAPI provides an API to debug LES light server functionality.
type PrivateDebugAPI struct { type DebugAPI struct {
server *LesServer server *LesServer
} }
// NewPrivateDebugAPI creates a new LES light server debug API. // NewDebugAPI creates a new LES light server debug API.
func NewPrivateDebugAPI(server *LesServer) *PrivateDebugAPI { func NewDebugAPI(server *LesServer) *DebugAPI {
return &PrivateDebugAPI{ return &DebugAPI{
server: server, server: server,
} }
} }
// FreezeClient forces a temporary client freeze which normally happens when the server is overloaded // FreezeClient forces a temporary client freeze which normally happens when the server is overloaded
func (api *PrivateDebugAPI) FreezeClient(node string) error { func (api *DebugAPI) FreezeClient(node string) error {
var ( var (
id enode.ID id enode.ID
err error err error
...@@ -353,14 +353,14 @@ func (api *PrivateDebugAPI) FreezeClient(node string) error { ...@@ -353,14 +353,14 @@ func (api *PrivateDebugAPI) FreezeClient(node string) error {
} }
} }
// PrivateLightAPI provides an API to access the LES light server or light client. // LightAPI provides an API to access the LES light server or light client.
type PrivateLightAPI struct { type LightAPI struct {
backend *lesCommons backend *lesCommons
} }
// NewPrivateLightAPI creates a new LES service API. // NewLightAPI creates a new LES service API.
func NewPrivateLightAPI(backend *lesCommons) *PrivateLightAPI { func NewLightAPI(backend *lesCommons) *LightAPI {
return &PrivateLightAPI{backend: backend} return &LightAPI{backend: backend}
} }
// LatestCheckpoint returns the latest local checkpoint package. // LatestCheckpoint returns the latest local checkpoint package.
...@@ -370,7 +370,7 @@ func NewPrivateLightAPI(backend *lesCommons) *PrivateLightAPI { ...@@ -370,7 +370,7 @@ func NewPrivateLightAPI(backend *lesCommons) *PrivateLightAPI {
// result[1], 32 bytes hex encoded latest section head hash // result[1], 32 bytes hex encoded latest section head hash
// result[2], 32 bytes hex encoded latest section canonical hash trie root hash // result[2], 32 bytes hex encoded latest section canonical hash trie root hash
// result[3], 32 bytes hex encoded latest section bloom trie root hash // result[3], 32 bytes hex encoded latest section bloom trie root hash
func (api *PrivateLightAPI) LatestCheckpoint() ([4]string, error) { func (api *LightAPI) LatestCheckpoint() ([4]string, error) {
var res [4]string var res [4]string
cp := api.backend.latestLocalCheckpoint() cp := api.backend.latestLocalCheckpoint()
if cp.Empty() { if cp.Empty() {
...@@ -387,7 +387,7 @@ func (api *PrivateLightAPI) LatestCheckpoint() ([4]string, error) { ...@@ -387,7 +387,7 @@ func (api *PrivateLightAPI) LatestCheckpoint() ([4]string, error) {
// result[0], 32 bytes hex encoded latest section head hash // result[0], 32 bytes hex encoded latest section head hash
// result[1], 32 bytes hex encoded latest section canonical hash trie root hash // result[1], 32 bytes hex encoded latest section canonical hash trie root hash
// result[2], 32 bytes hex encoded latest section bloom trie root hash // result[2], 32 bytes hex encoded latest section bloom trie root hash
func (api *PrivateLightAPI) GetCheckpoint(index uint64) ([3]string, error) { func (api *LightAPI) GetCheckpoint(index uint64) ([3]string, error) {
var res [3]string var res [3]string
cp := api.backend.localCheckpoint(index) cp := api.backend.localCheckpoint(index)
if cp.Empty() { if cp.Empty() {
...@@ -398,7 +398,7 @@ func (api *PrivateLightAPI) GetCheckpoint(index uint64) ([3]string, error) { ...@@ -398,7 +398,7 @@ func (api *PrivateLightAPI) GetCheckpoint(index uint64) ([3]string, error) {
} }
// GetCheckpointContractAddress returns the contract contract address in hex format. // GetCheckpointContractAddress returns the contract contract address in hex format.
func (api *PrivateLightAPI) GetCheckpointContractAddress() (string, error) { func (api *LightAPI) GetCheckpointContractAddress() (string, error) {
if api.backend.oracle == nil { if api.backend.oracle == nil {
return "", errNotActivated return "", errNotActivated
} }
......
...@@ -74,7 +74,7 @@ type LightEthereum struct { ...@@ -74,7 +74,7 @@ type LightEthereum struct {
eventMux *event.TypeMux eventMux *event.TypeMux
engine consensus.Engine engine consensus.Engine
accountManager *accounts.Manager accountManager *accounts.Manager
netRPCService *ethapi.PublicNetAPI netRPCService *ethapi.NetAPI
p2pServer *p2p.Server p2pServer *p2p.Server
p2pConfig *p2p.Config p2pConfig *p2p.Config
...@@ -189,7 +189,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) { ...@@ -189,7 +189,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
leth.blockchain.DisableCheckFreq() leth.blockchain.DisableCheckFreq()
} }
leth.netRPCService = ethapi.NewPublicNetAPI(leth.p2pServer, leth.config.NetworkId) leth.netRPCService = ethapi.NewNetAPI(leth.p2pServer, leth.config.NetworkId)
// Register the backend on the node // Register the backend on the node
stack.RegisterAPIs(leth.APIs()) stack.RegisterAPIs(leth.APIs())
...@@ -300,12 +300,12 @@ func (s *LightEthereum) APIs() []rpc.API { ...@@ -300,12 +300,12 @@ func (s *LightEthereum) APIs() []rpc.API {
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: downloader.NewPublicDownloaderAPI(s.handler.downloader, s.eventMux), Service: downloader.NewDownloaderAPI(s.handler.downloader, s.eventMux),
Public: true, Public: true,
}, { }, {
Namespace: "eth", Namespace: "eth",
Version: "1.0", Version: "1.0",
Service: filters.NewPublicFilterAPI(s.ApiBackend, true, 5*time.Minute), Service: filters.NewFilterAPI(s.ApiBackend, true, 5*time.Minute),
Public: true, Public: true,
}, { }, {
Namespace: "net", Namespace: "net",
...@@ -315,7 +315,7 @@ func (s *LightEthereum) APIs() []rpc.API { ...@@ -315,7 +315,7 @@ func (s *LightEthereum) APIs() []rpc.API {
}, { }, {
Namespace: "les", Namespace: "les",
Version: "1.0", Version: "1.0",
Service: NewPrivateLightAPI(&s.lesCommons), Service: NewLightAPI(&s.lesCommons),
Public: false, Public: false,
}, { }, {
Namespace: "vflux", Namespace: "vflux",
......
...@@ -25,21 +25,21 @@ import ( ...@@ -25,21 +25,21 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
// PublicDownloaderAPI provides an API which gives information about the current synchronisation status. // DownloaderAPI provides an API which gives information about the current synchronisation status.
// It offers only methods that operates on data that can be available to anyone without security risks. // It offers only methods that operates on data that can be available to anyone without security risks.
type PublicDownloaderAPI struct { type DownloaderAPI struct {
d *Downloader d *Downloader
mux *event.TypeMux mux *event.TypeMux
installSyncSubscription chan chan interface{} installSyncSubscription chan chan interface{}
uninstallSyncSubscription chan *uninstallSyncSubscriptionRequest uninstallSyncSubscription chan *uninstallSyncSubscriptionRequest
} }
// NewPublicDownloaderAPI create a new PublicDownloaderAPI. The API has an internal event loop that // NewDownloaderAPI create a new PublicDownloaderAPI. The API has an internal event loop that
// listens for events from the downloader through the global event mux. In case it receives one of // listens for events from the downloader through the global event mux. In case it receives one of
// these events it broadcasts it to all syncing subscriptions that are installed through the // these events it broadcasts it to all syncing subscriptions that are installed through the
// installSyncSubscription channel. // installSyncSubscription channel.
func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI { func NewDownloaderAPI(d *Downloader, m *event.TypeMux) *DownloaderAPI {
api := &PublicDownloaderAPI{ api := &DownloaderAPI{
d: d, d: d,
mux: m, mux: m,
installSyncSubscription: make(chan chan interface{}), installSyncSubscription: make(chan chan interface{}),
...@@ -53,7 +53,7 @@ func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAP ...@@ -53,7 +53,7 @@ func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAP
// eventLoop runs a loop until the event mux closes. It will install and uninstall new // eventLoop runs a loop until the event mux closes. It will install and uninstall new
// sync subscriptions and broadcasts sync status updates to the installed sync subscriptions. // sync subscriptions and broadcasts sync status updates to the installed sync subscriptions.
func (api *PublicDownloaderAPI) eventLoop() { func (api *DownloaderAPI) eventLoop() {
var ( var (
sub = api.mux.Subscribe(StartEvent{}, DoneEvent{}, FailedEvent{}) sub = api.mux.Subscribe(StartEvent{}, DoneEvent{}, FailedEvent{})
syncSubscriptions = make(map[chan interface{}]struct{}) syncSubscriptions = make(map[chan interface{}]struct{})
...@@ -90,7 +90,7 @@ func (api *PublicDownloaderAPI) eventLoop() { ...@@ -90,7 +90,7 @@ func (api *PublicDownloaderAPI) eventLoop() {
} }
// Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished. // Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.
func (api *PublicDownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error) { func (api *DownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error) {
notifier, supported := rpc.NotifierFromContext(ctx) notifier, supported := rpc.NotifierFromContext(ctx)
if !supported { if !supported {
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
...@@ -133,7 +133,7 @@ type uninstallSyncSubscriptionRequest struct { ...@@ -133,7 +133,7 @@ type uninstallSyncSubscriptionRequest struct {
// SyncStatusSubscription represents a syncing subscription. // SyncStatusSubscription represents a syncing subscription.
type SyncStatusSubscription struct { type SyncStatusSubscription struct {
api *PublicDownloaderAPI // register subscription in event loop of this api instance api *DownloaderAPI // register subscription in event loop of this api instance
c chan interface{} // channel where events are broadcasted to c chan interface{} // channel where events are broadcasted to
unsubOnce sync.Once // make sure unsubscribe logic is executed once unsubOnce sync.Once // make sure unsubscribe logic is executed once
} }
...@@ -160,7 +160,7 @@ func (s *SyncStatusSubscription) Unsubscribe() { ...@@ -160,7 +160,7 @@ func (s *SyncStatusSubscription) Unsubscribe() {
// SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates. // SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates.
// The given channel must receive interface values, the result can either // The given channel must receive interface values, the result can either
func (api *PublicDownloaderAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription { func (api *DownloaderAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription {
api.installSyncSubscription <- status api.installSyncSubscription <- status
return &SyncStatusSubscription{api: api, c: status} return &SyncStatusSubscription{api: api, c: status}
} }
...@@ -160,19 +160,19 @@ func (s *LesServer) APIs() []rpc.API { ...@@ -160,19 +160,19 @@ func (s *LesServer) APIs() []rpc.API {
{ {
Namespace: "les", Namespace: "les",
Version: "1.0", Version: "1.0",
Service: NewPrivateLightAPI(&s.lesCommons), Service: NewLightAPI(&s.lesCommons),
Public: false, Public: false,
}, },
{ {
Namespace: "les", Namespace: "les",
Version: "1.0", Version: "1.0",
Service: NewPrivateLightServerAPI(s), Service: NewLightServerAPI(s),
Public: false, Public: false,
}, },
{ {
Namespace: "debug", Namespace: "debug",
Version: "1.0", Version: "1.0",
Service: NewPrivateDebugAPI(s), Service: NewDebugAPI(s),
Public: false, Public: false,
}, },
} }
......
...@@ -36,11 +36,7 @@ func (n *Node) apis() []rpc.API { ...@@ -36,11 +36,7 @@ func (n *Node) apis() []rpc.API {
{ {
Namespace: "admin", Namespace: "admin",
Version: "1.0", Version: "1.0",
Service: &privateAdminAPI{n}, Service: &adminAPI{n},
}, {
Namespace: "admin",
Version: "1.0",
Service: &publicAdminAPI{n},
Public: true, Public: true,
}, { }, {
Namespace: "debug", Namespace: "debug",
...@@ -49,21 +45,21 @@ func (n *Node) apis() []rpc.API { ...@@ -49,21 +45,21 @@ func (n *Node) apis() []rpc.API {
}, { }, {
Namespace: "web3", Namespace: "web3",
Version: "1.0", Version: "1.0",
Service: &publicWeb3API{n}, Service: &web3API{n},
Public: true, Public: true,
}, },
} }
} }
// privateAdminAPI is the collection of administrative API methods exposed only // adminAPI is the collection of administrative API methods exposed over
// over a secure RPC channel. // both secure and unsecure RPC channels.
type privateAdminAPI struct { type adminAPI struct {
node *Node // Node interfaced by this API node *Node // Node interfaced by this API
} }
// AddPeer requests connecting to a remote node, and also maintaining the new // AddPeer requests connecting to a remote node, and also maintaining the new
// connection at all times, even reconnecting if it is lost. // connection at all times, even reconnecting if it is lost.
func (api *privateAdminAPI) AddPeer(url string) (bool, error) { func (api *adminAPI) AddPeer(url string) (bool, error) {
// Make sure the server is running, fail otherwise // Make sure the server is running, fail otherwise
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
...@@ -79,7 +75,7 @@ func (api *privateAdminAPI) AddPeer(url string) (bool, error) { ...@@ -79,7 +75,7 @@ func (api *privateAdminAPI) AddPeer(url string) (bool, error) {
} }
// RemovePeer disconnects from a remote node if the connection exists // RemovePeer disconnects from a remote node if the connection exists
func (api *privateAdminAPI) RemovePeer(url string) (bool, error) { func (api *adminAPI) RemovePeer(url string) (bool, error) {
// Make sure the server is running, fail otherwise // Make sure the server is running, fail otherwise
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
...@@ -95,7 +91,7 @@ func (api *privateAdminAPI) RemovePeer(url string) (bool, error) { ...@@ -95,7 +91,7 @@ func (api *privateAdminAPI) RemovePeer(url string) (bool, error) {
} }
// AddTrustedPeer allows a remote node to always connect, even if slots are full // AddTrustedPeer allows a remote node to always connect, even if slots are full
func (api *privateAdminAPI) AddTrustedPeer(url string) (bool, error) { func (api *adminAPI) AddTrustedPeer(url string) (bool, error) {
// Make sure the server is running, fail otherwise // Make sure the server is running, fail otherwise
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
...@@ -111,7 +107,7 @@ func (api *privateAdminAPI) AddTrustedPeer(url string) (bool, error) { ...@@ -111,7 +107,7 @@ func (api *privateAdminAPI) AddTrustedPeer(url string) (bool, error) {
// RemoveTrustedPeer removes a remote node from the trusted peer set, but it // RemoveTrustedPeer removes a remote node from the trusted peer set, but it
// does not disconnect it automatically. // does not disconnect it automatically.
func (api *privateAdminAPI) RemoveTrustedPeer(url string) (bool, error) { func (api *adminAPI) RemoveTrustedPeer(url string) (bool, error) {
// Make sure the server is running, fail otherwise // Make sure the server is running, fail otherwise
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
...@@ -127,7 +123,7 @@ func (api *privateAdminAPI) RemoveTrustedPeer(url string) (bool, error) { ...@@ -127,7 +123,7 @@ func (api *privateAdminAPI) RemoveTrustedPeer(url string) (bool, error) {
// PeerEvents creates an RPC subscription which receives peer events from the // PeerEvents creates an RPC subscription which receives peer events from the
// node's p2p.Server // node's p2p.Server
func (api *privateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error) { func (api *adminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error) {
// Make sure the server is running, fail otherwise // Make sure the server is running, fail otherwise
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
...@@ -164,7 +160,7 @@ func (api *privateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, ...@@ -164,7 +160,7 @@ func (api *privateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription,
} }
// StartHTTP starts the HTTP RPC API server. // StartHTTP starts the HTTP RPC API server.
func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) { func (api *adminAPI) StartHTTP(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
api.node.lock.Lock() api.node.lock.Lock()
defer api.node.lock.Unlock() defer api.node.lock.Unlock()
...@@ -219,26 +215,26 @@ func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, api ...@@ -219,26 +215,26 @@ func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, api
// StartRPC starts the HTTP RPC API server. // StartRPC starts the HTTP RPC API server.
// Deprecated: use StartHTTP instead. // Deprecated: use StartHTTP instead.
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) { func (api *adminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP") log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP")
return api.StartHTTP(host, port, cors, apis, vhosts) return api.StartHTTP(host, port, cors, apis, vhosts)
} }
// StopHTTP shuts down the HTTP server. // StopHTTP shuts down the HTTP server.
func (api *privateAdminAPI) StopHTTP() (bool, error) { func (api *adminAPI) StopHTTP() (bool, error) {
api.node.http.stop() api.node.http.stop()
return true, nil return true, nil
} }
// StopRPC shuts down the HTTP server. // StopRPC shuts down the HTTP server.
// Deprecated: use StopHTTP instead. // Deprecated: use StopHTTP instead.
func (api *privateAdminAPI) StopRPC() (bool, error) { func (api *adminAPI) StopRPC() (bool, error) {
log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP") log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP")
return api.StopHTTP() return api.StopHTTP()
} }
// StartWS starts the websocket RPC API server. // StartWS starts the websocket RPC API server.
func (api *privateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error) { func (api *adminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error) {
api.node.lock.Lock() api.node.lock.Lock()
defer api.node.lock.Unlock() defer api.node.lock.Unlock()
...@@ -290,21 +286,15 @@ func (api *privateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str ...@@ -290,21 +286,15 @@ func (api *privateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str
} }
// StopWS terminates all WebSocket servers. // StopWS terminates all WebSocket servers.
func (api *privateAdminAPI) StopWS() (bool, error) { func (api *adminAPI) StopWS() (bool, error) {
api.node.http.stopWS() api.node.http.stopWS()
api.node.ws.stop() api.node.ws.stop()
return true, nil return true, nil
} }
// publicAdminAPI is the collection of administrative API methods exposed over
// both secure and unsecure RPC channels.
type publicAdminAPI struct {
node *Node // Node interfaced by this API
}
// Peers retrieves all the information we know about each individual peer at the // Peers retrieves all the information we know about each individual peer at the
// protocol granularity. // protocol granularity.
func (api *publicAdminAPI) Peers() ([]*p2p.PeerInfo, error) { func (api *adminAPI) Peers() ([]*p2p.PeerInfo, error) {
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
return nil, ErrNodeStopped return nil, ErrNodeStopped
...@@ -314,7 +304,7 @@ func (api *publicAdminAPI) Peers() ([]*p2p.PeerInfo, error) { ...@@ -314,7 +304,7 @@ func (api *publicAdminAPI) Peers() ([]*p2p.PeerInfo, error) {
// NodeInfo retrieves all the information we know about the host node at the // NodeInfo retrieves all the information we know about the host node at the
// protocol granularity. // protocol granularity.
func (api *publicAdminAPI) NodeInfo() (*p2p.NodeInfo, error) { func (api *adminAPI) NodeInfo() (*p2p.NodeInfo, error) {
server := api.node.Server() server := api.node.Server()
if server == nil { if server == nil {
return nil, ErrNodeStopped return nil, ErrNodeStopped
...@@ -323,22 +313,22 @@ func (api *publicAdminAPI) NodeInfo() (*p2p.NodeInfo, error) { ...@@ -323,22 +313,22 @@ func (api *publicAdminAPI) NodeInfo() (*p2p.NodeInfo, error) {
} }
// Datadir retrieves the current data directory the node is using. // Datadir retrieves the current data directory the node is using.
func (api *publicAdminAPI) Datadir() string { func (api *adminAPI) Datadir() string {
return api.node.DataDir() return api.node.DataDir()
} }
// publicWeb3API offers helper utils // web3API offers helper utils
type publicWeb3API struct { type web3API struct {
stack *Node stack *Node
} }
// ClientVersion returns the node name // ClientVersion returns the node name
func (s *publicWeb3API) ClientVersion() string { func (s *web3API) ClientVersion() string {
return s.stack.Server().Name return s.stack.Server().Name
} }
// Sha3 applies the ethereum sha3 implementation on the input. // Sha3 applies the ethereum sha3 implementation on the input.
// It assumes the input is hex encoded. // It assumes the input is hex encoded.
func (s *publicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes { func (s *web3API) Sha3(input hexutil.Bytes) hexutil.Bytes {
return crypto.Keccak256(input) return crypto.Keccak256(input)
} }
...@@ -35,7 +35,7 @@ func TestStartRPC(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestStartRPC(t *testing.T) {
type test struct { type test struct {
name string name string
cfg Config cfg Config
fn func(*testing.T, *Node, *privateAdminAPI) fn func(*testing.T, *Node, *adminAPI)
// Checks. These run after the node is configured and all API calls have been made. // Checks. These run after the node is configured and all API calls have been made.
wantReachable bool // whether the HTTP server should be reachable at all wantReachable bool // whether the HTTP server should be reachable at all
...@@ -48,7 +48,7 @@ func TestStartRPC(t *testing.T) { ...@@ -48,7 +48,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "all off", name: "all off",
cfg: Config{}, cfg: Config{},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
}, },
wantReachable: false, wantReachable: false,
wantHandlers: false, wantHandlers: false,
...@@ -58,7 +58,7 @@ func TestStartRPC(t *testing.T) { ...@@ -58,7 +58,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "rpc enabled through config", name: "rpc enabled through config",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
}, },
wantReachable: true, wantReachable: true,
wantHandlers: true, wantHandlers: true,
...@@ -68,7 +68,7 @@ func TestStartRPC(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "rpc enabled through API", name: "rpc enabled through API",
cfg: Config{}, cfg: Config{},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil) _, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
}, },
...@@ -80,7 +80,7 @@ func TestStartRPC(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "rpc start again after failure", name: "rpc start again after failure",
cfg: Config{}, cfg: Config{},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
// Listen on a random port. // Listen on a random port.
listener, err := net.Listen("tcp", "127.0.0.1:0") listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil { if err != nil {
...@@ -108,7 +108,7 @@ func TestStartRPC(t *testing.T) { ...@@ -108,7 +108,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "rpc stopped through API", name: "rpc stopped through API",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StopHTTP() _, err := api.StopHTTP()
assert.NoError(t, err) assert.NoError(t, err)
}, },
...@@ -120,7 +120,7 @@ func TestStartRPC(t *testing.T) { ...@@ -120,7 +120,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "rpc stopped twice", name: "rpc stopped twice",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StopHTTP() _, err := api.StopHTTP()
assert.NoError(t, err) assert.NoError(t, err)
...@@ -143,7 +143,7 @@ func TestStartRPC(t *testing.T) { ...@@ -143,7 +143,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "ws enabled through API", name: "ws enabled through API",
cfg: Config{}, cfg: Config{},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StartWS(sp("127.0.0.1"), ip(0), nil, nil) _, err := api.StartWS(sp("127.0.0.1"), ip(0), nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
}, },
...@@ -155,7 +155,7 @@ func TestStartRPC(t *testing.T) { ...@@ -155,7 +155,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "ws stopped through API", name: "ws stopped through API",
cfg: Config{WSHost: "127.0.0.1"}, cfg: Config{WSHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StopWS() _, err := api.StopWS()
assert.NoError(t, err) assert.NoError(t, err)
}, },
...@@ -167,7 +167,7 @@ func TestStartRPC(t *testing.T) { ...@@ -167,7 +167,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "ws stopped twice", name: "ws stopped twice",
cfg: Config{WSHost: "127.0.0.1"}, cfg: Config{WSHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StopWS() _, err := api.StopWS()
assert.NoError(t, err) assert.NoError(t, err)
...@@ -182,7 +182,7 @@ func TestStartRPC(t *testing.T) { ...@@ -182,7 +182,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "ws enabled after RPC", name: "ws enabled after RPC",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
wsport := n.http.port wsport := n.http.port
_, err := api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil) _, err := api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
...@@ -195,7 +195,7 @@ func TestStartRPC(t *testing.T) { ...@@ -195,7 +195,7 @@ func TestStartRPC(t *testing.T) {
{ {
name: "ws enabled after RPC then stopped", name: "ws enabled after RPC then stopped",
cfg: Config{HTTPHost: "127.0.0.1"}, cfg: Config{HTTPHost: "127.0.0.1"},
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
wsport := n.http.port wsport := n.http.port
_, err := api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil) _, err := api.StartWS(sp("127.0.0.1"), ip(wsport), nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
...@@ -210,7 +210,7 @@ func TestStartRPC(t *testing.T) { ...@@ -210,7 +210,7 @@ func TestStartRPC(t *testing.T) {
}, },
{ {
name: "rpc stopped with ws enabled", name: "rpc stopped with ws enabled",
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil) _, err := api.StartHTTP(sp("127.0.0.1"), ip(0), nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
...@@ -228,7 +228,7 @@ func TestStartRPC(t *testing.T) { ...@@ -228,7 +228,7 @@ func TestStartRPC(t *testing.T) {
}, },
{ {
name: "rpc enabled after ws", name: "rpc enabled after ws",
fn: func(t *testing.T, n *Node, api *privateAdminAPI) { fn: func(t *testing.T, n *Node, api *adminAPI) {
_, err := api.StartWS(sp("127.0.0.1"), ip(0), nil, nil) _, err := api.StartWS(sp("127.0.0.1"), ip(0), nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
...@@ -271,7 +271,7 @@ func TestStartRPC(t *testing.T) { ...@@ -271,7 +271,7 @@ func TestStartRPC(t *testing.T) {
// Run the API call hook. // Run the API call hook.
if test.fn != nil { if test.fn != nil {
test.fn(t, stack, &privateAdminAPI{stack}) test.fn(t, stack, &adminAPI{stack})
} }
// Check if the HTTP endpoints are available. // Check if the HTTP endpoints are available.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment