Skip to content

Commit

Permalink
fix: Chain lookup done even when network prefix in chain ID is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Nikolashyn committed Jul 25, 2024
1 parent 2bd07e7 commit 057a002
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/isc/chainid.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ func ChainIDFromBytes(data []byte) (ret ChainID, err error) {
}

func ChainIDFromString(bech32 string) (ChainID, error) {
_, addr, err := iotago.ParseBech32(bech32)
netPrefix, addr, err := iotago.ParseBech32(bech32)
if err != nil {
return ChainID{}, err
}
if addr.Type() != iotago.AddressAlias {
return ChainID{}, fmt.Errorf("chainID must be an alias address (%s)", bech32)
}

expectedNetPrefix := parameters.L1().Protocol.Bech32HRP
if netPrefix != expectedNetPrefix {
return ChainID{}, fmt.Errorf("invalid network prefix: %s", netPrefix)
}

return ChainIDFromAddress(addr.(*iotago.AliasAddress)), nil
}

Expand Down Expand Up @@ -121,6 +127,10 @@ func (id ChainID) ShortString() string {

// String human-readable form (bech32)
func (id ChainID) String() string {
if id.Empty() {
return ""
}

return id.AsAddress().Bech32(parameters.L1().Protocol.Bech32HRP)
}

Expand Down

0 comments on commit 057a002

Please sign in to comment.