github.com/Finschia/finschia-sdk@v0.48.1/baseapp/options.go (about)

     1  package baseapp
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	dbm "github.com/tendermint/tm-db"
     8  
     9  	"github.com/Finschia/finschia-sdk/codec/types"
    10  	"github.com/Finschia/finschia-sdk/snapshots"
    11  	"github.com/Finschia/finschia-sdk/store"
    12  	"github.com/Finschia/finschia-sdk/store/cache"
    13  	sdk "github.com/Finschia/finschia-sdk/types"
    14  )
    15  
    16  // File for storing in-package BaseApp optional functions,
    17  // for options that need access to non-exported fields of the BaseApp
    18  
    19  // SetPruning sets a pruning option on the multistore associated with the app
    20  func SetPruning(opts sdk.PruningOptions) func(*BaseApp) {
    21  	return func(bapp *BaseApp) { bapp.cms.SetPruning(opts) }
    22  }
    23  
    24  // SetMinGasPrices returns an option that sets the minimum gas prices on the app.
    25  func SetMinGasPrices(gasPricesStr string) func(*BaseApp) {
    26  	gasPrices, err := sdk.ParseDecCoins(gasPricesStr)
    27  	if err != nil {
    28  		panic(fmt.Sprintf("invalid minimum gas prices: %v", err))
    29  	}
    30  
    31  	return func(bapp *BaseApp) { bapp.setMinGasPrices(gasPrices) }
    32  }
    33  
    34  // SetHaltHeight returns a BaseApp option function that sets the halt block height.
    35  func SetHaltHeight(blockHeight uint64) func(*BaseApp) {
    36  	return func(bapp *BaseApp) { bapp.setHaltHeight(blockHeight) }
    37  }
    38  
    39  // SetHaltTime returns a BaseApp option function that sets the halt block time.
    40  func SetHaltTime(haltTime uint64) func(*BaseApp) {
    41  	return func(bapp *BaseApp) { bapp.setHaltTime(haltTime) }
    42  }
    43  
    44  // SetMinRetainBlocks returns a BaseApp option function that sets the minimum
    45  // block retention height value when determining which heights to prune during
    46  // ABCI Commit.
    47  func SetMinRetainBlocks(minRetainBlocks uint64) func(*BaseApp) {
    48  	return func(bapp *BaseApp) { bapp.setMinRetainBlocks(minRetainBlocks) }
    49  }
    50  
    51  // SetTrace will turn on or off trace flag
    52  func SetTrace(trace bool) func(*BaseApp) {
    53  	return func(app *BaseApp) { app.setTrace(trace) }
    54  }
    55  
    56  // SetIndexEvents provides a BaseApp option function that sets the events to index.
    57  func SetIndexEvents(ie []string) func(*BaseApp) {
    58  	return func(app *BaseApp) { app.setIndexEvents(ie) }
    59  }
    60  
    61  // SetIAVLCacheSize provides a BaseApp option function that sets the size of IAVL cache.
    62  func SetIAVLCacheSize(size int) func(*BaseApp) {
    63  	return func(bapp *BaseApp) { bapp.cms.SetIAVLCacheSize(size) }
    64  }
    65  
    66  // SetIAVLDisableFastNode enables(false)/disables(true) fast node usage from the IAVL store.
    67  func SetIAVLDisableFastNode(disable bool) func(*BaseApp) {
    68  	return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) }
    69  }
    70  
    71  // SetInterBlockCache provides a BaseApp option function that sets the
    72  // inter-block cache.
    73  func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) {
    74  	return func(app *BaseApp) { app.setInterBlockCache(cache) }
    75  }
    76  
    77  // SetSnapshotInterval sets the snapshot interval.
    78  func SetSnapshotInterval(interval uint64) func(*BaseApp) {
    79  	return func(app *BaseApp) { app.SetSnapshotInterval(interval) }
    80  }
    81  
    82  // SetSnapshotKeepRecent sets the recent snapshots to keep.
    83  func SetSnapshotKeepRecent(keepRecent uint32) func(*BaseApp) {
    84  	return func(app *BaseApp) { app.SetSnapshotKeepRecent(keepRecent) }
    85  }
    86  
    87  // SetSnapshotStore sets the snapshot store.
    88  func SetSnapshotStore(snapshotStore *snapshots.Store) func(*BaseApp) {
    89  	return func(app *BaseApp) { app.SetSnapshotStore(snapshotStore) }
    90  }
    91  
    92  func SetChanCheckTxSize(size uint) func(*BaseApp) {
    93  	return func(app *BaseApp) { app.SetChanCheckTxSize(size) }
    94  }
    95  
    96  func (app *BaseApp) SetName(name string) {
    97  	if app.sealed {
    98  		panic("SetName() on sealed BaseApp")
    99  	}
   100  
   101  	app.name = name
   102  }
   103  
   104  // SetParamStore sets a parameter store on the BaseApp.
   105  func (app *BaseApp) SetParamStore(ps ParamStore) {
   106  	if app.sealed {
   107  		panic("SetParamStore() on sealed BaseApp")
   108  	}
   109  
   110  	app.paramStore = ps
   111  }
   112  
   113  // SetVersion sets the application's version string.
   114  func (app *BaseApp) SetVersion(v string) {
   115  	if app.sealed {
   116  		panic("SetVersion() on sealed BaseApp")
   117  	}
   118  	app.version = v
   119  }
   120  
   121  // SetProtocolVersion sets the application's protocol version
   122  func (app *BaseApp) SetProtocolVersion(v uint64) {
   123  	app.appVersion = v
   124  }
   125  
   126  func (app *BaseApp) SetDB(db dbm.DB) {
   127  	if app.sealed {
   128  		panic("SetDB() on sealed BaseApp")
   129  	}
   130  
   131  	app.db = db
   132  }
   133  
   134  func (app *BaseApp) SetCMS(cms store.CommitMultiStore) {
   135  	if app.sealed {
   136  		panic("SetEndBlocker() on sealed BaseApp")
   137  	}
   138  
   139  	app.cms = cms
   140  }
   141  
   142  func (app *BaseApp) SetInitChainer(initChainer sdk.InitChainer) {
   143  	if app.sealed {
   144  		panic("SetInitChainer() on sealed BaseApp")
   145  	}
   146  
   147  	app.initChainer = initChainer
   148  }
   149  
   150  func (app *BaseApp) SetBeginBlocker(beginBlocker sdk.BeginBlocker) {
   151  	if app.sealed {
   152  		panic("SetBeginBlocker() on sealed BaseApp")
   153  	}
   154  
   155  	app.beginBlocker = beginBlocker
   156  }
   157  
   158  func (app *BaseApp) SetEndBlocker(endBlocker sdk.EndBlocker) {
   159  	if app.sealed {
   160  		panic("SetEndBlocker() on sealed BaseApp")
   161  	}
   162  
   163  	app.endBlocker = endBlocker
   164  }
   165  
   166  func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) {
   167  	if app.sealed {
   168  		panic("SetAnteHandler() on sealed BaseApp")
   169  	}
   170  
   171  	app.anteHandler = ah
   172  }
   173  
   174  func (app *BaseApp) SetAddrPeerFilter(pf sdk.PeerFilter) {
   175  	if app.sealed {
   176  		panic("SetAddrPeerFilter() on sealed BaseApp")
   177  	}
   178  
   179  	app.addrPeerFilter = pf
   180  }
   181  
   182  func (app *BaseApp) SetIDPeerFilter(pf sdk.PeerFilter) {
   183  	if app.sealed {
   184  		panic("SetIDPeerFilter() on sealed BaseApp")
   185  	}
   186  
   187  	app.idPeerFilter = pf
   188  }
   189  
   190  func (app *BaseApp) SetFauxMerkleMode() {
   191  	if app.sealed {
   192  		panic("SetFauxMerkleMode() on sealed BaseApp")
   193  	}
   194  
   195  	app.fauxMerkleMode = true
   196  }
   197  
   198  // SetCommitMultiStoreTracer sets the store tracer on the BaseApp's underlying
   199  // CommitMultiStore.
   200  func (app *BaseApp) SetCommitMultiStoreTracer(w io.Writer) {
   201  	app.cms.SetTracer(w)
   202  }
   203  
   204  // SetStoreLoader allows us to customize the rootMultiStore initialization.
   205  func (app *BaseApp) SetStoreLoader(loader StoreLoader) {
   206  	if app.sealed {
   207  		panic("SetStoreLoader() on sealed BaseApp")
   208  	}
   209  
   210  	app.storeLoader = loader
   211  }
   212  
   213  // SetRouter allows us to customize the router.
   214  func (app *BaseApp) SetRouter(router sdk.Router) {
   215  	if app.sealed {
   216  		panic("SetRouter() on sealed BaseApp")
   217  	}
   218  	app.router = router
   219  }
   220  
   221  // SetSnapshotStore sets the snapshot store.
   222  func (app *BaseApp) SetSnapshotStore(snapshotStore *snapshots.Store) {
   223  	if app.sealed {
   224  		panic("SetSnapshotStore() on sealed BaseApp")
   225  	}
   226  	if snapshotStore == nil {
   227  		app.snapshotManager = nil
   228  		return
   229  	}
   230  	app.snapshotManager = snapshots.NewManager(snapshotStore, app.cms)
   231  }
   232  
   233  // SetSnapshotInterval sets the snapshot interval.
   234  func (app *BaseApp) SetSnapshotInterval(snapshotInterval uint64) {
   235  	if app.sealed {
   236  		panic("SetSnapshotInterval() on sealed BaseApp")
   237  	}
   238  	app.snapshotInterval = snapshotInterval
   239  }
   240  
   241  // SetSnapshotKeepRecent sets the number of recent snapshots to keep.
   242  func (app *BaseApp) SetSnapshotKeepRecent(snapshotKeepRecent uint32) {
   243  	if app.sealed {
   244  		panic("SetSnapshotKeepRecent() on sealed BaseApp")
   245  	}
   246  	app.snapshotKeepRecent = snapshotKeepRecent
   247  }
   248  
   249  // SetInterfaceRegistry sets the InterfaceRegistry.
   250  func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) {
   251  	app.interfaceRegistry = registry
   252  	app.grpcQueryRouter.SetInterfaceRegistry(registry)
   253  	app.msgServiceRouter.SetInterfaceRegistry(registry)
   254  }
   255  
   256  func (app *BaseApp) SetChanCheckTxSize(chanCheckTxSize uint) {
   257  	if app.sealed {
   258  		panic("SetChanCheckTxSize() on sealed BaseApp")
   259  	}
   260  	app.chCheckTxSize = chanCheckTxSize
   261  }
   262  
   263  func MetricsProvider(prometheus bool) cache.MetricsProvider {
   264  	namespace := "app"
   265  	if prometheus {
   266  		return cache.PrometheusMetricsProvider(namespace)
   267  	}
   268  	return cache.NopMetricsProvider()
   269  }
   270  
   271  // SetStreamingService is used to set a streaming service into the BaseApp hooks and load the listeners into the multistore
   272  func (app *BaseApp) SetStreamingService(s StreamingService) {
   273  	// add the listeners for each StoreKey
   274  	for key, lis := range s.Listeners() {
   275  		app.cms.AddListeners(key, lis)
   276  	}
   277  	// register the StreamingService within the BaseApp
   278  	// BaseApp will pass BeginBlock, DeliverTx, and EndBlock requests and responses to the streaming services to update their ABCI context
   279  	app.abciListeners = append(app.abciListeners, s)
   280  }