github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/cmd/util/ledger/reporters/storage_snapshot.go (about)

     1  package reporters
     2  
     3  import (
     4  	"github.com/onflow/flow-go/fvm/storage/snapshot"
     5  	"github.com/onflow/flow-go/ledger"
     6  	"github.com/onflow/flow-go/model/flow"
     7  )
     8  
     9  // NewStorageSnapshotFromPayload returns an instance of StorageSnapshot with
    10  // entries loaded from payloads (should only be used for migration)
    11  func NewStorageSnapshotFromPayload(
    12  	payloads []ledger.Payload,
    13  ) snapshot.MapStorageSnapshot {
    14  	snapshot := make(snapshot.MapStorageSnapshot, len(payloads))
    15  	for _, entry := range payloads {
    16  		key, err := entry.Key()
    17  		if err != nil {
    18  			panic(err)
    19  		}
    20  
    21  		id := flow.NewRegisterID(
    22  			flow.BytesToAddress(key.KeyParts[0].Value),
    23  			string(key.KeyParts[1].Value))
    24  
    25  		snapshot[id] = entry.Value()
    26  	}
    27  
    28  	return snapshot
    29  }