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

Commit

Permalink
user transaction process
Browse files Browse the repository at this point in the history
  • Loading branch information
sujine2 authored and boosik committed Sep 5, 2022
1 parent c87dbdd commit 16fbd89
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
66 changes: 66 additions & 0 deletions modules/apps/31-ibc-query/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
package cli

import (
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"

"github.com/cosmos/ibc-go/v4/modules/apps/31-ibc-query/client/utils"
"github.com/cosmos/ibc-go/v4/modules/apps/31-ibc-query/types"
clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
)

const (
flagPacketTimeoutHeight = "packet-timeout-height"
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
flagAbsoluteTimeouts = "absolute-timeouts"
)

func NewMsgCrossChainQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cross-chain-query [client-id] [query-path]",
Short: "Request ibc query on a given channel.",
Long: strings.TrimSpace(`Register a payee address on a given channel.`),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

creator := clientCtx.GetFromAddress().String()
queryId := utils.GetQueryIdentifier()

clientId := args[0]
path := args[1]

//TODO
// Get chain height from queried chain
temporaryQueryHeight := uint64(123)

timeoutHeightStr, err := cmd.Flags().GetString(flagPacketTimeoutHeight)
if err != nil {
return err
}
timeoutHeight, err := clienttypes.ParseHeight(timeoutHeightStr)
if err != nil {
return err
}

timeoutTimestamp, err := cmd.Flags().GetUint64(flagPacketTimeoutTimestamp)
if err != nil {
return err
}

msg := types.NewMsgSubmitCrossChainQuery(queryId, path, timeoutHeight.RevisionHeight, timeoutTimestamp, temporaryQueryHeight, clientId, creator)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
12 changes: 12 additions & 0 deletions modules/apps/31-ibc-query/client/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v4/modules/apps/31-ibc-query/keeper"
)


func GetQueryIdentifier() string {
return keeper.Keeper.GenerateQueryIdentifier(keeper.Keeper{}, sdk.Context{})
}

36 changes: 36 additions & 0 deletions modules/apps/31-ibc-query/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,42 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName)
}

func (k Keeper) GenerateQueryIdentifier(ctx sdk.Context) string {
nextQuerySeq := k.GetNextQuerySequence(ctx)
queryID := types.FormatQueryIdentifier(nextQuerySeq)

nextQuerySeq++
k.SetNextQuerySequence(ctx, nextQuerySeq)
return queryID
}


func (k Keeper) GetNextQuerySequence(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.KeyNextQuerySequence))
if bz == nil {
panic("next connection sequence is nil")
}

return sdk.BigEndianToUint64(bz)
}

func (k Keeper) SetNextQuerySequence(ctx sdk.Context, sequence uint64) {
store := ctx.KVStore(k.storeKey)
bz := sdk.Uint64ToBigEndian(sequence)
store.Set([]byte(types.KeyNextQuerySequence), bz)
}

func (k Keeper) SetQuery(ctx sdk.Context, query types.MsgSubmitCrossChainQuery) string {
store := ctx.KVStore(k.storeKey)
appendedValue := k.cdc.MustMarshal(&query)

store.Set([]byte(host.QueryPath(query.Id)), appendedValue)

return query.Id
}


// TODO
// func handleIbcQuery
// 1. set unique query Id
Expand Down

0 comments on commit 16fbd89

Please sign in to comment.