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:
commit
34c6c69e09
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue