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 Jul 20, 2018
1 parent f437f36 commit 266c540
Show file tree
Hide file tree
Showing 39 changed files with 1,397 additions and 624 deletions.
3 changes: 2 additions & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func TestCoinSend(t *testing.T) {
require.Equal(t, int64(1), mycoins.Amount.Int64())
}

/*
func TestIBCTransfer(t *testing.T) {
name, password := "test", "1234567890"
addr, seed := CreateAddr(t, "test", password, GetKB(t))
Expand Down Expand Up @@ -291,7 +292,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, GetKB(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 @@ -89,7 +88,6 @@ func createHandler(cdc *wire.Codec) http.Handler {
tx.RegisterRoutes(ctx, r, cdc)
auth.RegisterRoutes(ctx, r, cdc, "acc")
bank.RegisterRoutes(ctx, r, cdc, kb)
ibc.RegisterRoutes(ctx, r, cdc, kb)
stake.RegisterRoutes(ctx, r, cdc, kb)
slashing.RegisterRoutes(ctx, r, cdc, kb)
gov.RegisterRoutes(ctx, r, cdc)
Expand Down
6 changes: 3 additions & 3 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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 @@ -88,8 +88,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.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace))
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
Expand All @@ -98,7 +98,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 @@ -132,6 +131,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 @@ -140,7 +140,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 @@ -173,15 +173,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
15 changes: 7 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 @@ -66,12 +66,12 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
auth.ProtoBaseAccount, // prototype
)
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 @@ -92,12 +92,11 @@ 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)
bank.RegisterWire(cdc)

// register custom types
cdc.RegisterInterface((*auth.Account)(nil), nil)
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 @@ -57,7 +57,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 @@ -106,8 +106,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
117 changes: 117 additions & 0 deletions types/lib/linear_cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package lib

import (
"io"

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

type linearCLIStore struct {
ctx context.CoreContext
storeName string
prefix []byte
}

// Implements sdk.CacheWrapper
func (store linearCLIStore) CacheWrap() sdk.CacheWrap {
panic("Should not reach here")
}

// Implements sdk.KVStore
func (store linearCLIStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) sdk.CacheWrap {
panic("Should not reach here")
}

// Implements sdk.Store
func (store linearCLIStore) GetStoreType() sdk.StoreType {
panic("Should not reach here")
}

// Implements sdk.KVStore
func (store linearCLIStore) Get(key []byte) []byte {
bz, err := store.ctx.QueryStore(append(store.prefix, key...), store.storeName)
if err != nil {
panic(err)
}
return bz
}

// Implements sdk.KVStore
func (store linearCLIStore) Has(key []byte) bool {
panic("Should not reach here")
}

// Implements sdk.KVStore
func (store linearCLIStore) Set(key, value []byte) {
panic("Should not reach here")
}

// Implements sdk.KVStore
func (store linearCLIStore) Delete(key []byte) {
panic("Should not reach here")
}

// Implements sdk.KVstore
func (store linearCLIStore) Prefix(prefix []byte) sdk.KVStore {
panic("Should not reach here")
}

// Implements sdk.KVStore
func (store linearCLIStore) Iterator(start, end []byte) sdk.Iterator {
panic("Should not reach here")
}

// Implements sdk.KVStore
func (store linearCLIStore) ReverseIterator(start, end []byte) sdk.Iterator {
panic("Should not reach here")
}

type linearClient struct {
Linear
}

type LinearClient interface {
Len() uint64
Get(uint64, interface{}) error
Iterate(interface{}, func(uint64) bool)

Peek(interface{}) error
IsEmpty() bool
}

func NewLinearClient(ctx context.CoreContext, storeName string, cdc *wire.Codec, prefix []byte, keys *LinearKeys) LinearClient {
if keys == nil {
keys = cachedDefaultLinearKeys
}
if keys.LengthKey == nil || keys.ElemKey == nil || keys.TopKey == nil {
panic("Invalid LinearKeys")
}
return linearClient{
Linear: Linear{
cdc: cdc,
store: linearCLIStore{
ctx: ctx,
storeName: storeName,
prefix: prefix,
},
keys: keys,
},
}
}

func (cli linearClient) Iterate(ptr interface{}, fn func(uint64) bool) {
top := cli.getTop()
length := cli.Len()

var i uint64
for i = top; i < length; i++ {
if cli.Get(i, ptr) != nil {
continue
}
if fn(i) {
break
}
}
}
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"
)
Loading

0 comments on commit 266c540

Please sign in to comment.