Skip to content

Commit

Permalink
wasp-cli nonce fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BugFreeSoftware committed Dec 16, 2021
1 parent d48e2e3 commit e5de5f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/chainclient/chainclient.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package chainclient

import (
"time"

"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/hive.go/crypto/ed25519"
"github.com/iotaledger/wasp/client"
Expand All @@ -23,6 +21,7 @@ type Client struct {
WaspClient *client.WaspClient
ChainID *iscp.ChainID
KeyPair *ed25519.KeyPair
nonces map[ed25519.PublicKey]uint64
}

// New creates a new chainclient.Client
Expand All @@ -37,6 +36,7 @@ func New(
WaspClient: waspClient,
ChainID: chainID,
KeyPair: keyPair,
nonces: make(map[ed25519.PublicKey]uint64),
}
}

Expand Down Expand Up @@ -79,7 +79,8 @@ func (c *Client) PostOffLedgerRequest(
par = params[0]
}
if par.Nonce == 0 {
par.Nonce = uint64(time.Now().UnixNano())
c.nonces[c.KeyPair.PublicKey]++
par.Nonce = c.nonces[c.KeyPair.PublicKey]
}
offledgerReq := request.NewOffLedger(c.ChainID, contractHname, entrypoint, par.Args).WithTransfer(par.Transfer)
offledgerReq.WithNonce(par.Nonce)
Expand Down
2 changes: 2 additions & 0 deletions tools/wasp-cli/chain/postrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chain
import (
"strconv"
"strings"
"time"

"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/wasp/client/chainclient"
Expand Down Expand Up @@ -34,6 +35,7 @@ func postRequestCmd() *cobra.Command {
scClient := SCClient(iscp.Hn(args[0]))

if offLedger {
params.Nonce = uint64(time.Now().UnixNano())
util.WithOffLedgerRequest(GetCurrentChainID(), func() (*request.OffLedger, error) {
return scClient.PostOffLedgerRequest(fname, params)
})
Expand Down

0 comments on commit e5de5f7

Please sign in to comment.