Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from decipherhub/feature/add-CrossChainQuery-type
Browse files Browse the repository at this point in the history
Feature/add cross chain query type
  • Loading branch information
Woojinger authored Sep 14, 2022
2 parents 0436b84 + a44c850 commit ce4e210
Show file tree
Hide file tree
Showing 22 changed files with 271 additions and 857 deletions.
34 changes: 2 additions & 32 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@
- [ibc/applications/ibc_query/v1/tx.proto](#ibc/applications/ibc_query/v1/tx.proto)
- [MsgSubmitCrossChainQuery](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQuery)
- [MsgSubmitCrossChainQueryResponse](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResponse)
- [MsgSubmitCrossChainQueryResult](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResult)
- [MsgSubmitCrossChainQueryResultResponse](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResultResponse)

- [Msg](#ibc.applications.ibc_query.v1.Msg)

Expand Down Expand Up @@ -1455,7 +1453,7 @@ Msg defines the ICS29 Msg service.
<a name="ibc.applications.ibc_query.v1.EventQuerySubmitted"></a>

### EventQuerySubmitted

EventQuerySubmitted emitted when process MsgSubmitCrossChainQuery tx


| Field | Type | Label | Description |
Expand Down Expand Up @@ -1534,6 +1532,7 @@ GenesisState defines the ICS31 ibc-query genesis state
| ----- | ---- | ----- | ----------- |
| `queries` | [CrossChainQuery](#ibc.applications.ibc_query.v1.CrossChainQuery) | repeated | |
| `results` | [CrossChainQueryResult](#ibc.applications.ibc_query.v1.CrossChainQueryResult) | repeated | |
| `port_id` | [string](#string) | | |



Expand Down Expand Up @@ -1666,34 +1665,6 @@ MsgSubmitCrossChainQueryResponse




<a name="ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResult"></a>

### MsgSubmitCrossChainQueryResult
MsgSubmitCrossChainQueryResult


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `id` | [string](#string) | | |
| `result` | [QueryResult](#ibc.applications.ibc_query.v1.QueryResult) | | |
| `data` | [bytes](#bytes) | | |
| `relayer` | [string](#string) | | relayer address |






<a name="ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResultResponse"></a>

### MsgSubmitCrossChainQueryResultResponse
MsgSubmitCrossChainQueryResultResponse





<!-- end messages -->

<!-- end enums -->
Expand All @@ -1709,7 +1680,6 @@ Msg
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `SubmitCrossChainQuery` | [MsgSubmitCrossChainQuery](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQuery) | [MsgSubmitCrossChainQueryResponse](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResponse) | submit query request | |
| `SubmitCrossChainQueryResult` | [MsgSubmitCrossChainQueryResult](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResult) | [MsgSubmitCrossChainQueryResultResponse](#ibc.applications.ibc_query.v1.MsgSubmitCrossChainQueryResultResponse) | submit query result | |

<!-- end services -->

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ require (
github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87 // indirect
github.com/improbable-eng/grpc-web v0.14.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
github.com/klauspost/compress v1.13.6 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6l
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.25.48/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.40.45 h1:QN1nsY27ssD/JmW4s83qmSb+uL6DG4GmCDzjmJB4xUI=
github.com/aws/aws-sdk-go v1.40.45/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/aws/aws-sdk-go-v2 v1.9.1/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4=
Expand Down Expand Up @@ -578,9 +577,7 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/protoreflect v1.9.0 h1:npqHz788dryJiR/l6K/RUQAyh2SwV91+d1dnh4RjO9w=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
Expand Down
15 changes: 7 additions & 8 deletions modules/apps/31-ibc-query/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const (

func NewMsgCrossChainQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cross-chain-query [src-port] [src-channel] [query-path] [query-height]",
Short: "Request ibc query on a given channel.",
Long: strings.TrimSpace(`Register a payee address on a given channel.`),
Args: cobra.ExactArgs(3),
Use: "cross-chain-query [src-port] [src-channel] [query-path] [query-height]",
Short: "Request ibc query on a given channel.",
Long: strings.TrimSpace(`Register a payee address on a given channel.`),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -41,8 +41,7 @@ func NewMsgCrossChainQueryCmd() *cobra.Command {
srcPort := args[0]
srcChannel := args[1]
path := args[2]
queryHeight, _ := strconv.ParseUint(args[2],10, 64)

queryHeight, _ := strconv.ParseUint(args[2], 10, 64)

timeoutHeightStr, err := cmd.Flags().GetString(flagPacketTimeoutHeight)
if err != nil {
Expand All @@ -57,8 +56,8 @@ func NewMsgCrossChainQueryCmd() *cobra.Command {
if err != nil {
return err
}
msg := types.NewMsgSubmitCrossChainQuery(queryId, path, timeoutHeight, timeoutTimestamp, queryHeight, creator, srcPort, srcChannel)

msg := types.NewMsgSubmitCrossChainQuery(queryId, path, &timeoutHeight, timeoutTimestamp, queryHeight, creator, srcPort, srcChannel)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand Down
25 changes: 8 additions & 17 deletions modules/apps/31-ibc-query/ibc_module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ibc_query

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -36,7 +37,7 @@ func ValidateIBCQueryChannelParams(
portID string,
channelID string,
) error {

// Require portID is the portID transfer module is bound to
boundPort := keeper.GetPort(ctx)
if boundPort != portID {
Expand Down Expand Up @@ -156,24 +157,14 @@ func (im IBCModule) OnRecvPacket(
) ibcexported.Acknowledgement {
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})

var data types.MsgSubmitCrossChainQuery
var ackErr error
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
ackErr = sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ICS-20 transfer packet data")
ack = channeltypes.NewErrorAcknowledgement(ackErr)
}

// only attempt the application logic if the packet data
// was successfully decoded
if ack.Success() {
err := im.keeper.OnRecvPacket(ctx, packet, data)
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
}
err := im.keeper.OnRecvPacket(ctx, packet)
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
}

eventAttributes := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
}

ctx.EventManager().EmitEvent(
Expand Down Expand Up @@ -206,7 +197,7 @@ func (im IBCModule) OnAcknowledgementPacket(

if err := im.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil {
return err
};
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
Expand Down Expand Up @@ -257,5 +248,5 @@ func (im IBCModule) OnTimeoutPacket(
),
)

return nil
return nil
}
12 changes: 6 additions & 6 deletions modules/apps/31-ibc-query/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
k.SetPort(ctx, state.PortId)
for _, query := range state.Queries {
k.SetSubmitCrossChainQuery(ctx, *query)
k.SetCrossChainQuery(ctx, *query)
}
for _, result := range state.Results {
k.SetSubmitCrossChainQueryResult(ctx, *result)
k.SetCrossChainQueryResult(ctx, *result)
}

if !k.IsBound(ctx, state.PortId) {
if !k.IsBound(ctx, state.PortId) {
err := k.BindPort(ctx, state.PortId)
if err != nil {
if err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
Expand All @@ -28,7 +28,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
// ExportGenesis returns the application exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
Queries: k.GetAllSubmitCrossChainQueries(ctx),
Results: k.GetAllSubmitCrossChainQueryResults(ctx),
Queries: k.GetAllCrossChainQueries(ctx),
Results: k.GetAllCrossChainQueryResults(ctx),
}
}
39 changes: 19 additions & 20 deletions modules/apps/31-ibc-query/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName)
}


// IsBound checks if the IBC query module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
Expand Down Expand Up @@ -103,27 +102,27 @@ func (k Keeper) SetNextQuerySequence(ctx sdk.Context, sequence uint64) {
}

// SetSubmitCrossChainQuery stores the MsgSubmitCrossChainQuery in state keyed by the query id
func (k Keeper) SetSubmitCrossChainQuery(ctx sdk.Context, query types.MsgSubmitCrossChainQuery) {
func (k Keeper) SetCrossChainQuery(ctx sdk.Context, query types.CrossChainQuery) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.QueryKey)
bz := k.MustMarshalQuery(&query)
store.Set(host.QueryKey(query.Id), bz)
}

// GetSubmitCrossChainQuery retrieve the MsgSubmitCrossChainQuery stored in state given the query id
func (k Keeper) GetSubmitCrossChainQuery(ctx sdk.Context, queryId string) (types.MsgSubmitCrossChainQuery, bool) {
func (k Keeper) GetCrossChainQuery(ctx sdk.Context, queryId string) (types.CrossChainQuery, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.QueryKey)
key := host.QueryKey(queryId)
bz := store.Get(key)
if bz == nil {
return types.MsgSubmitCrossChainQuery{}, false
return types.CrossChainQuery{}, false
}

return k.MustUnmarshalQuery(bz), true
}

// GetAllSubmitCrossChainQueries returns a list of all MsgSubmitCrossChainQueries that are stored in state
func (k Keeper) GetAllSubmitCrossChainQueries(ctx sdk.Context) []*types.MsgSubmitCrossChainQuery {
var crossChainQueries []*types.MsgSubmitCrossChainQuery
func (k Keeper) GetAllCrossChainQueries(ctx sdk.Context) []*types.CrossChainQuery {
var crossChainQueries []*types.CrossChainQuery
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.QueryKey)

Expand All @@ -138,7 +137,7 @@ func (k Keeper) GetAllSubmitCrossChainQueries(ctx sdk.Context) []*types.MsgSubmi
}

// DeleteCrossChainQuery deletes MsgSubmitCrossChainQuery associated with the query id
func (k Keeper) DeleteSubmitCrossChainQuery(ctx sdk.Context, queryId string) {
func (k Keeper) DeleteCrossChainQuery(ctx sdk.Context, queryId string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.QueryKey)
store.Delete(host.QueryKey(queryId))
}
Expand All @@ -149,27 +148,27 @@ func (k Keeper) DeleteSubmitCrossChainQuery(ctx sdk.Context, queryId string) {
// 2. save query in private store

// SetCrossChainQueryResult stores the CrossChainQueryResult in state keyed by the query id
func (k Keeper) SetSubmitCrossChainQueryResult(ctx sdk.Context, result types.MsgSubmitCrossChainQueryResult) {
func (k Keeper) SetCrossChainQueryResult(ctx sdk.Context, result types.CrossChainQueryResult) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.QueryResultKey)
bz := k.MustMarshalQueryResult(&result)
store.Set(host.QueryResultKey(result.Id), bz)
}

// GetCrossChainQueryResult retrieve the CrossChainQueryResult stored in state given the query id
func (k Keeper) GetCrossChainQueryResult(ctx sdk.Context, queryId string) (types.MsgSubmitCrossChainQueryResult, bool) {
func (k Keeper) GetCrossChainQueryResult(ctx sdk.Context, queryId string) (types.CrossChainQueryResult, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.QueryResultKey)
key := host.QueryResultKey(queryId)
bz := store.Get(key)
if bz == nil {
return types.MsgSubmitCrossChainQueryResult{}, false
return types.CrossChainQueryResult{}, false
}

return k.MustUnmarshalQueryResult(bz), true
}

// GetAllCrossChainQueryResults returns a list of all CrossChainQueryResults that are stored in state
func (k Keeper) GetAllSubmitCrossChainQueryResults(ctx sdk.Context) []*types.MsgSubmitCrossChainQueryResult {
var crossChainQueryResults []*types.MsgSubmitCrossChainQueryResult
func (k Keeper) GetAllCrossChainQueryResults(ctx sdk.Context) []*types.CrossChainQueryResult {
var crossChainQueryResults []*types.CrossChainQueryResult
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.QueryResultKey)

Expand All @@ -184,35 +183,35 @@ func (k Keeper) GetAllSubmitCrossChainQueryResults(ctx sdk.Context) []*types.Msg
}

// DeleteCrossChainQueryResult deletes CrossChainQueryResult associated with the query id
func (k Keeper) DeleteSubmitCrossChainQueryResult(ctx sdk.Context, queryId string) {
func (k Keeper) DeleteCrossChainQueryResult(ctx sdk.Context, queryId string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.QueryResultKey)
store.Delete(host.QueryResultKey(queryId))
}

// MustMarshalQuery attempts to encode a CrossChainQuery object and returns the
// raw encoded bytes. It panics on error.
func (k Keeper) MustMarshalQuery(query *types.MsgSubmitCrossChainQuery) []byte {
func (k Keeper) MustMarshalQuery(query *types.CrossChainQuery) []byte {
return k.cdc.MustMarshal(query)
}

// MustUnmarshalQuery attempts to decode and return a CrossChainQuery object from
// raw encoded bytes. It panics on error.
func (k Keeper) MustUnmarshalQuery(bz []byte) types.MsgSubmitCrossChainQuery {
var query types.MsgSubmitCrossChainQuery
func (k Keeper) MustUnmarshalQuery(bz []byte) types.CrossChainQuery {
var query types.CrossChainQuery
k.cdc.MustUnmarshal(bz, &query)
return query
}

// MustMarshalQuery attempts to encode a CrossChainQuery object and returns the
// raw encoded bytes. It panics on error.
func (k Keeper) MustMarshalQueryResult(result *types.MsgSubmitCrossChainQueryResult) []byte {
func (k Keeper) MustMarshalQueryResult(result *types.CrossChainQueryResult) []byte {
return k.cdc.MustMarshal(result)
}

// MustUnmarshalQuery attempts to decode and return a CrossChainQuery object from
// raw encoded bytes. It panics on error.
func (k Keeper) MustUnmarshalQueryResult(bz []byte) types.MsgSubmitCrossChainQueryResult {
var result types.MsgSubmitCrossChainQueryResult
func (k Keeper) MustUnmarshalQueryResult(bz []byte) types.CrossChainQueryResult {
var result types.CrossChainQueryResult
k.cdc.MustUnmarshal(bz, &result)
return result
}
Expand All @@ -221,4 +220,4 @@ func (k Keeper) MustUnmarshalQueryResult(bz []byte) types.MsgSubmitCrossChainQue
// passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}
}
Loading

0 comments on commit ce4e210

Please sign in to comment.