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

Change fee rate type #100

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion proto/side/btcbridge/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ message MsgWithdrawBitcoinRequest {
// withdraw amount in satoshi, etc: 100000000sat = 1btc
string amount = 2;
// fee rate in sats/vB
int64 fee_rate = 3;
string fee_rate = 3;
}

// MsgWithdrawBitcoinResponse defines the Msg/WithdrawBitcoin response type.
Expand Down
8 changes: 1 addition & 7 deletions x/btcbridge/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -51,7 +50,7 @@
Short: "Submit Bitcoin block headers to the chain",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {

Check failure on line 53 in x/btcbridge/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
Expand Down Expand Up @@ -130,15 +129,10 @@
return fmt.Errorf("invalid amount")
}

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

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

if err := msg.ValidateBasic(); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion x/btcbridge/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bytes"
"context"
"encoding/base64"
"strconv"

"github.com/btcsuite/btcd/btcutil/psbt"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -72,7 +73,7 @@
)

return &types.MsgSubmitDepositTransactionResponse{}, nil

Check failure on line 76 in x/btcbridge/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
}

// SubmitTransaction implements types.MsgServer.
Expand Down Expand Up @@ -101,7 +102,7 @@
)

return &types.MsgSubmitWithdrawTransactionResponse{}, nil

Check failure on line 105 in x/btcbridge/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
}

// UpdateSenders implements types.MsgServer.
Expand Down Expand Up @@ -142,7 +143,12 @@
return nil, err
}

req, err := m.Keeper.NewSigningRequest(ctx, msg.Sender, coin, msg.FeeRate, "")
feeRate, err := strconv.ParseInt(msg.FeeRate, 10, 64)
if err != nil {
return nil, err
}

req, err := m.Keeper.NewSigningRequest(ctx, msg.Sender, coin, feeRate, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -200,7 +206,7 @@
m.SetSigningRequest(ctx, request)

return &types.MsgSubmitWithdrawSignaturesResponse{}, nil

Check failure on line 209 in x/btcbridge/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
}

func (m msgServer) SubmitWithdrawStatus(goCtx context.Context, msg *types.MsgSubmitWithdrawStatusRequest) (*types.MsgSubmitWithdrawStatusResponse, error) {
Expand Down
11 changes: 9 additions & 2 deletions x/btcbridge/types/message_withdraw_bitcoin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"strconv"

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -10,7 +12,7 @@ const TypeMsgWithdrawBitcoin = "withdraw_bitcoin"
func NewMsgWithdrawBitcoinRequest(
sender string,
amount string,
feeRate int64,
feeRate string,
) *MsgWithdrawBitcoinRequest {
return &MsgWithdrawBitcoinRequest{
Sender: sender,
Expand Down Expand Up @@ -56,7 +58,12 @@ func (msg *MsgWithdrawBitcoinRequest) ValidateBasic() error {
return err
}

if msg.FeeRate <= 0 {
feeRate, err := strconv.ParseInt(msg.FeeRate, 10, 64)
if err != nil {
return err
}

if feeRate <= 0 {
return sdkerrors.Wrap(ErrInvalidFeeRate, "fee rate must be greater than zero")
}

Expand Down
72 changes: 44 additions & 28 deletions x/btcbridge/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading