github.com/decred/politeia@v1.4.0/politeiad/backendv2/tstorebe/tstore/tlog.go (about)

     1  // Copyright (c) 2020-2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package tstore
     6  
     7  import (
     8  	"fmt"
     9  
    10  	backend "github.com/decred/politeia/politeiad/backendv2"
    11  	"github.com/google/trillian"
    12  	"google.golang.org/grpc/codes"
    13  	"google.golang.org/grpc/status"
    14  )
    15  
    16  // leavesAll provides a wrapper around the tlog LeavesAll method that unpacks
    17  // any tree not found errors and instead returns a backend ErrRecordNotFound
    18  // error.
    19  func (t *Tstore) leavesAll(treeID int64) ([]*trillian.LogLeaf, error) {
    20  	leaves, err := t.tlog.LeavesAll(treeID)
    21  	if err != nil {
    22  		if c := status.Code(err); c == codes.NotFound {
    23  			return nil, backend.ErrRecordNotFound
    24  		}
    25  		return nil, fmt.Errorf("LeavesAll: %v", err)
    26  	}
    27  	return leaves, nil
    28  }