Skip to content

Commit

Permalink
parse vault public key
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jun 18, 2024
1 parent 6b698f7 commit c05abc7
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions x/btcbridge/types/params.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package types

import sdk "github.com/cosmos/cosmos-sdk/types"
import (
"encoding/hex"
"encoding/json"

"github.com/cosmos/cosmos-sdk/crypto/keys/segwit"

Check failure on line 7 in x/btcbridge/types/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

github.com/cosmos/[email protected]: replacement directory ../cosmos-sdk does not exist
sdk "github.com/cosmos/cosmos-sdk/types"
)

// NewParams creates a new Params instance
func NewParams(relayers []string) Params {
Expand Down Expand Up @@ -61,10 +67,30 @@ func SelectVaultByBitcoinAddress(vaults []*Vault, address string) *Vault {
// returns the vault if the public key is found
func SelectVaultByPubKey(vaults []*Vault, pubKey string) *Vault {
for _, v := range vaults {
if v.PubKey == pubKey {
if ParseVaultPubKey(v) == pubKey {
return v
}
}

return nil
}

// ParseVaultPubKey parses the given vault public key
// Note: return empty if any error occured
func ParseVaultPubKey(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 = json.Unmarshal([]byte(pubKey), &pk)
if err != nil {
return ""
}

return hex.EncodeToString(pk.Bytes())
}

0 comments on commit c05abc7

Please sign in to comment.