Skip to content

Commit

Permalink
readd tracker IDs to permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormil committed Jan 22, 2024
1 parent 8fb7df5 commit ec5f1db
Show file tree
Hide file tree
Showing 12 changed files with 757 additions and 136 deletions.
58 changes: 48 additions & 10 deletions proto/badges/permissions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,30 @@ message CollectionApprovalPermission {
// Specifies the ownership times for the badges in the transfer.
repeated UintRange ownershipTimes = 6;

// Identifier for the amountTrackerId. You can use "All" or "!trackerId" for shorthand.
// If you use "All", this approval will match to all amountTrackerIds.
// If you use "!trackerId", this approval will match to all amountTrackerIds except for trackerId.
// If you use "trackerId", this approval will match to only the specified trackerId and fail on all others.
string amountTrackerId = 7;

// Identifier for the challengeTrackerId. You can use "All" or "!trackerId" for shorthand.
// If you use "All", this approval will match to all challengeTrackerIds.
// If you use "!trackerId", this approval will match to all challengeTrackerIds except for trackerId.
// If you use "trackerId", this approval will match to only the specified trackerId and fail on all others.
string challengeTrackerId = 8;


// Identifier for the approvalId. You can use "All" or "!approvalId" for shorthand.
// If you use "All", this approval will match to all approvalIds.
// If you use "!approvalId", this approval will match to all approvalIds except for approvalId.
// If you use "approvalId", this approval will match to only the specified approvalId and fail on all others.
string approvalId = 7;
string approvalId = 9;

// Specifies the times when this permission is permitted. Can not overlap with permanentlyForbiddenTimes.
repeated UintRange permanentlyPermittedTimes = 8;
repeated UintRange permanentlyPermittedTimes = 10;

// Specifies the times when this permission is forbidden. Can not overlap with permanentlyPermittedTimes.
repeated UintRange permanentlyForbiddenTimes = 9;
repeated UintRange permanentlyForbiddenTimes = 11;
}


Expand All @@ -157,17 +170,31 @@ message UserOutgoingApprovalPermission {
// Specifies the ownership times for the badges in the transfer.
repeated UintRange ownershipTimes = 5;

// Identifier for the amountTrackerId. You can use "All" or "!trackerId" for shorthand.
// If you use "All", this approval will match to all amountTrackerIds.
// If you use "!trackerId", this approval will match to all amountTrackerIds except for trackerId.
// If you use "trackerId", this approval will match to only the specified trackerId and fail on all others.
string amountTrackerId = 6;

// Identifier for the challengeTrackerId. You can use "All" or "!trackerId" for shorthand.
// If you use "All", this approval will match to all challengeTrackerIds.
// If you use "!trackerId", this approval will match to all challengeTrackerIds except for trackerId.
// If you use "trackerId", this approval will match to only the specified trackerId and fail on all others.
string challengeTrackerId = 7;


// Identifier for the approvalId. You can use "All" or "!approvalId" for shorthand.
// If you use "All", this approval will match to all approvalIds.
// If you use "!approvalId", this approval will match to all approvalIds except for approvalId.
// If you use "approvalId", this approval will match to only the specified approvalId and fail on all others.
string approvalId = 6;
string approvalId = 8;


// Specifies the times when this permission is permitted. Can not overlap with permanentlyForbiddenTimes.
repeated UintRange permanentlyPermittedTimes = 7;
repeated UintRange permanentlyPermittedTimes = 9;

// Specifies the times when this permission is forbidden. Can not overlap with permanentlyPermittedTimes.
repeated UintRange permanentlyForbiddenTimes = 8;
repeated UintRange permanentlyForbiddenTimes = 10;
}

/*
Expand All @@ -191,18 +218,29 @@ message UserIncomingApprovalPermission {
// Specifies the ownership times for the badges in the transfer.
repeated UintRange ownershipTimes = 5;

// Identifier for the amountTrackerId. You can use "All" or "!trackerId" for shorthand.
// If you use "All", this approval will match to all amountTrackerIds.
// If you use "!trackerId", this approval will match to all amountTrackerIds except for trackerId.
// If you use "trackerId", this approval will match to only the specified trackerId and fail on all others.
string amountTrackerId = 6;

// Identifier for the challengeTrackerId. You can use "All" or "!trackerId" for shorthand.
// If you use "All", this approval will match to all challengeTrackerIds.
// If you use "!trackerId", this approval will match to all challengeTrackerIds except for trackerId.
// If you use "trackerId", this approval will match to only the specified trackerId and fail on all others.
string challengeTrackerId = 7;

// Identifier for the approvalId. You can use "All" or "!approvalId" for shorthand.
// If you use "All", this approval will match to all approvalIds.
// If you use "!approvalId", this approval will match to all approvalIds except for approvalId.
// If you use "approvalId", this approval will match to only the specified approvalId and fail on all others.
string approvalId = 6;

string approvalId = 8;

// Specifies the times when this permission is permitted. Can not overlap with permanentlyForbiddenTimes.
repeated UintRange permanentlyPermittedTimes = 7;
repeated UintRange permanentlyPermittedTimes = 9;

// Specifies the times when this permission is forbidden. Can not overlap with permanentlyPermittedTimes.
repeated UintRange permanentlyForbiddenTimes = 8;
repeated UintRange permanentlyForbiddenTimes = 10;
}

/*
Expand Down
44 changes: 44 additions & 0 deletions x/badges/keeper/permission_casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ func (k Keeper) CastUserIncomingApprovalPermissionToUniversalPermission(ctx sdk.
return nil, err
}

amountTrackerList, err := k.GetTrackerListById(ctx, permission.AmountTrackerId)
if err != nil {
return nil, err
}

challengeTrackerList, err := k.GetTrackerListById(ctx, permission.ChallengeTrackerId)
if err != nil {
return nil, err
}

fromList, err := k.GetAddressListById(ctx, permission.FromListId)
if err != nil {
return nil, err
Expand All @@ -32,13 +42,17 @@ func (k Keeper) CastUserIncomingApprovalPermissionToUniversalPermission(ctx sdk.
FromList: fromList,
InitiatedByList: initiatedByList,
ApprovalIdList: approvalTrackerList,
AmountTrackerIdList: amountTrackerList,
ChallengeTrackerIdList: challengeTrackerList,

UsesBadgeIds: true,
UsesTransferTimes: true,
UsesOwnershipTimes: true,
UsesFromList: true,
UsesInitiatedByList: true,
UsesApprovalId: true,
UsesAmountTrackerId: true,
UsesChallengeTrackerId: true,
PermanentlyPermittedTimes: permission.PermanentlyPermittedTimes,
PermanentlyForbiddenTimes: permission.PermanentlyForbiddenTimes,
})
Expand All @@ -53,6 +67,17 @@ func (k Keeper) CastUserOutgoingApprovalPermissionToUniversalPermission(ctx sdk.
if err != nil {
return nil, err
}

amountTrackerList, err := k.GetTrackerListById(ctx, permission.AmountTrackerId)
if err != nil {
return nil, err
}

challengeTrackerList, err := k.GetTrackerListById(ctx, permission.ChallengeTrackerId)
if err != nil {
return nil, err
}

initiatedByList, err := k.GetAddressListById(ctx, permission.InitiatedByListId)
if err != nil {
return nil, err
Expand All @@ -70,6 +95,10 @@ func (k Keeper) CastUserOutgoingApprovalPermissionToUniversalPermission(ctx sdk.
ToList: toList,
InitiatedByList: initiatedByList,
ApprovalIdList: approvalTrackerList,
AmountTrackerIdList: amountTrackerList,
ChallengeTrackerIdList: challengeTrackerList,
UsesAmountTrackerId: true,
UsesChallengeTrackerId: true,
UsesApprovalId: true,
UsesBadgeIds: true,
UsesTransferTimes: true,
Expand Down Expand Up @@ -105,6 +134,17 @@ func (k Keeper) CastCollectionApprovalPermissionToUniversalPermission(ctx sdk.Co
}


amountTrackerList, err := k.GetTrackerListById(ctx, collectionUpdatePermission.AmountTrackerId)
if err != nil {
return nil, err
}

challengeTrackerList, err := k.GetTrackerListById(ctx, collectionUpdatePermission.ChallengeTrackerId)
if err != nil {
return nil, err
}


fromList, err := k.GetAddressListById(ctx, collectionUpdatePermission.FromListId)
if err != nil {
return nil, err
Expand All @@ -129,6 +169,10 @@ func (k Keeper) CastCollectionApprovalPermissionToUniversalPermission(ctx sdk.Co
InitiatedByList: initiatedByList,
BadgeIds: collectionUpdatePermission.BadgeIds,
ApprovalIdList: approvalTrackerList,
AmountTrackerIdList: amountTrackerList,
ChallengeTrackerIdList: challengeTrackerList,
UsesAmountTrackerId: true,
UsesChallengeTrackerId: true,
UsesApprovalId: true,
UsesBadgeIds: true,
UsesTransferTimes: true,
Expand Down
30 changes: 17 additions & 13 deletions x/badges/keeper/timeline_casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,20 @@ func (k Keeper) CastCollectionApprovalToUniversalPermission(ctx sdk.Context, app
return nil, err
}

//TODO: It can never be "All" right?
approvalTrackerList := &types.AddressList{}
if approval.ApprovalId == "All" {
approvalTrackerList = &types.AddressList{
Addresses: []string{},
Whitelist: false,
}
} else {
approvalTrackerList = &types.AddressList{
Addresses: []string{approval.ApprovalId},
Whitelist: true,
}
approvalTrackerList := &types.AddressList{
Addresses: []string{approval.ApprovalId},
Whitelist: true,
}

amountTrackerList := &types.AddressList{
Addresses: []string{approval.AmountTrackerId},
Whitelist: true,
}


challengeTrackerList := &types.AddressList{
Addresses: []string{approval.ChallengeTrackerId},
Whitelist: true,
}

castedPermissions = append(castedPermissions, &types.UniversalPermission{
BadgeIds: approval.BadgeIds,
Expand All @@ -66,19 +65,24 @@ func (k Keeper) CastCollectionApprovalToUniversalPermission(ctx sdk.Context, app
ToList: toList,
InitiatedByList: initiatedByList,
ApprovalIdList: approvalTrackerList,
AmountTrackerIdList: amountTrackerList,
ChallengeTrackerIdList: challengeTrackerList,
UsesBadgeIds: true,
UsesTransferTimes: true,
UsesToList: true,
UsesFromList: true,
UsesInitiatedByList: true,
UsesOwnershipTimes: true,
UsesApprovalId: true,
UsesAmountTrackerId: true,
UsesChallengeTrackerId: true,
ArbitraryValue: approval,
})
}
return castedPermissions, nil
}
//TODO: Unused currently .... keep?
//TODO: Note tracker ids may be msising when i uncomment
// func (k Keeper) CastUserOutgoingApprovalToUniversalPermission(ctx sdk.Context, approvals []*types.UserOutgoingApproval) ([]*types.UniversalPermission, error) {
// castedPermissions := []*types.UniversalPermission{}
// for _, approval := range approvals {
Expand Down
16 changes: 15 additions & 1 deletion x/badges/keeper/update_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func GetUpdateCombinationsToCheck(
FromList: detailToAdd.FromList,
InitiatedByList: detailToAdd.InitiatedByList,
ApprovalIdList: detailToAdd.ApprovalIdList,
AmountTrackerIdList: detailToAdd.AmountTrackerIdList,
ChallengeTrackerIdList: detailToAdd.ChallengeTrackerIdList,
})
}
}
Expand All @@ -68,6 +70,8 @@ func GetUpdateCombinationsToCheck(
FromList: detailToAdd.FromList,
InitiatedByList: detailToAdd.InitiatedByList,
ApprovalIdList: detailToAdd.ApprovalIdList,
AmountTrackerIdList: detailToAdd.AmountTrackerIdList,
ChallengeTrackerIdList: detailToAdd.ChallengeTrackerIdList,
})
}
}
Expand All @@ -91,6 +95,8 @@ func GetUpdateCombinationsToCheck(
FromList: detailToAdd.FromList,
InitiatedByList: detailToAdd.InitiatedByList,
ApprovalIdList: detailToAdd.ApprovalIdList,
AmountTrackerIdList: detailToAdd.AmountTrackerIdList,
ChallengeTrackerIdList: detailToAdd.ChallengeTrackerIdList,
})
}
}
Expand Down Expand Up @@ -216,7 +222,15 @@ func CheckNotForbiddenForAllOverlaps(ctx sdk.Context, permissionDetails []*types
if detailToCheck.ApprovalIdList == nil {
detailToCheck.ApprovalIdList = &types.AddressList{Addresses: []string{}, Whitelist: false}
}


if detailToCheck.AmountTrackerIdList == nil {
detailToCheck.AmountTrackerIdList = &types.AddressList{Addresses: []string{}, Whitelist: false}
}

if detailToCheck.ChallengeTrackerIdList == nil {
detailToCheck.ChallengeTrackerIdList = &types.AddressList{Addresses: []string{}, Whitelist: false}
}

if detailToCheck.ToList == nil {
detailToCheck.ToList = &types.AddressList{Addresses: []string{}, Whitelist: false}
}
Expand Down
18 changes: 6 additions & 12 deletions x/badges/keeper/update_checks_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func GetPotentialUpdatesForTimelineValues(times [][]*types.UintRange, values []i
// Make a struct witha bool flag isApproved and an approval details arr
type ApprovalCriteriaWithIsApproved struct {
ApprovalCriteria *types.ApprovalCriteria
AmountTrackerId string
ChallengeTrackerId string
}

func GetFirstMatchOnlyWithApprovalCriteria(permissions []*types.UniversalPermission) []*types.UniversalPermissionDetails {
Expand All @@ -76,6 +74,8 @@ func GetFirstMatchOnlyWithApprovalCriteria(permissions []*types.UniversalPermiss
initiatedByList := types.GetListWithOptions(permission.InitiatedByList, permission.UsesInitiatedByList)

approvalIdList := types.GetListWithOptions(permission.ApprovalIdList, permission.UsesApprovalId)
amountTrackerIdList := types.GetListWithOptions(permission.AmountTrackerIdList, permission.UsesAmountTrackerId)
challengeTrackerIdList := types.GetListWithOptions(permission.ChallengeTrackerIdList, permission.UsesChallengeTrackerId)

for _, badgeId := range badgeIds {
for _, timelineTime := range timelineTimes {
Expand All @@ -84,8 +84,6 @@ func GetFirstMatchOnlyWithApprovalCriteria(permissions []*types.UniversalPermiss
arbValue := []*ApprovalCriteriaWithIsApproved{
{
ApprovalCriteria: permission.ArbitraryValue.(*types.CollectionApproval).ApprovalCriteria,
AmountTrackerId: permission.ArbitraryValue.(*types.CollectionApproval).AmountTrackerId,
ChallengeTrackerId: permission.ArbitraryValue.(*types.CollectionApproval).ChallengeTrackerId,
},
}

Expand All @@ -99,6 +97,8 @@ func GetFirstMatchOnlyWithApprovalCriteria(permissions []*types.UniversalPermiss
FromList: fromList,
InitiatedByList: initiatedByList,
ApprovalIdList: approvalIdList,
AmountTrackerIdList: amountTrackerIdList,
ChallengeTrackerIdList: challengeTrackerIdList,

ArbitraryValue: arbValue,
},
Expand Down Expand Up @@ -130,6 +130,8 @@ func GetFirstMatchOnlyWithApprovalCriteria(permissions []*types.UniversalPermiss
InitiatedByList: overlap.Overlap.InitiatedByList,

ApprovalIdList: overlap.Overlap.ApprovalIdList,
AmountTrackerIdList: overlap.Overlap.AmountTrackerIdList,
ChallengeTrackerIdList: overlap.Overlap.ChallengeTrackerIdList,

//Appended for future lookups (not involved in overlap logic)
PermanentlyPermittedTimes: permanentlyPermittedTimes,
Expand Down Expand Up @@ -249,14 +251,6 @@ func (k Keeper) GetDetailsToCheck(ctx sdk.Context, collection *types.BadgeCollec
if proto.MarshalTextString(oldApprovalCriteria) != proto.MarshalTextString(newApprovalCriteria) {
different = true
}

if oldVal[i].AmountTrackerId != newVal[i].AmountTrackerId {
different = true
}

if oldVal[i].ChallengeTrackerId != newVal[i].ChallengeTrackerId {
different = true
}
}
}
}
Expand Down
Loading

0 comments on commit ec5f1db

Please sign in to comment.