From 76c9f10af8db39c5d0704f88eacc554008507fe0 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Mon, 26 Feb 2024 18:19:37 +0300 Subject: [PATCH] [#54] morph: Revise MorphRuleChainStorage interface * Split MorphRuleChainStorage interface by moving read-only methods to a separate interface MorphRuleChainStorageReader. Signed-off-by: Airat Arifullin --- pkg/engine/inmemory/morph_storage.go | 8 ++++++++ pkg/engine/interface.go | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/engine/inmemory/morph_storage.go b/pkg/engine/inmemory/morph_storage.go index 72b5439..ea31136 100644 --- a/pkg/engine/inmemory/morph_storage.go +++ b/pkg/engine/inmemory/morph_storage.go @@ -52,3 +52,11 @@ func (s *inmemoryMorphRuleChainStorage) ListMorphRuleChains(name chain.Name, tar } return nil, engine.ErrUnknownTarget } + +func (s *inmemoryMorphRuleChainStorage) GetAdmin() (util.Uint160, error) { + panic("not implemented") +} + +func (s *inmemoryMorphRuleChainStorage) SetAdmin(_ util.Uint160) (util.Uint256, uint32, error) { + panic("not implemented") +} diff --git a/pkg/engine/interface.go b/pkg/engine/interface.go index 66afff1..fa38737 100644 --- a/pkg/engine/interface.go +++ b/pkg/engine/interface.go @@ -93,17 +93,27 @@ func ContainerTarget(container string) Target { } } -// MorphRuleChainStorage is the interface to manage chains from the chain storage. +// MorphRuleChainStorageReader is the interface that provides read-only methods to receive +// data like chains, target or admin from a chain storage. +type MorphRuleChainStorageReader interface { + // ListMorphRuleChains just lists deserialized chains. + ListMorphRuleChains(name chain.Name, target Target) ([]*chain.Chain, error) + + GetAdmin() (util.Uint160, error) +} + +// MorphRuleChainStorage is the interface to read and manage data within a chain storage. // Basically, this implies that the storage manages rules stored in policy contract. type MorphRuleChainStorage interface { + MorphRuleChainStorageReader + // AddMorphRuleChain adds a chain rule to the policy contract and returns transaction hash, VUB and error. AddMorphRuleChain(name chain.Name, target Target, c *chain.Chain) (util.Uint256, uint32, error) // RemoveMorphRuleChain removes a chain rule to the policy contract and returns transaction hash, VUB and error. RemoveMorphRuleChain(name chain.Name, target Target, chainID chain.ID) (util.Uint256, uint32, error) - // ListMorphRuleChains just lists deserialized chains. - ListMorphRuleChains(name chain.Name, target Target) ([]*chain.Chain, error) + SetAdmin(addr util.Uint160) (util.Uint256, uint32, error) } // Engine is the interface that provides methods to check request permissions checking