From 3d25d6c2177b69554aeea771b05313d4c8bf165e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 21 Sep 2020 17:24:03 +0300 Subject: [PATCH] [#33] core/netmap: Define read-only storage interface Signed-off-by: Leonard Lyubich --- pkg/core/netmap/storage.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pkg/core/netmap/storage.go diff --git a/pkg/core/netmap/storage.go b/pkg/core/netmap/storage.go new file mode 100644 index 00000000..a03f7dcd --- /dev/null +++ b/pkg/core/netmap/storage.go @@ -0,0 +1,35 @@ +package netmap + +import ( + "errors" + + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" +) + +// Source is an interface that wraps +// basic network map receiving method. +type Source interface { + // GetNetMap reads the diff-th past network map from the storage. + // Calling with zero diff returns latest network map. + // It returns the pointer to requested network map and any error encountered. + // + // GetNetMap must return exactly one non-nil value. + // GetNetMap must return ErrNotFound if the network map is not in storage. + // + // Implementations must not retain the network map pointer and modify + // the network map through it. + GetNetMap(diff uint64) (*netmap.Netmap, error) +} + +// ErrNotFound is the error returned when network map was not found in storage. +var ErrNotFound = errors.New("network map not found") + +// GetLatestNetworkMap requests and returns latest network map from storage. +func GetLatestNetworkMap(src Source) (*netmap.Netmap, error) { + return src.GetNetMap(0) +} + +// GetPreviousNetworkMap requests and returns previous from latest network map from storage. +func GetPreviousNetworkMap(src Source) (*netmap.Netmap, error) { + return src.GetNetMap(1) +}