github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/core/ledger/ledgerconfig/ledger_config.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ledgerconfig
    18  
    19  import (
    20  	"path/filepath"
    21  
    22  	"github.com/spf13/viper"
    23  )
    24  
    25  var stateDatabase = "goleveldb"
    26  var couchDBAddress = "127.0.0.1:5984"
    27  var username = ""
    28  var password = ""
    29  var historyDatabase = true
    30  
    31  var maxBlockFileSize = 0
    32  
    33  // CouchDBDef contains parameters
    34  type CouchDBDef struct {
    35  	URL      string
    36  	Username string
    37  	Password string
    38  }
    39  
    40  //IsCouchDBEnabled exposes the useCouchDB variable
    41  func IsCouchDBEnabled() bool {
    42  	stateDatabase = viper.GetString("ledger.state.stateDatabase")
    43  	if stateDatabase == "CouchDB" {
    44  		return true
    45  	}
    46  	return false
    47  }
    48  
    49  // GetRootPath returns the filesystem path.
    50  // All ledger related contents are expected to be stored under this path
    51  func GetRootPath() string {
    52  	sysPath := viper.GetString("peer.fileSystemPath")
    53  	return filepath.Join(sysPath, "ledgersData")
    54  }
    55  
    56  // GetLedgerProviderPath returns the filesystem path for stroing ledger ledgerProvider contents
    57  func GetLedgerProviderPath() string {
    58  	return filepath.Join(GetRootPath(), "ledgerProvider")
    59  }
    60  
    61  // GetStateLevelDBPath returns the filesystem path that is used to maintain the state level db
    62  func GetStateLevelDBPath() string {
    63  	return filepath.Join(GetRootPath(), "stateLeveldb")
    64  }
    65  
    66  // GetHistoryLevelDBPath returns the filesystem path that is used to maintain the history level db
    67  func GetHistoryLevelDBPath() string {
    68  	return filepath.Join(GetRootPath(), "historyLeveldb")
    69  }
    70  
    71  // GetBlockStorePath returns the filesystem path that is used by the block store
    72  func GetBlockStorePath() string {
    73  	return filepath.Join(GetRootPath(), "blocks")
    74  }
    75  
    76  // GetMaxBlockfileSize returns maximum size of the block file
    77  func GetMaxBlockfileSize() int {
    78  	return 64 * 1024 * 1024
    79  }
    80  
    81  //GetCouchDBDefinition exposes the useCouchDB variable
    82  func GetCouchDBDefinition() *CouchDBDef {
    83  
    84  	couchDBAddress = viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
    85  	username = viper.GetString("ledger.state.couchDBConfig.username")
    86  	password = viper.GetString("ledger.state.couchDBConfig.password")
    87  
    88  	return &CouchDBDef{couchDBAddress, username, password}
    89  }
    90  
    91  //IsHistoryDBEnabled exposes the historyDatabase variable
    92  func IsHistoryDBEnabled() bool {
    93  	return viper.GetBool("ledger.state.historyDatabase")
    94  }
    95  
    96  // IsQueryReadsHashingEnabled enables or disables computing of hash
    97  // of range query results for phantom item validation
    98  func IsQueryReadsHashingEnabled() bool {
    99  	return true
   100  }
   101  
   102  // GetMaxDegreeQueryReadsHashing return the maximum degree of the merkle tree for hashes of
   103  // of range query results for phantom item validation
   104  // For more details - see description in kvledger/txmgmt/rwset/query_results_helper.go
   105  func GetMaxDegreeQueryReadsHashing() int {
   106  	return 50
   107  }