2018-04-27 17:36:11 -07:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2018-07-12 16:58:51 -07:00
|
|
|
"io"
|
|
|
|
"os"
|
2018-04-27 17:36:11 -07:00
|
|
|
"path/filepath"
|
|
|
|
|
2018-06-28 17:54:47 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-07-02 13:34:06 -07:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2018-07-02 21:33:53 -07:00
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2019-08-02 06:20:39 -07:00
|
|
|
dbm "github.com/tendermint/tm-db"
|
2019-04-04 07:36:39 -07:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-04-27 17:36:11 -07:00
|
|
|
)
|
|
|
|
|
2018-07-12 16:58:51 -07:00
|
|
|
type (
|
2018-10-10 15:45:41 -07:00
|
|
|
// AppCreator is a function that allows us to lazily initialize an
|
2018-07-12 16:58:51 -07:00
|
|
|
// application using various configurations.
|
2018-10-10 15:45:41 -07:00
|
|
|
AppCreator func(log.Logger, dbm.DB, io.Writer) abci.Application
|
2018-04-27 17:36:11 -07:00
|
|
|
|
2018-10-10 15:45:41 -07:00
|
|
|
// AppExporter is a function that dumps all app state to
|
2018-07-12 16:58:51 -07:00
|
|
|
// JSON-serializable structure and returns the current validator set.
|
2019-02-04 08:42:48 -08:00
|
|
|
AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, error)
|
2018-07-12 16:58:51 -07:00
|
|
|
)
|
|
|
|
|
2018-10-10 15:45:41 -07:00
|
|
|
func openDB(rootDir string) (dbm.DB, error) {
|
|
|
|
dataDir := filepath.Join(rootDir, "data")
|
2019-03-04 12:31:55 -08:00
|
|
|
db, err := sdk.NewLevelDB("application", dataDir)
|
2018-10-10 15:45:41 -07:00
|
|
|
return db, err
|
2018-04-27 17:36:11 -07:00
|
|
|
}
|
|
|
|
|
2018-10-10 15:45:41 -07:00
|
|
|
func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
|
|
|
|
if traceWriterFile != "" {
|
|
|
|
w, err = os.OpenFile(
|
|
|
|
traceWriterFile,
|
|
|
|
os.O_WRONLY|os.O_APPEND|os.O_CREATE,
|
|
|
|
0666,
|
|
|
|
)
|
|
|
|
return
|
2018-04-27 17:36:11 -07:00
|
|
|
}
|
2018-10-10 15:45:41 -07:00
|
|
|
return
|
2018-04-27 17:36:11 -07:00
|
|
|
}
|