Skip to content

Commit 876d2c8

Browse files
committed
fix: upgrade to latest cosmos-sdk
1 parent 5595b41 commit 876d2c8

File tree

19 files changed

+223
-140
lines changed

19 files changed

+223
-140
lines changed

packages/cosmic-swingset/app/app.go

+43-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
"net/http"
78
"os"
9+
"path/filepath"
810

11+
"github.com/cosmos/cosmos-sdk/client"
912
"github.com/cosmos/cosmos-sdk/codec/types"
10-
"github.com/cosmos/cosmos-sdk/std"
13+
"github.com/gorilla/mux"
14+
"github.com/rakyll/statik/fs"
1115

1216
abci "github.com/tendermint/tendermint/abci/types"
1317
"github.com/tendermint/tendermint/libs/log"
@@ -18,6 +22,7 @@ import (
1822
"github.com/cosmos/cosmos-sdk/client/rpc"
1923
"github.com/cosmos/cosmos-sdk/codec"
2024
"github.com/cosmos/cosmos-sdk/server/api"
25+
"github.com/cosmos/cosmos-sdk/server/config"
2126
"github.com/cosmos/cosmos-sdk/testutil/testdata"
2227
sdk "github.com/cosmos/cosmos-sdk/types"
2328
"github.com/cosmos/cosmos-sdk/types/module"
@@ -28,6 +33,7 @@ import (
2833
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
2934
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
3035
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
36+
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
3137
"github.com/cosmos/cosmos-sdk/x/bank"
3238
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
3339
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
@@ -50,11 +56,11 @@ import (
5056
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
5157
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
5258
"github.com/cosmos/cosmos-sdk/x/ibc"
53-
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
54-
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
55-
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
5659
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
5760
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
61+
transfer "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer"
62+
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
63+
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
5864
ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper"
5965
"github.com/cosmos/cosmos-sdk/x/mint"
6066
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
@@ -78,13 +84,16 @@ import (
7884

7985
gaiaappparams "github.com/Agoric/cosmic-swingset/app/params"
8086
"github.com/Agoric/cosmic-swingset/x/swingset"
87+
88+
// This is for the swagger file for legacy support
89+
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
8190
)
8291

8392
const appName = "agoric"
8493

8594
var (
8695
// DefaultNodeHome default home directories for the application daemon
87-
DefaultNodeHome = os.ExpandEnv("$HOME/.ag-chain-cosmos")
96+
DefaultNodeHome string
8897

8998
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
9099
// non-dependant module elements, such as codec registration
@@ -179,6 +188,15 @@ type GaiaApp struct {
179188
sm *module.SimulationManager
180189
}
181190

191+
func init() {
192+
userHomeDir, err := os.UserHomeDir()
193+
if err != nil {
194+
panic(err)
195+
}
196+
197+
DefaultNodeHome = filepath.Join(userHomeDir, ".ag-chain-cosmos")
198+
}
199+
182200
// NewGaia returns a reference to an initialized Gaia.
183201
// NewSimApp returns a reference to an initialized SimApp.
184202
func NewGaiaApp(
@@ -209,7 +227,7 @@ func NewAgoricApp(
209227
bApp.SetCommitMultiStoreTracer(traceStore)
210228
bApp.SetAppVersion(version.Version)
211229
bApp.GRPCQueryRouter().SetInterfaceRegistry(interfaceRegistry)
212-
bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry, std.DefaultPublicKeyCodec{})
230+
bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry)
213231

214232
keys := sdk.NewKVStoreKeys(
215233
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
@@ -339,6 +357,7 @@ func NewAgoricApp(
339357
encodingConfig.TxConfig,
340358
),
341359
auth.NewAppModule(appCodec, app.AccountKeeper, nil),
360+
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
342361
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
343362
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
344363
crisis.NewAppModule(&app.CrisisKeeper),
@@ -371,7 +390,7 @@ func NewAgoricApp(
371390
// so that other modules that want to create or claim capabilities afterwards in InitChain
372391
// can do so safely.
373392
app.mm.SetOrderInitGenesis(
374-
capabilitytypes.ModuleName, authtypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, banktypes.ModuleName,
393+
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
375394
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
376395
ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, swingset.ModuleName, ibctransfertypes.ModuleName,
377396
)
@@ -600,12 +619,28 @@ func (app *GaiaApp) SimulationManager() *module.SimulationManager {
600619

601620
// RegisterAPIRoutes registers all application module routes with the provided
602621
// API server.
603-
func (app *GaiaApp) RegisterAPIRoutes(apiSvr *api.Server) {
622+
func (app *GaiaApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
604623
clientCtx := apiSvr.ClientCtx
605624
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
606625
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
607626
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
608627
ModuleBasics.RegisterGRPCRoutes(apiSvr.ClientCtx, apiSvr.GRPCRouter)
628+
629+
// register swagger API from root so that other applications can override easily
630+
if apiConfig.Swagger {
631+
RegisterSwaggerAPI(clientCtx, apiSvr.Router)
632+
}
633+
}
634+
635+
// RegisterSwaggerAPI registers the swagger routes on the API router
636+
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
637+
statikFS, err := fs.New()
638+
if err != nil {
639+
panic(err)
640+
}
641+
642+
staticServer := http.FileServer(statikFS)
643+
rtr.PathPrefix("/swagger").Handler(http.StripPrefix("/swagger/", staticServer))
609644
}
610645

611646
// GetMaccPerms returns a copy of the module account permissions

packages/cosmic-swingset/app/benchmarks/txsize_test.go

-46
This file was deleted.

packages/cosmic-swingset/app/encoding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
// MakeEncodingConfig creates an EncodingConfig for testing
99
func MakeEncodingConfig() params.EncodingConfig {
1010
encodingConfig := params.MakeEncodingConfig()
11-
std.RegisterCodec(encodingConfig.Amino)
11+
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
1212
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
13-
ModuleBasics.RegisterCodec(encodingConfig.Amino)
13+
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
1414
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
1515
return encodingConfig
1616
}

packages/cosmic-swingset/app/export.go

+25-11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"encoding/json"
55
"log"
66

7-
abci "github.com/tendermint/tendermint/abci/types"
87
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
9-
tmtypes "github.com/tendermint/tendermint/types"
108

9+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
1110
sdk "github.com/cosmos/cosmos-sdk/types"
1211
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
1312
"github.com/cosmos/cosmos-sdk/x/staking"
@@ -19,23 +18,32 @@ import (
1918
// file.
2019
func (app *GaiaApp) ExportAppStateAndValidators(
2120
forZeroHeight bool, jailAllowedAddrs []string,
22-
) (appState json.RawMessage, validators []tmtypes.GenesisValidator, cp *abci.ConsensusParams, err error) {
21+
) (servertypes.ExportedApp, error) {
2322

2423
// as if they could withdraw from the start of the next block
2524
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
2625

26+
// We export at last height + 1, because that's the height at which
27+
// Tendermint will start InitChain.
28+
height := app.LastBlockHeight() + 1
2729
if forZeroHeight {
30+
height = 0
2831
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
2932
}
3033

3134
genState := app.mm.ExportGenesis(ctx, app.appCodec)
32-
appState, err = json.MarshalIndent(genState, "", " ")
35+
appState, err := json.MarshalIndent(genState, "", " ")
3336
if err != nil {
34-
return nil, nil, nil, err
37+
return servertypes.ExportedApp{}, err
3538
}
3639

37-
validators = staking.WriteValidators(ctx, app.StakingKeeper)
38-
return appState, validators, app.BaseApp.GetConsensusParams(ctx), nil
40+
validators := staking.WriteValidators(ctx, app.StakingKeeper)
41+
return servertypes.ExportedApp{
42+
AppState: appState,
43+
Validators: validators,
44+
Height: height,
45+
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
46+
}, nil
3947
}
4048

4149
// prepare for fresh start at zero height
@@ -66,14 +74,20 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
6674

6775
// withdraw all validator commission
6876
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
69-
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
77+
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
78+
if err != nil {
79+
panic(err)
80+
}
7081
return false
7182
})
7283

7384
// withdraw all delegator rewards
7485
dels := app.StakingKeeper.GetAllDelegations(ctx)
7586
for _, delegation := range dels {
76-
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.DelegatorAddress, delegation.ValidatorAddress)
87+
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
88+
if err != nil {
89+
panic(err)
90+
}
7791
}
7892

7993
// clear validator slash events
@@ -100,8 +114,8 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
100114

101115
// reinitialize all delegations
102116
for _, del := range dels {
103-
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.DelegatorAddress, del.ValidatorAddress)
104-
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.DelegatorAddress, del.ValidatorAddress)
117+
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
118+
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
105119
}
106120

107121
// reset context height

packages/cosmic-swingset/app/params/proto.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ package params
55
import (
66
"github.com/cosmos/cosmos-sdk/codec"
77
"github.com/cosmos/cosmos-sdk/codec/types"
8-
"github.com/cosmos/cosmos-sdk/std"
98
"github.com/cosmos/cosmos-sdk/x/auth/tx"
109
)
1110

1211
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
1312
func MakeEncodingConfig() EncodingConfig {
14-
amino := codec.New()
13+
amino := codec.NewLegacyAmino()
1514
interfaceRegistry := types.NewInterfaceRegistry()
1615
marshaler := codec.NewProtoCodec(interfaceRegistry)
17-
txCfg := tx.NewTxConfig(marshaler, std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)
16+
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
1817

1918
return EncodingConfig{
2019
InterfaceRegistry: interfaceRegistry,

packages/cosmic-swingset/app/state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"math/rand"
99
"time"
1010

11-
"github.com/tendermint/tendermint/crypto/secp256k1"
11+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
1212
tmtypes "github.com/tendermint/tendermint/types"
1313

1414
"github.com/cosmos/cosmos-sdk/codec"

packages/cosmic-swingset/app/types.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package app
22

33
import (
4-
"encoding/json"
5-
64
abci "github.com/tendermint/tendermint/abci/types"
7-
tmtypes "github.com/tendermint/tendermint/types"
85

96
"github.com/cosmos/cosmos-sdk/codec"
7+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
108
sdk "github.com/cosmos/cosmos-sdk/types"
119
"github.com/cosmos/cosmos-sdk/types/module"
1210
)
@@ -36,7 +34,7 @@ type App interface {
3634
// Exports the state of the application for a genesis file.
3735
ExportAppStateAndValidators(
3836
forZeroHeight bool, jailAllowedAddrs []string,
39-
) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error)
37+
) (servertypes.ExportedApp, error)
4038

4139
// All the registered module account addreses.
4240
ModuleAccountAddrs() map[string]bool

packages/cosmic-swingset/app/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func CheckExportSimulation(
7979
) error {
8080
if config.ExportStatePath != "" {
8181
fmt.Println("exporting app state...")
82-
appState, _, _, err := app.ExportAppStateAndValidators(false, nil)
82+
exported, err := app.ExportAppStateAndValidators(false, nil)
8383
if err != nil {
8484
return err
8585
}
8686

87-
if err := ioutil.WriteFile(config.ExportStatePath, []byte(appState), 0600); err != nil {
87+
if err := ioutil.WriteFile(config.ExportStatePath, []byte(exported.AppState), 0600); err != nil {
8888
return err
8989
}
9090
}

packages/cosmic-swingset/cmd/ag-cosmos-helper/main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ import "C"
66

77
import (
88
"os"
9+
"path/filepath"
910

1011
"github.com/Agoric/cosmic-swingset/app"
1112
"github.com/Agoric/cosmic-swingset/lib/daemon"
1213
)
1314

1415
func main() {
15-
app.DefaultNodeHome = os.ExpandEnv("$HOME/.ag-cosmos-helper")
16+
userHomeDir, err := os.UserHomeDir()
17+
if err != nil {
18+
panic(err)
19+
}
20+
21+
app.DefaultNodeHome = filepath.Join(userHomeDir, ".ag-cosmos-helper")
1622
daemon.Run()
1723
}

0 commit comments

Comments
 (0)