Skip to content

Commit

Permalink
enhance vault type check
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jan 3, 2025
1 parent 33b6d2e commit 43dfc21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
5 changes: 5 additions & 0 deletions x/btcbridge/types/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ func AssetTypeFromDenom(denom string, p Params) AssetType {

return AssetType_ASSET_TYPE_UNSPECIFIED
}

// SupportedAssetTypes returns the currently supported asset types
func SupportedAssetTypes() []AssetType {
return []AssetType{AssetType_ASSET_TYPE_BTC, AssetType_ASSET_TYPE_RUNES}
}
19 changes: 3 additions & 16 deletions x/btcbridge/types/msg_initiate_dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"encoding/base64"
"slices"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand Down Expand Up @@ -43,22 +44,8 @@ func (m *MsgInitiateDKG) ValidateBasic() error {
participants[p.ConsensusPubkey] = true
}

if len(m.VaultTypes) == 0 {
return errorsmod.Wrap(ErrInvalidDKGParams, "vault types can not be empty")
}

vaultTypes := make(map[AssetType]bool)

for _, t := range m.VaultTypes {
if t == AssetType_ASSET_TYPE_UNSPECIFIED {
return errorsmod.Wrap(ErrInvalidDKGParams, "invalid vault type")
}

if vaultTypes[t] {
return errorsmod.Wrap(ErrInvalidDKGParams, "duplicate vault type")
}

vaultTypes[t] = true
if !slices.Equal(m.VaultTypes, SupportedAssetTypes()) {
return errorsmod.Wrap(ErrInvalidDKGParams, "incorrect vault types")
}

if m.EnableTransfer {
Expand Down

0 comments on commit 43dfc21

Please sign in to comment.