-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/segwit" | ||
Check failure on line 7 in x/btcbridge/types/params.go GitHub Actions / tests (01)
|
||
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()) | ||
} |