api.go 907 Bytes
Newer Older
1 2 3 4
package rpc

import (
	"context"
5

6
	"github.com/ethereum/go-ethereum/log"
7
	gethrpc "github.com/ethereum/go-ethereum/rpc"
8 9

	"github.com/ethereum-optimism/optimism/op-service/metrics"
10
	"github.com/ethereum-optimism/optimism/op-service/rpc"
11 12
)

13 14 15
type BatcherDriver interface {
	StartBatchSubmitting() error
	StopBatchSubmitting(ctx context.Context) error
16 17 18
}

type adminAPI struct {
19
	*rpc.CommonAdminAPI
20
	b BatcherDriver
21 22
}

23
func NewAdminAPI(dr BatcherDriver, m metrics.RPCMetricer, log log.Logger) *adminAPI {
24
	return &adminAPI{
25 26
		CommonAdminAPI: rpc.NewCommonAdminAPI(m, log),
		b:              dr,
27 28 29
	}
}

30 31 32 33 34 35 36
func GetAdminAPI(api *adminAPI) gethrpc.API {
	return gethrpc.API{
		Namespace: "admin",
		Service:   api,
	}
}

37
func (a *adminAPI) StartBatcher(_ context.Context) error {
38
	return a.b.StartBatchSubmitting()
39 40
}

41
func (a *adminAPI) StopBatcher(ctx context.Context) error {
42
	return a.b.StopBatchSubmitting(ctx)
43
}