cosmos-sdk/examples/democoin/cmd/democoind/main.go

73 lines
1.8 KiB
Go
Raw Normal View History

package main
import (
"encoding/json"
"os"
"github.com/spf13/cobra"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tmlibs/cli"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log"
"github.com/cosmos/cosmos-sdk/examples/democoin/app"
"github.com/cosmos/cosmos-sdk/server"
2018-04-21 19:26:46 -07:00
"github.com/cosmos/cosmos-sdk/wire"
)
2018-04-23 17:05:58 -07:00
// init parameters
var CoolAppInit = server.AppInit{
AppGenState: CoolAppGenState,
AppGenTx: server.SimpleAppGenTx,
2018-04-23 17:05:58 -07:00
}
2018-04-21 22:32:47 -07:00
// coolGenAppParams sets up the app_state and appends the cool app state
func CoolAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) {
appState, err = server.SimpleAppGenState(cdc, appGenTxs)
2018-04-05 03:24:53 -07:00
if err != nil {
2018-04-21 19:26:46 -07:00
return
2018-04-05 03:24:53 -07:00
}
2018-04-21 19:26:46 -07:00
key := "cool"
value := json.RawMessage(`{
"trend": "ice-cold"
2018-04-26 08:53:07 -07:00
}`)
appState, err = server.AppendJSON(cdc, appState, key, value)
key = "pow"
value = json.RawMessage(`{
"difficulty": 1,
"count": 0
2018-04-05 03:24:53 -07:00
}`)
2018-04-21 19:26:46 -07:00
appState, err = server.AppendJSON(cdc, appState, key, value)
return
}
func newApp(logger log.Logger, db dbm.DB) abci.Application {
return app.NewDemocoinApp(logger, db)
}
2018-04-27 17:36:11 -07:00
func exportAppState(logger log.Logger, db dbm.DB) (json.RawMessage, error) {
dapp := app.NewDemocoinApp(logger, db)
2018-04-27 17:36:11 -07:00
return dapp.ExportAppStateJSON()
2018-04-26 08:53:07 -07:00
}
func main() {
2018-04-21 19:26:46 -07:00
cdc := app.MakeCodec()
ctx := server.NewDefaultContext()
rootCmd := &cobra.Command{
Use: "democoind",
Short: "Democoin Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}
server.AddCommands(ctx, cdc, rootCmd, CoolAppInit,
2018-04-27 17:36:11 -07:00
server.ConstructAppCreator(newApp, "democoin"),
server.ConstructAppExporter(exportAppState, "democoin"))
// prepare and add flags
rootDir := os.ExpandEnv("$HOME/.democoind")
2018-04-05 03:24:53 -07:00
executor := cli.PrepareBaseCmd(rootCmd, "BC", rootDir)
executor.Execute()
}