Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADR 015 Implementation #5401

Merged
merged 39 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
66b5f56
implement in progress
mossid Dec 12, 2019
54d329a
rm unneccessary change under simapp, modify baseapp for codetxbreak
mossid Dec 12, 2019
4ddd022
fix test in progress
mossid Dec 12, 2019
764c02c
Merge branch 'ibc-alpha' of github.com:cosmos/cosmos-sdk into joon/ad…
mossid Dec 20, 2019
0bc1dd2
fix test error
mossid Dec 20, 2019
70a2ba6
fix golangci
mossid Dec 20, 2019
07f9d57
address minor comments
mossid Jan 2, 2020
4f6e9f0
mv antehandler to ante/, address comments
mossid Jan 2, 2020
1eb8e77
fix GetCommitment => GetData, fix syntax
mossid Jan 3, 2020
43e5cc8
Merge branch 'ibc-alpha' of github.com:cosmos/cosmos-sdk into joon/ad…
mossid Jan 7, 2020
2ed95bd
Merge branch 'ibc-alpha' of github.com:cosmos/cosmos-sdk into joon/ad…
mossid Jan 7, 2020
df4676e
checkout types/ to ibc-alpha
mossid Jan 7, 2020
c527db2
checkout to origin/ibc-alpha
mossid Jan 7, 2020
974c8ea
fix branch problem
mossid Jan 7, 2020
bc13263
fix syntax error
mossid Jan 7, 2020
3f6b012
recover PacketI interface
mossid Jan 7, 2020
9aee39d
mv recvpacket rest from 20 -> 04
mossid Jan 7, 2020
e1ab431
address minor comments
mossid Jan 8, 2020
12bd7ef
Apply suggestions from code review
mossid Jan 8, 2020
a868338
rm wrong files
mossid Jan 8, 2020
425f9c4
Apply suggestions from code review
fedekunze Jan 8, 2020
e5f6d51
PacketDataI field is now named, not embed
mossid Jan 9, 2020
6cfb61c
Merge branch 'joon/adr-015-impl-3' of github.com:cosmos/cosmos-sdk in…
mossid Jan 9, 2020
84d07cc
add acknowledgement hashing
mossid Jan 9, 2020
82f51c0
rename finalization functiosn
mossid Jan 10, 2020
0d2e9c9
Apply suggestions from code review
cwgoes Jan 10, 2020
568de83
Rename GetCommitment() to GetBytes()
cwgoes Jan 10, 2020
4c5615c
Add recv sequence incr to RecvPacket()
cwgoes Jan 10, 2020
158bd7a
Revert but where is PacketExecuted() called
cwgoes Jan 10, 2020
b483944
Call PacketExecuted(), check seq in RecvPacket()
cwgoes Jan 10, 2020
e42404a
The port is called "bank"
cwgoes Jan 10, 2020
05073c8
Apply suggestions from code review
cwgoes Jan 10, 2020
115fa5e
Update simapp/app.go
cwgoes Jan 10, 2020
415d6da
Remove omitempty
cwgoes Jan 10, 2020
a2d30b6
Add godoc
cwgoes Jan 10, 2020
f358a63
Move events
cwgoes Jan 10, 2020
2c91a6e
set ProofVerificationDecorator on AnteHandler
fedekunze Jan 14, 2020
1339b55
Apply suggestions from code review
cwgoes Jan 14, 2020
4bea0ef
format
fedekunze Jan 14, 2020
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
32 changes: 23 additions & 9 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
ibctransfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer"
transfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
Expand Down Expand Up @@ -65,17 +65,18 @@ var (
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
ibctransfer.GetModuleAccountName(): {supply.Minter, supply.Burner},
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
transfer.GetModuleAccountName(): {supply.Minter, supply.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -127,6 +128,7 @@ type SimApp struct {
ParamsKeeper params.Keeper
IBCKeeper ibc.Keeper
EvidenceKeeper evidence.Keeper
TransferKeeper transfer.Keeper

// the module manager
mm *module.Manager
Expand All @@ -151,6 +153,7 @@ func NewSimApp(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey,
mint.StoreKey, distr.StoreKey, slashing.StoreKey, gov.StoreKey,
params.StoreKey, ibc.StoreKey, upgrade.StoreKey, evidence.StoreKey,
transfer.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

Expand Down Expand Up @@ -233,6 +236,12 @@ func NewSimApp(

app.IBCKeeper = ibc.NewKeeper(app.cdc, keys[ibc.StoreKey], app.BankKeeper, app.SupplyKeeper)

transferCapKey := app.IBCKeeper.PortKeeper.BindPort(bank.ModuleName)
app.TransferKeeper = transfer.NewKeeper(
app.cdc, keys[transfer.StoreKey], transferCapKey,
app.IBCKeeper.ChannelKeeper, app.BankKeeper, app.SupplyKeeper,
)

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(
Expand Down Expand Up @@ -293,7 +302,12 @@ func NewSimApp(
// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, auth.DefaultSigVerificationGasConsumer))
app.SetAnteHandler(
ante.NewAnteHandler(
app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper,
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
ante.DefaultSigVerificationGasConsumer,
),
)
app.SetEndBlocker(app.EndBlocker)

if loadLatest {
Expand Down
19 changes: 6 additions & 13 deletions x/auth/alias.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/ante
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/types
package auth

import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/types

const (
ModuleName = types.ModuleName
StoreKey = types.StoreKey
Expand All @@ -28,11 +27,6 @@ const (

var (
// functions aliases
NewAnteHandler = ante.NewAnteHandler
GetSignerAcc = ante.GetSignerAcc
DefaultSigVerificationGasConsumer = ante.DefaultSigVerificationGasConsumer
DeductFees = ante.DeductFees
SetGasMeter = ante.SetGasMeter
NewAccountKeeper = keeper.NewAccountKeeper
NewQuerier = keeper.NewQuerier
NewBaseAccount = types.NewBaseAccount
Expand Down Expand Up @@ -74,7 +68,6 @@ var (
)

type (
SignatureVerificationGasConsumer = ante.SignatureVerificationGasConsumer
AccountKeeper = keeper.AccountKeeper
BaseAccount = types.BaseAccount
NodeQuerier = types.NodeQuerier
Expand Down
10 changes: 8 additions & 2 deletions x/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/cosmos-sdk/x/ibc/ante"
ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper"
)

// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(ak keeper.AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasConsumer SignatureVerificationGasConsumer) sdk.AnteHandler {
func NewAnteHandler(
ak keeper.AccountKeeper, supplyKeeper types.SupplyKeeper, ibcKeeper ibckeeper.Keeper,
sigGasConsumer SignatureVerificationGasConsumer,
) sdk.AnteHandler {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
return sdk.ChainAnteDecorators(
NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewMempoolFeeDecorator(),
Expand All @@ -21,6 +26,7 @@ func NewAnteHandler(ak keeper.AccountKeeper, supplyKeeper types.SupplyKeeper, si
NewDeductFeeDecorator(ak, supplyKeeper),
NewSigGasConsumeDecorator(ak, sigGasConsumer),
NewSigVerificationDecorator(ak),
NewIncrementSequenceDecorator(ak), // innermost AnteDecorator
NewIncrementSequenceDecorator(ak),
ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper),// innermost AnteDecorator
)
}
26 changes: 13 additions & 13 deletions x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSimulateGasCost(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestSimulateGasCost(t *testing.T) {
func TestAnteHandlerSigErrors(t *testing.T) {
// setup
app, ctx := createTestApp(true)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestAnteHandlerAccountNumbers(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(0)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestAnteHandlerSequences(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestAnteHandlerSequences(t *testing.T) {
func TestAnteHandlerFees(t *testing.T) {
// setup
app, ctx := createTestApp(true)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestAnteHandlerMemoGas(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestAnteHandlerMultiSigner(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -534,7 +534,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -652,7 +652,7 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
Expand Down Expand Up @@ -692,7 +692,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) {
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
// setup an ante handler that only accepts PubKeyEd25519
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params) error {
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params) error {
switch pubkey := pubkey.(type) {
case ed25519.PubKeyEd25519:
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
Expand Down Expand Up @@ -749,7 +749,7 @@ func TestAnteHandlerReCheck(t *testing.T) {
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)

antehandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)
antehandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)

// test that operations skipped on recheck do not run

Expand Down
24 changes: 24 additions & 0 deletions x/ibc/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ func (k Keeper) CreateClient(
k.SetClientState(ctx, clientState)
k.SetClientType(ctx, clientID, clientType)
k.Logger(ctx).Info(fmt.Sprintf("client %s created at height %d", clientID, consensusState.GetHeight()))

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeCreateClient,
sdk.NewAttribute(types.AttributeKeyClientID, clientID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
})

return clientState, nil
}

Expand Down Expand Up @@ -72,6 +84,18 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
k.SetCommitter(ctx, clientID, consensusState.GetHeight(), consensusState.GetCommitter())
k.SetVerifiedRoot(ctx, clientID, consensusState.GetHeight(), consensusState.GetRoot())
k.Logger(ctx).Info(fmt.Sprintf("client %s updated to height %d", clientID, consensusState.GetHeight()))

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeUpdateClient,
sdk.NewAttribute(types.AttributeKeyClientID, clientID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
})

return nil
}

Expand Down
8 changes: 6 additions & 2 deletions x/ibc/04-channel/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ var (
NewMsgChannelOpenConfirm = types.NewMsgChannelOpenConfirm
NewMsgChannelCloseInit = types.NewMsgChannelCloseInit
NewMsgChannelCloseConfirm = types.NewMsgChannelCloseConfirm
NewMsgPacket = types.NewMsgPacket
NewMsgTimeout = types.NewMsgTimeout
NewMsgAcknowledgement = types.NewMsgAcknowledgement
NewPacket = types.NewPacket
NewOpaquePacket = types.NewOpaquePacket
NewChannelResponse = types.NewChannelResponse
NewQueryChannelParams = types.NewQueryChannelParams

Expand Down Expand Up @@ -108,8 +110,10 @@ type (
MsgChannelOpenConfirm = types.MsgChannelOpenConfirm
MsgChannelCloseInit = types.MsgChannelCloseInit
MsgChannelCloseConfirm = types.MsgChannelCloseConfirm
MsgPacket = types.MsgPacket
MsgAcknowledgement = types.MsgAcknowledgement
MsgTimeout = types.MsgTimeout
Packet = types.Packet
OpaquePacket = types.OpaquePacket
ChannelResponse = types.ChannelResponse
QueryChannelParams = types.QueryChannelParams
)
8 changes: 8 additions & 0 deletions x/ibc/04-channel/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ type ChannelCloseConfirmReq struct {
ProofInit commitment.ProofI `json:"proof_init" yaml:"proof_init"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
}

// RecvPacketReq defines the properties of a receive packet request's body.
type RecvPacketReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Packet types.Packet `json:"packet" yaml:"packet"`
Proofs commitment.ProofI `json:"proofs" yaml:"proofs"`
Height uint64 `json:"height" yaml:"height"`
}
46 changes: 46 additions & 0 deletions x/ibc/04-channel/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/ibc/ports/{%s}/channels/{%s}/open-confirm", RestPortID, RestChannelID), channelOpenConfirmHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/ibc/ports/{%s}/channels/{%s}/close-init", RestPortID, RestChannelID), channelCloseInitHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/ibc/ports/{%s}/channels/{%s}/close-confirm", RestPortID, RestChannelID), channelCloseConfirmHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/ibc/packets/receive"), recvPacketHandlerFn(cliCtx)).Methods("POST")
}

// channelOpenInitHandlerFn implements a channel open init handler
Expand Down Expand Up @@ -334,3 +335,48 @@ func channelCloseConfirmHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

// recvPacketHandlerFn implements a receive packet handler
//
// @Summary Receive packet
// @Tags IBC
// @Accept json
// @Produce json
// @Param body body rest.RecvPacketReq true "Receive packet request body"
// @Success 200 {object} PostRecvPacket "OK"
// @Failure 500 {object} rest.ErrorResponse "Internal Server Error"
// @Router /ibc/packets/receive [post]
func recvPacketHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req RecvPacketReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}

req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}

fromAddr, err := sdk.AccAddressFromBech32(req.BaseReq.From)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

// create the message
msg := types.NewMsgPacket(
req.Packet,
req.Proofs,
req.Height,
fromAddr,
)

if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
Loading