Skip to content

Commit

Permalink
Merge pull request #1416 from 0chain/fix-mint-nonce
Browse files Browse the repository at this point in the history
default nonce as 0 when http badrequest occurs
  • Loading branch information
dabasov authored Mar 10, 2024
2 parents 14c6161 + 351d6c8 commit ba68b3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions wasmsdk/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/0chain/gosdk/zcnbridge"
"github.com/0chain/gosdk/zcnbridge/errors"
"github.com/0chain/gosdk/zcnbridge/log"
"github.com/0chain/gosdk/zcnbridge/transaction"
"github.com/0chain/gosdk/zcnbridge/wallet"
"github.com/0chain/gosdk/zcncore"
Expand Down Expand Up @@ -123,6 +124,7 @@ func getNotProcessedWZCNBurnEvents() string {
return errors.New("getNotProcessedWZCNBurnEvents", "failed to retreive last ZCN processed mint nonce").Error()
}

log.Logger.Debug("MintNonce = " + strconv.Itoa(int(mintNonce)))
burnEvents, err := bridge.QueryEthereumBurnEvents(strconv.Itoa(int(mintNonce)))
if err != nil {
return errors.Wrap("getNotProcessedWZCNBurnEvents", "failed to retreive WZCN burn events", err).Error()
Expand Down
11 changes: 10 additions & 1 deletion zcnbridge/wallet/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"sync"

Expand Down Expand Up @@ -80,8 +81,16 @@ func (zcn *ZCNStatus) OnWalletCreateComplete(status int, wallet string, err stri
zcn.walletString = wallet
}

func (zcn *ZCNStatus) OnInfoAvailable(_ int, status int, info string, err string) {
func (zcn *ZCNStatus) OnInfoAvailable(op int, status int, info string, err string) {
defer zcn.Wg.Done()

// If status is 400 for OpGetMintNonce, mintNonce is considered as 0
if op == zcncore.OpGetMintNonce && status == http.StatusBadRequest {
zcn.Err = nil
zcn.Success = true
return
}

if status != zcncore.StatusSuccess {
zcn.Err = errors.New(err)
zcn.Success = false
Expand Down
5 changes: 5 additions & 0 deletions zcncore/transaction_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ func GetInfoFromSharders(urlSuffix string, op int, cb GetInfoCallback) {

qr, err := tq.GetInfo(context.TODO(), urlSuffix)
if err != nil {
if qr != nil && op == OpGetMintNonce {
logging.Debug("OpGetMintNonce QueryResult error", "; Content = ", qr.Content, "; Error = ", qr.Error.Error(), "; StatusCode = ", qr.StatusCode)
cb.OnInfoAvailable(op, qr.StatusCode, "", qr.Error.Error())
return
}
cb.OnInfoAvailable(op, StatusError, "", err.Error())
return
}
Expand Down

0 comments on commit ba68b3a

Please sign in to comment.