From a0591098b6cd95482326332e859ba5db052d426b Mon Sep 17 00:00:00 2001 From: YashK Date: Thu, 21 Nov 2024 15:54:00 +0530 Subject: [PATCH] refactor: removed fatal logs from GetTxnOpts() --- cmd/addStake.go | 5 +++- cmd/approve.go | 5 +++- cmd/claimBounty.go | 5 +++- cmd/claimCommission.go | 3 ++- cmd/commit.go | 5 +++- cmd/confirm.go | 5 +++- cmd/createCollection.go | 5 +++- cmd/createJob.go | 5 +++- cmd/delegate.go | 5 +++- cmd/dispute.go | 44 ++++++++++++++++++++++++++++------- cmd/initiateWithdraw.go | 5 +++- cmd/modifyCollectionStatus.go | 5 +++- cmd/propose.go | 5 +++- cmd/resetUnstakeLock.go | 5 +++- cmd/reveal.go | 2 +- cmd/setDelegation.go | 6 ++++- cmd/transfer.go | 5 +++- cmd/unlockWithdraw.go | 5 +++- cmd/unstake.go | 10 ++++++-- cmd/updateCollection.go | 5 +++- cmd/updateCommission.go | 5 +++- cmd/updateJob.go | 5 +++- utils/interface.go | 2 +- utils/options.go | 24 +++++++++++++------ 24 files changed, 137 insertions(+), 39 deletions(-) diff --git a/cmd/addStake.go b/cmd/addStake.go index 5f2c70c1..a32c4425 100644 --- a/cmd/addStake.go +++ b/cmd/addStake.go @@ -105,7 +105,10 @@ func (*UtilsStruct) StakeCoins(rpcParameters rpc.RPCParameters, txnArgs types.Tr txnArgs.MethodName = "stake" txnArgs.Parameters = []interface{}{epoch, txnArgs.Amount} txnArgs.ABI = bindings.StakeManagerMetaData.ABI - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/approve.go b/cmd/approve.go index 96826d01..a583c114 100644 --- a/cmd/approve.go +++ b/cmd/approve.go @@ -25,7 +25,10 @@ func (*UtilsStruct) Approve(rpcParameters rpc.RPCParameters, txnArgs types.Trans txnArgs.MethodName = "approve" txnArgs.ABI = bindings.RAZORMetaData.ABI txnArgs.Parameters = []interface{}{common.HexToAddress(core.StakeManagerAddress), txnArgs.Amount} - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/claimBounty.go b/cmd/claimBounty.go index 18e98bbf..16d23fc8 100644 --- a/cmd/claimBounty.go +++ b/cmd/claimBounty.go @@ -163,7 +163,10 @@ func (*UtilsStruct) ClaimBounty(rpcParameters rpc.RPCParameters, config types.Co return core.NilHash, nil } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { return core.NilHash, err diff --git a/cmd/claimCommission.go b/cmd/claimCommission.go index 90e28122..5930596d 100644 --- a/cmd/claimCommission.go +++ b/cmd/claimCommission.go @@ -38,7 +38,7 @@ func (*UtilsStruct) ClaimCommission(flagSet *pflag.FlagSet) { log.Debugf("ClaimCommission: Staker Info: %+v", stakerInfo) if stakerInfo.StakerReward.Cmp(big.NewInt(0)) > 0 { - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.StakeManagerAddress, @@ -47,6 +47,7 @@ func (*UtilsStruct) ClaimCommission(flagSet *pflag.FlagSet) { ABI: bindings.StakeManagerMetaData.ABI, Account: account, }) + utils.CheckError("Error in getting txn options: ", err) log.Info("Claiming commission...") diff --git a/cmd/commit.go b/cmd/commit.go index 7ec339b6..1e5a01d5 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -151,7 +151,7 @@ func (*UtilsStruct) Commit(rpcParameters rpc.RPCParameters, config types.Configu return core.NilHash, err } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.VoteManagerAddress, @@ -160,6 +160,9 @@ func (*UtilsStruct) Commit(rpcParameters rpc.RPCParameters, config types.Configu Parameters: []interface{}{epoch, commitmentToSend}, Account: account, }) + if err != nil { + return core.NilHash, err + } log.Info("Commitment sent...") client, err := rpcParameters.RPCManager.GetBestRPCClient() diff --git a/cmd/confirm.go b/cmd/confirm.go index 22cf5c0f..7f4e0413 100644 --- a/cmd/confirm.go +++ b/cmd/confirm.go @@ -46,7 +46,10 @@ func (*UtilsStruct) ClaimBlockReward(rpcParameters rpc.RPCParameters, options ty if selectedProposedBlock.ProposerId == stakerID { log.Info("Claiming block reward...") - txnOpts := razorUtils.GetTxnOpts(rpcParameters, options) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, options) + if err != nil { + return core.NilHash, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/createCollection.go b/cmd/createCollection.go index f6a19dcf..c7067c5f 100644 --- a/cmd/createCollection.go +++ b/cmd/createCollection.go @@ -76,7 +76,7 @@ func (*UtilsStruct) CreateCollection(rpcParameters rpc.RPCParameters, config typ log.Error("Error in fetching state") return core.NilHash, err } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -85,6 +85,9 @@ func (*UtilsStruct) CreateCollection(rpcParameters rpc.RPCParameters, config typ ABI: bindings.CollectionManagerMetaData.ABI, Account: collectionInput.Account, }) + if err != nil { + return core.NilHash, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/createJob.go b/cmd/createJob.go index 0cd44188..68b320ab 100644 --- a/cmd/createJob.go +++ b/cmd/createJob.go @@ -84,7 +84,10 @@ func (*UtilsStruct) CreateJob(rpcParameters rpc.RPCParameters, config types.Conf Account: jobInput.Account, } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } log.Info("Creating Job...") client, err := rpcParameters.RPCManager.GetBestRPCClient() diff --git a/cmd/delegate.go b/cmd/delegate.go index f5c02582..49a49aca 100644 --- a/cmd/delegate.go +++ b/cmd/delegate.go @@ -81,7 +81,10 @@ func (*UtilsStruct) Delegate(rpcParameters rpc.RPCParameters, txnArgs types.Tran txnArgs.MethodName = "delegate" txnArgs.ABI = bindings.StakeManagerMetaData.ABI txnArgs.Parameters = []interface{}{stakerId, txnArgs.Amount} - delegationTxnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + delegationTxnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } log.Info("Sending Delegate transaction...") client, err := rpcParameters.RPCManager.GetBestRPCClient() diff --git a/cmd/dispute.go b/cmd/dispute.go index 61acaed4..9d9d6c93 100644 --- a/cmd/dispute.go +++ b/cmd/dispute.go @@ -85,11 +85,15 @@ func (*UtilsStruct) HandleDispute(rpcParameters rpc.RPCParameters, config types. log.Debug("Biggest Stake in proposed block: ", proposedBlock.BiggestStake) log.Warn("PROPOSED BIGGEST STAKE DOES NOT MATCH WITH ACTUAL BIGGEST STAKE") log.Info("Disputing BiggestStakeProposed...") - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, Account: account, }) + if err != nil { + log.Error(err) + continue + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { @@ -277,7 +281,10 @@ func (*UtilsStruct) CheckDisputeForIds(rpcParameters rpc.RPCParameters, transact transactionOpts.ABI = bindings.BlockManagerMetaData.ABI transactionOpts.MethodName = "disputeOnOrderOfIds" transactionOpts.Parameters = []interface{}{epoch, blockIndex, index0, index1} - txnOpts := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + if err != nil { + return nil, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { @@ -295,7 +302,10 @@ func (*UtilsStruct) CheckDisputeForIds(rpcParameters rpc.RPCParameters, transact transactionOpts.ABI = bindings.BlockManagerMetaData.ABI transactionOpts.MethodName = "disputeCollectionIdShouldBePresent" transactionOpts.Parameters = []interface{}{epoch, blockIndex, missingCollectionId} - txnOpts := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + if err != nil { + return nil, err + } gasLimit := txnOpts.GasLimit incrementedGasLimit, err := gasUtils.IncreaseGasLimitValue(rpcParameters, gasLimit, core.DisputeGasMultiplier) if err != nil { @@ -319,7 +329,10 @@ func (*UtilsStruct) CheckDisputeForIds(rpcParameters rpc.RPCParameters, transact transactionOpts.ABI = bindings.BlockManagerMetaData.ABI transactionOpts.MethodName = "disputeCollectionIdShouldBeAbsent" transactionOpts.Parameters = []interface{}{epoch, blockIndex, presentCollectionId, big.NewInt(int64(positionOfPresentValue))} - txnOpts := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + if err != nil { + return nil, err + } gasLimit := txnOpts.GasLimit incrementedGasLimit, err := gasUtils.IncreaseGasLimitValue(rpcParameters, gasLimit, core.DisputeGasMultiplier) if err != nil { @@ -368,7 +381,10 @@ func (*UtilsStruct) Dispute(rpcParameters rpc.RPCParameters, config types.Config end = end / 2 } else { log.Error("Error in GiveSorted: ", err) - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return err + } log.Debugf("Dispute: Calling CheckToDoResetDispute with arguments epoch = %d, sortedValues = %s", epoch, sortedValues) cmdUtils.CheckToDoResetDispute(rpcParameters, txnOpts, epoch, sortedValues) return err @@ -397,7 +413,10 @@ func (*UtilsStruct) Dispute(rpcParameters rpc.RPCParameters, config types.Config finalizeDisputeTxnArgs.MethodName = "finalizeDispute" finalizeDisputeTxnArgs.ABI = bindings.BlockManagerMetaData.ABI finalizeDisputeTxnArgs.Parameters = []interface{}{epoch, blockIndex, positionOfCollectionInBlock} - finalizeDisputeTxnOpts := razorUtils.GetTxnOpts(rpcParameters, finalizeDisputeTxnArgs) + finalizeDisputeTxnOpts, err := razorUtils.GetTxnOpts(rpcParameters, finalizeDisputeTxnArgs) + if err != nil { + return err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { @@ -437,7 +456,10 @@ func (*UtilsStruct) Dispute(rpcParameters rpc.RPCParameters, config types.Config resetDisputeTxnArgs.MethodName = "resetDispute" resetDisputeTxnArgs.ABI = bindings.BlockManagerMetaData.ABI resetDisputeTxnArgs.Parameters = []interface{}{epoch} - resetDisputeTxnOpts := razorUtils.GetTxnOpts(rpcParameters, resetDisputeTxnArgs) + resetDisputeTxnOpts, err := razorUtils.GetTxnOpts(rpcParameters, resetDisputeTxnArgs) + if err != nil { + return err + } cmdUtils.ResetDispute(rpcParameters, resetDisputeTxnOpts, epoch) @@ -449,10 +471,14 @@ func GiveSorted(rpcParameters rpc.RPCParameters, txnArgs types.TransactionOption if len(sortedValues) == 0 { return errors.New("length of sortedValues is 0") } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + log.Error("Error in getting txnOpts: ", err) + return err + } disputesMapping, err := razorUtils.Disputes(rpcParameters, epoch, common.HexToAddress(txnArgs.Account.Address)) if err != nil { - log.Error("Error in getting disputes mapping: ", disputesMapping) + log.Error("Error in getting disputes mapping: ", err) return err } log.Debugf("GiveSorted: Disputes mapping: %+v", disputesMapping) diff --git a/cmd/initiateWithdraw.go b/cmd/initiateWithdraw.go index cf53823b..36a095d2 100644 --- a/cmd/initiateWithdraw.go +++ b/cmd/initiateWithdraw.go @@ -106,7 +106,10 @@ func (*UtilsStruct) HandleUnstakeLock(rpcParameters rpc.RPCParameters, account t Parameters: []interface{}{stakerId}, Account: account, } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } if big.NewInt(int64(epoch)).Cmp(unstakeLock.UnlockAfter) >= 0 && big.NewInt(int64(epoch)).Cmp(withdrawBefore) <= 0 { log.Debug("Calling InitiateWithdraw() with arguments stakerId: ", stakerId) diff --git a/cmd/modifyCollectionStatus.go b/cmd/modifyCollectionStatus.go index ead50fcc..a9119444 100644 --- a/cmd/modifyCollectionStatus.go +++ b/cmd/modifyCollectionStatus.go @@ -82,7 +82,10 @@ func (*UtilsStruct) ModifyCollectionStatus(rpcParameters rpc.RPCParameters, conf Account: modifyCollectionInput.Account, } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } log.Infof("Changing active status of collection: %d from %t to %t", modifyCollectionInput.CollectionId, !modifyCollectionInput.Status, modifyCollectionInput.Status) client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/propose.go b/cmd/propose.go index f0213418..1f74baf8 100644 --- a/cmd/propose.go +++ b/cmd/propose.go @@ -140,7 +140,7 @@ func (*UtilsStruct) Propose(rpcParameters rpc.RPCParameters, config types.Config log.Debugf("Propose: Iteration: %d Biggest Staker Id: %d", iteration, biggestStakerId) log.Info("Proposing block...") - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.BlockManagerAddress, @@ -149,6 +149,9 @@ func (*UtilsStruct) Propose(rpcParameters rpc.RPCParameters, config types.Config Parameters: []interface{}{epoch, ids, medians, big.NewInt(int64(iteration)), biggestStakerId}, Account: account, }) + if err != nil { + return err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/resetUnstakeLock.go b/cmd/resetUnstakeLock.go index 348dc4f7..9f594a55 100644 --- a/cmd/resetUnstakeLock.go +++ b/cmd/resetUnstakeLock.go @@ -51,7 +51,7 @@ func (*UtilsStruct) ExecuteExtendLock(flagSet *pflag.FlagSet) { //This function is used to reset the lock once the withdraw lock period is over func (*UtilsStruct) ResetUnstakeLock(rpcParameters rpc.RPCParameters, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) { - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.StakeManagerAddress, @@ -60,6 +60,9 @@ func (*UtilsStruct) ResetUnstakeLock(rpcParameters rpc.RPCParameters, config typ ABI: bindings.StakeManagerMetaData.ABI, Account: extendLockInput.Account, }) + if err != nil { + return core.NilHash, err + } log.Info("Extending lock...") client, err := rpcParameters.RPCManager.GetBestRPCClient() diff --git a/cmd/reveal.go b/cmd/reveal.go index 49b451ef..6e872272 100644 --- a/cmd/reveal.go +++ b/cmd/reveal.go @@ -55,7 +55,7 @@ func (*UtilsStruct) Reveal(rpcParameters rpc.RPCParameters, config types.Configu log.Info("Revealing votes...") - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.VoteManagerAddress, diff --git a/cmd/setDelegation.go b/cmd/setDelegation.go index 36f28ca5..690cd63a 100644 --- a/cmd/setDelegation.go +++ b/cmd/setDelegation.go @@ -97,7 +97,11 @@ func (*UtilsStruct) SetDelegation(rpcParameters rpc.RPCParameters, config types. return core.NilHash, nil } log.Infof("Setting delegation acceptance of Staker %d to %t", delegationInput.StakerId, delegationInput.Status) - setDelegationAcceptanceTxnOpts := razorUtils.GetTxnOpts(rpcParameters, txnOpts) + setDelegationAcceptanceTxnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnOpts) + if err != nil { + return core.NilHash, err + } + client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { return core.NilHash, err diff --git a/cmd/transfer.go b/cmd/transfer.go index a2413897..24c1e71a 100644 --- a/cmd/transfer.go +++ b/cmd/transfer.go @@ -80,7 +80,7 @@ func (*UtilsStruct) Transfer(rpcParameters rpc.RPCParameters, config types.Confi log.Debug("Checking for sufficient balance...") razorUtils.CheckAmountAndBalance(transferInput.ValueInWei, transferInput.Balance) - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.RAZORAddress, @@ -89,6 +89,9 @@ func (*UtilsStruct) Transfer(rpcParameters rpc.RPCParameters, config types.Confi ABI: bindings.RAZORMetaData.ABI, Account: transferInput.Account, }) + if err != nil { + return core.NilHash, err + } log.Infof("Transferring %g tokens from %s to %s", utils.GetAmountInDecimal(transferInput.ValueInWei), transferInput.Account.Address, transferInput.ToAddress) client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/unlockWithdraw.go b/cmd/unlockWithdraw.go index e9dfd9f7..1081a16c 100644 --- a/cmd/unlockWithdraw.go +++ b/cmd/unlockWithdraw.go @@ -84,7 +84,10 @@ func (*UtilsStruct) HandleWithdrawLock(rpcParameters rpc.RPCParameters, account Parameters: []interface{}{stakerId}, Account: account, } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } log.Debug("HandleWithdrawLock: Calling UnlockWithdraw() with arguments stakerId = ", stakerId) return cmdUtils.UnlockWithdraw(rpcParameters, txnOpts, stakerId) } diff --git a/cmd/unstake.go b/cmd/unstake.go index 11b4829b..4b9c52d6 100644 --- a/cmd/unstake.go +++ b/cmd/unstake.go @@ -108,7 +108,10 @@ func (*UtilsStruct) Unstake(rpcParameters rpc.RPCParameters, config types.Config } txnArgs.Parameters = []interface{}{stakerId, txnArgs.Amount} - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } log.Info("Unstaking coins") client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { @@ -128,7 +131,10 @@ func (*UtilsStruct) Unstake(rpcParameters rpc.RPCParameters, config types.Config //This function approves the unstake func (*UtilsStruct) ApproveUnstake(rpcParameters rpc.RPCParameters, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) { - txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + if err != nil { + return core.NilHash, err + } client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { return core.NilHash, err diff --git a/cmd/updateCollection.go b/cmd/updateCollection.go index 807f1cc1..d9896aaa 100644 --- a/cmd/updateCollection.go +++ b/cmd/updateCollection.go @@ -74,7 +74,7 @@ func (*UtilsStruct) UpdateCollection(rpcParameters rpc.RPCParameters, config typ log.Error("Error in fetching state") return core.NilHash, err } - txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnOpts, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -83,6 +83,9 @@ func (*UtilsStruct) UpdateCollection(rpcParameters rpc.RPCParameters, config typ ABI: bindings.CollectionManagerMetaData.ABI, Account: collectionInput.Account, }) + if err != nil { + return core.NilHash, err + } log.Info("Updating collection...") client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/updateCommission.go b/cmd/updateCommission.go index 63425ab4..548b15aa 100644 --- a/cmd/updateCommission.go +++ b/cmd/updateCommission.go @@ -101,7 +101,10 @@ func (*UtilsStruct) UpdateCommission(rpcParameters rpc.RPCParameters, config typ Parameters: []interface{}{updateCommissionInput.Commission}, Account: updateCommissionInput.Account, } - updateCommissionTxnOpts := razorUtils.GetTxnOpts(rpcParameters, txnOpts) + updateCommissionTxnOpts, err := razorUtils.GetTxnOpts(rpcParameters, txnOpts) + if err != nil { + return err + } log.Infof("Setting the commission value of Staker %d to %d%%", updateCommissionInput.StakerId, updateCommissionInput.Commission) client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/cmd/updateJob.go b/cmd/updateJob.go index 2954ffaa..4bd06223 100644 --- a/cmd/updateJob.go +++ b/cmd/updateJob.go @@ -77,7 +77,7 @@ func (*UtilsStruct) UpdateJob(rpcParameters rpc.RPCParameters, config types.Conf log.Error("Error in fetching state") return core.NilHash, err } - txnArgs := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ + txnArgs, err := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -86,6 +86,9 @@ func (*UtilsStruct) UpdateJob(rpcParameters rpc.RPCParameters, config types.Conf ABI: bindings.CollectionManagerMetaData.ABI, Account: jobInput.Account, }) + if err != nil { + return core.NilHash, err + } log.Info("Updating Job...") client, err := rpcParameters.RPCManager.GetBestRPCClient() if err != nil { diff --git a/utils/interface.go b/utils/interface.go index 4f250c2f..aafc18a3 100644 --- a/utils/interface.go +++ b/utils/interface.go @@ -73,7 +73,7 @@ var GasInterface GasUtils type Utils interface { MultiplyFloatAndBigInt(bigIntVal *big.Int, floatingVal float64) *big.Int - GetTxnOpts(rpcParameters rpc.RPCParameters, transactionData types.TransactionOptions) *bind.TransactOpts + GetTxnOpts(rpcParameters rpc.RPCParameters, transactionData types.TransactionOptions) (*bind.TransactOpts, error) GetBlockManager(client *ethclient.Client) *bindings.BlockManager GetOptions() bind.CallOpts GetNumberOfProposedBlocks(rpcParameters rpc.RPCParameters, epoch uint32) (uint8, error) diff --git a/utils/options.go b/utils/options.go index 246c6aaf..e48f8991 100644 --- a/utils/options.go +++ b/utils/options.go @@ -24,21 +24,28 @@ func (*UtilsStruct) GetOptions() bind.CallOpts { } } -func (*UtilsStruct) GetTxnOpts(rpcParameters rpc.RPCParameters, transactionData types.TransactionOptions) *bind.TransactOpts { +func (*UtilsStruct) GetTxnOpts(rpcParameters rpc.RPCParameters, transactionData types.TransactionOptions) (*bind.TransactOpts, error) { log.Debug("Getting transaction options...") account := transactionData.Account if account.AccountManager == nil { - log.Fatal("Account Manager in transaction data is not initialised") + log.Error("Account Manager in transaction data is not initialised") + return nil, errors.New("account manager not initialised") } privateKey, err := account.AccountManager.GetPrivateKey(account.Address, account.Password) CheckError("Error in fetching private key: ", err) nonce, err := ClientInterface.GetNonceAtWithRetry(rpcParameters, common.HexToAddress(account.Address)) - CheckError("Error in fetching nonce: ", err) + if err != nil { + log.Error("Error in fetching nonce: ", err) + return nil, err + } gasPrice := GasInterface.GetGasPrice(rpcParameters, transactionData.Config) txnOpts, err := BindInterface.NewKeyedTransactorWithChainID(privateKey, transactionData.ChainId) - CheckError("Error in getting transactor: ", err) + if err != nil { + log.Error("Error in getting transactor: ", err) + return nil, err + } txnOpts.Nonce = big.NewInt(int64(nonce)) txnOpts.GasPrice = gasPrice txnOpts.Value = transactionData.EtherValue @@ -48,18 +55,21 @@ func (*UtilsStruct) GetTxnOpts(rpcParameters rpc.RPCParameters, transactionData errString := err.Error() if ContainsStringFromArray(errString, []string{"500", "501", "502", "503", "504"}) || errString == errors.New("intrinsic gas too low").Error() { latestBlock, err := ClientInterface.GetLatestBlockWithRetry(rpcParameters) - CheckError("Error in fetching block: ", err) + if err != nil { + log.Error("Error in fetching block: ", err) + return nil, err + } txnOpts.GasLimit = latestBlock.GasLimit log.Debug("Error occurred due to RPC issue, sending block gas limit...") log.Debug("Gas Limit: ", txnOpts.GasLimit) - return txnOpts + return txnOpts, nil } log.Error("Error in getting gas limit: ", err) } log.Debug("Gas after increment: ", gasLimit) txnOpts.GasLimit = gasLimit - return txnOpts + return txnOpts, nil } func (*GasStruct) GetGasPrice(rpcParameters rpc.RPCParameters, config types.Configurations) *big.Int {