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