github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/sdk/helpers.go (about) 1 package sdk 2 3 import ( 4 "fmt" 5 "regexp" 6 7 abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types" 8 ) 9 10 var isAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString 11 12 func (app *BaseApp) Check(tx Tx) (result Result) { 13 return app.runTx(RunTxModeCheck, nil, tx) 14 } 15 16 func (app *BaseApp) Simulate(txBytes []byte, tx Tx) (result Result) { 17 return app.runTx(RunTxModeSimulate, txBytes, tx) 18 } 19 20 func (app *BaseApp) Deliver(tx Tx) (result Result) { 21 return app.runTx(RunTxModeDeliver, nil, tx) 22 } 23 24 // Context with current {check, deliver}State of the app 25 // used by tests 26 func (app *BaseApp) NewContext(mode RunTxMode, header abci.Header) Context { 27 if mode == RunTxModeCheck { 28 return NewContext(mode, app.checkState.ms, header, app.logger). 29 WithMinGasPrices(app.minGasPrices) 30 } 31 32 return NewContext(mode, app.deliverState.ms, header, app.logger) 33 } 34 35 // TODO: replace with abci.ABCIErrorOrStringError(). 36 func ABCIError(err error) abci.Error { 37 return abci.ABCIErrorOrStringError(err) 38 } 39 40 func ABCIResultFromError(err error) (res Result) { 41 res.Error = ABCIError(err) 42 res.Log = fmt.Sprintf("%#v", err) 43 return 44 } 45 46 func ABCIResponseQueryFromError(err error) (res abci.ResponseQuery) { 47 res.Error = ABCIError(err) 48 res.Log = fmt.Sprintf("%#v", err) 49 return 50 }