github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/storage/snapshot/storage_snapshot.go (about) 1 package snapshot 2 3 import ( 4 "github.com/onflow/flow-go/model/flow" 5 ) 6 7 // Note: StorageSnapshot must be thread safe (or immutable). 8 type StorageSnapshot interface { 9 // Get returns the register id's value, or an empty RegisterValue if the id 10 // is not found. Get should be idempotent (i.e., the same value is returned 11 // for the same id). 12 Get(id flow.RegisterID) (flow.RegisterValue, error) 13 } 14 15 type EmptyStorageSnapshot struct{} 16 17 func (EmptyStorageSnapshot) Get( 18 id flow.RegisterID, 19 ) ( 20 flow.RegisterValue, 21 error, 22 ) { 23 return nil, nil 24 } 25 26 type ReadFuncStorageSnapshot struct { 27 ReadFunc func(flow.RegisterID) (flow.RegisterValue, error) 28 } 29 30 func NewReadFuncStorageSnapshot( 31 readFunc func(flow.RegisterID) (flow.RegisterValue, error), 32 ) StorageSnapshot { 33 return &ReadFuncStorageSnapshot{ 34 ReadFunc: readFunc, 35 } 36 } 37 38 func (storage ReadFuncStorageSnapshot) Get( 39 id flow.RegisterID, 40 ) ( 41 flow.RegisterValue, 42 error, 43 ) { 44 return storage.ReadFunc(id) 45 } 46 47 type Peeker interface { 48 Peek(id flow.RegisterID) (flow.RegisterValue, error) 49 } 50 51 func NewPeekerStorageSnapshot(peeker Peeker) StorageSnapshot { 52 return NewReadFuncStorageSnapshot(peeker.Peek) 53 } 54 55 type MapStorageSnapshot map[flow.RegisterID]flow.RegisterValue 56 57 func (storage MapStorageSnapshot) Get( 58 id flow.RegisterID, 59 ) ( 60 flow.RegisterValue, 61 error, 62 ) { 63 return storage[id], nil 64 }