Skip to content

Commit

Permalink
Merge pull request #2761 from onflow/sainati/account-mapping-include
Browse files Browse the repository at this point in the history
update account type mappings to include identity
  • Loading branch information
dsainati1 authored Sep 1, 2023
2 parents 5442fb5 + cdd1075 commit 4b32c22
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 164 deletions.
48 changes: 2 additions & 46 deletions runtime/sema/account.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -445,38 +445,7 @@ entitlement IssueAccountCapabilityController
/* Entitlement mappings */

entitlement mapping AccountMapping {
// TODO: include Identity
Storage -> Storage
Contracts -> Contracts
Keys -> Keys
Inbox -> Inbox
Capabilities -> Capabilities

SaveValue -> SaveValue
LoadValue -> LoadValue
BorrowValue -> BorrowValue

AddContract -> AddContract
UpdateContract -> UpdateContract
RemoveContract -> RemoveContract

AddKey -> AddKey
RevokeKey -> RevokeKey

PublishInboxCapability -> PublishInboxCapability
UnpublishInboxCapability -> UnpublishInboxCapability

StorageCapabilities -> StorageCapabilities
AccountCapabilities -> AccountCapabilities

GetStorageCapabilityController -> GetStorageCapabilityController
IssueStorageCapabilityController -> IssueStorageCapabilityController

GetAccountCapabilityController -> GetAccountCapabilityController
IssueAccountCapabilityController -> IssueAccountCapabilityController

// ---
include Identity

Storage -> SaveValue
Storage -> LoadValue
Expand All @@ -498,20 +467,7 @@ entitlement mapping AccountMapping {
}

entitlement mapping CapabilitiesMapping {
// TODO: include Identity
Capabilities -> Capabilities

StorageCapabilities -> StorageCapabilities
AccountCapabilities -> AccountCapabilities

GetStorageCapabilityController -> GetStorageCapabilityController
IssueStorageCapabilityController -> IssueStorageCapabilityController

GetAccountCapabilityController -> GetAccountCapabilityController
IssueAccountCapabilityController -> IssueAccountCapabilityController

// ---
include Identity

StorageCapabilities -> GetStorageCapabilityController
StorageCapabilities -> IssueStorageCapabilityController
Expand Down
118 changes: 4 additions & 114 deletions runtime/sema/account.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions runtime/sema/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1732,13 +1732,21 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement
// }
// }

includesIdentity := false
relationExprs := make([]dst.Expr, 0, len(elements))

for _, element := range elements {

relation, ok := element.(*ast.EntitlementMapRelation)
if !ok {
panic(fmt.Errorf("non-relation map element is not supported: %s", element))
relation, isRelation := element.(*ast.EntitlementMapRelation)
include, isInclude := element.(*ast.NominalType)
if !isRelation && !isInclude {
panic(fmt.Errorf("invalid map element: expected relations or include, got '%s'", element))
}
if isInclude && include.Identifier.Identifier == "Identity" {
includesIdentity = true
continue
} else if isInclude {
panic(fmt.Errorf("non-Identity map include is not supported: %s", element))
}

relationExpr := &dst.CompositeLit{
Expand Down Expand Up @@ -1768,6 +1776,7 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement
Type: dst.NewIdent("EntitlementMapType"),
Elts: []dst.Expr{
goKeyValue("Identifier", goStringLit(name)),
goKeyValue("IncludesIdentity", goBoolLit(includesIdentity)),
goKeyValue("Relations", relationsExpr),
},
},
Expand Down
5 changes: 5 additions & 0 deletions runtime/sema/gen/testdata/entitlement.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ entitlement Bar
entitlement mapping Baz {
Foo -> Bar
}

entitlement mapping Qux {
include Identity
Foo -> Bar
}
16 changes: 15 additions & 1 deletion runtime/sema/gen/testdata/entitlement.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b32c22

Please sign in to comment.