diff --git a/x/btcbridge/keeper/keeper_withdraw.go b/x/btcbridge/keeper/keeper_withdraw.go index e6b7e52..6071e71 100644 --- a/x/btcbridge/keeper/keeper_withdraw.go +++ b/x/btcbridge/keeper/keeper_withdraw.go @@ -191,7 +191,7 @@ func (k Keeper) ProcessBitcoinWithdrawTransaction(ctx sdk.Context, msg *types.Ms senderPubKey := uTx.MsgTx().TxIn[0].Witness[1] // check if the first sender is one of the vault addresses - vault := types.SelectVaultByPubKey(param.Vaults, hex.EncodeToString(senderPubKey)) + vault := types.SelectVaultByPubKey(k.cdc, param.Vaults, hex.EncodeToString(senderPubKey)) if vault == nil { return types.ErrInvalidSenders } diff --git a/x/btcbridge/types/params.go b/x/btcbridge/types/params.go index f6d8dc7..a741392 100644 --- a/x/btcbridge/types/params.go +++ b/x/btcbridge/types/params.go @@ -1,6 +1,12 @@ package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + "encoding/hex" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/segwit" + sdk "github.com/cosmos/cosmos-sdk/types" +) // NewParams creates a new Params instance func NewParams(relayers []string) Params { @@ -59,12 +65,32 @@ func SelectVaultByBitcoinAddress(vaults []*Vault, address string) *Vault { // SelectVaultByPubKey returns the vault if the public key is found // returns the vault if the public key is found -func SelectVaultByPubKey(vaults []*Vault, pubKey string) *Vault { +func SelectVaultByPubKey(cdc codec.BinaryCodec, vaults []*Vault, pubKey string) *Vault { for _, v := range vaults { - if v.PubKey == pubKey { + if ParseVaultPubKey(cdc, v) == pubKey { return v } } return nil } + +// ParseVaultPubKey parses the given vault public key +// Note: return empty if any error occured +func ParseVaultPubKey(cdc codec.BinaryCodec, vault *Vault) string { + pubKey := vault.PubKey + + _, err := hex.DecodeString(pubKey) + if err == nil { + // pub key is hex encoded + return pubKey + } + + var pk segwit.PubKey + err = cdc.Unmarshal([]byte(pubKey), &pk) + if err != nil { + return "" + } + + return hex.EncodeToString(pk.Bytes()) +}