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

Add withdraw btc cmd to cli #83

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions x/btcbridge/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"

Expand All @@ -12,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"

// "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/sideprotocol/side/x/btcbridge/types"
Expand All @@ -38,6 +40,8 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdUpdateSenders())
// this line is used by starport scaffolding # 1

cmd.AddCommand(CmdWithdrawBitcoin())

return cmd
}

Expand Down Expand Up @@ -109,6 +113,47 @@ func CmdUpdateSenders() *cobra.Command {
return cmd
}

// Withdraw Bitcoin
func CmdWithdrawBitcoin() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-bitcoin [sender] [amount] [fee-rate]",
Short: "Withdraw bitcoin to the given sender",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

_, err = sdk.ParseCoinsNormalized(args[1])
if err != nil {
return fmt.Errorf("invalid amount")
}

feeRate, err := strconv.ParseInt(args[2], 10, 64)
if err != nil {
return fmt.Errorf("invalid fee rate")
}

msg := types.NewMsgWithdrawBitcoinRequest(
args[0],
args[1],
feeRate,
)

if err := msg.ValidateBasic(); err != nil {
return err
}

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

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// readBlockHeadersFromFile reads the block headers from the file
func readBlockHeadersFromFile(filePath string) ([]*types.BlockHeader, error) {
// read the file
Expand Down
Loading