From 2766782f83838eef2321d15582365b4e3ad29fd8 Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Tue, 24 Sep 2024 09:31:23 -0400 Subject: [PATCH] Move ErrNotFound from internal to pkg Signed-off-by: Jim Zhang --- go-sdk/internal/sparse-merkle-tree/smt/merkletree.go | 3 +-- go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go | 3 +-- go-sdk/internal/sparse-merkle-tree/storage/sql.go | 4 ++-- .../storage => pkg/sparse-merkle-tree/core}/errors.go | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) rename go-sdk/{internal/sparse-merkle-tree/storage => pkg/sparse-merkle-tree/core}/errors.go (97%) diff --git a/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go b/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go index 3a2dfcc..ca490e9 100644 --- a/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go +++ b/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go @@ -23,7 +23,6 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/internal/log" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" - "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/storage" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/utils" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" ) @@ -46,7 +45,7 @@ func NewMerkleTree(db core.Storage, maxLevels int) (core.SparseMerkleTree, error mt := sparseMerkleTree{db: db, maxLevels: maxLevels} root, err := mt.db.GetRootNodeIndex() - if err == storage.ErrNotFound { + if err == core.ErrNotFound { mt.rootKey = node.ZERO_INDEX err = mt.db.UpsertRootNodeIndex(mt.rootKey) if err != nil { diff --git a/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go b/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go index d80ff83..77ef41c 100644 --- a/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go +++ b/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go @@ -20,7 +20,6 @@ import ( "fmt" "testing" - "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/storage" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" "github.com/stretchr/testify/assert" ) @@ -33,7 +32,7 @@ func (ms *mockStorage) GetRootNodeIndex() (core.NodeIndex, error) { if ms.GetRootNodeIndex_customError { return nil, fmt.Errorf("nasty error in get root") } - return nil, storage.ErrNotFound + return nil, core.ErrNotFound } func (ms *mockStorage) UpsertRootNodeIndex(core.NodeIndex) error { return fmt.Errorf("nasty error in upsert root") diff --git a/go-sdk/internal/sparse-merkle-tree/storage/sql.go b/go-sdk/internal/sparse-merkle-tree/storage/sql.go index 6c08182..73418f6 100644 --- a/go-sdk/internal/sparse-merkle-tree/storage/sql.go +++ b/go-sdk/internal/sparse-merkle-tree/storage/sql.go @@ -47,7 +47,7 @@ func (s *sqlStorage) GetRootNodeIndex() (core.NodeIndex, error) { } err := s.p.DB().Table(core.TreeRootsTable).First(&root).Error if err == gorm.ErrRecordNotFound { - return nil, ErrNotFound + return nil, core.ErrNotFound } else if err != nil { return nil, err } @@ -121,7 +121,7 @@ func getNode(batchOrDb *gorm.DB, nodesTableName string, ref core.NodeIndex) (cor } err := batchOrDb.Table(nodesTableName).First(&n).Error if err == gorm.ErrRecordNotFound { - return nil, ErrNotFound + return nil, core.ErrNotFound } else if err != nil { return nil, err } diff --git a/go-sdk/internal/sparse-merkle-tree/storage/errors.go b/go-sdk/pkg/sparse-merkle-tree/core/errors.go similarity index 97% rename from go-sdk/internal/sparse-merkle-tree/storage/errors.go rename to go-sdk/pkg/sparse-merkle-tree/core/errors.go index 379ed77..6e36ede 100644 --- a/go-sdk/internal/sparse-merkle-tree/storage/errors.go +++ b/go-sdk/pkg/sparse-merkle-tree/core/errors.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package storage +package core import "errors"