Skip to content

Commit

Permalink
Merge pull request #101 from dappledger/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
needkane authored Feb 7, 2020
2 parents e865eca + 61b5ba8 commit 881c88c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 6 deletions.
35 changes: 34 additions & 1 deletion cmd/client/commands/state_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ var (
anntoolFlags.addr,
},
},
{
Name: "pending_nonce",
Usage: "query account's pending nonce",
Action: queryPendingNonce,
Flags: []cli.Flag{
anntoolFlags.addr,
},
},
{
Name: "receipt",
Usage: "",
Expand All @@ -69,10 +77,35 @@ func queryNonce(ctx *cli.Context) error {
}

nonce := new(uint64)
rlp.DecodeBytes(rpcResult.Result.Data, nonce)
err = rlp.DecodeBytes(rpcResult.Result.Data, nonce)
if err != nil {
return cli.NewExitError(err.Error(), 127)
}

fmt.Println("query result:", *nonce)
return nil
}

func queryPendingNonce(ctx *cli.Context) error {
clientJSON := cl.NewClientJSONRPC(commons.QueryServer)
rpcResult := new(gtypes.ResultQuery)

addrHex := gcmn.SanitizeHex(ctx.String("address"))
addr := common.Hex2Bytes(addrHex)
query := append([]byte{13}, addr...)

_, err := clientJSON.Call("query", []interface{}{query}, rpcResult)
if err != nil {
return cli.NewExitError(err.Error(), 127)
}

nonce := new(uint64)
err = rlp.DecodeBytes(rpcResult.Result.Data, nonce)
if err != nil {
return cli.NewExitError(err.Error(), 127)
}

fmt.Println("query result:", *nonce)
return nil
}

Expand Down
21 changes: 21 additions & 0 deletions docs/cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ query result nonce
query result: 2
```

## Query Pending Nonce

##### Command

```
gtool --backend <validator's IP:RPC Port> query pending_nonce --address <account address>
```

##### Result

```
query result pending nonce
```

##### Demo

```
./build/gtool --backend "tcp://127.0.0.1:46657" query pending_nonce --address 771403c283a3f46cda462f7aeff5dfd28b00f106
query result: 2
```

## Query Receipt

##### Commadn
Expand Down
29 changes: 26 additions & 3 deletions docs/cmd_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,36 @@ query result nonce
query result: 2
```

## 查询 Pending Nonce

##### 命令

```
gtool --backend <validator's IP:RPC Port> query pending_nonce --address <account address>
```

##### 结果

```
query result pending nonce
```

##### Demo

```
./build/gtool --backend "tcp://127.0.0.1:46657" query pending_nonce --address 771403c283a3f46cda462f7aeff5dfd28b00f106
query result: 2
```

## 查询 Receipt

##### Commadn
##### 命令

```
gtool --backend <validator's IP:RPC Port> query receipt --hash <tx hash>
```

##### 命令
##### 结果

```
query result receipt
Expand Down Expand Up @@ -291,7 +312,7 @@ Check the files generated, make sure everything is OK.
Node Privkey for user://CA node's private key
```

##### Result
##### 结果

```
<new node's public key>:<CA node's signature>
Expand Down Expand Up @@ -375,6 +396,8 @@ hash= 0x110ee98edba177ede906e5d8175d9f787bfed61f3bb841537327d6f8128c6dbe

## 删除节点

##### 命令

```
./build/gtool admin remove_node --validator_pubkey <the public key of the node which needed to be removed> --nPrivs <the number of CA nodes which needed to validate the behavior>
need n private keys; please input n' keys //CA nodes' private keys,n is the number of CA nodes which needed to validate the behavior
Expand Down
25 changes: 23 additions & 2 deletions gemmill/modules/go-log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"os"
"path"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -39,7 +40,7 @@ func ensureDir(dir string) error {
}

func productionLogger(logPath string) *zap.Logger {
zapEncodeConfig := zap.NewProductionEncoderConfig()
zapEncodeConfig := productionConfig()
jsonEncoder := zapcore.NewJSONEncoder(zapEncodeConfig)

w := zapcore.AddSync(&lumberjack.Logger{
Expand All @@ -58,6 +59,26 @@ func productionLogger(logPath string) *zap.Logger {
return zap.New(core)
}

func productionConfig() zapcore.EncoderConfig {
return zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: productionTimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
}

func productionTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("2006-01-02T15:04:05.000Z07:00"))
}

func Initialize(env, logpath string) (*zap.Logger, error) {
if err := ensureDir(path.Dir(logpath)); err != nil {
return nil, err
Expand Down Expand Up @@ -222,4 +243,4 @@ func Debugf(template string, args ...interface{}) {
return
}
slogger.Debugf(template, args...)
}
}

0 comments on commit 881c88c

Please sign in to comment.