Skip to content

Commit

Permalink
feat(btclightclient): add fee rate related implementation in the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
secp256r1 committed Apr 2, 2024
1 parent fbef5c5 commit 7f46c02
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
26 changes: 26 additions & 0 deletions x/btclightclient/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func GetQueryCmd(_ string) *cobra.Command {
cmd.AddCommand(CmdTip())
cmd.AddCommand(CmdBaseHeader())
cmd.AddCommand(CmdHeaderDepth())
cmd.AddCommand(CmdFeeRate())
cmd.AddCommand(CmdQueryParams())

return cmd
Expand Down Expand Up @@ -200,6 +201,31 @@ func CmdHeaderDepth() *cobra.Command {
return cmd
}

func CmdFeeRate() *cobra.Command {
cmd := &cobra.Command{
Use: "fee-rate",
Short: "get bitcoin fee rate",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

params := types.NewQueryFeeRateRequest()
res, err := queryClient.FeeRate(context.Background(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Expand Down
27 changes: 27 additions & 0 deletions x/btclightclient/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"

"github.com/Lorenzo-Protocol/lorenzo/x/btclightclient/types"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -21,6 +22,7 @@ func GetTxCmd() *cobra.Command {
}

cmd.AddCommand(CmdTxInsertHeader())
cmd.AddCommand(CmdTxUpdateFeeRate())

return cmd
}
Expand Down Expand Up @@ -49,3 +51,28 @@ func CmdTxInsertHeader() *cobra.Command {

return cmd
}

func CmdTxUpdateFeeRate() *cobra.Command {
cmd := &cobra.Command{
Use: "update-fee-rate fee-rate",
Short: "submit bitcoin fee rate",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

feeRate, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
msg := types.MsgUpdateFeeRate{Signer: clientCtx.GetFromAddress().String(), FeeRate: feeRate}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
4 changes: 4 additions & 0 deletions x/btclightclient/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ func NewQueryTipRequest() *QueryTipRequest {
func NewQueryBaseHeaderRequest() *QueryBaseHeaderRequest {
return &QueryBaseHeaderRequest{}
}

func NewQueryFeeRateRequest() *QueryFeeRateRequest {
return &QueryFeeRateRequest{}
}

0 comments on commit 7f46c02

Please sign in to comment.