github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/server/constructors.go (about)

     1  package server
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    10  	"github.com/fibonacci-chain/fbc/libs/tendermint/libs/log"
    11  	tmtypes "github.com/fibonacci-chain/fbc/libs/tendermint/types"
    12  	dbm "github.com/fibonacci-chain/fbc/libs/tm-db"
    13  
    14  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    15  )
    16  
    17  type (
    18  	// AppCreator is a function that allows us to lazily initialize an
    19  	// application using various configurations.
    20  	AppCreator func(log.Logger, dbm.DB, io.Writer) abci.Application
    21  
    22  	// AppExporter is a function that dumps all app state to
    23  	// JSON-serializable structure and returns the current validator set.
    24  	AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, error)
    25  
    26  	AppStop func(app abci.Application)
    27  )
    28  
    29  func openDB(rootDir string) (dbm.DB, error) {
    30  	dataDir := filepath.Join(rootDir, "data")
    31  	db, err := sdk.NewDB("application", dataDir)
    32  	return db, err
    33  }
    34  
    35  func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
    36  	if traceWriterFile != "" {
    37  		w, err = os.OpenFile(
    38  			traceWriterFile,
    39  			os.O_WRONLY|os.O_APPEND|os.O_CREATE,
    40  			0666,
    41  		)
    42  		return
    43  	}
    44  	return
    45  }