From 8d6b0929fb5fb170d4a8543e517b23f793af2fcb Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Fri, 16 Nov 2018 09:12:24 -0800 Subject: [PATCH] Codespaces as Strings (#2821) --- Gopkg.lock | 3 +- PENDING.md | 2 + baseapp/baseapp.go | 42 +++++++-------- baseapp/baseapp_test.go | 18 ++++--- cmd/gaia/app/app.go | 8 +-- cmd/gaia/cmd/gaiadebug/hack.go | 4 +- docs/_attic/sdk/core/examples/app1.go | 7 +-- docs/_attic/sdk/core/examples/app2.go | 2 +- docs/examples/basecoin/app/app.go | 2 +- docs/examples/democoin/app/app.go | 8 +-- docs/examples/democoin/x/cool/app_test.go | 2 +- docs/examples/democoin/x/cool/errors.go | 2 +- docs/examples/democoin/x/oracle/handler.go | 2 +- docs/examples/democoin/x/pow/app_test.go | 2 +- docs/examples/democoin/x/pow/errors.go | 2 +- .../examples/democoin/x/simplestake/errors.go | 2 +- .../democoin/x/simplestake/handler.go | 4 +- store/rootmultistore_test.go | 15 +++--- types/codespacer.go | 35 ------------- types/codespacer_test.go | 47 ----------------- types/errors.go | 52 +++++-------------- types/errors_test.go | 7 +-- types/result.go | 5 +- types/result_test.go | 2 +- x/auth/ante_test.go | 7 +-- x/bank/app_test.go | 3 +- x/bank/errors.go | 2 +- x/distribution/types/errors.go | 2 +- x/gov/errors.go | 2 +- x/gov/test_common.go | 2 +- x/ibc/app_test.go | 2 +- x/ibc/errors.go | 2 +- x/mock/app_test.go | 4 +- x/mock/test_utils.go | 12 ++--- x/slashing/app_test.go | 7 +-- x/slashing/errors.go | 2 +- x/slashing/handler_test.go | 3 +- x/stake/app_test.go | 2 +- x/stake/types/errors.go | 2 +- 39 files changed, 119 insertions(+), 210 deletions(-) delete mode 100644 types/codespacer.go delete mode 100644 types/codespacer_test.go diff --git a/Gopkg.lock b/Gopkg.lock index bcc306edb951..40192b2afd24 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -165,12 +165,13 @@ version = "v1.2.0" [[projects]] - digest = "1:ea40c24cdbacd054a6ae9de03e62c5f252479b96c716375aace5c120d68647c8" + digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" name = "github.com/hashicorp/hcl" packages = [ ".", "hcl/ast", "hcl/parser", + "hcl/printer", "hcl/scanner", "hcl/strconv", "hcl/token", diff --git a/PENDING.md b/PENDING.md index 050646593fa7..a3034c01ebcb 100644 --- a/PENDING.md +++ b/PENDING.md @@ -56,8 +56,10 @@ IMPROVEMENTS - #2773 Require moniker to be provided on `gaiad init`. - #2672 [Makefile] Updated for better Windows compatibility and ledger support logic, get_tools was rewritten as a cross-compatible Makefile. - [#110](https://github.com/tendermint/devops/issues/110) Updated CircleCI job to trigger website build when cosmos docs are updated. + * SDK - [x/mock/simulation] [\#2720] major cleanup, introduction of helper objects, reorganization + - \#2821 Codespaces are now strings * Tendermint - #2796 Update to go-amino 0.14.1 diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 827536d21562..34041dff20a6 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -47,7 +47,6 @@ type BaseApp struct { cms sdk.CommitMultiStore // Main (uncached) state router Router // handle any kind of message queryRouter QueryRouter // router for redirecting query calls - codespacer *sdk.Codespacer // handle module codespacing txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx anteHandler sdk.AnteHandler // ante handler for fee and auth @@ -94,13 +93,9 @@ func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecod cms: store.NewCommitMultiStore(db), router: NewRouter(), queryRouter: NewQueryRouter(), - codespacer: sdk.NewCodespacer(), txDecoder: txDecoder, } - // Register the undefined & root codespaces, which should not be used by - // any modules. - app.codespacer.RegisterOrPanic(sdk.CodespaceRoot) for _, option := range options { option(app) } @@ -118,11 +113,6 @@ func (app *BaseApp) SetCommitMultiStoreTracer(w io.Writer) { app.cms.WithTracer(w) } -// Register the next available codespace through the baseapp's codespacer, starting from a default -func (app *BaseApp) RegisterCodespace(codespace sdk.CodespaceType) sdk.CodespaceType { - return app.codespacer.RegisterNext(codespace) -} - // Mount IAVL stores to the provided keys in the BaseApp multistore func (app *BaseApp) MountStoresIAVL(keys ...*sdk.KVStoreKey) { for _, key := range keys { @@ -329,8 +319,9 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc } case "version": return abci.ResponseQuery{ - Code: uint32(sdk.ABCICodeOK), - Value: []byte(version.GetVersion()), + Code: uint32(sdk.CodeOK), + Codespace: string(sdk.CodespaceRoot), + Value: []byte(version.GetVersion()), } default: result = sdk.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result() @@ -339,8 +330,9 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc // Encode with json value := codec.Cdc.MustMarshalBinaryLengthPrefixed(result) return abci.ResponseQuery{ - Code: uint32(sdk.ABCICodeOK), - Value: value, + Code: uint32(sdk.CodeOK), + Codespace: string(sdk.CodespaceRoot), + Value: value, } } msg := "Expected second parameter to be either simulate or version, neither was present" @@ -400,12 +392,13 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res resBytes, err := querier(ctx, path[2:], req) if err != nil { return abci.ResponseQuery{ - Code: uint32(err.ABCICode()), - Log: err.ABCILog(), + Code: uint32(err.Code()), + Codespace: string(err.Codespace()), + Log: err.ABCILog(), } } return abci.ResponseQuery{ - Code: uint32(sdk.ABCICodeOK), + Code: uint32(sdk.CodeOK), Value: resBytes, } } @@ -482,6 +475,7 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) { // Tell the blockchain engine (i.e. Tendermint). return abci.ResponseDeliverTx{ Code: uint32(result.Code), + Codespace: string(result.Codespace), Data: result.Data, Log: result.Log, GasWanted: result.GasWanted, @@ -501,7 +495,6 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error { // Validate the Msg. err := msg.ValidateBasic() if err != nil { - err = err.WithDefaultCodespace(sdk.CodespaceRoot) return err } } @@ -526,7 +519,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re logs := make([]string, 0, len(msgs)) var data []byte // NOTE: we just append them all (?!) var tags sdk.Tags // also just append them all - var code sdk.ABCICodeType + var code sdk.CodeType + var codespace sdk.CodespaceType for msgIdx, msg := range msgs { // Match route. msgRoute := msg.Route() @@ -553,6 +547,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re if !msgResult.IsOK() { logs = append(logs, fmt.Sprintf("Msg %d failed: %s", msgIdx, msgResult.Log)) code = msgResult.Code + codespace = msgResult.Codespace break } @@ -562,10 +557,11 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re // Set the final gas values. result = sdk.Result{ - Code: code, - Data: data, - Log: strings.Join(logs, "\n"), - GasUsed: ctx.GasMeter().GasConsumed(), + Code: code, + Codespace: codespace, + Data: data, + Log: strings.Join(logs, "\n"), + GasUsed: ctx.GasMeter().GasConsumed(), // TODO: FeeAmount/FeeDenom Tags: tags, } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 9f6414214bbb..35f9fa42469f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -678,7 +678,8 @@ func TestRunInvalidTransaction(t *testing.T) { { emptyTx := &txTest{} err := app.Deliver(emptyTx) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeInternal), err.Code) + require.EqualValues(t, sdk.CodeInternal, err.Code) + require.EqualValues(t, sdk.CodespaceRoot, err.Codespace) } // Transaction where ValidateBasic fails @@ -701,7 +702,8 @@ func TestRunInvalidTransaction(t *testing.T) { tx := testCase.tx res := app.Deliver(tx) if testCase.fail { - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeInvalidSequence), res.Code) + require.EqualValues(t, sdk.CodeInvalidSequence, res.Code) + require.EqualValues(t, sdk.CodespaceRoot, res.Codespace) } else { require.True(t, res.IsOK(), fmt.Sprintf("%v", res)) } @@ -712,11 +714,13 @@ func TestRunInvalidTransaction(t *testing.T) { { unknownRouteTx := txTest{[]sdk.Msg{msgNoRoute{}}, 0} err := app.Deliver(unknownRouteTx) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), err.Code) + require.EqualValues(t, sdk.CodeUnknownRequest, err.Code) + require.EqualValues(t, sdk.CodespaceRoot, err.Codespace) unknownRouteTx = txTest{[]sdk.Msg{msgCounter{}, msgNoRoute{}}, 0} err = app.Deliver(unknownRouteTx) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), err.Code) + require.EqualValues(t, sdk.CodeUnknownRequest, err.Code) + require.EqualValues(t, sdk.CodespaceRoot, err.Codespace) } // Transaction with an unregistered message @@ -732,7 +736,8 @@ func TestRunInvalidTransaction(t *testing.T) { txBytes, err := newCdc.MarshalBinaryLengthPrefixed(tx) require.NoError(t, err) res := app.DeliverTx(txBytes) - require.EqualValues(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeTxDecode), res.Code) + require.EqualValues(t, sdk.CodeTxDecode, res.Code) + require.EqualValues(t, sdk.CodespaceRoot, res.Codespace) } } @@ -819,7 +824,8 @@ func TestTxGasLimits(t *testing.T) { if !tc.fail { require.True(t, res.IsOK(), fmt.Sprintf("%d: %v, %v", i, tc, res)) } else { - require.Equal(t, res.Code, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOutOfGas), fmt.Sprintf("%d: %v, %v", i, tc, res)) + require.Equal(t, sdk.CodeOutOfGas, res.Code, fmt.Sprintf("%d: %v, %v", i, tc, res)) + require.Equal(t, sdk.CodespaceRoot, res.Codespace) } } } diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index fb8455b5aea8..c06d82bb175a 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -113,7 +113,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace), - app.RegisterCodespace(stake.DefaultCodespace), + stake.DefaultCodespace, ) app.mintKeeper = mint.NewKeeper(app.cdc, app.keyMint, app.paramsKeeper.Subspace(mint.DefaultParamspace), @@ -124,19 +124,19 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio app.keyDistr, app.paramsKeeper.Subspace(distr.DefaultParamspace), app.bankKeeper, &stakeKeeper, app.feeCollectionKeeper, - app.RegisterCodespace(stake.DefaultCodespace), + distr.DefaultCodespace, ) app.slashingKeeper = slashing.NewKeeper( app.cdc, app.keySlashing, &stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), - app.RegisterCodespace(slashing.DefaultCodespace), + slashing.DefaultCodespace, ) app.govKeeper = gov.NewKeeper( app.cdc, app.keyGov, app.paramsKeeper, app.paramsKeeper.Subspace(gov.DefaultParamspace), app.bankKeeper, &stakeKeeper, - app.RegisterCodespace(gov.DefaultCodespace), + gov.DefaultCodespace, ) // register the staking hooks diff --git a/cmd/gaia/cmd/gaiadebug/hack.go b/cmd/gaia/cmd/gaiadebug/hack.go index 734a83df304f..e9f3b56589f4 100644 --- a/cmd/gaia/cmd/gaiadebug/hack.go +++ b/cmd/gaia/cmd/gaiadebug/hack.go @@ -175,8 +175,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp // add handlers app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper) app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams) - app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace), app.RegisterCodespace(stake.DefaultCodespace)) - app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), app.RegisterCodespace(slashing.DefaultCodespace)) + app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace), stake.DefaultCodespace) + app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), slashing.DefaultCodespace) // register message routes app.Router(). diff --git a/docs/_attic/sdk/core/examples/app1.go b/docs/_attic/sdk/core/examples/app1.go index 8ee34fca59e7..25e8b40def5f 100644 --- a/docs/_attic/sdk/core/examples/app1.go +++ b/docs/_attic/sdk/core/examples/app1.go @@ -12,7 +12,8 @@ import ( ) const ( - app1Name = "App1" + app1Name = "App1" + bankCodespace = "BANK" ) func NewApp1(logger log.Logger, db dbm.DB) *bapp.BaseApp { @@ -107,7 +108,7 @@ func handleMsgSend(key *sdk.KVStoreKey) sdk.Handler { if !ok { // Create custom error message and return result // Note: Using unreserved error codespace - return sdk.NewError(2, 1, "MsgSend is malformed").Result() + return sdk.NewError(bankCodespace, 1, "MsgSend is malformed").Result() } // Load the store. @@ -137,7 +138,7 @@ func handleFrom(store sdk.KVStore, from sdk.AccAddress, amt sdk.Coins) sdk.Resul accBytes := store.Get(from) if accBytes == nil { // Account was not added to store. Return the result of the error. - return sdk.NewError(2, 101, "Account not added to store").Result() + return sdk.NewError(bankCodespace, 101, "Account not added to store").Result() } // Unmarshal the JSON account bytes. diff --git a/docs/_attic/sdk/core/examples/app2.go b/docs/_attic/sdk/core/examples/app2.go index 24458384c0d3..620a1911355b 100644 --- a/docs/_attic/sdk/core/examples/app2.go +++ b/docs/_attic/sdk/core/examples/app2.go @@ -126,7 +126,7 @@ func handleMsgIssue(keyIssue *sdk.KVStoreKey, keyAcc *sdk.KVStoreKey) sdk.Handle return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { issueMsg, ok := msg.(MsgIssue) if !ok { - return sdk.NewError(2, 1, "MsgIssue is malformed").Result() + return sdk.NewError(bankCodespace, 1, "MsgIssue is malformed").Result() } // Retrieve stores diff --git a/docs/examples/basecoin/app/app.go b/docs/examples/basecoin/app/app.go index 9515feaadc52..3e58e71f920a 100644 --- a/docs/examples/basecoin/app/app.go +++ b/docs/examples/basecoin/app/app.go @@ -75,7 +75,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba }, ) app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper) - app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) + app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, ibc.DefaultCodespace) // register message routes app.Router(). diff --git a/docs/examples/democoin/app/app.go b/docs/examples/democoin/app/app.go index bc618e3606ae..ec9db1ae87f5 100644 --- a/docs/examples/democoin/app/app.go +++ b/docs/examples/democoin/app/app.go @@ -83,10 +83,10 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp { // Add handlers. app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper) - app.coolKeeper = cool.NewKeeper(app.capKeyMainStore, app.bankKeeper, app.RegisterCodespace(cool.DefaultCodespace)) - app.powKeeper = pow.NewKeeper(app.capKeyPowStore, pow.NewConfig("pow", int64(1)), app.bankKeeper, app.RegisterCodespace(pow.DefaultCodespace)) - app.ibcMapper = ibc.NewMapper(app.cdc, app.capKeyIBCStore, app.RegisterCodespace(ibc.DefaultCodespace)) - app.stakeKeeper = simplestake.NewKeeper(app.capKeyStakingStore, app.bankKeeper, app.RegisterCodespace(simplestake.DefaultCodespace)) + app.coolKeeper = cool.NewKeeper(app.capKeyMainStore, app.bankKeeper, cool.DefaultCodespace) + app.powKeeper = pow.NewKeeper(app.capKeyPowStore, pow.NewConfig("pow", int64(1)), app.bankKeeper, pow.DefaultCodespace) + app.ibcMapper = ibc.NewMapper(app.cdc, app.capKeyIBCStore, ibc.DefaultCodespace) + app.stakeKeeper = simplestake.NewKeeper(app.capKeyStakingStore, app.bankKeeper, simplestake.DefaultCodespace) app.Router(). AddRoute("bank", bank.NewHandler(app.bankKeeper)). AddRoute("cool", cool.NewHandler(app.coolKeeper)). diff --git a/docs/examples/democoin/x/cool/app_test.go b/docs/examples/democoin/x/cool/app_test.go index 01cb73ef1738..3f1dd6734c9b 100644 --- a/docs/examples/democoin/x/cool/app_test.go +++ b/docs/examples/democoin/x/cool/app_test.go @@ -50,7 +50,7 @@ func getMockApp(t *testing.T) *mock.App { RegisterCodec(mapp.Cdc) keyCool := sdk.NewKVStoreKey("cool") bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper) - keeper := NewKeeper(keyCool, bankKeeper, mapp.RegisterCodespace(DefaultCodespace)) + keeper := NewKeeper(keyCool, bankKeeper, DefaultCodespace) mapp.Router().AddRoute("cool", NewHandler(keeper)) mapp.SetInitChainer(getInitChainer(mapp, keeper, "ice-cold")) diff --git a/docs/examples/democoin/x/cool/errors.go b/docs/examples/democoin/x/cool/errors.go index 73df2386efad..e31d664708df 100644 --- a/docs/examples/democoin/x/cool/errors.go +++ b/docs/examples/democoin/x/cool/errors.go @@ -8,7 +8,7 @@ import ( // Cool errors reserve 400 ~ 499. const ( - DefaultCodespace sdk.CodespaceType = 6 + DefaultCodespace sdk.CodespaceType = "cool" // Cool module reserves error 400-499 lawl CodeIncorrectCoolAnswer sdk.CodeType = 400 diff --git a/docs/examples/democoin/x/oracle/handler.go b/docs/examples/democoin/x/oracle/handler.go index c525222c4c42..fb7587a12683 100644 --- a/docs/examples/democoin/x/oracle/handler.go +++ b/docs/examples/democoin/x/oracle/handler.go @@ -94,7 +94,7 @@ func (keeper Keeper) Handle(h Handler, ctx sdk.Context, o Msg, codespace sdk.Cod err := h(cctx, payload) if err != nil { return sdk.Result{ - Code: sdk.ABCICodeOK, + Code: sdk.CodeOK, Log: err.ABCILog(), } } diff --git a/docs/examples/democoin/x/pow/app_test.go b/docs/examples/democoin/x/pow/app_test.go index 5009b7ec5460..41901f097924 100644 --- a/docs/examples/democoin/x/pow/app_test.go +++ b/docs/examples/democoin/x/pow/app_test.go @@ -27,7 +27,7 @@ func getMockApp(t *testing.T) *mock.App { keyPOW := sdk.NewKVStoreKey("pow") bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper) config := Config{"pow", 1} - keeper := NewKeeper(keyPOW, config, bankKeeper, mapp.RegisterCodespace(DefaultCodespace)) + keeper := NewKeeper(keyPOW, config, bankKeeper, DefaultCodespace) mapp.Router().AddRoute("pow", keeper.Handler) mapp.SetInitChainer(getInitChainer(mapp, keeper)) diff --git a/docs/examples/democoin/x/pow/errors.go b/docs/examples/democoin/x/pow/errors.go index e25964da73b4..8368c2359d47 100644 --- a/docs/examples/democoin/x/pow/errors.go +++ b/docs/examples/democoin/x/pow/errors.go @@ -9,7 +9,7 @@ type CodeType = sdk.CodeType // POW errors reserve 200 ~ 299 const ( - DefaultCodespace sdk.CodespaceType = 5 + DefaultCodespace sdk.CodespaceType = "pow" CodeInvalidDifficulty CodeType = 201 CodeNonexistentDifficulty CodeType = 202 CodeNonexistentReward CodeType = 203 diff --git a/docs/examples/democoin/x/simplestake/errors.go b/docs/examples/democoin/x/simplestake/errors.go index 8125e57aabcf..a0fc6e1accd0 100644 --- a/docs/examples/democoin/x/simplestake/errors.go +++ b/docs/examples/democoin/x/simplestake/errors.go @@ -6,7 +6,7 @@ import ( // simple stake errors reserve 300 ~ 399. const ( - DefaultCodespace sdk.CodespaceType = 4 + DefaultCodespace sdk.CodespaceType = moduleName // simplestake errors reserve 300 - 399. CodeEmptyValidator sdk.CodeType = 300 diff --git a/docs/examples/democoin/x/simplestake/handler.go b/docs/examples/democoin/x/simplestake/handler.go index 114f066436c5..104058eec2c1 100644 --- a/docs/examples/democoin/x/simplestake/handler.go +++ b/docs/examples/democoin/x/simplestake/handler.go @@ -22,12 +22,12 @@ func handleMsgBond() sdk.Result { // Removed ValidatorSet from result because it does not get used. // TODO: Implement correct bond/unbond handling return sdk.Result{ - Code: sdk.ABCICodeOK, + Code: sdk.CodeOK, } } func handleMsgUnbond() sdk.Result { return sdk.Result{ - Code: sdk.ABCICodeOK, + Code: sdk.CodeOK, } } diff --git a/store/rootmultistore_test.go b/store/rootmultistore_test.go index 501c5b730c25..cd555d6f2d5a 100644 --- a/store/rootmultistore_test.go +++ b/store/rootmultistore_test.go @@ -156,34 +156,37 @@ func TestMultiStoreQuery(t *testing.T) { // Test bad path. query := abci.RequestQuery{Path: "/key", Data: k, Height: ver} qres := multi.Query(query) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) + require.EqualValues(t, sdk.CodeUnknownRequest, qres.Code) + require.EqualValues(t, sdk.CodespaceRoot, qres.Codespace) query.Path = "h897fy32890rf63296r92" qres = multi.Query(query) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) + require.EqualValues(t, sdk.CodeUnknownRequest, qres.Code) + require.EqualValues(t, sdk.CodespaceRoot, qres.Codespace) // Test invalid store name. query.Path = "/garbage/key" qres = multi.Query(query) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) + require.EqualValues(t, sdk.CodeUnknownRequest, qres.Code) + require.EqualValues(t, sdk.CodespaceRoot, qres.Codespace) // Test valid query with data. query.Path = "/store1/key" qres = multi.Query(query) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) + require.EqualValues(t, sdk.CodeOK, qres.Code) require.Equal(t, v, qres.Value) // Test valid but empty query. query.Path = "/store2/key" query.Prove = true qres = multi.Query(query) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) + require.EqualValues(t, sdk.CodeOK, qres.Code) require.Nil(t, qres.Value) // Test store2 data. query.Data = k2 qres = multi.Query(query) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) + require.EqualValues(t, sdk.CodeOK, qres.Code) require.Equal(t, v2, qres.Value) } diff --git a/types/codespacer.go b/types/codespacer.go deleted file mode 100644 index 92025c1a6361..000000000000 --- a/types/codespacer.go +++ /dev/null @@ -1,35 +0,0 @@ -package types - -// Codespacer is a simple struct to track reserved codespaces -type Codespacer struct { - reserved map[CodespaceType]bool -} - -// NewCodespacer generates a new Codespacer with the starting codespace -func NewCodespacer() *Codespacer { - return &Codespacer{ - reserved: make(map[CodespaceType]bool), - } -} - -// RegisterNext reserves and returns the next available codespace, starting from a default, and panics if the maximum codespace is reached -func (c *Codespacer) RegisterNext(codespace CodespaceType) CodespaceType { - for { - if !c.reserved[codespace] { - c.reserved[codespace] = true - return codespace - } - codespace++ - if codespace == MaximumCodespace { - panic("Maximum codespace reached!") - } - } -} - -// RegisterOrPanic reserved a codespace or panics if it is unavailable -func (c *Codespacer) RegisterOrPanic(codespace CodespaceType) { - if c.reserved[codespace] { - panic("Cannot register codespace, already reserved") - } - c.reserved[codespace] = true -} diff --git a/types/codespacer_test.go b/types/codespacer_test.go deleted file mode 100644 index 7052aa92a30d..000000000000 --- a/types/codespacer_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package types - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestRegisterNext(t *testing.T) { - codespacer := NewCodespacer() - // unregistered, allow - code1 := codespacer.RegisterNext(CodespaceType(2)) - require.Equal(t, code1, CodespaceType(2)) - // registered, pick next - code2 := codespacer.RegisterNext(CodespaceType(2)) - require.Equal(t, code2, CodespaceType(3)) - // pick next - code3 := codespacer.RegisterNext(CodespaceType(2)) - require.Equal(t, code3, CodespaceType(4)) - // skip 1 - code4 := codespacer.RegisterNext(CodespaceType(6)) - require.Equal(t, code4, CodespaceType(6)) - code5 := codespacer.RegisterNext(CodespaceType(2)) - require.Equal(t, code5, CodespaceType(5)) - code6 := codespacer.RegisterNext(CodespaceType(2)) - require.Equal(t, code6, CodespaceType(7)) - // panic on maximum - defer func() { - r := recover() - require.NotNil(t, r, "Did not panic on maximum codespace") - }() - codespacer.RegisterNext(MaximumCodespace - 1) - codespacer.RegisterNext(MaximumCodespace - 1) -} - -func TestRegisterOrPanic(t *testing.T) { - codespacer := NewCodespacer() - // unregistered, allow - code1 := codespacer.RegisterNext(CodespaceType(2)) - require.Equal(t, code1, CodespaceType(2)) - // panic on duplicate - defer func() { - r := recover() - require.NotNil(t, r, "Did not panic on duplicate codespace") - }() - codespacer.RegisterOrPanic(CodespaceType(2)) -} diff --git a/types/errors.go b/types/errors.go index 965a97c872f4..46436531ef54 100644 --- a/types/errors.go +++ b/types/errors.go @@ -10,37 +10,22 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// ABCICodeType - combined codetype / codespace -type ABCICodeType uint32 - -// CodeType - code identifier within codespace -type CodeType uint16 +// CodeType - ABCI code identifier within codespace +type CodeType uint32 // CodespaceType - codespace identifier -type CodespaceType uint16 +type CodespaceType string // IsOK - is everything okay? -func (code ABCICodeType) IsOK() bool { - if code == ABCICodeOK { +func (code CodeType) IsOK() bool { + if code == CodeOK { return true } return false } -// get the abci code from the local code and codespace -func ToABCICode(space CodespaceType, code CodeType) ABCICodeType { - // TODO: Make Tendermint more aware of codespaces. - if space == CodespaceRoot && code == CodeOK { - return ABCICodeOK - } - return ABCICodeType((uint32(space) << 16) | uint32(code)) -} - // SDK error codes const ( - // ABCI error codes - ABCICodeOK ABCICodeType = 0 - // Base error codes CodeOK CodeType = 0 CodeInternal CodeType = 1 @@ -62,11 +47,8 @@ const ( // CodespaceRoot is a codespace for error codes in this file only. // Notice that 0 is an "unset" codespace, which can be overridden with // Error.WithDefaultCodespace(). - CodespaceUndefined CodespaceType = 0 - CodespaceRoot CodespaceType = 1 - - // Maximum reservable codespace (2^16 - 1) - MaximumCodespace CodespaceType = 65535 + CodespaceUndefined CodespaceType = "" + CodespaceRoot CodespaceType = "sdk" ) func unknownCodeMsg(code CodeType) string { @@ -185,7 +167,6 @@ type Error interface { Code() CodeType Codespace() CodespaceType ABCILog() string - ABCICode() ABCICodeType Result() Result QueryResult() abci.ResponseQuery } @@ -239,17 +220,12 @@ func (err *sdkError) TraceSDK(format string, args ...interface{}) Error { // Implements ABCIError. func (err *sdkError) Error() string { return fmt.Sprintf(`ERROR: -Codespace: %d +Codespace: %s Code: %d Message: %#v `, err.codespace, err.code, err.cmnError.Error()) } -// Implements ABCIError. -func (err *sdkError) ABCICode() ABCICodeType { - return ToABCICode(err.codespace, err.code) -} - // Implements Error. func (err *sdkError) Codespace() CodespaceType { return err.codespace @@ -267,7 +243,6 @@ func (err *sdkError) ABCILog() string { jsonErr := humanReadableError{ Codespace: err.codespace, Code: err.code, - ABCICode: err.ABCICode(), Message: errMsg, } bz, er := cdc.MarshalJSON(jsonErr) @@ -280,16 +255,18 @@ func (err *sdkError) ABCILog() string { func (err *sdkError) Result() Result { return Result{ - Code: err.ABCICode(), - Log: err.ABCILog(), + Code: err.Code(), + Codespace: err.Codespace(), + Log: err.ABCILog(), } } // QueryResult allows us to return sdk.Error.QueryResult() in query responses func (err *sdkError) QueryResult() abci.ResponseQuery { return abci.ResponseQuery{ - Code: uint32(err.ABCICode()), - Log: err.ABCILog(), + Code: uint32(err.Code()), + Codespace: string(err.Codespace()), + Log: err.ABCILog(), } } @@ -324,6 +301,5 @@ func mustGetMsgIndex(abciLog string) int { type humanReadableError struct { Codespace CodespaceType `json:"codespace"` Code CodeType `json:"code"` - ABCICode ABCICodeType `json:"abci_code"` Message string `json:"message"` } diff --git a/types/errors_test.go b/types/errors_test.go index 1d63e09908e2..8d4f8822633e 100644 --- a/types/errors_test.go +++ b/types/errors_test.go @@ -42,7 +42,7 @@ var errFns = []errFn{ } func TestCodeType(t *testing.T) { - require.True(t, ABCICodeOK.IsOK()) + require.True(t, CodeOK.IsOK()) for tcnum, c := range codeTypes { msg := CodeToDefaultMsg(c) @@ -59,12 +59,9 @@ func TestErrFn(t *testing.T) { codeType := codeTypes[i] require.Equal(t, err.Code(), codeType, "Err function expected to return proper code. tc #%d", i) require.Equal(t, err.Codespace(), CodespaceRoot, "Err function expected to return proper codespace. tc #%d", i) - require.Equal(t, err.Result().Code, ToABCICode(CodespaceRoot, codeType), "Err function expected to return proper ABCICode. tc #%d") - require.Equal(t, err.QueryResult().Code, uint32(err.ABCICode()), "Err function expected to return proper ABCICode from QueryResult. tc #%d") + require.Equal(t, err.QueryResult().Code, uint32(err.Code()), "Err function expected to return proper Code from QueryResult. tc #%d") require.Equal(t, err.QueryResult().Log, err.ABCILog(), "Err function expected to return proper ABCILog from QueryResult. tc #%d") } - - require.Equal(t, ABCICodeOK, ToABCICode(CodespaceRoot, CodeOK)) } func TestAppendMsgToErr(t *testing.T) { diff --git a/types/result.go b/types/result.go index 63b8a6e18fd2..20893a076fe3 100644 --- a/types/result.go +++ b/types/result.go @@ -4,7 +4,10 @@ package types type Result struct { // Code is the response code, is stored back on the chain. - Code ABCICodeType + Code CodeType + + // Codespace is the string referring to the domain of an error + Codespace CodespaceType // Data is any data returned from the app. Data []byte diff --git a/types/result_test.go b/types/result_test.go index e0305932cf48..9765933d98c7 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -13,6 +13,6 @@ func TestResult(t *testing.T) { res.Data = []byte("data") require.True(t, res.IsOK()) - res.Code = ABCICodeType(1) + res.Code = CodeType(1) require.False(t, res.IsOK()) } diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index 98725a74bd31..c376d29961d4 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -43,7 +43,7 @@ func privAndAddr() (crypto.PrivKey, sdk.AccAddress) { func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool) { _, result, abort := anteHandler(ctx, tx, simulate) require.False(t, abort) - require.Equal(t, sdk.ABCICodeOK, result.Code) + require.Equal(t, sdk.CodeOK, result.Code) require.True(t, result.IsOK()) } @@ -51,8 +51,9 @@ func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool, code sdk.CodeType) { newCtx, result, abort := anteHandler(ctx, tx, simulate) require.True(t, abort) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, code), result.Code, - fmt.Sprintf("Expected %v, got %v", sdk.ToABCICode(sdk.CodespaceRoot, code), result)) + + require.Equal(t, code, result.Code, fmt.Sprintf("Expected %v, got %v", code, result)) + require.Equal(t, sdk.CodespaceRoot, result.Codespace) if code == sdk.CodeOutOfGas { stdTx, ok := tx.(StdTx) diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 906573eae21f..c71a9b392b5a 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -144,7 +144,8 @@ func TestMsgSendWithAccounts(t *testing.T) { tx.Signatures[0].Sequence = 1 res := mapp.Deliver(tx) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) + require.EqualValues(t, sdk.CodeUnauthorized, res.Code, res.Log) + require.EqualValues(t, sdk.CodespaceRoot, res.Codespace) // resigning the tx with the bumped sequence should work mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1, sendMsg2}, []int64{0}, []int64{1}, true, true, priv1) diff --git a/x/bank/errors.go b/x/bank/errors.go index cf11ddc22f50..5df5cfdce501 100644 --- a/x/bank/errors.go +++ b/x/bank/errors.go @@ -7,7 +7,7 @@ import ( // Bank errors reserve 100 ~ 199. const ( - DefaultCodespace sdk.CodespaceType = 2 + DefaultCodespace sdk.CodespaceType = "bank" CodeInvalidInput sdk.CodeType = 101 CodeInvalidOutput sdk.CodeType = 102 diff --git a/x/distribution/types/errors.go b/x/distribution/types/errors.go index 605c1b38db33..36de11f740c8 100644 --- a/x/distribution/types/errors.go +++ b/x/distribution/types/errors.go @@ -8,7 +8,7 @@ import ( type CodeType = sdk.CodeType const ( - DefaultCodespace sdk.CodespaceType = 6 + DefaultCodespace sdk.CodespaceType = "DISTR" CodeInvalidInput CodeType = 103 CodeNoDistributionInfo CodeType = 104 ) diff --git a/x/gov/errors.go b/x/gov/errors.go index e803d080eacd..9b9aa25dbdd4 100644 --- a/x/gov/errors.go +++ b/x/gov/errors.go @@ -8,7 +8,7 @@ import ( ) const ( - DefaultCodespace sdk.CodespaceType = 5 + DefaultCodespace sdk.CodespaceType = "GOV" CodeUnknownProposal sdk.CodeType = 1 CodeInactiveProposal sdk.CodeType = 2 diff --git a/x/gov/test_common.go b/x/gov/test_common.go index a0bc80fc2e3e..67b9fd902e63 100644 --- a/x/gov/test_common.go +++ b/x/gov/test_common.go @@ -35,7 +35,7 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, pk := params.NewKeeper(mapp.Cdc, keyGlobalParams, tkeyGlobalParams) ck := bank.NewBaseKeeper(mapp.AccountKeeper) - sk := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, ck, pk.Subspace(stake.DefaultParamspace), mapp.RegisterCodespace(stake.DefaultCodespace)) + sk := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, ck, pk.Subspace(stake.DefaultParamspace), stake.DefaultCodespace) keeper := NewKeeper(mapp.Cdc, keyGov, pk, pk.Subspace("testgov"), ck, sk, DefaultCodespace) mapp.Router().AddRoute("gov", NewHandler(keeper)) diff --git a/x/ibc/app_test.go b/x/ibc/app_test.go index 9b360c7c247a..e59588a5aca3 100644 --- a/x/ibc/app_test.go +++ b/x/ibc/app_test.go @@ -20,7 +20,7 @@ func getMockApp(t *testing.T) *mock.App { RegisterCodec(mapp.Cdc) keyIBC := sdk.NewKVStoreKey("ibc") - ibcMapper := NewMapper(mapp.Cdc, keyIBC, mapp.RegisterCodespace(DefaultCodespace)) + ibcMapper := NewMapper(mapp.Cdc, keyIBC, DefaultCodespace) bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper) mapp.Router().AddRoute("ibc", NewHandler(ibcMapper, bankKeeper)) diff --git a/x/ibc/errors.go b/x/ibc/errors.go index 7a3194baf1ff..96ae58066a5c 100644 --- a/x/ibc/errors.go +++ b/x/ibc/errors.go @@ -6,7 +6,7 @@ import ( // IBC errors reserve 200 ~ 299. const ( - DefaultCodespace sdk.CodespaceType = 3 + DefaultCodespace sdk.CodespaceType = "ibc" // IBC errors reserve 200 - 299. CodeInvalidSequence sdk.CodeType = 200 diff --git a/x/mock/app_test.go b/x/mock/app_test.go index 9e12cac8ecc4..c47ddb7179fc 100644 --- a/x/mock/app_test.go +++ b/x/mock/app_test.go @@ -71,7 +71,9 @@ func TestCheckAndDeliverGenTx(t *testing.T) { []int64{accs[1].GetAccountNumber()}, []int64{accs[1].GetSequence() + 1}, true, false, privKeys[1], ) - require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) + + require.Equal(t, sdk.CodeUnauthorized, res.Code, res.Log) + require.Equal(t, sdk.CodespaceRoot, res.Codespace) // Resigning the tx with the correct privKey should result in an OK result SignCheckDeliver( diff --git a/x/mock/test_utils.go b/x/mock/test_utils.go index 4e60478fa4b8..130339d0e77f 100644 --- a/x/mock/test_utils.go +++ b/x/mock/test_utils.go @@ -57,9 +57,9 @@ func CheckGenTx( res := app.Check(tx) if expPass { - require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log) + require.Equal(t, sdk.CodeOK, res.Code, res.Log) } else { - require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log) + require.NotEqual(t, sdk.CodeOK, res.Code, res.Log) } return res @@ -78,9 +78,9 @@ func SignCheckDeliver( res := app.Simulate(tx) if expSimPass { - require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log) + require.Equal(t, sdk.CodeOK, res.Code, res.Log) } else { - require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log) + require.NotEqual(t, sdk.CodeOK, res.Code, res.Log) } // Simulate a sending a transaction and committing a block @@ -88,9 +88,9 @@ func SignCheckDeliver( res = app.Deliver(tx) if expPass { - require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log) + require.Equal(t, sdk.CodeOK, res.Code, res.Log) } else { - require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log) + require.NotEqual(t, sdk.CodeOK, res.Code, res.Log) } app.EndBlock(abci.RequestEndBlock{}) diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index dd96ff51e24f..bfcbcba0b2bf 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -36,8 +36,8 @@ func getMockApp(t *testing.T) (*mock.App, stake.Keeper, Keeper) { bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper) paramsKeeper := params.NewKeeper(mapp.Cdc, keyParams, tkeyParams) - stakeKeeper := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, bankKeeper, paramsKeeper.Subspace(stake.DefaultParamspace), mapp.RegisterCodespace(stake.DefaultCodespace)) - keeper := NewKeeper(mapp.Cdc, keySlashing, stakeKeeper, paramsKeeper.Subspace(DefaultParamspace), mapp.RegisterCodespace(DefaultCodespace)) + stakeKeeper := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, bankKeeper, paramsKeeper.Subspace(stake.DefaultParamspace), stake.DefaultCodespace) + keeper := NewKeeper(mapp.Cdc, keySlashing, stakeKeeper, paramsKeeper.Subspace(DefaultParamspace), DefaultCodespace) mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper)) mapp.Router().AddRoute("slashing", NewHandler(keeper)) @@ -126,5 +126,6 @@ func TestSlashingMsgs(t *testing.T) { // unjail should fail with unknown validator res := mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{unjailMsg}, []int64{0}, []int64{1}, false, false, priv1) - require.Equal(t, sdk.ToABCICode(DefaultCodespace, CodeValidatorNotJailed), res.Code) + require.EqualValues(t, CodeValidatorNotJailed, res.Code) + require.EqualValues(t, DefaultCodespace, res.Codespace) } diff --git a/x/slashing/errors.go b/x/slashing/errors.go index 77cb2d28e33c..0fa523c256ce 100644 --- a/x/slashing/errors.go +++ b/x/slashing/errors.go @@ -10,7 +10,7 @@ type CodeType = sdk.CodeType const ( // Default slashing codespace - DefaultCodespace sdk.CodespaceType = 10 + DefaultCodespace sdk.CodespaceType = "SLASH" CodeInvalidValidator CodeType = 101 CodeValidatorJailed CodeType = 102 diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index ef307547c640..9041bfe56c6d 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -26,7 +26,8 @@ func TestCannotUnjailUnlessJailed(t *testing.T) { // assert non-jailed validator can't be unjailed got = slh(ctx, NewMsgUnjail(addr)) require.False(t, got.IsOK(), "allowed unjail of non-jailed validator") - require.Equal(t, sdk.ToABCICode(DefaultCodespace, CodeValidatorNotJailed), got.Code) + require.EqualValues(t, CodeValidatorNotJailed, got.Code) + require.EqualValues(t, DefaultCodespace, got.Codespace) } func TestJailedValidatorDelegations(t *testing.T) { diff --git a/x/stake/app_test.go b/x/stake/app_test.go index b24018a6cedf..2866acf1d15a 100644 --- a/x/stake/app_test.go +++ b/x/stake/app_test.go @@ -29,7 +29,7 @@ func getMockApp(t *testing.T) (*mock.App, Keeper) { bankKeeper := bank.NewBaseKeeper(mApp.AccountKeeper) pk := params.NewKeeper(mApp.Cdc, keyParams, tkeyParams) - keeper := NewKeeper(mApp.Cdc, keyStake, tkeyStake, bankKeeper, pk.Subspace(DefaultParamspace), mApp.RegisterCodespace(DefaultCodespace)) + keeper := NewKeeper(mApp.Cdc, keyStake, tkeyStake, bankKeeper, pk.Subspace(DefaultParamspace), DefaultCodespace) mApp.Router().AddRoute("stake", NewHandler(keeper)) mApp.SetEndBlocker(getEndBlocker(keeper)) diff --git a/x/stake/types/errors.go b/x/stake/types/errors.go index 1a6ed6a64169..bbef528d5095 100644 --- a/x/stake/types/errors.go +++ b/x/stake/types/errors.go @@ -11,7 +11,7 @@ import ( type CodeType = sdk.CodeType const ( - DefaultCodespace sdk.CodespaceType = 4 + DefaultCodespace sdk.CodespaceType = "STAKE" CodeInvalidValidator CodeType = 101 CodeInvalidDelegation CodeType = 102