Skip to content

Commit

Permalink
Merge pull request #90 from sideprotocol/ping/feat/update-fee-rate
Browse files Browse the repository at this point in the history
Ping/feat/update fee rate
  • Loading branch information
liangping authored Jun 21, 2024
2 parents e70c608 + 2e68c99 commit bb5d80a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 36 deletions.
4 changes: 2 additions & 2 deletions local_node_dev.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

KEYS=("dev0" "dev1" "dev2")
KEYS=("validator" "user" "relayer")
CHAINID="devnet"
MONIKER="Side Labs"
BINARY="$HOME/go/bin/sided"
DENOM_STR="uside,sat"
DENOM_STR="uside,uusdt"
INITIAL_ACCOUNT_STR=""
set -f
IFS=,
Expand Down
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
6 changes: 4 additions & 2 deletions x/btcbridge/keeper/keeper_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func (k Keeper) NewSigningRequest(ctx sdk.Context, sender string, coin sdk.Coin,
k.LockUTXOs(ctx, selectedUTXOs)

// save the change utxo and mark minted
k.saveUTXO(ctx, changeUTXO)
k.addToMintHistory(ctx, psbt.UnsignedTx.TxHash().String())
if changeUTXO != nil {
k.saveUTXO(ctx, changeUTXO)
k.addToMintHistory(ctx, psbt.UnsignedTx.TxHash().String())
}

signingRequest := &types.BitcoinSigningRequest{
Address: sender,
Expand Down
12 changes: 11 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 @@ import (
"bytes"
"context"
"encoding/base64"
"strconv"

"github.com/btcsuite/btcd/btcutil/psbt"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -137,7 +138,11 @@ func (m msgServer) WithdrawBitcoin(goCtx context.Context, msg *types.MsgWithdraw
return nil, err
}

_, err = m.Keeper.NewSigningRequest(ctx, msg.Sender, coin, msg.FeeRate, "")
feeRate, err := strconv.ParseInt(msg.FeeRate, 10, 64)
if err != nil {
return nil, err
}
_, err = m.Keeper.NewSigningRequest(ctx, msg.Sender, coin, feeRate, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -170,6 +175,11 @@ func (m msgServer) SubmitWithdrawSignatures(goCtx context.Context, msg *types.Ms
if err != nil {
return nil, err
}

if packet.UnsignedTx.TxHash().String() != msg.Txid {
return nil, types.ErrInvalidSignatures
}

if err = packet.SanityCheck(); err != nil {
return nil, err
}
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.

0 comments on commit bb5d80a

Please sign in to comment.