Skip to content

Commit

Permalink
issue account capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Aug 8, 2024
1 parent 622118d commit dbc07d3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions migrations/capcons/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ func (m *AccountsCapabilities) ForEach(
}
}
}

func (m *AccountsCapabilities) Get(address common.Address) *AccountCapabilities {
rawAccountCapabilities, ok := m.accountCapabilities.Load(address)
if !ok {
return nil
}
return rawAccountCapabilities.(*AccountCapabilities)
}
22 changes: 22 additions & 0 deletions migrations/capcons/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,28 @@ func testPathCapabilityValueMigration(

handler := &testCapConHandler{}

storageDomainCapabilities := &AccountsCapabilities{}

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
&StorageCapMigration{
StorageDomainCapabilities: storageDomainCapabilities,
},
),
)

storageCapabilities := storageDomainCapabilities.Get(testAddress)
if storageCapabilities != nil {
IssueAccountCapabilities(
inter,
testAddress,
storageCapabilities,
handler,
capabilityMapping,
)
}

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
Expand Down
31 changes: 31 additions & 0 deletions migrations/capcons/storagecapmigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/onflow/cadence/migrations"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/stdlib"
)

// StorageCapMigration records path capabilities with storage domain target.
Expand Down Expand Up @@ -68,3 +70,32 @@ func (m *StorageCapMigration) Migrate(
func (m *StorageCapMigration) CanSkip(valueType interpreter.StaticType) bool {
return CanSkipCapabilityValueMigration(valueType)
}

func IssueAccountCapabilities(
inter *interpreter.Interpreter,
address common.Address,
capabilities *AccountCapabilities,
handler stdlib.CapabilityControllerIssueHandler,
mapping *CapabilityMapping,
) {

for _, capability := range capabilities.Capabilities {
borrowType := inter.MustConvertStaticToSemaType(capability.BorrowType).(*sema.ReferenceType)

capabilityID, _ := stdlib.IssueStorageCapabilityController(
inter,
interpreter.EmptyLocationRange,
handler,
address,
borrowType,
capability.Path,
)

addressPath := interpreter.AddressPath{
Address: address,
Path: capability.Path,
}

mapping.Record(addressPath, capabilityID, borrowType)
}
}

0 comments on commit dbc07d3

Please sign in to comment.