diff --git a/proto/side/btcbridge/tx.proto b/proto/side/btcbridge/tx.proto index 764cfe1..0b373ea 100644 --- a/proto/side/btcbridge/tx.proto +++ b/proto/side/btcbridge/tx.proto @@ -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. diff --git a/x/btcbridge/client/cli/tx.go b/x/btcbridge/client/cli/tx.go index 0b6c85e..d3316ba 100644 --- a/x/btcbridge/client/cli/tx.go +++ b/x/btcbridge/client/cli/tx.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "os" - "strconv" "strings" "time" @@ -130,15 +129,10 @@ func CmdWithdrawBitcoin() *cobra.Command { 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 { diff --git a/x/btcbridge/keeper/msg_server.go b/x/btcbridge/keeper/msg_server.go index 1379ac5..88dcebc 100644 --- a/x/btcbridge/keeper/msg_server.go +++ b/x/btcbridge/keeper/msg_server.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/base64" + "strconv" "github.com/btcsuite/btcd/btcutil/psbt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -142,7 +143,12 @@ func (m msgServer) WithdrawBitcoin(goCtx context.Context, msg *types.MsgWithdraw 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 } diff --git a/x/btcbridge/types/message_withdraw_bitcoin.go b/x/btcbridge/types/message_withdraw_bitcoin.go index 287a412..6889829 100644 --- a/x/btcbridge/types/message_withdraw_bitcoin.go +++ b/x/btcbridge/types/message_withdraw_bitcoin.go @@ -1,6 +1,8 @@ package types import ( + "strconv" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -10,7 +12,7 @@ const TypeMsgWithdrawBitcoin = "withdraw_bitcoin" func NewMsgWithdrawBitcoinRequest( sender string, amount string, - feeRate int64, + feeRate string, ) *MsgWithdrawBitcoinRequest { return &MsgWithdrawBitcoinRequest{ Sender: sender, @@ -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") } diff --git a/x/btcbridge/types/tx.pb.go b/x/btcbridge/types/tx.pb.go index bd83d70..2feb849 100644 --- a/x/btcbridge/types/tx.pb.go +++ b/x/btcbridge/types/tx.pb.go @@ -539,7 +539,7 @@ type MsgWithdrawBitcoinRequest struct { // withdraw amount in satoshi, etc: 100000000sat = 1btc Amount string `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` // fee rate in sats/vB - FeeRate int64 `protobuf:"varint,3,opt,name=fee_rate,json=feeRate,proto3" json:"fee_rate,omitempty"` + FeeRate string `protobuf:"bytes,3,opt,name=fee_rate,json=feeRate,proto3" json:"fee_rate,omitempty"` } func (m *MsgWithdrawBitcoinRequest) Reset() { *m = MsgWithdrawBitcoinRequest{} } @@ -589,11 +589,11 @@ func (m *MsgWithdrawBitcoinRequest) GetAmount() string { return "" } -func (m *MsgWithdrawBitcoinRequest) GetFeeRate() int64 { +func (m *MsgWithdrawBitcoinRequest) GetFeeRate() string { if m != nil { return m.FeeRate } - return 0 + return "" } // MsgWithdrawBitcoinResponse defines the Msg/WithdrawBitcoin response type. @@ -751,7 +751,7 @@ func init() { func init() { proto.RegisterFile("side/btcbridge/tx.proto", fileDescriptor_785ca8e1e4227068) } var fileDescriptor_785ca8e1e4227068 = []byte{ - // 692 bytes of a gzipped FileDescriptorProto + // 690 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcd, 0x4e, 0xdb, 0x40, 0x10, 0xc6, 0x04, 0x02, 0x19, 0x0a, 0x95, 0x56, 0x08, 0x82, 0x01, 0x13, 0x5c, 0x5a, 0xa5, 0xad, 0xea, 0xa8, 0xa1, 0xbd, 0x57, 0x51, 0x0f, 0x5c, 0x72, 0xa8, 0xa1, 0x42, 0xea, 0x25, 0x5a, 0xc7, @@ -780,22 +780,22 @@ var fileDescriptor_785ca8e1e4227068 = []byte{ 0xc3, 0xe7, 0x72, 0x6a, 0xe3, 0x39, 0xeb, 0xb0, 0x1c, 0x2a, 0xa8, 0x5c, 0x95, 0x92, 0x9d, 0xda, 0xe6, 0x81, 0x9c, 0x73, 0x6e, 0x62, 0x55, 0xbe, 0x03, 0x5b, 0x4d, 0xee, 0xdd, 0x10, 0x6c, 0x24, 0x6a, 0x9b, 0x54, 0x76, 0x03, 0x8a, 0xb8, 0xcf, 0x22, 0x5f, 0xa8, 0x3e, 0x29, 0x2b, 0x6e, 0x52, - 0x87, 0x90, 0x56, 0x88, 0x05, 0x91, 0x93, 0x2f, 0xd8, 0x4b, 0x1d, 0x42, 0x6c, 0x2c, 0x88, 0xb9, - 0x03, 0x7a, 0x56, 0x1d, 0xc5, 0xc2, 0x1d, 0xda, 0xc9, 0x54, 0x51, 0xd4, 0xf3, 0xb1, 0x88, 0x42, - 0xf2, 0x4f, 0xd2, 0x46, 0xb0, 0x10, 0x70, 0x47, 0xa8, 0x05, 0x94, 0xe7, 0x3b, 0x8b, 0x94, 0x55, - 0x25, 0x21, 0x53, 0xff, 0x53, 0x84, 0x42, 0x93, 0x7b, 0x28,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1, - 0xa6, 0x08, 0x00, 0x00, + 0x87, 0x90, 0x56, 0x88, 0x05, 0x51, 0x93, 0x5f, 0xea, 0x10, 0x62, 0x63, 0x41, 0xcc, 0x1d, 0xd0, + 0xb3, 0xea, 0x28, 0x16, 0xee, 0xd0, 0x4e, 0xa6, 0x8a, 0xa2, 0x9e, 0x8f, 0x45, 0x14, 0x92, 0x7f, + 0x92, 0x36, 0x82, 0x85, 0x80, 0x3b, 0x42, 0xd1, 0x90, 0xe7, 0x3b, 0x8b, 0x94, 0x55, 0x25, 0x21, + 0x53, 0xff, 0x53, 0x84, 0x42, 0x93, 0x7b, 0x28, 0x00, 0x74, 0x5f, 0x47, 0xe8, 0xf9, 0xa8, 0x16, + 0xc7, 0xe8, 0x5c, 0x7f, 0x31, 0x0d, 0x38, 0xad, 0x8c, 0x2e, 0x34, 0x28, 0xe7, 0xed, 0x39, 0xaa, + 0xe7, 0xe6, 0xca, 0x55, 0xb1, 0x7e, 0x38, 0x53, 0x8c, 0x62, 0xf1, 0x55, 0x83, 0xad, 0xdc, 0xbd, + 0x45, 0xf9, 0x29, 0xf3, 0x35, 0xa7, 0xbf, 0x9a, 0x2d, 0x48, 0x11, 0xf9, 0xa2, 0xc1, 0x66, 0xce, + 0xfe, 0xa2, 0x97, 0x19, 0x19, 0xc7, 0x8b, 0x48, 0xaf, 0xcf, 0x12, 0xa2, 0x28, 0x74, 0xe1, 0xe1, + 0xc8, 0xce, 0xa2, 0xa7, 0x19, 0x69, 0xb2, 0xf5, 0xa3, 0x3f, 0x9b, 0x06, 0x7a, 0x6f, 0xf6, 0xf7, + 0x57, 0x73, 0xcc, 0xec, 0x73, 0xd5, 0xa2, 0x1f, 0xce, 0x14, 0xa3, 0x58, 0x9c, 0xc1, 0x7a, 0xd6, + 0x77, 0x0d, 0x59, 0x93, 0x93, 0x0d, 0x7f, 0x85, 0xf5, 0xda, 0xd4, 0xf8, 0xa4, 0x70, 0xe3, 0xe8, + 0xe7, 0x95, 0xa1, 0x5d, 0x5e, 0x19, 0xda, 0xef, 0x2b, 0x43, 0xfb, 0x7e, 0x6d, 0xcc, 0x5d, 0x5e, + 0x1b, 0x73, 0xbf, 0xae, 0x8d, 0xb9, 0x0f, 0x96, 0x47, 0x45, 0x37, 0x72, 0xac, 0x36, 0xeb, 0xd7, + 0xe2, 0xa4, 0xf2, 0x4f, 0xa0, 0xcd, 0x7a, 0xd2, 0xa8, 0x0d, 0x86, 0xff, 0x43, 0xce, 0x03, 0xc2, + 0x9d, 0xa2, 0x04, 0x1c, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x49, 0x27, 0x26, 0xd6, 0xa6, 0x08, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1481,10 +1481,12 @@ func (m *MsgWithdrawBitcoinRequest) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l - if m.FeeRate != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.FeeRate)) + if len(m.FeeRate) > 0 { + i -= len(m.FeeRate) + copy(dAtA[i:], m.FeeRate) + i = encodeVarintTx(dAtA, i, uint64(len(m.FeeRate))) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x1a } if len(m.Amount) > 0 { i -= len(m.Amount) @@ -1779,8 +1781,9 @@ func (m *MsgWithdrawBitcoinRequest) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.FeeRate != 0 { - n += 1 + sovTx(uint64(m.FeeRate)) + l = len(m.FeeRate) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) } return n } @@ -2925,10 +2928,10 @@ func (m *MsgWithdrawBitcoinRequest) Unmarshal(dAtA []byte) error { m.Amount = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FeeRate", wireType) } - m.FeeRate = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -2938,11 +2941,24 @@ func (m *MsgWithdrawBitcoinRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.FeeRate |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FeeRate = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:])