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

Parse vault public key #82

Closed
wants to merge 1 commit into from
Closed
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
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 @@
// 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 GetVaultPubKey(v) == pubKey {
return v
}
}

return nil
}

// GetVaultPubKey gets the public key from the given vault
// Note: return empty if any error occured
func GetVaultPubKey(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())
}
Loading