From def903261503b90a8ef86eb456ea0ce03c363cbb Mon Sep 17 00:00:00 2001 From: aarifullin Date: Tue, 12 Dec 2023 18:45:59 +0300 Subject: [PATCH] [#32] morph: Remove name transformer in morph policy client * It is not required to transform long names because container chains will be added by container ID but not by a resource name. Signed-off-by: Airat Arifullin --- go.mod | 2 +- pkg/morph/policy/policy_contract_storage.go | 20 +++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 3f36791..28836a0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.20 require ( git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.1-0.20231129062201-a1b61d394958 - github.com/mr-tron/base58 v1.2.0 github.com/nspcc-dev/neo-go v0.103.0 github.com/stretchr/testify v1.8.4 ) @@ -14,6 +13,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/google/uuid v1.3.0 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect + github.com/mr-tron/base58 v1.2.0 // indirect github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 // indirect github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 // indirect github.com/nspcc-dev/rfc6979 v0.2.0 // indirect diff --git a/pkg/morph/policy/policy_contract_storage.go b/pkg/morph/policy/policy_contract_storage.go index 37da1a7..6e85339 100644 --- a/pkg/morph/policy/policy_contract_storage.go +++ b/pkg/morph/policy/policy_contract_storage.go @@ -10,7 +10,6 @@ import ( client "git.frostfs.info/TrueCloudLab/frostfs-contract/rpcclient/policy" "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain" "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine" - "github.com/mr-tron/base58" "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -44,16 +43,6 @@ func NewContractStorageWithSimpleActor(rpcActor actor.RPCActor, acc *wallet.Acco return NewContractStorage(act, contract), nil } -func transformNameIfContainer(target engine.Target) (name string) { - name = target.Name - if target.Type == engine.Container { - // Container name can be too long and, thus, cannot be - // used as a key name for policy-contract storage. - name = base58.FastBase58Encoding([]byte(target.Name)) - } - return -} - func (s *ContractStorage) AddMorphRuleChain(name chain.Name, target engine.Target, c *chain.Chain) (txHash util.Uint256, vub uint32, err error) { if c.ID == "" { err = ErrEmptyChainID @@ -66,9 +55,8 @@ func (s *ContractStorage) AddMorphRuleChain(name chain.Name, target engine.Targe return } fullName := prefixedChainName(name, c.ID) - targetName := transformNameIfContainer(target) - txHash, vub, err = s.contractInterface.AddChain(big.NewInt(int64(kind)), targetName, fullName, c.Bytes()) + txHash, vub, err = s.contractInterface.AddChain(big.NewInt(int64(kind)), target.Name, fullName, c.Bytes()) return } @@ -84,9 +72,8 @@ func (s *ContractStorage) RemoveMorphRuleChain(name chain.Name, target engine.Ta return } fullName := prefixedChainName(name, chainID) - targetName := transformNameIfContainer(target) - txHash, vub, err = s.contractInterface.RemoveChain(big.NewInt(int64(kind)), targetName, fullName) + txHash, vub, err = s.contractInterface.RemoveChain(big.NewInt(int64(kind)), target.Name, fullName) return } @@ -95,9 +82,8 @@ func (s *ContractStorage) ListMorphRuleChains(name chain.Name, target engine.Tar if err != nil { return nil, err } - targetName := transformNameIfContainer(target) - items, err := s.contractInterface.ListChainsByPrefix(big.NewInt(int64(kind)), targetName, []byte(name)) + items, err := s.contractInterface.ListChainsByPrefix(big.NewInt(int64(kind)), target.Name, []byte(name)) if err != nil { return nil, err }