Skip to content

Commit

Permalink
fix group member key collision issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Aug 9, 2023
1 parent e207200 commit 9f0b70a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions x/permission/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ func GetPolicyByIDKey(policyID math.Uint) []byte {
}

func GroupMembersPrefix(groupID math.Uint) []byte {
return append(GroupMemberPrefix, groupID.Bytes()...)
return append(GroupMemberPrefix, LengthPrefix(groupID.Bytes())...)
}

func GetGroupMemberKey(groupID math.Uint, member sdk.AccAddress) []byte {
return append(GroupMemberPrefix, append(groupID.Bytes(), member.Bytes()...)...)
return append(GroupMemberPrefix, append(LengthPrefix(groupID.Bytes()), member.Bytes()...)...)
}

func GetGroupMemberByIDKey(memberID math.Uint) []byte {
return append(GroupMemberByIDPrefix, memberID.Bytes()...)
}

func LengthPrefix(bz []byte) []byte {
bzLen := len(bz)
if bzLen == 0 {
return bz
}

return append([]byte{byte(bzLen)}, bz...)
}

0 comments on commit 9f0b70a

Please sign in to comment.