Skip to content

Commit

Permalink
update account type mappings to include identity
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Sep 1, 2023
1 parent 978dc9d commit 9b8b4ee
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 161 deletions.
46 changes: 2 additions & 44 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,18 +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

// ---
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.

13 changes: 11 additions & 2 deletions runtime/sema/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1732,14 +1732,22 @@ 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 {
relation, isRelation := element.(*ast.EntitlementMapRelation)
include, isInclude := element.(*ast.NominalType)
if !isRelation && !isInclude {
panic(fmt.Errorf("non-relation map element is not supported: %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{
Type: dst.NewIdent("EntitlementRelation"),
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 9b8b4ee

Please sign in to comment.