Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Tracking PR: cosmos SDK update #142

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions golang/fake_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/summa-tx/relays/golang/x/relay"
"github.com/summa-tx/relays/golang/x/relay/keeper"
relayKeeper "github.com/summa-tx/relays/golang/x/relay/keeper"
relayTypes "github.com/summa-tx/relays/golang/x/relay/types"

bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -77,7 +80,7 @@ type relayApp struct {
supplyKeeper supply.Keeper
paramsKeeper params.Keeper

relayKeeper relay.Keeper
relayKeeper relayKeeper.Keeper

// Module Manager
mm *module.Manager
Expand Down Expand Up @@ -108,7 +111,7 @@ func NewRelayApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseA
distr.StoreKey,
slashing.StoreKey,
params.StoreKey,
relay.StoreKey)
relayTypes.StoreKey)
tkeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)

// Here you initialize your application with the store keys it requires
Expand Down Expand Up @@ -192,11 +195,11 @@ func NewRelayApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseA

// The RelayKeeper is the Keeper from the module for this tutorial
// It handles interactions with the store
app.relayKeeper = relay.NewKeeper(
keys[relay.StoreKey],
app.relayKeeper = keeper.NewKeeper(
keys[relayTypes.StoreKey],
app.cdc,
true, // Mainnet // TODO: pass this in somehow
relay.NullHandler{}, // Proof Handler. real apps should fill this in
relayTypes.NullHandler{}, // Proof Handler. real apps should fill this in
)

app.mm = module.NewManager(
Expand All @@ -222,7 +225,7 @@ func NewRelayApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseA
auth.ModuleName,
bank.ModuleName,
slashing.ModuleName,
relay.ModuleName,
relayTypes.ModuleName,
genutil.ModuleName,
)

Expand Down
24 changes: 5 additions & 19 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
module github.com/summa-tx/relays/golang

go 1.12
go 1.15

require (
github.com/bombsimon/wsl v1.2.8 // indirect
github.com/cosmos/cosmos-sdk v0.37.11
github.com/go-critic/go-critic v0.4.0 // indirect
github.com/gogo/protobuf v1.3.1
github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d // indirect
github.com/golangci/golangci-lint v1.21.0 // indirect
github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039 // indirect
github.com/gorilla/mux v1.7.0
github.com/gostaticanalysis/analysisutil v0.0.3 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/securego/gosec v0.0.0-20191119104125-df484bfa9e9f // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.5.1
github.com/summa-tx/bitcoin-spv/golang v1.4.0
github.com/summa-tx/relays/proto v0.0.0-00010101000000-000000000000
github.com/tendermint/go-amino v0.15.0
github.com/tendermint/tendermint v0.32.10
github.com/tendermint/tm-db v0.2.0
github.com/uudashr/gocognit v1.0.0 // indirect
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect
mvdan.cc/unparam v0.0.0-20191111180625-960b1ec0f2c2 // indirect
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
)

replace github.com/summa-tx/relays/proto => ../proto
318 changes: 59 additions & 259 deletions golang/go.sum

Large diffs are not rendered by default.

67 changes: 0 additions & 67 deletions golang/x/relay/alias.go

This file was deleted.

6 changes: 4 additions & 2 deletions golang/x/relay/gen_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"io/ioutil"
"os"
"strings"

"github.com/summa-tx/relays/golang/x/relay/types"
)

func getGenesisHeaders() (BitcoinHeader, []BitcoinHeader) {
func getGenesisHeaders() (types.BitcoinHeader, []types.BitcoinHeader) {
// get path to root directory
path, err := os.Getwd()
if err != nil {
Expand All @@ -21,7 +23,7 @@ func getGenesisHeaders() (BitcoinHeader, []BitcoinHeader) {
panic("could not retreive data in gen_state: " + jsonErr.Error())
}

var genesisHeaders []BitcoinHeader
var genesisHeaders []types.BitcoinHeader
err = json.Unmarshal([]byte(headerJSON), &genesisHeaders)
if err != nil {
panic("bad json in gen_state: " + err.Error())
Expand Down
12 changes: 7 additions & 5 deletions golang/x/relay/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
btcspv "github.com/summa-tx/bitcoin-spv/golang/btcspv"
"github.com/summa-tx/relays/golang/x/relay/keeper"
"github.com/summa-tx/relays/golang/x/relay/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// GenesisState is the genesis state
type GenesisState struct {
Headers []BitcoinHeader `json:"headers"`
PeriodStart BitcoinHeader `json:"periodStart"`
Headers []types.BitcoinHeader `json:"headers"`
PeriodStart types.BitcoinHeader `json:"periodStart"`
}

// NewGenesisState instantiates a genesis state
func NewGenesisState(headers []BitcoinHeader, periodStart BitcoinHeader) GenesisState {
func NewGenesisState(headers []types.BitcoinHeader, periodStart types.BitcoinHeader) GenesisState {
return GenesisState{Headers: headers, PeriodStart: periodStart}
}

Expand Down Expand Up @@ -53,7 +55,7 @@ func DefaultGenesisState() GenesisState {
}

// InitGenesis inits the app state based on the genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) []abci.ValidatorUpdate {
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data GenesisState) []abci.ValidatorUpdate {
err := keeper.SetGenesisState(ctx, data.Headers[0], data.PeriodStart)
if err != nil {
panic("already init!")
Expand All @@ -70,6 +72,6 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) []abci.Valid
// ExportGenesis exports the genesis state
// TODO: export GenesisState
// May need special store keys for it
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) GenesisState {
panic("Not implemented")
}
42 changes: 27 additions & 15 deletions golang/x/relay/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/summa-tx/relays/golang/x/relay/client/cli"
"github.com/summa-tx/relays/golang/x/relay/client/rest"
"github.com/summa-tx/relays/golang/x/relay/keeper"
"github.com/summa-tx/relays/golang/x/relay/types"

"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -29,23 +30,23 @@ type AppModuleBasic struct{}

// Name is
func (AppModuleBasic) Name() string {
return ModuleName
return types.ModuleName
}

// RegisterCodec is
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
types.RegisterCodec(cdc)
}

// DefaultGenesis is
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState())
}

// ValidateGenesis validates check of the Genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
err := types.ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
}
Expand All @@ -55,27 +56,38 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {

// RegisterRESTRoutes registers rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr, StoreKey)
rest.RegisterRoutes(ctx, rtr, types.StoreKey)
}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}

// GetQueryCmd get the root query command of this module
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
return cli.GetQueryCmd(types.StoreKey, cdc)
}

// GetTxCmd get the root tx command of this module
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetTxCmd(StoreKey, cdc)
return cli.GetTxCmd(types.StoreKey, cdc)
}

// AppModule is the AppModule
type AppModule struct {
AppModuleBasic
keeper Keeper
keeper keeper.Keeper
}

// NewAppModule creates a new AppModule Object
func NewAppModule(k Keeper) AppModule {
func NewAppModule(k keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: k,
Expand All @@ -84,15 +96,15 @@ func NewAppModule(k Keeper) AppModule {

// Name is
func (AppModule) Name() string {
return ModuleName
return types.ModuleName
}

// RegisterInvariants is
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}

// Route is
func (am AppModule) Route() string {
return RouterKey
return types.RouterKey
}

// NewHandler makes a new handler
Expand All @@ -102,12 +114,12 @@ func (am AppModule) NewHandler() sdk.Handler {

// QuerierRoute is
func (am AppModule) QuerierRoute() string {
return ModuleName
return types.ModuleName
}

// NewQuerierHandler is
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(am.keeper)
return keeper.NewQuerier(am.keeper)
}

// BeginBlock is
Expand All @@ -121,12 +133,12 @@ func (am AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.Validator
// InitGenesis is
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
return InitGenesis(ctx, am.keeper, genesisState)
}

// ExportGenesis is
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.keeper)
return ModuleCdc.MustMarshalJSON(gs)
return types.ModuleCdc.MustMarshalJSON(gs)
}
Loading