Skip to content

Commit

Permalink
server init command修改
Browse files Browse the repository at this point in the history
  • Loading branch information
TokenxyWZY authored and kauchy committed Jan 8, 2019
1 parent 43a09cb commit 0a0380e
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 493 deletions.
68 changes: 53 additions & 15 deletions example/basecoin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,50 @@ $ go install
```
2. 初始化
```
$ basecoind init --chain-id basecoin --name basecoind-node
$ basecoind init --chain-id basecoin --moniker basecoin-node
```

```
{
"chain_id": "basecoin",
"node_id": "bada889c78e1a3936863e6a89eb766c28b398032",
"app_message": {
"name": "Jia",
"pass": "12345678",
"secret": "problem dutch dilemma climb endorse clitnt despair ostrich cannon path once suspect place base brisk deposit area spike veteran coin injury dove electric famous"
}
"moniker": "basecoin-node",
"chain_id": "basecoin",
"node_id": "0048c2db694c91b2b3b272ec901cce0636d13ff3",
"gentxs_dir": "",
"app_message": {
"qcps": [
{
"name": "qstar",
"chain_id": "qstar",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "ish2+qpPsoHxf7m+uwi8FOAWw6iMaDZgLKl1la4yMAs="
}
}
],
"accounts": [
{
"address": "address1y0nwp6hmxm0g0zhvuglr2jdgglns8tsdctdre6",
"coins": [
{
"coin_name": "qstar",
"amount": "100000000"
}
]
}
]
}
}
```
创建配置文件,以及创世账户“Jia”

3. 创建账户"Liu"
命令执行完成后,配置文件初始化完成并创建了创世账户“address1y0nwp6hmxm0g0zhvuglr2jdgglns8tsdctdre6”.

> 配置文件默认目录为$HOME/.basecoind/config
> 创世账户默认名称为`Jia`,密码为`123456`. 可以通过`basecli keys命令进行查看操作`


3. 创建本地账户"Liu"

```
$ basecli keys add Liu
Expand All @@ -49,7 +76,7 @@ book distance cart design another view olympic orbit leopard indoor tumble dutch
```
$ basecoind start
```
5. 账户查询状态
5. 查询账户信息
```
$ basecli query account Jia
```
Expand All @@ -70,8 +97,19 @@ $ basecli query account Jia
}
]
}
} <nil>
}
```

```
$ basecli query account Liu
```

```
ERROR: account not exists
```

> 本地账户`Liu`未在链上
6. 链内交易
```
$ basecli tx send --from=Jia --to=Liu --coin-name=qstar --coin-amount=10
Expand All @@ -81,7 +119,7 @@ $ basecli tx send --from=Jia --to=Liu --coin-name=qstar --coin-amount=10
Password to sign with 'Jia':
{"check_tx":{},"deliver_tx":{},"hash":"0677BB2E156496064960ED759BFEDBE6D09A8282","height":"22"}
```
7. 账户查询状态
7. 查询账户信息
```
$ basecli query account Jia
```
Expand All @@ -105,7 +143,7 @@ $ basecli query account Jia
}
]
}
} <nil>
}
```

Expand All @@ -129,7 +167,7 @@ $ basecli query account Liu
}
]
}
} <nil>
}
```

8. 查询交易
Expand Down
34 changes: 33 additions & 1 deletion example/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"github.com/QOSGroup/qbase/server"
"github.com/QOSGroup/qbase/version"
"github.com/spf13/cobra"
go_amino "github.com/tendermint/go-amino"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/cli"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
"io"
)

Expand All @@ -26,7 +29,10 @@ func main() {
// version cmd
rootCmd.AddCommand(version.VersionCmd)

server.AddCommands(ctx, cdc, rootCmd, types.BaseCoinInit(), newApp)
//add init command
rootCmd.AddCommand(server.InitCmd(ctx, cdc, genBaseCoindGenesisDoc, types.DefaultNodeHome))

server.AddCommands(ctx, cdc, rootCmd, newApp)

executor := cli.PrepareBaseCmd(rootCmd, "basecoin", types.DefaultNodeHome)

Expand All @@ -39,3 +45,29 @@ func main() {
func newApp(logger log.Logger, db dbm.DB, storeTracer io.Writer) abci.Application {
return app.NewApp(logger, db, storeTracer)
}

func genBaseCoindGenesisDoc(ctx *server.Context, cdc *go_amino.Codec, chainID string, nodeValidatorPubKey crypto.PubKey) (tmtypes.GenesisDoc, error) {

validator := tmtypes.GenesisValidator{
PubKey: nodeValidatorPubKey,
Power: 10,
}

addr, _, err := types.GenerateCoinKey(cdc, types.DefaultCLIHome)
if err != nil {
return tmtypes.GenesisDoc{}, err
}

genTx := types.BaseCoinGenTx{addr}
appState, err := types.BaseCoinAppGenState(cdc, genTx)
if err != nil {
return tmtypes.GenesisDoc{}, err
}

return tmtypes.GenesisDoc{
ChainID: chainID,
Validators: []tmtypes.GenesisValidator{validator},
AppState: appState,
}, nil

}
75 changes: 5 additions & 70 deletions example/basecoin/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ package types

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/QOSGroup/qbase/account"
clikeys "github.com/QOSGroup/qbase/client/keys"
"github.com/QOSGroup/qbase/keys"
"github.com/QOSGroup/qbase/server"
"github.com/QOSGroup/qbase/server/config"
"github.com/QOSGroup/qbase/types"
"github.com/spf13/pflag"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"
"os"
"path/filepath"

dbm "github.com/tendermint/tendermint/libs/db"
)
Expand Down Expand Up @@ -60,72 +56,11 @@ func (ga *GenesisAccount) ToAppAccount() (acc *AppAccount, err error) {
}, nil
}

func BaseCoinInit() server.AppInit {
fsAppGenState := pflag.NewFlagSet("", pflag.ContinueOnError)

fsAppGenTx := pflag.NewFlagSet("", pflag.ContinueOnError)
fsAppGenTx.String(server.FlagName, "", "validator moniker, required")
fsAppGenTx.String(server.FlagClientHome, DefaultCLIHome,
"home directory for the client, used for key generation")
fsAppGenTx.Bool(server.FlagOWK, false, "overwrite the accounts created")

return server.AppInit{
FlagsAppGenState: fsAppGenState,
FlagsAppGenTx: fsAppGenTx,
AppGenTx: BaseCoinAppGenTx,
AppGenState: BaseCoinAppGenState,
}
}

type BaseCoinGenTx struct {
Addr types.Address `json:"addr"`
}

// Generate a genesis transaction
func BaseCoinAppGenTx(cdc *amino.Codec, pk crypto.PubKey, genTxConfig config.GenTx) (
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {

var addr types.Address
var secret string
addr, secret, err = GenerateCoinKey(cdc, genTxConfig.CliRoot)
if err != nil {
return
}

var bz []byte
simpleGenTx := BaseCoinGenTx{addr}
bz, err = cdc.MarshalJSON(simpleGenTx)
if err != nil {
return
}
appGenTx = json.RawMessage(bz)

mm := map[string]string{"name": DefaultAccountName, "pass": DefaultAccountPass, "secret": secret}
bz, err = cdc.MarshalJSON(mm)
if err != nil {
return
}
cliPrint = json.RawMessage(bz)

validator = tmtypes.GenesisValidator{
PubKey: pk,
Power: 10,
}
return
}

func BaseCoinAppGenState(cdc *amino.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) {

if len(appGenTxs) != 1 {
err = errors.New("must provide a single genesis transaction")
return
}

var genTx BaseCoinGenTx
err = cdc.UnmarshalJSON(appGenTxs[0], &genTx)
if err != nil {
return
}
func BaseCoinAppGenState(cdc *amino.Codec, appGenTxs BaseCoinGenTx) (appState json.RawMessage, err error) {

appState = json.RawMessage(fmt.Sprintf(`{
"qcps":[{
Expand All @@ -145,7 +80,7 @@ func BaseCoinAppGenState(cdc *amino.Codec, appGenTxs []json.RawMessage) (appStat
}
]
}]
}`, genTx.Addr))
}`, appGenTxs.Addr))
return
}

Expand Down
7 changes: 0 additions & 7 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ const (
defaultMinimumFees = ""
)

type GenTx struct {
Name string
CliRoot string
Overwrite bool
IP string
}

// BaseConfig defines the server's basic configuration
type BaseConfig struct {
// Tx minimum fee
Expand Down
Loading

0 comments on commit 0a0380e

Please sign in to comment.