Skip to content

Commit

Permalink
refactor slab index writing
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Nov 18, 2024
1 parent 29aea54 commit 4addf32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
18 changes: 6 additions & 12 deletions runtime/account_storage_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 6 additions & 12 deletions runtime/account_storage_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions runtime/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4addf32

Please sign in to comment.