From 8e66c67a74f8a006c2840526f06cda9e38de5168 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 22 Jul 2021 12:40:06 +0300 Subject: [PATCH] [#705] pkg/innerring: Add IR keys fetchers Add `IrFetcherWithNotary` and `IrFetcherWithoutNotary` that can fetch IR keys with and without usage of notary contract. Both can be hidden behind `InnerRingKeys() (keys.PublicKeys, error)` interface. Signed-off-by: Pavel Karpy --- pkg/innerring/fetcher.go | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 pkg/innerring/fetcher.go diff --git a/pkg/innerring/fetcher.go b/pkg/innerring/fetcher.go new file mode 100644 index 000000000..3d2fc6af3 --- /dev/null +++ b/pkg/innerring/fetcher.go @@ -0,0 +1,58 @@ +package innerring + +import ( + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" + nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" +) + +// NewIRFetcherWithNotary creates IrFetcherWithNotary. +// +// IrFetcherWithNotary can be used to obtain innerring key list if +// network that client is connected to supports notary contract. +// +// Passed client is required. Panics if nil. +func NewIRFetcherWithNotary(cli *client.Client) *IrFetcherWithNotary { + if cli == nil { + panic("could not init IRFetcher with notary: client must not be nil") + } + return &IrFetcherWithNotary{cli: cli} +} + +// NewIRFetcherWithoutNotary creates IrFetcherWithoutNotary. +// +// IrFetcherWithoutNotary must be used to obtain innerring key list if +// network that netmap wrapper is connected to does not support notary +// contract. +// +// Passed netmap wrapper is required. Panics if nil. +func NewIRFetcherWithoutNotary(nm *nmWrapper.Wrapper) *IrFetcherWithoutNotary { + if nm == nil { + panic("could not init IRFetcher without notary: netmap wrapper must not be nil") + } + return &IrFetcherWithoutNotary{nm: nm} +} + +// IrFetcherWithNotary fetches keys using notary contract. Must be created +// with NewIRFetcherWithNotary. +type IrFetcherWithNotary struct { + cli *client.Client +} + +// IrFetcherWithoutNotary fetches keys using netmap contract. Must be created +// with NewIRFetcherWithoutNotary. +type IrFetcherWithoutNotary struct { + nm *nmWrapper.Wrapper +} + +// InnerRingKeys fetches list of innerring keys from NeoFSAlphabet +// role in side chain. +func (fN IrFetcherWithNotary) InnerRingKeys() (keys.PublicKeys, error) { + return fN.cli.NeoFSAlphabetList() +} + +// InnerRingKeys fetches list of innerring keys from netmap contract +// in side chain. +func (f IrFetcherWithoutNotary) InnerRingKeys() (keys.PublicKeys, error) { + return f.nm.GetInnerRingList() +}