github.com/anjalikarhana/fabric@v2.1.1+incompatible/orderer/common/server/util.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package server 8 9 import ( 10 "io/ioutil" 11 12 "github.com/hyperledger/fabric/common/ledger/blockledger" 13 "github.com/hyperledger/fabric/common/ledger/blockledger/fileledger" 14 "github.com/hyperledger/fabric/common/metrics" 15 config "github.com/hyperledger/fabric/orderer/common/localconfig" 16 "github.com/pkg/errors" 17 ) 18 19 func createLedgerFactory(conf *config.TopLevel, metricsProvider metrics.Provider) (blockledger.Factory, string, error) { 20 ld := conf.FileLedger.Location 21 var err error 22 if ld == "" { 23 if ld, err = ioutil.TempDir("", conf.FileLedger.Prefix); err != nil { 24 logger.Panic("Error creating temp dir:", err) 25 } 26 } 27 28 logger.Debug("Ledger dir:", ld) 29 lf, err := fileledger.New(ld, metricsProvider) 30 if err != nil { 31 return nil, "", errors.WithMessage(err, "Error in opening ledger factory") 32 } 33 return lf, ld, nil 34 }