github.com/Night-mk/quorum@v21.1.0+incompatible/extension/services_factory.go (about) 1 package extension 2 3 import ( 4 "context" 5 6 "github.com/ethereum/go-ethereum/accounts" 7 "github.com/ethereum/go-ethereum/eth" 8 "github.com/ethereum/go-ethereum/extension/privacyExtension" 9 "github.com/ethereum/go-ethereum/node" 10 "github.com/ethereum/go-ethereum/private" 11 ) 12 13 type ServicesFactory interface { 14 BackendService() *PrivacyService 15 16 AccountManager() *accounts.Manager 17 DataHandler() DataHandler 18 StateFetcher() *StateFetcher 19 } 20 21 type DefaultServicesFactory struct { 22 backendService *PrivacyService 23 accountManager *accounts.Manager 24 dataHandler *JsonFileDataHandler 25 stateFetcher *StateFetcher 26 } 27 28 func NewServicesFactory(node *node.Node, ptm private.PrivateTransactionManager, ethService *eth.Ethereum) (*DefaultServicesFactory, error) { 29 factory := &DefaultServicesFactory{} 30 31 factory.accountManager = ethService.AccountManager() 32 factory.dataHandler = NewJsonFileDataHandler(node.InstanceDir()) 33 factory.stateFetcher = NewStateFetcher(ethService.BlockChain()) 34 35 backendService, err := New(ptm, factory.AccountManager(), factory.DataHandler(), factory.StateFetcher(), ethService.APIBackend) 36 if err != nil { 37 return nil, err 38 } 39 factory.backendService = backendService 40 41 _, isMultitenant := ethService.BlockChain().SupportsMultitenancy(context.Background()) 42 privacyExtension.DefaultExtensionHandler.SupportMultitenancy(isMultitenant) 43 44 ethService.BlockChain().PopulateSetPrivateState(privacyExtension.DefaultExtensionHandler.CheckExtensionAndSetPrivateState) 45 46 go backendService.initialise(node) 47 48 return factory, nil 49 } 50 51 func (factory *DefaultServicesFactory) BackendService() *PrivacyService { 52 return factory.backendService 53 } 54 55 func (factory *DefaultServicesFactory) AccountManager() *accounts.Manager { 56 return factory.accountManager 57 } 58 59 func (factory *DefaultServicesFactory) DataHandler() DataHandler { 60 return factory.dataHandler 61 } 62 63 func (factory *DefaultServicesFactory) StateFetcher() *StateFetcher { 64 return factory.stateFetcher 65 }