diff --git a/runtime/account_storage_v1.go b/runtime/account_storage_v1.go index 76ff904d5..fe1419a35 100644 --- a/runtime/account_storage_v1.go +++ b/runtime/account_storage_v1.go @@ -175,18 +175,12 @@ func (s *AccountStorageV1) writeStorageDomainSlabIndex( storageDomainKey interpreter.StorageDomainKey, slabIndex atree.SlabIndex, ) error { - var err error - errors.WrapPanic(func() { - err = s.ledger.SetValue( - storageDomainKey.Address[:], - []byte(storageDomainKey.Domain.Identifier()), - slabIndex[:], - ) - }) - if err != nil { - return interpreter.WrappedExternalError(err) - } - return nil + return writeSlabIndex( + s.ledger, + storageDomainKey.Address, + []byte(storageDomainKey.Domain.Identifier()), + slabIndex, + ) } // getDomainStorageMapFromV1DomainRegister returns domain storage map from legacy domain register. diff --git a/runtime/account_storage_v2.go b/runtime/account_storage_v2.go index 8f2330fe1..32619ac45 100644 --- a/runtime/account_storage_v2.go +++ b/runtime/account_storage_v2.go @@ -238,18 +238,12 @@ func (s *AccountStorageV2) writeAccountStorageSlabIndex( address common.Address, slabIndex atree.SlabIndex, ) error { - var err error - errors.WrapPanic(func() { - err = s.ledger.SetValue( - address[:], - []byte(AccountStorageKey), - slabIndex[:], - ) - }) - if err != nil { - return interpreter.WrappedExternalError(err) - } - return nil + return writeSlabIndex( + s.ledger, + address, + []byte(AccountStorageKey), + slabIndex, + ) } func getAccountStorageSlabIndex( diff --git a/runtime/storage.go b/runtime/storage.go index ef2c5cf14..1ca3906dc 100644 --- a/runtime/storage.go +++ b/runtime/storage.go @@ -606,3 +606,23 @@ func (UnreferencedRootSlabsError) IsInternalError() {} func (e UnreferencedRootSlabsError) Error() string { return fmt.Sprintf("slabs not referenced: %s", e.UnreferencedRootSlabIDs) } + +func writeSlabIndex( + ledger atree.Ledger, + address common.Address, + key []byte, + slabIndex atree.SlabIndex, +) error { + var err error + errors.WrapPanic(func() { + err = ledger.SetValue( + address[:], + key, + slabIndex[:], + ) + }) + if err != nil { + return interpreter.WrappedExternalError(err) + } + return nil +}