Skip to content

Commit

Permalink
fix: Use block time to create relay msg in process payment (#535)
Browse files Browse the repository at this point in the history
* fix: Use unix timestamp to create relay msg in process payment

* time value fix and upgrade handler

* timestamp in relay cli

* return funds im upgrade handler

* remove handler

* pr comment

* gofmt
  • Loading branch information
rbajollari authored Oct 22, 2024
1 parent 87fa35f commit 6b80c67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
30 changes: 6 additions & 24 deletions x/gmp/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetTxCmd() *cobra.Command {

func GetCmdRelay() *cobra.Command {
cmd := &cobra.Command{
Use: `relay [destination-chain] [ojo-contract-address] [timestamp] [denoms] [amount]`,
Use: `relay [destination-chain] [ojo-contract-address] [denoms] [amount]`,
Args: cobra.ExactArgs(5),
Short: "Relay oracle data via Axelar GMP",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -52,9 +52,6 @@ func GetCmdRelay() *cobra.Command {
return fmt.Errorf("ojo-contract-address cannot be empty")
}
if args[2] == "" {
return fmt.Errorf("timestamp cannot be empty")
}
if args[3] == "" {
return fmt.Errorf("denoms cannot be empty")
}

Expand All @@ -73,13 +70,7 @@ func GetCmdRelay() *cobra.Command {
}

// convert denoms to string array
denoms := strings.Split(args[3], ",")

// convert timestamp string to int64
timestamp, err := strconv.ParseInt(args[2], 10, 64)
if err != nil {
return err
}
denoms := strings.Split(args[2], ",")

commandSelector, err := base64.StdEncoding.DecodeString("")
if err != nil {
Expand All @@ -99,7 +90,7 @@ func GetCmdRelay() *cobra.Command {
denoms, // denoms
commandSelector, // command-selector
commandParams, // command-params
timestamp, // timestamp
0,
)
err = msg.ValidateBasic()
if err != nil {
Expand All @@ -118,7 +109,7 @@ func GetCmdRelay() *cobra.Command {
func GetCmdRelayWithContractCall() *cobra.Command {
cmd := &cobra.Command{
Use: `relay-with-contract-call [destination-chain] [ojo-contract-address] [client-contract-address] ` +
`[command-selector] [command-params] [timestamp] [denoms] [amount]`,
`[command-selector] [command-params] [denoms] [amount]`,
Args: cobra.ExactArgs(8),
Short: "Relay oracle data via Axelar GMP and call contract method with oracle data",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -143,9 +134,6 @@ func GetCmdRelayWithContractCall() *cobra.Command {
return fmt.Errorf("command-params cannot be empty")
}
if args[5] == "" {
return fmt.Errorf("timestamp cannot be empty")
}
if args[6] == "" {
return fmt.Errorf("denoms cannot be empty")
}

Expand All @@ -164,13 +152,7 @@ func GetCmdRelayWithContractCall() *cobra.Command {
}

// convert denoms to string array
denoms := strings.Split(args[6], ",")

// convert timestamp string to int64
timestamp, err := strconv.ParseInt(args[5], 10, 64)
if err != nil {
return err
}
denoms := strings.Split(args[5], ",")

commandSelector, err := base64.StdEncoding.DecodeString(args[3])
if err != nil {
Expand All @@ -190,7 +172,7 @@ func GetCmdRelayWithContractCall() *cobra.Command {
denoms, // denoms
commandSelector, // command-selector
commandParams, // command-params
timestamp, // timestamp
0,
)
err = msg.ValidateBasic()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion x/gmp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func (k Keeper) RelayPrice(
ctx := sdk.UnwrapSDKContext(goCtx)
params := k.GetParams(ctx)

// set the timestamp to the current block time
msg.Timestamp = ctx.BlockTime().Unix()

bz, err := msg.Marshal()
if err != nil {
return nil, err
Expand Down Expand Up @@ -299,7 +302,7 @@ func (k Keeper) ProcessPayment(
[]string{payment.Denom},
types.EmptyByteSlice,
types.EmptyByteSlice,
ctx.BlockHeight(),
0,
)
_, err = k.RelayPrice(goCtx, msg)
if err != nil {
Expand Down

0 comments on commit 6b80c67

Please sign in to comment.