Skip to content

Commit

Permalink
fix getting new nonce in delegated and direct funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed Aug 28, 2024
1 parent b2c8740 commit d1873d0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions node/pkg/chain/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,26 +243,26 @@ func (t *ChainHelper) PublicAddressString() (string, error) {
}

func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) error {
nonce, err := noncemanager.GetAndIncrementNonce(t.wallet)
if err != nil {
return err
}

if t.delegatorUrl != "" {
err, tryDirect := t.submitDelegated(ctx, contractAddress, functionString, maxRetrial, nonce, args...)
err, tryDirect := t.submitDelegated(ctx, contractAddress, functionString, maxRetrial, args...)
if !tryDirect {
return err
}
}

return t.submitDirect(ctx, contractAddress, functionString, maxRetrial, nonce, args...)
return t.submitDirect(ctx, contractAddress, functionString, maxRetrial, args...)
}

func (t *ChainHelper) submitDelegated(ctx context.Context, contractAddress string, functionString string, maxRetrial int, nonce uint64, args ...interface{}) (error, bool) {
func (t *ChainHelper) submitDelegated(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) (error, bool) {
var err error
var tx *types.Transaction
clientIndex := 0

nonce, err := noncemanager.GetAndIncrementNonce(t.wallet)
if err != nil {
return err, false
}

for i := 0; i < maxRetrial; i++ {
tx, err = utils.MakeFeeDelegatedTx(ctx, t.clients[clientIndex], contractAddress, t.wallet, functionString, t.chainID, nonce, args...)
if err != nil {
Expand Down Expand Up @@ -296,11 +296,16 @@ func (t *ChainHelper) submitDelegated(ctx context.Context, contractAddress strin
return err, true
}

func (t *ChainHelper) submitDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, nonce uint64, args ...interface{}) error {
func (t *ChainHelper) submitDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) error {
var err error
var tx *types.Transaction
clientIndex := 0

nonce, err := noncemanager.GetAndIncrementNonce(t.wallet)
if err != nil {
return err
}

for i := 0; i < maxRetrial; i++ {
tx, err = utils.MakeDirectTx(ctx, t.clients[clientIndex], contractAddress, t.wallet, functionString, t.chainID, nonce, args...)
if err != nil {
Expand Down

0 comments on commit d1873d0

Please sign in to comment.