Skip to content

Commit b2813ac

Browse files
committed
feat: upgrade to cosmos-sdk v0.40.1
1 parent a53c1af commit b2813ac

22 files changed

+151
-571
lines changed

go.mod

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,30 @@ go 1.14
55
require (
66
github.com/btcsuite/btcd v0.21.0-beta
77
github.com/btcsuite/btcutil v1.0.2
8-
github.com/cosmos/cosmos-sdk v0.40.0-rc4
8+
github.com/cosmos/cosmos-sdk v0.40.1
99
github.com/ethereum/go-ethereum v1.9.22
10-
github.com/gogo/protobuf v1.3.1
10+
github.com/gogo/protobuf v1.3.3
1111
github.com/gorilla/mux v1.8.0
12-
github.com/grpc-ecosystem/grpc-gateway v1.15.2
12+
github.com/grpc-ecosystem/grpc-gateway v1.16.0
1313
github.com/pkg/errors v0.9.1
1414
github.com/rakyll/statik v0.1.7
1515
github.com/spf13/cast v1.3.1
1616
github.com/spf13/cobra v1.1.1
17-
github.com/tendermint/tendermint v0.34.0-rc6
18-
github.com/tendermint/tm-db v0.6.2
19-
google.golang.org/genproto v0.0.0-20201014134559-03b6142f0dc9
20-
google.golang.org/grpc v1.33.0
17+
github.com/tendermint/tendermint v0.34.3
18+
github.com/tendermint/tm-db v0.6.3
19+
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
20+
google.golang.org/grpc v1.35.0
2121
)
2222

2323
// Silence a warning on MacOS
2424
replace github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
2525

2626
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
2727

28-
// At least until v0.40.0-rc3 is released.
28+
// At least until tendermint v0.34.4 is released.
29+
// replace github.com/tendermint/tendermint => github.com/agoric-labs/tendermint v0.33.1-dev2.0.20210126214117-87803b32fbb4
30+
31+
// At least until cosmos-sdk v0.40.0-rc3 is released.
2932
// replace github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.34.4-0.20201011165527-9684bf64c2db
3033

3134
// For testing against a local cosmos-sdk or tendermint

go.sum

+72
Large diffs are not rendered by default.

golang/cosmos/app/app.go

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
package app
1+
package gaia
22

33
import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
stdlog "log"
78
"net/http"
89
"os"
910
"path/filepath"
1011

1112
"github.com/cosmos/cosmos-sdk/client"
1213
"github.com/cosmos/cosmos-sdk/codec/types"
14+
"github.com/cosmos/cosmos-sdk/simapp"
1315
"github.com/gorilla/mux"
1416
"github.com/rakyll/statik/fs"
1517

@@ -21,6 +23,7 @@ import (
2123
dbm "github.com/tendermint/tm-db"
2224

2325
"github.com/cosmos/cosmos-sdk/baseapp"
26+
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
2427
"github.com/cosmos/cosmos-sdk/client/rpc"
2528
"github.com/cosmos/cosmos-sdk/codec"
2629
"github.com/cosmos/cosmos-sdk/server/api"
@@ -143,14 +146,14 @@ var (
143146
)
144147

145148
var (
146-
_ App = (*GaiaApp)(nil)
149+
_ simapp.App = (*GaiaApp)(nil)
147150
_ servertypes.Application = (*GaiaApp)(nil)
148151
)
149152

150-
// Gaia extends an ABCI application, but with most of its parameters exported.
153+
// GaiaApp extends an ABCI application, but with most of its parameters exported.
151154
// They are exported for convenience in creating helper functions, as object
152155
// capabilities aren't needed for testing.
153-
type GaiaApp struct {
156+
type GaiaApp struct { // nolint: golint
154157
*baseapp.BaseApp
155158
legacyAmino *codec.LegacyAmino
156159
appCodec codec.Marshaler
@@ -201,14 +204,13 @@ type GaiaApp struct {
201204
func init() {
202205
userHomeDir, err := os.UserHomeDir()
203206
if err != nil {
204-
panic(err)
207+
stdlog.Println("Failed to get home dir %2", err)
205208
}
206209

207210
DefaultNodeHome = filepath.Join(userHomeDir, ".ag-chain-cosmos")
208211
}
209212

210-
// NewGaia returns a reference to an initialized Gaia.
211-
// NewSimApp returns a reference to an initialized SimApp.
213+
// NewGaiaApp returns a reference to an initialized Gaia.
212214
func NewGaiaApp(
213215
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
214216
homePath string, invCheckPeriod uint, encodingConfig gaiaappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
@@ -302,7 +304,7 @@ func NewAgoricApp(
302304

303305
// Create IBC Keeper
304306
app.IBCKeeper = ibckeeper.NewKeeper(
305-
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
307+
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper,
306308
)
307309

308310
// register the proposal types
@@ -375,6 +377,8 @@ func NewAgoricApp(
375377
// NOTE: Any module instantiated in the module manager that is later modified
376378
// must be passed by reference here.
377379

380+
// NOTE: Any module instantiated in the module manager that is later modified
381+
// must be passed by reference here.
378382
app.mm = module.NewManager(
379383
genutil.NewAppModule(
380384
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
@@ -491,8 +495,8 @@ type cosmosInitAction struct {
491495
}
492496

493497
// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
494-
// simapp. It is useful for tests and clients who do not want to construct the
495-
// full simapp
498+
// Gaia. It is useful for tests and clients who do not want to construct the
499+
// full gaia application
496500
func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) {
497501
config := MakeEncodingConfig()
498502
return config.Marshaler, config.Amino
@@ -586,7 +590,7 @@ func (app *GaiaApp) BlockedAddrs() map[string]bool {
586590
return blockedAddrs
587591
}
588592

589-
// LegacyAmino returns SimApp's amino codec.
593+
// LegacyAmino returns GaiaApp's amino codec.
590594
//
591595
// NOTE: This is solely to be used for testing purposes as it may be desirable
592596
// for modules to register their own custom testing types.
@@ -646,17 +650,20 @@ func (app *GaiaApp) SimulationManager() *module.SimulationManager {
646650
func (app *GaiaApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
647651
clientCtx := apiSvr.ClientCtx
648652
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
653+
// Register legacy tx routes.
649654
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
650655
// Register new tx routes from grpc-gateway.
651-
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter)
656+
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
657+
// Register new tendermint queries routes from grpc-gateway.
658+
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
652659

653660
// Register legacy and grpc-gateway routes for all modules.
654661
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
655-
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter)
662+
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
656663

657664
// register swagger API from root so that other applications can override easily
658665
if apiConfig.Swagger {
659-
RegisterSwaggerAPI(clientCtx, apiSvr.Router)
666+
RegisterSwaggerAPI(apiSvr.Router)
660667
}
661668
}
662669

@@ -665,8 +672,13 @@ func (app *GaiaApp) RegisterTxService(clientCtx client.Context) {
665672
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
666673
}
667674

675+
// RegisterTendermintService implements the Application.RegisterTendermintService method.
676+
func (app *GaiaApp) RegisterTendermintService(clientCtx client.Context) {
677+
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
678+
}
679+
668680
// RegisterSwaggerAPI registers swagger route with API Server
669-
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
681+
func RegisterSwaggerAPI(rtr *mux.Router) {
670682
statikFS, err := fs.New()
671683
if err != nil {
672684
panic(err)
@@ -698,6 +710,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
698710
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
699711
paramsKeeper.Subspace(crisistypes.ModuleName)
700712
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
713+
paramsKeeper.Subspace(ibchost.ModuleName)
701714

702715
return paramsKeeper
703716
}

golang/cosmos/app/config.go

-75
This file was deleted.

golang/cosmos/app/encoding.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app
1+
package gaia
22

33
import (
44
"github.com/Agoric/agoric-sdk/golang/cosmos/app/params"

golang/cosmos/app/export.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app
1+
package gaia
22

33
import (
44
"encoding/json"

golang/cosmos/app/genesis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app
1+
package gaia
22

33
import (
44
"encoding/json"

golang/cosmos/app/genesis_account.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app
1+
package gaia
22

33
import (
44
"errors"
+1-72
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,6 @@
11
package helpers
22

3-
import (
4-
"math/rand"
5-
"time"
6-
7-
"github.com/tendermint/tendermint/crypto"
8-
9-
"github.com/cosmos/cosmos-sdk/client"
10-
sdk "github.com/cosmos/cosmos-sdk/types"
11-
"github.com/cosmos/cosmos-sdk/types/simulation"
12-
"github.com/cosmos/cosmos-sdk/types/tx/signing"
13-
authsign "github.com/cosmos/cosmos-sdk/x/auth/signing"
14-
)
15-
163
// SimAppChainID hardcoded chainID for simulation
174
const (
18-
DefaultGenTxGas = 1000000
19-
SimAppChainID = "simulation-app"
5+
SimAppChainID = "gaia-app"
206
)
21-
22-
// GenTx generates a signed mock transaction.
23-
func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) (sdk.Tx, error) {
24-
sigs := make([]signing.SignatureV2, len(priv))
25-
26-
// create a random length memo
27-
r := rand.New(rand.NewSource(time.Now().UnixNano()))
28-
29-
memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100))
30-
31-
signMode := gen.SignModeHandler().DefaultMode()
32-
33-
for i, p := range priv {
34-
sigs[i] = signing.SignatureV2{
35-
PubKey: p.PubKey(),
36-
Data: &signing.SingleSignatureData{
37-
SignMode: signMode,
38-
},
39-
}
40-
}
41-
42-
tx := gen.NewTxBuilder()
43-
err := tx.SetMsgs(msgs...)
44-
if err != nil {
45-
return nil, err
46-
}
47-
err = tx.SetSignatures(sigs...)
48-
if err != nil {
49-
return nil, err
50-
}
51-
tx.SetMemo(memo)
52-
tx.SetFeeAmount(feeAmt)
53-
tx.SetGasLimit(gas)
54-
for i, p := range priv {
55-
// use a empty chainID for ease of testing
56-
signerData := authsign.SignerData{
57-
ChainID: chainID,
58-
AccountNumber: accnums[i],
59-
Sequence: seq[i],
60-
}
61-
signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx())
62-
if err != nil {
63-
panic(err)
64-
}
65-
sig, err := p.Sign(signBytes)
66-
if err != nil {
67-
panic(err)
68-
}
69-
sigs[i].Data.(*signing.SingleSignatureData).Signature = sig
70-
err = tx.SetSignatures(sigs...)
71-
if err != nil {
72-
panic(err)
73-
}
74-
}
75-
76-
return tx.GetTx(), nil
77-
}

0 commit comments

Comments
 (0)