Skip to content

Commit

Permalink
fix: cmd: tx spend queries node for Nonce if not specified. also acce…
Browse files Browse the repository at this point in the history
…pts text payload
  • Loading branch information
randomshinichi committed May 27, 2019
1 parent 911392d commit b2879fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var (
waitForTx bool
payload string
spendTxPayload string
printPrivateKey bool
accountFileName string
password string
Expand Down
14 changes: 12 additions & 2 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ func txSpendFunc(cmd *cobra.Command, args []string) (err error) {
return errors.New("Error, missing or invalid fee")
}

tx := aeternity.NewSpendTx(sender, recipient, *amount, *feeBigInt, "", ttl, nonce)
// Connect to the node to find out sender nonce only
if nonce == 0 {
client := aeternity.NewClient(aeternity.Config.Node.URL, false)
nonce, err = client.GetNextNonce(sender)
if err != nil {
return err
}
}

tx := aeternity.NewSpendTx(sender, recipient, *amount, *feeBigInt, spendTxPayload, ttl, nonce)
if err != nil {
return err
}
Expand All @@ -74,7 +83,7 @@ func txSpendFunc(cmd *cobra.Command, args []string) (err error) {
"TTL", ttl,
"Fee", fee,
"Nonce", nonce,
"Payload", "not implemented",
"Payload", spendTxPayload,
"Encoded", base64Tx,
)
return nil
Expand Down Expand Up @@ -141,4 +150,5 @@ func init() {
txSpendCmd.Flags().StringVar(&fee, "fee", aeternity.Config.Client.Fee.String(), fmt.Sprintf("Set the transaction fee (default=%s)", aeternity.Config.Client.Fee.String()))
txSpendCmd.Flags().Uint64Var(&ttl, "ttl", aeternity.Config.Client.TTL, fmt.Sprintf("Set the TTL in keyblocks (default=%d)", aeternity.Config.Client.TTL))
txSpendCmd.Flags().Uint64Var(&nonce, "nonce", 0, fmt.Sprint("Set the sender account nonce, if not the chain will be queried for its value"))
txSpendCmd.Flags().StringVar(&spendTxPayload, "payload", "", fmt.Sprint("Optional text payload for Spend Transactions"))
}

0 comments on commit b2879fb

Please sign in to comment.