Skip to content

Commit 96f1e28

Browse files
authored
refactor: fetched block number from block monitor module in voting process (#1269)
* refactor: fetched block number from block monitor in voting * refactor: fixed tests * fix: added nil check for header from block monitor * refactor: replaced empty block monitor reference with nil in case of error
1 parent ce4180e commit 96f1e28

28 files changed

+49
-50
lines changed

cmd/addStake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func initialiseStake(cmd *cobra.Command, args []string) {
3232

3333
//This function sets the flags appropriately and executes the StakeCoins function
3434
func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) {
35-
config, rpcParameters, account, err := InitializeCommandDependencies(flagSet)
35+
config, rpcParameters, _, account, err := InitializeCommandDependencies(flagSet)
3636
utils.CheckError("Error in initialising command dependencies: ", err)
3737

3838
balance, err := razorUtils.FetchBalance(rpcParameters, account.Address)

cmd/claimBounty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func initialiseClaimBounty(cmd *cobra.Command, args []string) {
3434

3535
//This function sets the flags appropriately and executes the ClaimBounty function
3636
func (*UtilsStruct) ExecuteClaimBounty(flagSet *pflag.FlagSet) {
37-
config, rpcParameters, account, err := InitializeCommandDependencies(flagSet)
37+
config, rpcParameters, _, account, err := InitializeCommandDependencies(flagSet)
3838
utils.CheckError("Error in initialising command dependencies: ", err)
3939

4040
if razorUtils.IsFlagPassed("bountyId") {

cmd/claimCommission.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Example:
2626

2727
//This function allows the staker to claim the rewards earned from delegator's pool share as commission
2828
func (*UtilsStruct) ClaimCommission(flagSet *pflag.FlagSet) {
29-
config, rpcParameters, account, err := InitializeCommandDependencies(flagSet)
29+
config, rpcParameters, _, account, err := InitializeCommandDependencies(flagSet)
3030
utils.CheckError("Error in initialising command dependencies: ", err)
3131

3232
stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address)

cmd/cmd-utils.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func GetFormattedStateNames(states []int) string {
130130
return statesAllowed
131131
}
132132

133-
func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations, rpc.RPCParameters, types.Account, error) {
133+
func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations, rpc.RPCParameters, *block.BlockMonitor, types.Account, error) {
134134
var (
135135
account types.Account
136136
client *ethclient.Client
@@ -141,15 +141,15 @@ func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations
141141
config, err := cmdUtils.GetConfigData()
142142
if err != nil {
143143
log.Error("Error in getting config: ", err)
144-
return types.Configurations{}, rpc.RPCParameters{}, types.Account{}, err
144+
return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
145145
}
146146
log.Debugf("Config: %+v", config)
147147

148148
if razorUtils.IsFlagPassed("address") {
149149
address, err := flagSetUtils.GetStringAddress(flagSet)
150150
if err != nil {
151151
log.Error("Error in getting address: ", err)
152-
return types.Configurations{}, rpc.RPCParameters{}, types.Account{}, err
152+
return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
153153
}
154154
log.Debugf("Address: %v", address)
155155

@@ -159,21 +159,21 @@ func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations
159159
accountManager, err := razorUtils.AccountManagerForKeystore()
160160
if err != nil {
161161
log.Error("Error in getting accounts manager for keystore: ", err)
162-
return types.Configurations{}, rpc.RPCParameters{}, types.Account{}, err
162+
return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
163163
}
164164

165165
account = accounts.InitAccountStruct(address, password, accountManager)
166166
err = razorUtils.CheckPassword(account)
167167
if err != nil {
168168
log.Error("Error in fetching private key from given password: ", err)
169-
return types.Configurations{}, rpc.RPCParameters{}, types.Account{}, err
169+
return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
170170
}
171171
}
172172

173173
rpcManager, err := rpc.InitializeRPCManager(config.Provider)
174174
if err != nil {
175175
log.Error("Error in initializing RPC Manager: ", err)
176-
return types.Configurations{}, rpc.RPCParameters{}, types.Account{}, err
176+
return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
177177
}
178178

179179
rpcParameters = rpc.RPCParameters{
@@ -184,7 +184,7 @@ func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations
184184
client, err = rpcManager.GetBestRPCClient()
185185
if err != nil {
186186
log.Error("Error in getting best RPC client: ", err)
187-
return types.Configurations{}, rpc.RPCParameters{}, types.Account{}, err
187+
return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
188188
}
189189

190190
// Initialize BlockMonitor with RPCManager
@@ -196,5 +196,5 @@ func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations
196196
// Update Logger Instance
197197
logger.UpdateLogger(account.Address, client, blockMonitor)
198198

199-
return config, rpcParameters, account, nil
199+
return config, rpcParameters, blockMonitor, account, nil
200200
}

cmd/collectionList.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func initialiseCollectionList(cmd *cobra.Command, args []string) {
3131

3232
//This function sets the flags appropriately and and executes the GetCollectionList function
3333
func (*UtilsStruct) ExecuteCollectionList(flagSet *pflag.FlagSet) {
34-
_, rpcParameters, _, err := InitializeCommandDependencies(flagSet)
34+
_, rpcParameters, _, _, err := InitializeCommandDependencies(flagSet)
3535
utils.CheckError("Error in initialising command dependencies: ", err)
3636

3737
log.Debug("Calling GetCollectionList()")

cmd/contractAddresses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func initialiseContractAddresses(cmd *cobra.Command, args []string) {
2525

2626
//This function sets the flag appropriatley and executes the ContractAddresses function
2727
func (*UtilsStruct) ExecuteContractAddresses(flagSet *pflag.FlagSet) {
28-
_, _, _, err := InitializeCommandDependencies(flagSet)
28+
_, _, _, _, err := InitializeCommandDependencies(flagSet)
2929
utils.CheckError("Error in initialising command dependencies: ", err)
3030

3131
fmt.Println("The contract addresses are: ")

cmd/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func initialiseCreate(cmd *cobra.Command, args []string) {
2828

2929
//This function sets the flags appropriately and executes the Create function
3030
func (*UtilsStruct) ExecuteCreate(flagSet *pflag.FlagSet) {
31-
_, _, _, err := InitializeCommandDependencies(flagSet)
31+
_, _, _, _, err := InitializeCommandDependencies(flagSet)
3232
utils.CheckError("Error in initialising command dependencies: ", err)
3333
log.Info("The password should be of minimum 8 characters containing least 1 uppercase, lowercase, digit and special character.")
3434
password := razorUtils.AssignPassword(flagSet)

cmd/createCollection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func initialiseCreateCollection(cmd *cobra.Command, args []string) {
3434

3535
//This function sets the flags appropriately and executes the CreateCollection function
3636
func (*UtilsStruct) ExecuteCreateCollection(flagSet *pflag.FlagSet) {
37-
config, rpcParameters, account, err := InitializeCommandDependencies(flagSet)
37+
config, rpcParameters, _, account, err := InitializeCommandDependencies(flagSet)
3838
utils.CheckError("Error in initialising command dependencies: ", err)
3939

4040
name, err := flagSetUtils.GetStringName(flagSet)

cmd/createJob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func initialiseCreateJob(cmd *cobra.Command, args []string) {
3535

3636
//This function sets the flags appropriately and executes the CreateJob function
3737
func (*UtilsStruct) ExecuteCreateJob(flagSet *pflag.FlagSet) {
38-
config, rpcParameters, account, err := InitializeCommandDependencies(flagSet)
38+
config, rpcParameters, _, account, err := InitializeCommandDependencies(flagSet)
3939
utils.CheckError("Error in initialising command dependencies: ", err)
4040

4141
name, err := flagSetUtils.GetStringName(flagSet)

cmd/delegate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func initialiseDelegate(cmd *cobra.Command, args []string) {
3232

3333
//This function sets the flags appropriately and executes the Delegate function
3434
func (*UtilsStruct) ExecuteDelegate(flagSet *pflag.FlagSet) {
35-
config, rpcParameters, account, err := InitializeCommandDependencies(flagSet)
35+
config, rpcParameters, _, account, err := InitializeCommandDependencies(flagSet)
3636
utils.CheckError("Error in initialising command dependencies: ", err)
3737

3838
stakerId, err := flagSetUtils.GetUint32StakerId(flagSet)

0 commit comments

Comments
 (0)