github.com/cosmos/cosmos-sdk@v0.50.10/runtime/builder.go (about)

     1  package runtime
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	dbm "github.com/cosmos/cosmos-db"
     8  
     9  	"github.com/cosmos/cosmos-sdk/baseapp"
    10  	"github.com/cosmos/cosmos-sdk/types/module"
    11  	"github.com/cosmos/cosmos-sdk/version"
    12  )
    13  
    14  // AppBuilder is a type that is injected into a container by the runtime module
    15  // (as *AppBuilder) which can be used to create an app which is compatible with
    16  // the existing app.go initialization conventions.
    17  type AppBuilder struct {
    18  	app *App
    19  }
    20  
    21  // DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
    22  func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage {
    23  	return a.app.DefaultGenesis()
    24  }
    25  
    26  // Build builds an *App instance.
    27  func (a *AppBuilder) Build(db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*baseapp.BaseApp)) *App {
    28  	for _, option := range a.app.baseAppOptions {
    29  		baseAppOptions = append(baseAppOptions, option)
    30  	}
    31  
    32  	// set routers first in case they get modified by other options
    33  	baseAppOptions = append(
    34  		[]func(*baseapp.BaseApp){
    35  			func(bApp *baseapp.BaseApp) {
    36  				bApp.SetMsgServiceRouter(a.app.msgServiceRouter)
    37  				bApp.SetGRPCQueryRouter(a.app.grpcQueryRouter)
    38  			},
    39  		},
    40  		baseAppOptions...,
    41  	)
    42  
    43  	bApp := baseapp.NewBaseApp(a.app.config.AppName, a.app.logger, db, nil, baseAppOptions...)
    44  	bApp.SetCommitMultiStoreTracer(traceStore)
    45  	bApp.SetVersion(version.Version)
    46  	bApp.SetInterfaceRegistry(a.app.interfaceRegistry)
    47  	bApp.MountStores(a.app.storeKeys...)
    48  
    49  	a.app.BaseApp = bApp
    50  	a.app.configurator = module.NewConfigurator(a.app.cdc, a.app.MsgServiceRouter(), a.app.GRPCQueryRouter())
    51  
    52  	if err := a.app.ModuleManager.RegisterServices(a.app.configurator); err != nil {
    53  		panic(err)
    54  	}
    55  
    56  	return a.app
    57  }