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 79205a1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions x/permission/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,23 @@ func GetPolicyByIDKey(policyID math.Uint) []byte {
}

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

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

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

func LengthPrefix(id math.Uint) []byte {
bz := id.Bytes()
bzLen := len(bz)
if bzLen == 0 {
return bz
}

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

0 comments on commit 79205a1

Please sign in to comment.