From 97ddc3129f3cb6a6ed90f24887f77c21042ddcd1 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Fri, 9 Aug 2024 12:40:12 -0700 Subject: [PATCH] Refactor code --- migrations/capcons/capabilitymigration.go | 10 ---------- migrations/capcons/migration_test.go | 3 ++- migrations/capcons/storagecapmigration.go | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/migrations/capcons/capabilitymigration.go b/migrations/capcons/capabilitymigration.go index 9aa3fb697f..21916bf231 100644 --- a/migrations/capcons/capabilitymigration.go +++ b/migrations/capcons/capabilitymigration.go @@ -37,16 +37,6 @@ type CapabilityMigrationReporter interface { accountAddress common.Address, addressPath interpreter.AddressPath, ) - MissingBorrowType( - accountAddress common.Address, - addressPath interpreter.AddressPath, - ) - IssuedStorageCapability( - accountAddress common.Address, - addressPath interpreter.AddressPath, - borrowType *interpreter.ReferenceStaticType, - capabilityID interpreter.UInt64Value, - ) } // CapabilityValueMigration migrates all path capabilities to ID capabilities, diff --git a/migrations/capcons/migration_test.go b/migrations/capcons/migration_test.go index f658d322af..4e4268637f 100644 --- a/migrations/capcons/migration_test.go +++ b/migrations/capcons/migration_test.go @@ -119,6 +119,7 @@ type testMigrationReporter struct { var _ migrations.Reporter = &testMigrationReporter{} var _ LinkMigrationReporter = &testMigrationReporter{} var _ CapabilityMigrationReporter = &testMigrationReporter{} +var _ StorageCapabilityMigrationReporter = &testMigrationReporter{} func (t *testMigrationReporter) Migrated( storageKey interpreter.StorageKey, @@ -194,7 +195,7 @@ func (t *testMigrationReporter) MissingBorrowType( ) } -func (t *testMigrationReporter) IssuedStorageCapability( +func (t *testMigrationReporter) IssuedStorageCapabilityController( accountAddress common.Address, addressPath interpreter.AddressPath, borrowType *interpreter.ReferenceStaticType, diff --git a/migrations/capcons/storagecapmigration.go b/migrations/capcons/storagecapmigration.go index 811f4a4c26..6ab7b74c46 100644 --- a/migrations/capcons/storagecapmigration.go +++ b/migrations/capcons/storagecapmigration.go @@ -26,6 +26,19 @@ import ( "github.com/onflow/cadence/runtime/stdlib" ) +type StorageCapabilityMigrationReporter interface { + MissingBorrowType( + accountAddress common.Address, + addressPath interpreter.AddressPath, + ) + IssuedStorageCapabilityController( + accountAddress common.Address, + addressPath interpreter.AddressPath, + borrowType *interpreter.ReferenceStaticType, + capabilityID interpreter.UInt64Value, + ) +} + // StorageCapMigration records path capabilities with storage domain target. // It does not actually migrate any values. type StorageCapMigration struct { @@ -73,7 +86,7 @@ func (m *StorageCapMigration) CanSkip(valueType interpreter.StaticType) bool { func IssueAccountCapabilities( inter *interpreter.Interpreter, - reporter CapabilityMigrationReporter, + reporter StorageCapabilityMigrationReporter, address common.Address, capabilities *AccountCapabilities, handler stdlib.CapabilityControllerIssueHandler, @@ -105,7 +118,7 @@ func IssueAccountCapabilities( mapping.Record(addressPath, capabilityID, borrowType) - reporter.IssuedStorageCapability( + reporter.IssuedStorageCapabilityController( address, addressPath, borrowStaticType.(*interpreter.ReferenceStaticType),