Merge pull request #301 from meshplus/fix/sendtx-cmd-nonce

fix(cmd): fix cmd client send tx with random nonce
This commit is contained in:
levi9311 2020-12-25 13:41:15 +08:00 committed by GitHub
commit 34c6c69e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -11,11 +11,6 @@ var clientCMD = cli.Command{
Usage: "Specific gateway address",
Value: "http://localhost:9091/v1/",
},
cli.StringFlag{
Name: "grpc",
Usage: "Specific grpc address",
Value: "localhost:60011",
},
cli.StringFlag{
Name: "cert",
Usage: "Specific ca cert file if https is enabled",

View File

@ -3,7 +3,7 @@ package client
import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"time"
"github.com/meshplus/bitxhub-kit/types"
@ -108,11 +108,31 @@ func sendTransaction(ctx *cli.Context) error {
return err
}
getNonceUrl, err := getURL(ctx, fmt.Sprintf("pendingNonce/%s", from.String()))
if err != nil {
return err
}
encodedNonce, err := httpGet(ctx, getNonceUrl)
if err != nil {
return err
}
ret, err := parseResponse(encodedNonce)
if err != nil {
return err
}
nonce, err := strconv.ParseUint(ret, 10, 64)
if err != nil {
return fmt.Errorf("parse pending nonce :%w", err)
}
tx := &pb.Transaction{
From: from,
To: to,
Timestamp: time.Now().UnixNano(),
Nonce: rand.Uint64(),
Nonce: nonce,
Payload: payload,
}