Skip to content

Commit

Permalink
Merge pull request #1481: IBC MVP Refactor
Browse files Browse the repository at this point in the history
in progress

in progress

fix all keeper/handler/types, start working on test

finalize rebase

fixing clients

add linear_cli.go, refactor relayer cli

fix examples

add wire, msg naming format, fix examples

in progress

in progress

add client/store

in progress

in progress

cleanup

finalize cleanup

fix errors

refactor ibc
  • Loading branch information
mossid committed Aug 30, 2018
1 parent fd8c1e5 commit 3fc0192
Show file tree
Hide file tree
Showing 37 changed files with 1,279 additions and 554 deletions.
3 changes: 2 additions & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func TestCoinSend(t *testing.T) {
require.Equal(t, http.StatusOK, res.StatusCode, body)
}

/*
func TestIBCTransfer(t *testing.T) {
name, password := "test", "1234567890"
addr, seed := CreateAddr(t, "test", password, GetKeyBase(t))
Expand Down Expand Up @@ -301,7 +302,7 @@ func TestIBCTransfer(t *testing.T) {
// TODO: query ibc egress packet state
}

*/
func TestTxs(t *testing.T) {
name, password := "test", "1234567890"
addr, seed := CreateAddr(t, "test", password, GetKeyBase(t))
Expand Down
2 changes: 0 additions & 2 deletions client/lcd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/client/rest"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
stake "github.com/cosmos/cosmos-sdk/x/stake/client/rest"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -93,6 +92,5 @@ func createHandler(cdc *wire.Codec) http.Handler {
stake.RegisterRoutes(cliCtx, r, cdc, kb)
slashing.RegisterRoutes(cliCtx, r, cdc, kb)
gov.RegisterRoutes(cliCtx, r, cdc)

return r
}
6 changes: 3 additions & 3 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type GaiaApp struct {
accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper
ibcMapper ibc.Mapper
ibcKeeper ibc.Keeper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
govKeeper gov.Keeper
Expand Down Expand Up @@ -90,8 +90,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio

// add handlers
app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams)
app.ibcKeeper = ibc.NewKeeper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.paramsKeeper.Setter(), app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace))
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
Expand All @@ -100,7 +100,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
// register message routes
app.Router().
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper)).
AddRoute("slashing", slashing.NewHandler(app.slashingKeeper)).
AddRoute("gov", gov.NewHandler(app.govKeeper))
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func main() {
}
ibcCmd.AddCommand(
client.PostCommands(
ibccmd.IBCTransferCmd(cdc),
ibccmd.IBCRelayCmd(cdc),
)...)

Expand Down Expand Up @@ -131,6 +130,7 @@ func main() {
rootCmd.AddCommand(
client.PostCommands(
bankcmd.SendTxCmd(cdc),
bankcmd.IBCSendTxCmd(cdc),
)...)

// add proxy, version and key info
Expand Down
6 changes: 3 additions & 3 deletions cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type GaiaApp struct {
accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper
ibcMapper ibc.Mapper
ibcKeeper ibc.Keeper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
paramsKeeper params.Keeper
Expand Down Expand Up @@ -174,15 +174,15 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp

// add handlers
app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams)
app.ibcKeeper = ibc.NewKeeper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace))

// register message routes
app.Router().
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper))

// initialize BaseApp
Expand Down
14 changes: 6 additions & 8 deletions examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type BasecoinApp struct {
accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper
ibcMapper ibc.Mapper
ibcKeeper ibc.Keeper
}

// NewBasecoinApp returns a reference to a new BasecoinApp given a logger and
Expand Down Expand Up @@ -68,12 +68,12 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
},
)
app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.ibcKeeper = ibc.NewKeeper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))

// register message routes
app.Router().
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper))
AddRoute("ibc", ibc.NewHandler(app.ibcKeeper))

// perform initialization logic
app.SetInitChainer(app.initChainer)
Expand All @@ -96,11 +96,9 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
// MakeCodec creates a new wire codec and registers all the necessary types
// with the codec.
func MakeCodec() *wire.Codec {
cdc := wire.NewCodec()

wire.RegisterCrypto(cdc)
sdk.RegisterWire(cdc)
bank.RegisterWire(cdc)
var cdc = wire.NewCodec()
wire.RegisterCrypto(cdc) // Register crypto.
sdk.RegisterWire(cdc) // Register Msgs
ibc.RegisterWire(cdc)
auth.RegisterWire(cdc)

Expand Down
2 changes: 1 addition & 1 deletion examples/basecoin/cmd/basecli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
rootCmd.AddCommand(
client.PostCommands(
bankcmd.SendTxCmd(cdc),
ibccmd.IBCTransferCmd(cdc),
bankcmd.IBCSendTxCmd(cdc),
ibccmd.IBCRelayCmd(cdc),
stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditValidator(cdc),
Expand Down
8 changes: 4 additions & 4 deletions examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type DemocoinApp struct {
coinKeeper bank.Keeper
coolKeeper cool.Keeper
powKeeper pow.Keeper
ibcMapper ibc.Mapper
ibcKeeper ibc.Keeper
stakeKeeper simplestake.Keeper

// Manage getting and setting accounts
Expand Down Expand Up @@ -78,14 +78,14 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.coolKeeper = cool.NewKeeper(app.capKeyMainStore, app.coinKeeper, app.RegisterCodespace(cool.DefaultCodespace))
app.powKeeper = pow.NewKeeper(app.capKeyPowStore, pow.NewConfig("pow", int64(1)), app.coinKeeper, app.RegisterCodespace(pow.DefaultCodespace))
app.ibcMapper = ibc.NewMapper(app.cdc, app.capKeyIBCStore, app.RegisterCodespace(ibc.DefaultCodespace))
app.ibcKeeper = ibc.NewKeeper(app.cdc, app.capKeyIBCStore, app.RegisterCodespace(ibc.DefaultCodespace))
app.stakeKeeper = simplestake.NewKeeper(app.capKeyStakingStore, app.coinKeeper, app.RegisterCodespace(simplestake.DefaultCodespace))
app.Router().
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("cool", cool.NewHandler(app.coolKeeper)).
AddRoute("pow", app.powKeeper.Handler).
AddRoute("sketchy", sketchy.NewHandler()).
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcKeeper)).
AddRoute("simplestake", simplestake.NewHandler(app.stakeKeeper))

// Initialize BaseApp.
Expand All @@ -109,8 +109,8 @@ func MakeCodec() *wire.Codec {
sdk.RegisterWire(cdc) // Register Msgs
cool.RegisterWire(cdc)
pow.RegisterWire(cdc)
bank.RegisterWire(cdc)
ibc.RegisterWire(cdc)
bank.RegisterWire(cdc)
simplestake.RegisterWire(cdc)

// Register AppAccount
Expand Down
5 changes: 1 addition & 4 deletions examples/democoin/cmd/democli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ func main() {
rootCmd.AddCommand(
client.PostCommands(
bankcmd.SendTxCmd(cdc),
)...)
rootCmd.AddCommand(
client.PostCommands(
ibccmd.IBCTransferCmd(cdc),
bankcmd.IBCSendTxCmd(cdc),
)...)
rootCmd.AddCommand(
client.PostCommands(
Expand Down
43 changes: 43 additions & 0 deletions types/lib/value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lib

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
)

type Value struct {
store sdk.KVStore
cdc *wire.Codec
key []byte
}

func NewValue(store sdk.KVStore, cdc *wire.Codec, key []byte) Value {
return Value{
store: store,
cdc: cdc,
key: key,
}
}

func (v Value) MustGet(ptr interface{}) {
bz := v.store.Get(v.key)
v.cdc.MustUnmarshalBinary(bz, ptr)
}

func (v Value) Get(ptr interface{}) bool {
bz := v.store.Get(v.key)
if bz == nil {
return false
}
v.cdc.MustUnmarshalBinary(bz, ptr)
return true
}

func (v Value) Has() bool {
bz := v.store.Get(v.key)
return bz != nil
}

func (v Value) Set(val interface{}) {
v.store.Set(v.key, v.cdc.MustMarshalBinary(val))
}
7 changes: 7 additions & 0 deletions x/bank/client/cli/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cli

const (
FlagTo = "to"
FlagAmount = "amount"
FlagDestChain = "dest-chain-id"
)
34 changes: 16 additions & 18 deletions x/ibc/client/cli/ibctx.go → x/bank/client/cli/ibctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/hex"
"os"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -15,16 +14,12 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const (
flagTo = "to"
flagAmount = "amount"
flagChain = "chain"
"github.com/cosmos/cosmos-sdk/x/bank"
)

// IBCTransferCmd implements the IBC transfer command.
func IBCTransferCmd(cdc *wire.Codec) *cobra.Command {
// IBC transfer command
func IBCSendTxCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "transfer",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -48,32 +43,35 @@ func IBCTransferCmd(cdc *wire.Codec) *cobra.Command {
},
}

cmd.Flags().String(flagTo, "", "Address to send coins")
cmd.Flags().String(flagAmount, "", "Amount of coins to send")
cmd.Flags().String(flagChain, "", "Destination chain to send coins")

cmd.Flags().String(FlagTo, "", "Address to send coins")
cmd.Flags().String(FlagAmount, "", "Amount of coins to send")
cmd.Flags().String(FlagDestChain, "", "Destination chain to send coins")
return cmd
}

func buildMsg(from sdk.AccAddress) (sdk.Msg, error) {
amount := viper.GetString(flagAmount)
amount := viper.GetString(FlagAmount)
coins, err := sdk.ParseCoins(amount)
if err != nil {
return nil, err
}

dest := viper.GetString(flagTo)
dest := viper.GetString(FlagTo)
bz, err := hex.DecodeString(dest)
if err != nil {
return nil, err
}
to := sdk.AccAddress(bz)

packet := ibc.NewIBCPacket(from, to, coins, viper.GetString(client.FlagChainID),
viper.GetString(flagChain))
payload := bank.PayloadSend{
SrcAddr: from,
DestAddr: to,
Coins: coins,
}

msg := ibc.IBCTransferMsg{
IBCPacket: packet,
msg := bank.MsgIBCSend{
PayloadSend: payload,
DestChain: viper.GetString(FlagDestChain),
}

return msg, nil
Expand Down
15 changes: 4 additions & 11 deletions x/bank/client/cli/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import (
"github.com/spf13/viper"
)

const (
flagTo = "to"
flagAmount = "amount"
)

// SendTxCmd will create a send tx and sign it with the given key.
// SendTxCmd will create a send tx and sign it with the given key
func SendTxCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "send",
Expand All @@ -38,14 +33,13 @@ func SendTxCmd(cdc *wire.Codec) *cobra.Command {
}

toStr := viper.GetString(flagTo)

to, err := sdk.AccAddressFromBech32(toStr)
if err != nil {
return err
}

// parse coins trying to be sent
amount := viper.GetString(flagAmount)
amount := viper.GetString(FlagAmount)
coins, err := sdk.ParseCoins(amount)
if err != nil {
return err
Expand Down Expand Up @@ -73,8 +67,7 @@ func SendTxCmd(cdc *wire.Codec) *cobra.Command {
},
}

cmd.Flags().String(flagTo, "", "Address to send coins")
cmd.Flags().String(flagAmount, "", "Amount of coins to send")

cmd.Flags().String(FlagTo, "", "Address to send coins")
cmd.Flags().String(FlagAmount, "", "Amount of coins to send")
return cmd
}
16 changes: 16 additions & 0 deletions x/bank/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package rest

import (
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/crypto/keys"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/wire"
)

// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {

r.HandleFunc("/accounts/{address}/send", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
}
5 changes: 0 additions & 5 deletions x/bank/client/rest/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import (
"github.com/gorilla/mux"
)

// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
r.HandleFunc("/accounts/{address}/send", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
}

type sendBody struct {
// fees is not used currently
// Fees sdk.Coin `json="fees"`
Expand Down
Loading

0 comments on commit 3fc0192

Please sign in to comment.