Skip to content

Commit

Permalink
refactor: removed fatal logs from GetTxnOpts()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashk767 committed Dec 13, 2024
1 parent 52d8d2a commit a059109
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 39 deletions.
5 changes: 4 additions & 1 deletion cmd/addStake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/claimBounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/claimCommission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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...")

Expand Down
5 changes: 4 additions & 1 deletion cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion cmd/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/createCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/createJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion cmd/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
44 changes: 35 additions & 9 deletions cmd/dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion cmd/initiateWithdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion cmd/modifyCollectionStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/resetUnstakeLock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmd/reveal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion cmd/setDelegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cmd/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/unlockWithdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/unstake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cmd/updateCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit a059109

Please sign in to comment.