github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/sdk/options.go (about) 1 package sdk 2 3 import ( 4 "fmt" 5 6 dbm "github.com/gnolang/gno/tm2/pkg/db" 7 "github.com/gnolang/gno/tm2/pkg/store" 8 ) 9 10 // File for storing in-package BaseApp optional functions, 11 // for options that need access to non-exported fields of the BaseApp 12 13 // SetStoreOptions sets store options on the multistore associated with the app 14 func SetStoreOptions(opts store.StoreOptions) func(*BaseApp) { 15 return func(bap *BaseApp) { bap.cms.SetStoreOptions(opts) } 16 } 17 18 // SetPruningOptions sets pruning options on the multistore associated with the app 19 func SetPruningOptions(opts store.PruningOptions) func(*BaseApp) { 20 return func(bap *BaseApp) { 21 sopts := bap.cms.GetStoreOptions() 22 sopts.PruningOptions = opts 23 bap.cms.SetStoreOptions(sopts) 24 } 25 } 26 27 // SetMinGasPrices returns an option that sets the minimum gas prices on the app. 28 func SetMinGasPrices(gasPricesStr string) func(*BaseApp) { 29 gasPrices, err := ParseGasPrices(gasPricesStr) 30 if err != nil { 31 panic(fmt.Sprintf("invalid minimum gas prices: %v", err)) 32 } 33 34 return func(bap *BaseApp) { bap.setMinGasPrices(gasPrices) } 35 } 36 37 // SetHaltHeight returns a BaseApp option function that sets the halt block height. 38 func SetHaltHeight(blockHeight uint64) func(*BaseApp) { 39 return func(bap *BaseApp) { bap.setHaltHeight(blockHeight) } 40 } 41 42 // SetHaltTime returns a BaseApp option function that sets the halt block time. 43 func SetHaltTime(haltTime uint64) func(*BaseApp) { 44 return func(bap *BaseApp) { bap.setHaltTime(haltTime) } 45 } 46 47 func (app *BaseApp) SetName(name string) { 48 if app.sealed { 49 panic("SetName() on sealed BaseApp") 50 } 51 app.name = name 52 } 53 54 // SetAppVersion sets the application's version string. 55 func (app *BaseApp) SetAppVersion(v string) { 56 if app.sealed { 57 panic("SetAppVersion() on sealed BaseApp") 58 } 59 app.appVersion = v 60 } 61 62 func (app *BaseApp) SetDB(db dbm.DB) { 63 if app.sealed { 64 panic("SetDB() on sealed BaseApp") 65 } 66 app.db = db 67 } 68 69 func (app *BaseApp) SetCMS(cms store.CommitMultiStore) { 70 if app.sealed { 71 panic("SetEndBlocker() on sealed BaseApp") 72 } 73 app.cms = cms 74 } 75 76 func (app *BaseApp) SetInitChainer(initChainer InitChainer) { 77 if app.sealed { 78 panic("SetInitChainer() on sealed BaseApp") 79 } 80 app.initChainer = initChainer 81 } 82 83 func (app *BaseApp) SetBeginBlocker(beginBlocker BeginBlocker) { 84 if app.sealed { 85 panic("SetBeginBlocker() on sealed BaseApp") 86 } 87 app.beginBlocker = beginBlocker 88 } 89 90 func (app *BaseApp) SetEndBlocker(endBlocker EndBlocker) { 91 if app.sealed { 92 panic("SetEndBlocker() on sealed BaseApp") 93 } 94 app.endBlocker = endBlocker 95 } 96 97 func (app *BaseApp) SetAnteHandler(ah AnteHandler) { 98 if app.sealed { 99 panic("SetAnteHandler() on sealed BaseApp") 100 } 101 app.anteHandler = ah 102 }